Maven-helper-plugin-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 427 discussions
r570 - in trunk/src: main/java/org/nuiton/io/xpp3 test/java/org/nuiton/util
by tchemit@users.nuiton.org 08 Sep '09
by tchemit@users.nuiton.org 08 Sep '09
08 Sep '09
Author: tchemit
Date: 2009-09-08 18:02:25 +0200 (Tue, 08 Sep 2009)
New Revision: 570
Modified:
trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java
trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
Log:
[FEATURE #46] ajout d'un contrat pour faire des parseurs xpp3
Modified: trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2009-09-07 22:54:20 UTC (rev 569)
+++ trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2009-09-08 16:02:25 UTC (rev 570)
@@ -3,10 +3,12 @@
import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.Reader;
+import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.TreeMap;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
@@ -22,20 +24,22 @@
* The logic of setting properties from xml (tag and attributes) is done in
*
* <ul>
- * <li>{@link #read(org.codehaus.plexus.util.xml.pull.XmlPullParser, boolean)} </li>
- * <li>{@link #readArray(org.codehaus.plexus.util.xml.pull.XmlPullParser, boolean)} </li>
+ * <li>{@link #read(String, Class, org.codehaus.plexus.util.xml.pull.XmlPullParser, boolean)} </li>
+ * <li>{@link #readArray(String, String, Class, org.codehaus.plexus.util.xml.pull.XmlPullParser, boolean)}</li>
* </ul>
*
* The default implementation is to map tag text to a pojo's property.
*
* If you want to do something more complex, override these methods.
*
+ * @param <O> the type of object to be build by the reader
+ *
* @author chemit
* @since 1.0.0
* @see PropertyMapper
* @see Xpp3Reader
*/
-public abstract class AbstractXpp3Reader implements Xpp3Reader {
+public abstract class AbstractXpp3Reader<O> implements Xpp3Reader<O> {
/**
* If set the parser will be loaded with all single characters
@@ -51,13 +55,17 @@
/**
* the type of the object to produce from the xml streams.
*/
- protected final Class<?> type;
+ protected final Class<O> type;
/**
* the root tag of an object to retreave from xml streams.
*
*/
- protected final String rootTagName;
+ protected String rootTagName;
/**
+ * the root tag of an array of objets to retreave from xml streams.
+ */
+ protected String arrayRootTagName;
+ /**
* the univers of mappers availables, initialized in {@link #initMappers()}.
*
* Each mapper of the dictionary is associated to the fully qualified name
@@ -69,18 +77,22 @@
* org.nuiton.util.MyPojo#my-attribute
* </pre>
*/
- protected final Map<String, PropertyMapper> allMappers;
- /**
- * a flag to display in console the generated code :
- * an easy way to build to generate java pojos mocks from xml file (to test the parser for example :)
- */
- protected boolean showGeneratedCode;
+ protected Map<String, PropertyMapper> allMappers;
protected abstract void initMappers() throws IntrospectionException;
- protected AbstractXpp3Reader(Class<?> type, String rootTagName) {
+ protected AbstractXpp3Reader(Class<O> type) {
+ this(type, null, null);
+ }
+
+ protected AbstractXpp3Reader(Class<O> type, String rootTagName) {
+ this(type, null, rootTagName);
+ }
+
+ protected AbstractXpp3Reader(Class<O> type, String arrayRootTagName, String rootTagName) {
this.type = type;
this.rootTagName = rootTagName;
+ this.arrayRootTagName = arrayRootTagName;
this.allMappers = new TreeMap<String, PropertyMapper>();
try {
initMappers();
@@ -90,29 +102,33 @@
}
@Override
- public Class<?> getType() {
+ public Class<O> getType() {
return type;
}
+ @Override
public String getRootTagName() {
return rootTagName;
}
- public String getArrayRootTagName() {
- return rootTagName + "s";
+ @Override
+ public void setRootTagName(String rootTagName) {
+ this.rootTagName = rootTagName;
}
@Override
- public boolean isAddDefaultEntities() {
- return addDefaultEntities;
+ public String getArrayRootTagName() {
+ return arrayRootTagName;
}
- public boolean isShowGeneratedCode() {
- return showGeneratedCode;
+ @Override
+ public void setParentRootTagName(String parentRootTagName) {
+ this.arrayRootTagName = parentRootTagName;
}
- public void setShowGeneratedCode(boolean showGeneratedCode) {
- this.showGeneratedCode = showGeneratedCode;
+ @Override
+ public boolean isAddDefaultEntities() {
+ return addDefaultEntities;
}
@Override
@@ -121,12 +137,12 @@
}
@Override
- public Object read(Reader reader) throws IOException, XmlPullParserException {
+ public O read(Reader reader) throws IOException, XmlPullParserException {
return read(reader, true);
}
@Override
- public Object read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
+ public O read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
XmlPullParser parser = new MXParser();
parser.setInput(reader);
@@ -138,16 +154,26 @@
}
parser.next();
- return read(parser, strict);
+
+ // read the first open tag getRootTagName() and consume the matching ending tag
+ O result = read(getRootTagName(), getType(), parser, strict);
+
+ // go after the ending tag getRootTagName()
+ parser.next();
+
+ // must be at the end of the document
+ checkEndOfXml(parser);
+
+ return result;
}
@Override
- public Object[] readArray(Reader reader) throws IOException, XmlPullParserException {
+ public O[] readArray(Reader reader) throws IOException, XmlPullParserException {
return readArray(reader, true);
}
@Override
- public Object[] readArray(Reader reader, boolean strict) throws IOException, XmlPullParserException {
+ public O[] readArray(Reader reader, boolean strict) throws IOException, XmlPullParserException {
XmlPullParser parser = new MXParser();
parser.setInput(reader);
@@ -155,11 +181,19 @@
if (addDefaultEntities) {
Xpp3Helper.addDefaultEntities(parser);
-
}
parser.next();
- return readArray(parser, strict);
+
+ parser.getEventType();
+
+ O[] result = readArray(getArrayRootTagName(), getRootTagName(), getType(), parser, strict);
+
+ parser.next();
+
+ checkEndOfXml(parser);
+
+ return result;
}
/**
@@ -194,57 +228,78 @@
*
* No work is done on attribute values here.
*
- * Note: The xml stream must contains one object to build on the root node.
- *
- * the root node name is given by <code>getRootTagName()</code>
+ * Note: The parser must accept as a next open tag the required one .
*
+ * the next node name is given by <code>getRootTagName()</code>
+ *
* Example :
* <pre>
+ * ...
* <my-pojo>
* <my-property>myValue</my-property>
* </my-pojo>
* </pre>
- *
+ *
+ * @param <T> the type of object to build
+ * @param rootTagName the name of the root tag matching the object to build
+ * @param type the type of object to build
* @param parser the xpp3 parser
* @param strict flag to indicate if should fail if a unknown tag (or attribute ?) is scanned
* @return the single object build from the xml stream.
* @throws IOException if any io pb
* @throws XmlPullParserException if any parsing pb
*/
- protected Object read(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
+ protected <T> T read(String rootTagName, Class<T> type, XmlPullParser parser, boolean strict) throws XmlPullParserException, IOException {
- Object result;
+ // search open tag rootTagName
+ gotoNextOpenTag(rootTagName, parser);
+
+ // can init result
+ T result = null;
try {
- result = getType().newInstance();
+ result = type.newInstance();
} catch (Exception ex) {
// should never happens!
throw new RuntimeException("could not instanciate a new " + getType().getName() + " for reason : " + ex.getMessage(), ex);
}
- java.util.Set<String> parsed = new java.util.HashSet<String>();
- int eventType = parser.getEventType();
- boolean foundRoot = false;
+ // prepare alvailable mappers for the given type
+ Map<String, PropertyMapper> mappers = getMappers(type);
- Map<String, PropertyMapper> mappers = getMappers(getType());
- if (showGeneratedCode) {
- System.out.println(getType().getName() + " i = new " + getType().getSimpleName() + "();");
- }
- while (eventType != XmlPullParser.END_DOCUMENT) {
- if (eventType == XmlPullParser.START_TAG) {
- if (parser.getName().equals(rootTagName)) {
- foundRoot = true;
- } else {
+ Set<String> parsed = parsed = new java.util.HashSet<String>();
+ try {
+ // go to next tag
+ int eventType = parser.next();
+
+ while (true) {
+
+ checkNotEndOfXml(parser, rootTagName);
+
+ if (eventType == XmlPullParser.START_TAG) {
+// System.out.println("reading tag " + parser.getName());
PropertyMapper mapper = mappers.get(parser.getName());
if (mapper != null) {
mapper.setProperty(result, parser, parsed, strict);
} else if (strict) {
throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
}
+ } else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals(rootTagName)) {
+ // have reach the end of the object
+ break;
+ }
}
+
+ // try next event
+ eventType = parser.next();
}
- eventType = parser.next();
+ return result;
+ } finally {
+ parsed.clear();
+ if (mappers != null) {
+ mappers.clear();
+ }
}
- return result;
}
/**
@@ -254,14 +309,12 @@
*
* No work is done on attribute values here.
*
- * Note: The xml stream must contains a root node.
+ * Note: The next node of the parser must be the one given by
+ * {@code parentRootTagName} and sub nodes with names {@code rootTagName}.
*
- * the root node name is given by <code>getArrayRootTagName()</code>
- *
- * and sub nodes with names <code>getRootTagName()</code>
- *
* Example :
* <pre>
+ * ...
* <my-pojos>
* <my-pojo>
* <my-property>myValue</my-property>
@@ -272,67 +325,117 @@
* </my-pojos>
* </pre>
*
+ * @param <T> the type of objects to build
+ * @param parentRootTagName the tag's name of the array container
+ * @param rootTagName the tag's name of each object to build
+ * @param type the type of objects to build
* @param parser the xpp3 parser
* @param strict flag to indicate if should fail if a unknown tag (or attribute ?) is scanned
* @return the single object build from the xml stream.
* @throws IOException if any io pb
* @throws XmlPullParserException if any parsing pb
*/
- protected Object[] readArray(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
+ protected <T> T[] readArray(String parentRootTagName, String rootTagName, Class<T> type, XmlPullParser parser, boolean strict) throws XmlPullParserException, IOException {
- List<Object> results = new ArrayList<Object>();
+ // search open tag parentRootTagName
+ // if not found, will raise an parsing exception
+ gotoNextOpenTag(parentRootTagName, parser);
+ // can init result
+ List<T> results = new ArrayList<T>();
- java.util.Set<String> parsed = new java.util.HashSet<String>();
- int eventType = parser.getEventType();
- boolean foundRoot = false;
+ boolean addChild = false;
+ boolean quit = false;
- Map<String, PropertyMapper> mappers = getMappers(getType());
- Object result = null;
- String root = getArrayRootTagName();
- if (showGeneratedCode) {
- System.out.println(getType().getSimpleName() + " i = null;");
- }
- while (eventType != XmlPullParser.END_DOCUMENT) {
- if (eventType == XmlPullParser.START_TAG) {
- if (parser.getName().equals(root)) {
- foundRoot = true;
- if (showGeneratedCode) {
- System.out.println("List<" + getType().getSimpleName() + "> list = new ArrayList<" + getType().getSimpleName() + ">();");
- }
- } else if (parser.getName().equals(this.rootTagName)) {
- try {
- result = getType().newInstance();
- if (showGeneratedCode) {
- System.out.println("i = new " + getType().getSimpleName() + "();");
- }
- } catch (Exception ex) {
- // should never happens!
- throw new RuntimeException("could not instanciate a new " + getType().getName() + " for reason : " + ex.getMessage(), ex);
- }
+ while (!quit) {
- } else {
- PropertyMapper mapper = mappers.get(parser.getName());
- if (mapper != null) {
- mapper.setProperty(result, parser, parsed, strict);
+ addChild = false;
+ quit = false;
- } else if (strict) {
- throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
- }
+ // search next opening tag (rootTagName) or ending tag (parentRootTagName)
+
+ while (true) {
+
+ checkNotEndOfXml(parser, parentRootTagName);
+
+ int eventType = parser.getEventType();
+
+ if (eventType == XmlPullParser.START_TAG && rootTagName.equals(parser.getName())) {
+ // there is a child to read
+ addChild = true;
+ break;
}
- } else if (eventType == XmlPullParser.END_TAG) {
- if (parser.getName().equals(this.rootTagName)) {
- // save it
- results.add(result);
- // clear parsed attributes
- parsed.clear();
- if (showGeneratedCode) {
- System.out.println("list.add(i);");
- }
+
+ if (eventType == XmlPullParser.END_TAG && parentRootTagName.equals(parser.getName())) {
+ // can quit main loop, end of work
+ quit = true;
+ break;
}
+
+ eventType = parser.next();
}
+
+ if (addChild) {
+
+ // find an object to add
+ T result = read(rootTagName, type, parser, strict);
+
+ results.add(result);
+
+ // go for another round
+ continue;
+ }
+
+ // no more child
+ // must be at the end of tag
+ if (!quit) {
+ throw new XmlPullParserException("should be on " + parentRootTagName + " but was not : " + parser.getName());
+ }
+ }
+
+ // can not directly instanciate a generic array (or don't known how ?)
+ return results.toArray((T[]) Array.newInstance(type, results.size()));
+ }
+
+ protected int gotoNextOpenTag(String tagName, XmlPullParser parser) throws XmlPullParserException, IOException {
+ // search next open tag tagName
+
+ int eventType = parser.getEventType();
+
+ while (eventType != XmlPullParser.START_TAG || !parser.getName().equals(tagName)) {
+
+ checkNotEndOfXml(parser, tagName);
+
eventType = parser.next();
}
- return results.toArray(new Object[results.size()]);
+
+ return eventType;
}
+
+ /**
+ * Checks that a given parser is not at the end of the xml document.
+ *
+ * @param parser the parser to check
+ * @param tagName the endign tag's name
+ * @throws XmlPullParserException if the parser is at the end of the xml stream, instead of the {@code tagName} ending tag
+ */
+ protected void checkNotEndOfXml(XmlPullParser parser, String tagName) throws XmlPullParserException {
+ if (parser.getEventType() == XmlPullParser.END_DOCUMENT) {
+ // can not be here ?
+ throw new XmlPullParserException("end of document found... but required at least the ending tag " + tagName);
+ }
+ }
+
+ /**
+ * Checks that a given parser is at the end of the xml document.
+ *
+ * @param parser the parser to check
+ * @throws XmlPullParserException if the parser is not at the end of the xml stream.
+ */
+ protected void checkEndOfXml(XmlPullParser parser) throws XmlPullParserException {
+ // must be at the end of the document
+ if (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+ throw new XmlPullParserException("should be at the end of document but was not... : " + parser.getName());
+ }
+ }
}
Modified: trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2009-09-07 22:54:20 UTC (rev 569)
+++ trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2009-09-08 16:02:25 UTC (rev 570)
@@ -4,6 +4,7 @@
import java.io.IOException;
import java.text.ParseException;
import java.util.Set;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -16,6 +17,13 @@
* <li>{@link TagTextContentToProperty} to map the text content of a tag to a pojo's property</li>
* <li>{@link AttributeValueToProperty} to map the text content of a tag to a pojo's property</li>
* </ul>
+ *
+ * There is two convinient factory methods in {@link Xpp3Helper} to add some new mappers into a given
+ * dictionnary of mappers.
+ * <ul>
+ * <li> {@link Xpp3Helper#addTagTextContentMappers(Class, org.nuiton.io.xpp3.DataConverter, boolean, java.util.Map, String[])}</li>
+ * <li>{@link Xpp3Helper#addAttributeValueMappers(Class, org.nuiton.io.xpp3.DataConverter, boolean, java.util.Map, String[])}</li>
+ * </ul>
*
* @author chemit
* @since 1.0.3
@@ -24,8 +32,8 @@
public static class TagTextContentToProperty extends PropertyMapper {
- public TagTextContentToProperty(String tagName, String propertyName, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
- super(tagName, propertyName, type, onlyOne, descriptor);
+ public TagTextContentToProperty(String tagName, String propertyName, Class<?> containerType, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
+ super(tagName, propertyName, containerType, type, onlyOne, descriptor);
}
@Override
@@ -41,8 +49,8 @@
public static class AttributeValueToProperty extends PropertyMapper {
- public AttributeValueToProperty(String tagName, String propertyName, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
- super(tagName, propertyName, type, onlyOne, descriptor);
+ public AttributeValueToProperty(String tagName, String propertyName, Class<?> containerType, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
+ super(tagName, propertyName, containerType, type, onlyOne, descriptor);
}
@Override
@@ -68,6 +76,10 @@
*/
protected final DataConverter type;
/**
+ * the type of the pojo container of the property
+ */
+ protected final Class<?> containerType;
+ /**
* the pojo's property descriptor
*/
protected final PropertyDescriptor descriptor;
@@ -77,11 +89,12 @@
*/
protected final boolean onlyOne;
- protected PropertyMapper(String tagName, String propertyName, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
+ protected PropertyMapper(String tagName, String propertyName, Class<?> containerType, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
this.name = tagName;
this.propertyName = propertyName;
this.type = type;
this.onlyOne = onlyOne;
+ this.containerType = containerType;
this.descriptor = descriptor;
}
@@ -131,4 +144,23 @@
public DataConverter getType() {
return type;
}
+
+ public Class<?> getContainerType() {
+ return containerType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ ToStringBuilder toStringBuilder = new ToStringBuilder(this);
+ toStringBuilder.append("name", name);
+ toStringBuilder.append("propertyName", propertyName);
+ toStringBuilder.append("onlyOne", onlyOne);
+ toStringBuilder.append("type", type);
+ toStringBuilder.append("containerType", containerType);
+ return toStringBuilder.toString();
+ }
}
Modified: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java 2009-09-07 22:54:20 UTC (rev 569)
+++ trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java 2009-09-08 16:02:25 UTC (rev 570)
@@ -1,5 +1,9 @@
package org.nuiton.io.xpp3;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -7,11 +11,16 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
+import org.apache.commons.lang.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.nuiton.io.xpp3.PropertyMapper.AttributeValueToProperty;
+import org.nuiton.io.xpp3.PropertyMapper.TagTextContentToProperty;
/**
* A Helper to read some data stored in xml with a {@link Xpp3Reader}.
@@ -29,20 +38,21 @@
* les readers enregistres via un {@link ServiceLoader}
* sur le contrat {@link Xpp3Reader}.
*/
- protected static Map<Class<?>, Xpp3Reader> readers;
+ protected static Map<Class<?>, Xpp3Reader<?>> readers;
/**
* Read a single object from a xml stream.
*
+ * @param <O> the type of object to read
* @param klass the type of object to read
* @param reader the reader where to parse the xml
* @return the loaded object
* @throws IOException if any io pb
* @throws XmlPullParserException if any parsing pb
*/
- public static Object readObject(Class<?> klass, Reader reader) throws IOException, XmlPullParserException {
+ public static <O> O readObject(Class<O> klass, Reader reader) throws IOException, XmlPullParserException {
- Object result = null;
+ O result = null;
try {
@@ -54,7 +64,7 @@
StringReader sReader = new StringReader(rawInput);
- Xpp3Reader modelReader = getReader(klass);
+ Xpp3Reader<O> modelReader = getReader(klass);
result = modelReader.read(sReader);
@@ -68,15 +78,16 @@
/**
* Read an array of objects from a xml stream.
*
+ * @param <O> the type of objects to return
* @param klass the type of object to read
* @param reader the reader where to parse the xml
* @return the loaded objects
* @throws IOException if any io pb
* @throws XmlPullParserException if any parsing pb
*/
- public static Object[] readObjects(Class<?> klass, Reader reader) throws IOException, XmlPullParserException {
+ public static <O> O[] readObjects(Class<O> klass, Reader reader) throws IOException, XmlPullParserException {
- Object[] result = null;
+ O[] result = null;
try {
@@ -88,7 +99,7 @@
StringReader sReader = new StringReader(rawInput);
- Xpp3Reader modelReader = getReader(klass);
+ Xpp3Reader<O> modelReader = getReader(klass);
result = modelReader.readArray(sReader);
@@ -103,7 +114,7 @@
*
* @return an iterator on all registred {@link Xpp3Reader}.
*/
- public static Iterator<Xpp3Reader> getReaderItetator() {
+ public static Iterator<Xpp3Reader<?>> getReaderItetator() {
return getReaders().values().iterator();
}
@@ -115,8 +126,8 @@
* @param klass the type of the data which should be parsed by the researched parser
* @return the parser for the given type
*/
- public static <T> Xpp3Reader getReader(Class<?> klass) {
- Xpp3Reader reader = getReaders().get(klass);
+ public static <T> Xpp3Reader<T> getReader(Class<T> klass) {
+ Xpp3Reader<T> reader = (Xpp3Reader<T>) getReaders().get(klass);
return reader;
}
@@ -405,17 +416,72 @@
parser.defineEntityReplacementText("diams", "\u2666");
}
+ public static void addTagTextContentMappers(Class<?> containerType, DataConverter type, boolean onlyOne, Map<String, PropertyMapper> allMappers, String... tagNames) throws IntrospectionException {
+ try {
+ addMappers(TagTextContentToProperty.class, containerType, type, onlyOne, allMappers, tagNames);
+ } catch (Exception ex) {
+ throw new RuntimeException("could not addMappers for reason : " + ex.getMessage(), ex);
+ }
+ }
+
+ public static void addAttributeValueMappers(Class<?> containerType, DataConverter type, boolean onlyOne, Map<String, PropertyMapper> allMappers, String... tagNames) throws IntrospectionException {
+ try {
+ addMappers(AttributeValueToProperty.class, containerType, type, onlyOne, allMappers, tagNames);
+ } catch (Exception ex) {
+ throw new RuntimeException("could not addMappers for reason : " + ex.getMessage(), ex);
+ }
+ }
+
+ protected static void addMappers(Class<? extends PropertyMapper> mapperClass, Class<?> containerType, DataConverter type, boolean onlyOne, Map<String, PropertyMapper> allMappers, String... tagNames) throws IntrospectionException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ for (String tagName : tagNames) {
+
+ // the tag-name is transformed to tagName
+ String[] parts = tagName.split("-");
+ StringBuilder buffer = new StringBuilder();
+ for (int i = 0, j = parts.length; i < j; i++) {
+ if (i == 0) {
+ buffer.append(parts[i]);
+ } else {
+ buffer.append(StringUtils.capitalize(parts[i]));
+ }
+ }
+ String propertyName = buffer.toString();
+ BeanInfo beanInfo = Introspector.getBeanInfo(containerType);
+ PropertyDescriptor descriptor = null;
+ for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
+ if (propertyDescriptor.getName().equals(propertyName)) {
+ descriptor = propertyDescriptor;
+ break;
+ }
+ }
+ if (descriptor == null) {
+ throw new IllegalArgumentException("could not find a property descriptor for property " + propertyName + " of " + containerType);
+ }
+ Constructor<? extends PropertyMapper> constructor = mapperClass.getConstructor(String.class, String.class, Class.class, DataConverter.class, boolean.class, PropertyDescriptor.class);
+
+ PropertyMapper mapper = constructor.newInstance(tagName, propertyName, containerType, type, onlyOne, descriptor);
+// System.out.println("adding a mapper " + mapper);
+
+ allMappers.put(containerType.getName() + "#" + tagName, mapper);
+ }
+ }
+
/**
+ * Load (if {@link #readers} is {@code null} the readers via a
+ * {@link ServiceLoader} of contract {@link Xpp3Reader} and returns
+ * the dictionnary of discovered associated to their type
+ * ({@link Xpp3Reader#getType()}).
*
+ *
* @return all the {@link Xpp3Reader} registred via a {@link ServiceLoader}
- * on the contract {@link Xpp3Reader}.
+ * on the contract {@link Xpp3Reader} associated to their type
+ * ({@link Xpp3Reader#getType()}).
*
*/
- protected static Map<Class<?>, Xpp3Reader> getReaders() {
+ protected static Map<Class<?>, Xpp3Reader<?>> getReaders() {
if (readers == null) {
- readers = new HashMap<Class<?>, Xpp3Reader>();
- ServiceLoader<Xpp3Reader> load = ServiceLoader.load(Xpp3Reader.class);
- for (Xpp3Reader r : load) {
+ readers = new HashMap<Class<?>, Xpp3Reader<?>>();
+ for (Xpp3Reader<?> r : ServiceLoader.load(Xpp3Reader.class)) {
readers.put(r.getType(), r);
}
}
Modified: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java 2009-09-07 22:54:20 UTC (rev 569)
+++ trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java 2009-09-08 16:02:25 UTC (rev 570)
@@ -2,7 +2,6 @@
import java.io.IOException;
import java.io.Reader;
-import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
@@ -17,73 +16,147 @@
*
* to make possible auto-discovering of availables reader at runtime.
*
- * See {@link Xpp3Helper#getReader(java.lang.Class)}.
+ * See {@link Xpp3Helper#getReader(java.lang.Class)} and
+ * {@link Xpp3Helper#getReaders()}.
*
*
+ * @param <O> the type of object to be build by the reader.
+ *
* @author chemit
* @since 1.0.3
*/
-public interface Xpp3Reader {
+public interface Xpp3Reader<O> {
/**
*
* @return the type of main object to read
*/
- Class<?> getType();
+ Class<O> getType();
/**
- * @see ReaderFactory#newXmlReader
+ * Read a single instance of the typed object and return it.
*
+ * Note : this is a convinient method to call
+ * {@link #read(java.io.Reader, boolean)} in strict mode.
+ *
+ * In the xml stream, the root tag must be the {@link #getRootTagName()}.
+ *
+ * Example :
+ * <pre>
+ * <issue>:
+ * ...
+ * </issue>:
+ * </pre>
+ *
* @param reader
* @throws IOException
* @throws XmlPullParserException
* @return Settings
*/
- Object read(Reader reader) throws IOException, XmlPullParserException;
+ O read(Reader reader) throws IOException, XmlPullParserException;
/**
- * @see ReaderFactory#newXmlReader
+ * Read a single instance of the typed object and return it.
*
- * @param reader
- * @param strict
- * @throws IOException
- * @throws XmlPullParserException
- * @return Settings
+ * In the xml stream, the root tag must be the {@link #getRootTagName()}.
+ *
+ * Example :
+ * <pre>
+ * <issue>:
+ * ...
+ * </issue>:
+ * </pre>
+ *
+ * @param reader the xml input reader
+ * @param strict flag to be strict while parsing
+ * @throws IOException if any io pb
+ * @throws XmlPullParserException if any parsing pb
+ * @return the
*/
- Object read(Reader reader, boolean strict) throws IOException, XmlPullParserException;
+ O read(Reader reader, boolean strict) throws IOException, XmlPullParserException;
/**
- * @see ReaderFactory#newXmlReader
+ * Read some instances of the typed object and return it.
*
- * @param reader
- * @throws IOException
- * @throws XmlPullParserException
- * @return Settings
+ * In the xml stream, the root tag must be the {@link #getArrayRootTagName()}.
+ *
+ * Note : this is a convinient method to call :
+ * {@link #readArray(java.io.Reader, boolean)} in stritc mode.
+ *
+ * Example :
+ * <pre>
+ * <issues>:
+ * <issue>:
+ * ...
+ * </issue>:
+ * </issues>:
+ * </pre>
+ *
+ * @param reader the xml input reader
+ * @throws IOException if any io pb
+ * @throws XmlPullParserException if any parsing pb
+ * @return the array of read objects.
*/
- Object[] readArray(Reader reader) throws IOException, XmlPullParserException;
+ O[] readArray(Reader reader) throws IOException, XmlPullParserException;
/**
- * @see ReaderFactory#newXmlReader
+ * Read some instances of the typed object and return it.
*
- * @param reader
- * @param strict
- * @throws IOException
- * @throws XmlPullParserException
- * @return Settings
+ * In the xml stream, the root tag must be the {@link #getArrayRootTagName()}.
+ *
+ * Example :
+ * <pre>
+ * <issues>:
+ * <issue>:
+ * ...
+ * </issue>:
+ * </issues>:
+ * </pre>
+ *
+ * @param reader the xml input reader
+ * @param strict flag to be strict while parsing
+ * @throws IOException if any io pb
+ * @throws XmlPullParserException if any parsing pb
+ * @return the array of read objects.
*/
- Object[] readArray(Reader reader, boolean strict) throws IOException, XmlPullParserException;
+ O[] readArray(Reader reader, boolean strict) throws IOException, XmlPullParserException;
/**
- * Returns the state of the "add default entities" flag.
*
- * @return boolean
+ * @return the name of the root tag of a object to read
*/
+ String getRootTagName();
+
+ /**
+ * Set the name of the root tag of an object to read.
+ *
+ * @param rootTagName the name of the tag
+ */
+ void setRootTagName(String rootTagName);
+
+ /**
+ *
+ * @return the name of the root tag of an array of objets to read
+ */
+ String getArrayRootTagName();
+
+ /**
+ * Set the name of the root tag for an array of object to read.
+ *
+ * @param parentRootTagName the name of the tag
+ */
+ void setParentRootTagName(String parentRootTagName);
+
+ /**
+ * @return <code>true</code> if parser will load the default entities,
+ * <code>false</code> otherwise.
+ */
boolean isAddDefaultEntities();
/**
- * Sets the state of the "add default entities" flag.
+ * Set the new value of the {@code defaultEntities} flag.
*
- * @param addDefaultEntities
+ * @param addDefaultEntities the new value.
*/
void setAddDefaultEntities(boolean addDefaultEntities);
}
Modified: trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-07 22:54:20 UTC (rev 569)
+++ trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-08 16:02:25 UTC (rev 570)
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.apache.maven.plugin.logging.SystemStreamLog;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusTestCase;
import org.junit.Ignore;
@@ -41,6 +42,7 @@
* @author chemit */
public abstract class BasePluginTestCase<P extends AbstractPlugin> {
+ protected static SystemStreamLog log;
protected static File basedir;
protected static File testDir;
protected static Iterator<PluginConfig> configItr;
@@ -63,6 +65,7 @@
}
protected static <P extends AbstractPlugin> void initConfigs(Class<? extends BasePluginTestCase<P>> klass, String... testNames) throws Exception {
+ log = new SystemStreamLog();
List<PluginConfig> configs = new ArrayList<PluginConfig>();
String rep = klass.getName();
rep = rep.replaceAll("\\.", File.separator);
@@ -70,7 +73,7 @@
File f = new File(getBaseDir(), "target" + File.separator + "test-classes");
//File f = new File(getBaseDir(), "src" + File.separator + "test" + File.separator + "resources");
testDir = new File(f, rep);
- System.out.println("test dir : " + testDir);
+ log.info("test dir : " + testDir.getAbsolutePath().substring(getBaseDir().getAbsolutePath().length()+1));
if (testNames.length == 0) {
@@ -85,8 +88,8 @@
if (annotation != null) {
Test t = m.getAnnotation(Test.class);
if (t != null) {
- Ignore i = m.getAnnotation(Ignore.class);
- if (i==null) {
+ Ignore i = m.getAnnotation(Ignore.class);
+ if (i == null) {
testNamesList.add(m.getName());
}
}
1
0
r569 - in trunk: . src/main/java/org/nuiton src/main/java/org/nuiton/io src/main/java/org/nuiton/io/xpp3
by tchemit@users.nuiton.org 07 Sep '09
by tchemit@users.nuiton.org 07 Sep '09
07 Sep '09
Author: tchemit
Date: 2009-09-08 00:54:20 +0200 (Tue, 08 Sep 2009)
New Revision: 569
Added:
trunk/src/main/java/org/nuiton/io/
trunk/src/main/java/org/nuiton/io/xpp3/
trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
trunk/src/main/java/org/nuiton/io/xpp3/DataConverter.java
trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java
Modified:
trunk/changelog.txt
Log:
[FEATURE #46] ajout d'un contrat pour faire des parseurs xpp3
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2009-09-06 20:27:59 UTC (rev 568)
+++ trunk/changelog.txt 2009-09-07 22:54:20 UTC (rev 569)
@@ -1,5 +1,6 @@
maven-helper-plugin (1.0.3) stable; urgency=high
+ * [FEATURE #46] ajout d'un contrat pour faire des parseurs xpp3
* [FEATURE #45] utiliser des generics dans le framework de test de mojos
-- chemit --
Added: trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2009-09-07 22:54:20 UTC (rev 569)
@@ -0,0 +1,338 @@
+package org.nuiton.io.xpp3;
+
+import java.beans.IntrospectionException;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import org.codehaus.plexus.util.xml.pull.MXParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * An abstract xpp3Reader based on {@link PropertyMapper} to set properties of
+ * the objects to build.
+ *
+ * To implements a new parser, just implements method {@link #initMappers()} to
+ * see authorized mapping from tag to pojo properties.
+ *
+ * The logic of setting properties from xml (tag and attributes) is done in
+ *
+ * <ul>
+ * <li>{@link #read(org.codehaus.plexus.util.xml.pull.XmlPullParser, boolean)} </li>
+ * <li>{@link #readArray(org.codehaus.plexus.util.xml.pull.XmlPullParser, boolean)} </li>
+ * </ul>
+ *
+ * The default implementation is to map tag text to a pojo's property.
+ *
+ * If you want to do something more complex, override these methods.
+ *
+ * @author chemit
+ * @since 1.0.0
+ * @see PropertyMapper
+ * @see Xpp3Reader
+ */
+public abstract class AbstractXpp3Reader implements Xpp3Reader {
+
+ /**
+ * If set the parser will be loaded with all single characters
+ * from the XHTML specification.
+ * The entities used:
+ * <ul>
+ * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
+ * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
+ * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
+ * </ul>
+ */
+ protected boolean addDefaultEntities = true;
+ /**
+ * the type of the object to produce from the xml streams.
+ */
+ protected final Class<?> type;
+ /**
+ * the root tag of an object to retreave from xml streams.
+ *
+ */
+ protected final String rootTagName;
+ /**
+ * the univers of mappers availables, initialized in {@link #initMappers()}.
+ *
+ * Each mapper of the dictionary is associated to the fully qualified name
+ * of the target class # the tag name or attribute name.
+ *
+ * Example :
+ * <pre>
+ * org.nuiton.util.MyPojo#my-tag
+ * org.nuiton.util.MyPojo#my-attribute
+ * </pre>
+ */
+ protected final Map<String, PropertyMapper> allMappers;
+ /**
+ * a flag to display in console the generated code :
+ * an easy way to build to generate java pojos mocks from xml file (to test the parser for example :)
+ */
+ protected boolean showGeneratedCode;
+
+ protected abstract void initMappers() throws IntrospectionException;
+
+ protected AbstractXpp3Reader(Class<?> type, String rootTagName) {
+ this.type = type;
+ this.rootTagName = rootTagName;
+ this.allMappers = new TreeMap<String, PropertyMapper>();
+ try {
+ initMappers();
+ } catch (IntrospectionException e) {
+ throw new IllegalStateException("could not init " + this + " for reason " + e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public Class<?> getType() {
+ return type;
+ }
+
+ public String getRootTagName() {
+ return rootTagName;
+ }
+
+ public String getArrayRootTagName() {
+ return rootTagName + "s";
+ }
+
+ @Override
+ public boolean isAddDefaultEntities() {
+ return addDefaultEntities;
+ }
+
+ public boolean isShowGeneratedCode() {
+ return showGeneratedCode;
+ }
+
+ public void setShowGeneratedCode(boolean showGeneratedCode) {
+ this.showGeneratedCode = showGeneratedCode;
+ }
+
+ @Override
+ public void setAddDefaultEntities(boolean addDefaultEntities) {
+ this.addDefaultEntities = addDefaultEntities;
+ }
+
+ @Override
+ public Object read(Reader reader) throws IOException, XmlPullParserException {
+ return read(reader, true);
+ }
+
+ @Override
+ public Object read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
+ XmlPullParser parser = new MXParser();
+
+ parser.setInput(reader);
+
+ if (addDefaultEntities) {
+
+ Xpp3Helper.addDefaultEntities(parser);
+
+ }
+
+ parser.next();
+ return read(parser, strict);
+ }
+
+ @Override
+ public Object[] readArray(Reader reader) throws IOException, XmlPullParserException {
+ return readArray(reader, true);
+ }
+
+ @Override
+ public Object[] readArray(Reader reader, boolean strict) throws IOException, XmlPullParserException {
+ XmlPullParser parser = new MXParser();
+
+ parser.setInput(reader);
+
+ if (addDefaultEntities) {
+
+ Xpp3Helper.addDefaultEntities(parser);
+
+ }
+
+ parser.next();
+ return readArray(parser, strict);
+ }
+
+ /**
+ * Obtain all mappers for a given type.
+ *
+ * In the result, the keys are now the tag-name of attribute-name.
+ *
+ * Example :
+ * <pre>
+ * my-tag
+ * my-attribute
+ * </pre>
+ *
+ * @param srcType the target type of the searched mappers
+ * @return the dictionnary of mappers for the given type.
+ */
+ public Map<String, PropertyMapper> getMappers(Class<?> srcType) {
+ Map<String, PropertyMapper> result = new TreeMap<String, PropertyMapper>();
+ String prefix = srcType.getName() + "#";
+ for (Entry<String, PropertyMapper> e : this.allMappers.entrySet()) {
+ if (e.getKey().startsWith(prefix)) {
+ result.put(e.getValue().getTagName(), e.getValue());
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Parse the xml stream from the given parser and a build the associated object.
+ *
+ * This default implementation just match a tag text content to a pojo property.
+ *
+ * No work is done on attribute values here.
+ *
+ * Note: The xml stream must contains one object to build on the root node.
+ *
+ * the root node name is given by <code>getRootTagName()</code>
+ *
+ * Example :
+ * <pre>
+ * <my-pojo>
+ * <my-property>myValue</my-property>
+ * </my-pojo>
+ * </pre>
+ *
+ * @param parser the xpp3 parser
+ * @param strict flag to indicate if should fail if a unknown tag (or attribute ?) is scanned
+ * @return the single object build from the xml stream.
+ * @throws IOException if any io pb
+ * @throws XmlPullParserException if any parsing pb
+ */
+ protected Object read(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
+
+ Object result;
+ try {
+ result = getType().newInstance();
+ } catch (Exception ex) {
+ // should never happens!
+ throw new RuntimeException("could not instanciate a new " + getType().getName() + " for reason : " + ex.getMessage(), ex);
+ }
+
+ java.util.Set<String> parsed = new java.util.HashSet<String>();
+ int eventType = parser.getEventType();
+ boolean foundRoot = false;
+
+ Map<String, PropertyMapper> mappers = getMappers(getType());
+ if (showGeneratedCode) {
+ System.out.println(getType().getName() + " i = new " + getType().getSimpleName() + "();");
+ }
+ while (eventType != XmlPullParser.END_DOCUMENT) {
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals(rootTagName)) {
+ foundRoot = true;
+ } else {
+ PropertyMapper mapper = mappers.get(parser.getName());
+ if (mapper != null) {
+ mapper.setProperty(result, parser, parsed, strict);
+ } else if (strict) {
+ throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
+ }
+ }
+ }
+ eventType = parser.next();
+ }
+ return result;
+ }
+
+ /**
+ * Parse the xml stream from the given parser and a build an array of associated object.
+ *
+ * This default implementation just match a tag text content to a pojo property.
+ *
+ * No work is done on attribute values here.
+ *
+ * Note: The xml stream must contains a root node.
+ *
+ * the root node name is given by <code>getArrayRootTagName()</code>
+ *
+ * and sub nodes with names <code>getRootTagName()</code>
+ *
+ * Example :
+ * <pre>
+ * <my-pojos>
+ * <my-pojo>
+ * <my-property>myValue</my-property>
+ * </my-pojo>
+ * <my-pojo>
+ * <my-property>myValue2</my-property>
+ * </my-pojo>
+ * </my-pojos>
+ * </pre>
+ *
+ * @param parser the xpp3 parser
+ * @param strict flag to indicate if should fail if a unknown tag (or attribute ?) is scanned
+ * @return the single object build from the xml stream.
+ * @throws IOException if any io pb
+ * @throws XmlPullParserException if any parsing pb
+ */
+ protected Object[] readArray(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
+
+ List<Object> results = new ArrayList<Object>();
+
+
+ java.util.Set<String> parsed = new java.util.HashSet<String>();
+ int eventType = parser.getEventType();
+ boolean foundRoot = false;
+
+ Map<String, PropertyMapper> mappers = getMappers(getType());
+ Object result = null;
+ String root = getArrayRootTagName();
+ if (showGeneratedCode) {
+ System.out.println(getType().getSimpleName() + " i = null;");
+ }
+ while (eventType != XmlPullParser.END_DOCUMENT) {
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals(root)) {
+ foundRoot = true;
+ if (showGeneratedCode) {
+ System.out.println("List<" + getType().getSimpleName() + "> list = new ArrayList<" + getType().getSimpleName() + ">();");
+ }
+ } else if (parser.getName().equals(this.rootTagName)) {
+ try {
+ result = getType().newInstance();
+ if (showGeneratedCode) {
+ System.out.println("i = new " + getType().getSimpleName() + "();");
+ }
+ } catch (Exception ex) {
+ // should never happens!
+ throw new RuntimeException("could not instanciate a new " + getType().getName() + " for reason : " + ex.getMessage(), ex);
+ }
+
+ } else {
+ PropertyMapper mapper = mappers.get(parser.getName());
+ if (mapper != null) {
+ mapper.setProperty(result, parser, parsed, strict);
+
+ } else if (strict) {
+ throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
+ }
+ }
+ } else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals(this.rootTagName)) {
+ // save it
+ results.add(result);
+ // clear parsed attributes
+ parsed.clear();
+ if (showGeneratedCode) {
+ System.out.println("list.add(i);");
+ }
+ }
+ }
+ eventType = parser.next();
+ }
+ return results.toArray(new Object[results.size()]);
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/xpp3/DataConverter.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/DataConverter.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/xpp3/DataConverter.java 2009-09-07 22:54:20 UTC (rev 569)
@@ -0,0 +1,15 @@
+package org.nuiton.io.xpp3;
+
+/**
+ * A contract to a data converter from a text value to a typed value.
+ *
+ * We does not here use the commons-beans classes, since we could have different
+ * types of converter for a same type....
+ *
+ * @author chemit
+ * @since 1.0.3
+ */
+public interface DataConverter {
+
+ Object convert(String t) throws Exception;
+}
Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/DataConverter.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2009-09-07 22:54:20 UTC (rev 569)
@@ -0,0 +1,134 @@
+package org.nuiton.io.xpp3;
+
+import java.beans.PropertyDescriptor;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.Set;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * A abstract object to map an xml value (tag or attribute, or esle?) to a pojo property.
+ *
+ * Two implementations are given :
+ *
+ * <ul>
+ * <li>{@link TagTextContentToProperty} to map the text content of a tag to a pojo's property</li>
+ * <li>{@link AttributeValueToProperty} to map the text content of a tag to a pojo's property</li>
+ * </ul>
+ *
+ * @author chemit
+ * @since 1.0.3
+ */
+public abstract class PropertyMapper {
+
+ public static class TagTextContentToProperty extends PropertyMapper {
+
+ public TagTextContentToProperty(String tagName, String propertyName, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
+ super(tagName, propertyName, type, onlyOne, descriptor);
+ }
+
+ @Override
+ protected Object getDataFromXml(XmlPullParser parser) throws XmlPullParserException, Exception {
+ String t = parser.nextText();
+ Object result = null;
+ if (t != null && !(t = t.trim()).isEmpty()) {
+ result = type.convert(t);
+ }
+ return result;
+ }
+ }
+
+ public static class AttributeValueToProperty extends PropertyMapper {
+
+ public AttributeValueToProperty(String tagName, String propertyName, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
+ super(tagName, propertyName, type, onlyOne, descriptor);
+ }
+
+ @Override
+ protected Object getDataFromXml(XmlPullParser parser) throws XmlPullParserException, Exception {
+ String t = parser.getAttributeValue("", name);
+ Object result = null;
+ if (t != null && !(t = t.trim()).isEmpty()) {
+ result = type.convert(t);
+ }
+ return result;
+ }
+ }
+ /**
+ * name of tag (or attribute to deal with)
+ */
+ protected final String name;
+ /**
+ * the pojo's property to set
+ */
+ protected final String propertyName;
+ /**
+ * the converter from xml to pojo's property type
+ */
+ protected final DataConverter type;
+ /**
+ * the pojo's property descriptor
+ */
+ protected final PropertyDescriptor descriptor;
+ /**
+ * a flag to check to use only once the mapper. (should not be used for
+ * attributes implementations).
+ */
+ protected final boolean onlyOne;
+
+ protected PropertyMapper(String tagName, String propertyName, DataConverter type, boolean onlyOne, PropertyDescriptor descriptor) {
+ this.name = tagName;
+ this.propertyName = propertyName;
+ this.type = type;
+ this.onlyOne = onlyOne;
+ this.descriptor = descriptor;
+ }
+
+ protected abstract Object getDataFromXml(XmlPullParser parser) throws XmlPullParserException, Exception;
+
+ public void setProperty(Object src, XmlPullParser parser, Set<String> parsed, boolean strict) throws XmlPullParserException, IOException, IOException {
+ if (onlyOne && parsed.contains(name)) {
+ throw new XmlPullParserException("Duplicated tag: \'" + parser.getName() + "\'", parser, null);
+ }
+ parsed.add(name);
+ try {
+ Object r = getDataFromXml(parser);
+ if (r != null) {
+ descriptor.getWriteMethod().invoke(src, r);
+ }
+ } catch (XmlPullParserException e) {
+ throw e;
+ } catch (NumberFormatException e) {
+ if (strict) {
+ throw new XmlPullParserException(e.getMessage());
+ }
+ } catch (ParseException e) {
+ if (strict) {
+ throw new XmlPullParserException(e.getMessage());
+ }
+ } catch (Exception e) {
+ throw new XmlPullParserException(e.getMessage());
+ }
+ }
+
+ public PropertyDescriptor getDescriptor() {
+ return descriptor;
+ }
+
+ public boolean isOnlyOne() {
+ return onlyOne;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public String getTagName() {
+ return name;
+ }
+
+ public DataConverter getType() {
+ return type;
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java 2009-09-07 22:54:20 UTC (rev 569)
@@ -0,0 +1,424 @@
+package org.nuiton.io.xpp3;
+
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ServiceLoader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+
+/**
+ * A Helper to read some data stored in xml with a {@link Xpp3Reader}.
+ *
+ * In this class, there is some methods to obtain a discovered {@link Xpp3Reader}
+ * registred by a {@link ServiceLoader} mecanism.
+ *
+ * @author chemit
+ * @since 1.0.3
+ * @see Xpp3Reader
+ */
+public class Xpp3Helper {
+
+ /**
+ * les readers enregistres via un {@link ServiceLoader}
+ * sur le contrat {@link Xpp3Reader}.
+ */
+ protected static Map<Class<?>, Xpp3Reader> readers;
+
+ /**
+ * Read a single object from a xml stream.
+ *
+ * @param klass the type of object to read
+ * @param reader the reader where to parse the xml
+ * @return the loaded object
+ * @throws IOException if any io pb
+ * @throws XmlPullParserException if any parsing pb
+ */
+ public static Object readObject(Class<?> klass, Reader reader) throws IOException, XmlPullParserException {
+
+ Object result = null;
+
+ try {
+
+ StringWriter sWriter = new StringWriter();
+
+ IOUtil.copy(reader, sWriter);
+
+ String rawInput = sWriter.toString();
+
+ StringReader sReader = new StringReader(rawInput);
+
+ Xpp3Reader modelReader = getReader(klass);
+
+ result = modelReader.read(sReader);
+
+ } finally {
+ IOUtil.close(reader);
+ }
+
+ return result;
+ }
+
+ /**
+ * Read an array of objects from a xml stream.
+ *
+ * @param klass the type of object to read
+ * @param reader the reader where to parse the xml
+ * @return the loaded objects
+ * @throws IOException if any io pb
+ * @throws XmlPullParserException if any parsing pb
+ */
+ public static Object[] readObjects(Class<?> klass, Reader reader) throws IOException, XmlPullParserException {
+
+ Object[] result = null;
+
+ try {
+
+ StringWriter sWriter = new StringWriter();
+
+ IOUtil.copy(reader, sWriter);
+
+ String rawInput = sWriter.toString();
+
+ StringReader sReader = new StringReader(rawInput);
+
+ Xpp3Reader modelReader = getReader(klass);
+
+ result = modelReader.readArray(sReader);
+
+ } finally {
+ IOUtil.close(reader);
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ * @return an iterator on all registred {@link Xpp3Reader}.
+ */
+ public static Iterator<Xpp3Reader> getReaderItetator() {
+ return getReaders().values().iterator();
+ }
+
+ /**
+ * Obtain the loaded reader which match his {@link Xpp3Reader#getType()} whith
+ * the given type.
+ *
+ * @param <T> the type of the data which should be parsed by the researched parser
+ * @param klass the type of the data which should be parsed by the researched parser
+ * @return the parser for the given type
+ */
+ public static <T> Xpp3Reader getReader(Class<?> klass) {
+ Xpp3Reader reader = getReaders().get(klass);
+ return reader;
+ }
+
+ /**
+ * Clean all the registred readers.
+ *
+ * To reload them, just call a {@link #getReader(java.lang.Class)}.
+ *
+ */
+ public static void clearReaders() {
+ if (readers != null) {
+ readers.clear();
+ readers = null;
+ }
+ }
+
+ /**
+ * Add to the parser, the default replacers for all single characters
+ * from the XHTML specification.
+ * The entities used:
+ * <ul>
+ * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
+ * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
+ * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
+ * </ul>
+ * @param parser the parser to configure
+ * @throws XmlPullParserException if any pb
+ */
+ public static void addDefaultEntities(XmlPullParser parser) throws XmlPullParserException {
+ // ----------------------------------------------------------------------
+ // Latin 1 entities
+ // ----------------------------------------------------------------------
+ parser.defineEntityReplacementText("nbsp", "\u00a0");
+ parser.defineEntityReplacementText("iexcl", "\u00a1");
+ parser.defineEntityReplacementText("cent", "\u00a2");
+ parser.defineEntityReplacementText("pound", "\u00a3");
+ parser.defineEntityReplacementText("curren", "\u00a4");
+ parser.defineEntityReplacementText("yen", "\u00a5");
+ parser.defineEntityReplacementText("brvbar", "\u00a6");
+ parser.defineEntityReplacementText("sect", "\u00a7");
+ parser.defineEntityReplacementText("uml", "\u00a8");
+ parser.defineEntityReplacementText("copy", "\u00a9");
+ parser.defineEntityReplacementText("ordf", "\u00aa");
+ parser.defineEntityReplacementText("laquo", "\u00ab");
+ parser.defineEntityReplacementText("not", "\u00ac");
+ parser.defineEntityReplacementText("shy", "\u00ad");
+ parser.defineEntityReplacementText("reg", "\u00ae");
+ parser.defineEntityReplacementText("macr", "\u00af");
+ parser.defineEntityReplacementText("deg", "\u00b0");
+ parser.defineEntityReplacementText("plusmn", "\u00b1");
+ parser.defineEntityReplacementText("sup2", "\u00b2");
+ parser.defineEntityReplacementText("sup3", "\u00b3");
+ parser.defineEntityReplacementText("acute", "\u00b4");
+ parser.defineEntityReplacementText("micro", "\u00b5");
+ parser.defineEntityReplacementText("para", "\u00b6");
+ parser.defineEntityReplacementText("middot", "\u00b7");
+ parser.defineEntityReplacementText("cedil", "\u00b8");
+ parser.defineEntityReplacementText("sup1", "\u00b9");
+ parser.defineEntityReplacementText("ordm", "\u00ba");
+ parser.defineEntityReplacementText("raquo", "\u00bb");
+ parser.defineEntityReplacementText("frac14", "\u00bc");
+ parser.defineEntityReplacementText("frac12", "\u00bd");
+ parser.defineEntityReplacementText("frac34", "\u00be");
+ parser.defineEntityReplacementText("iquest", "\u00bf");
+ parser.defineEntityReplacementText("Agrave", "\u00c0");
+ parser.defineEntityReplacementText("Aacute", "\u00c1");
+ parser.defineEntityReplacementText("Acirc", "\u00c2");
+ parser.defineEntityReplacementText("Atilde", "\u00c3");
+ parser.defineEntityReplacementText("Auml", "\u00c4");
+ parser.defineEntityReplacementText("Aring", "\u00c5");
+ parser.defineEntityReplacementText("AElig", "\u00c6");
+ parser.defineEntityReplacementText("Ccedil", "\u00c7");
+ parser.defineEntityReplacementText("Egrave", "\u00c8");
+ parser.defineEntityReplacementText("Eacute", "\u00c9");
+ parser.defineEntityReplacementText("Ecirc", "\u00ca");
+ parser.defineEntityReplacementText("Euml", "\u00cb");
+ parser.defineEntityReplacementText("Igrave", "\u00cc");
+ parser.defineEntityReplacementText("Iacute", "\u00cd");
+ parser.defineEntityReplacementText("Icirc", "\u00ce");
+ parser.defineEntityReplacementText("Iuml", "\u00cf");
+ parser.defineEntityReplacementText("ETH", "\u00d0");
+ parser.defineEntityReplacementText("Ntilde", "\u00d1");
+ parser.defineEntityReplacementText("Ograve", "\u00d2");
+ parser.defineEntityReplacementText("Oacute", "\u00d3");
+ parser.defineEntityReplacementText("Ocirc", "\u00d4");
+ parser.defineEntityReplacementText("Otilde", "\u00d5");
+ parser.defineEntityReplacementText("Ouml", "\u00d6");
+ parser.defineEntityReplacementText("times", "\u00d7");
+ parser.defineEntityReplacementText("Oslash", "\u00d8");
+ parser.defineEntityReplacementText("Ugrave", "\u00d9");
+ parser.defineEntityReplacementText("Uacute", "\u00da");
+ parser.defineEntityReplacementText("Ucirc", "\u00db");
+ parser.defineEntityReplacementText("Uuml", "\u00dc");
+ parser.defineEntityReplacementText("Yacute", "\u00dd");
+ parser.defineEntityReplacementText("THORN", "\u00de");
+ parser.defineEntityReplacementText("szlig", "\u00df");
+ parser.defineEntityReplacementText("agrave", "\u00e0");
+ parser.defineEntityReplacementText("aacute", "\u00e1");
+ parser.defineEntityReplacementText("acirc", "\u00e2");
+ parser.defineEntityReplacementText("atilde", "\u00e3");
+ parser.defineEntityReplacementText("auml", "\u00e4");
+ parser.defineEntityReplacementText("aring", "\u00e5");
+ parser.defineEntityReplacementText("aelig", "\u00e6");
+ parser.defineEntityReplacementText("ccedil", "\u00e7");
+ parser.defineEntityReplacementText("egrave", "\u00e8");
+ parser.defineEntityReplacementText("eacute", "\u00e9");
+ parser.defineEntityReplacementText("ecirc", "\u00ea");
+ parser.defineEntityReplacementText("euml", "\u00eb");
+ parser.defineEntityReplacementText("igrave", "\u00ec");
+ parser.defineEntityReplacementText("iacute", "\u00ed");
+ parser.defineEntityReplacementText("icirc", "\u00ee");
+ parser.defineEntityReplacementText("iuml", "\u00ef");
+ parser.defineEntityReplacementText("eth", "\u00f0");
+ parser.defineEntityReplacementText("ntilde", "\u00f1");
+ parser.defineEntityReplacementText("ograve", "\u00f2");
+ parser.defineEntityReplacementText("oacute", "\u00f3");
+ parser.defineEntityReplacementText("ocirc", "\u00f4");
+ parser.defineEntityReplacementText("otilde", "\u00f5");
+ parser.defineEntityReplacementText("ouml", "\u00f6");
+ parser.defineEntityReplacementText("divide", "\u00f7");
+ parser.defineEntityReplacementText("oslash", "\u00f8");
+ parser.defineEntityReplacementText("ugrave", "\u00f9");
+ parser.defineEntityReplacementText("uacute", "\u00fa");
+ parser.defineEntityReplacementText("ucirc", "\u00fb");
+ parser.defineEntityReplacementText("uuml", "\u00fc");
+ parser.defineEntityReplacementText("yacute", "\u00fd");
+ parser.defineEntityReplacementText("thorn", "\u00fe");
+ parser.defineEntityReplacementText("yuml", "\u00ff");
+ // ----------------------------------------------------------------------
+ // Special entities
+ // ----------------------------------------------------------------------
+ parser.defineEntityReplacementText("OElig", "\u0152");
+ parser.defineEntityReplacementText("oelig", "\u0153");
+ parser.defineEntityReplacementText("Scaron", "\u0160");
+ parser.defineEntityReplacementText("scaron", "\u0161");
+ parser.defineEntityReplacementText("Yuml", "\u0178");
+ parser.defineEntityReplacementText("circ", "\u02c6");
+ parser.defineEntityReplacementText("tilde", "\u02dc");
+ parser.defineEntityReplacementText("ensp", "\u2002");
+ parser.defineEntityReplacementText("emsp", "\u2003");
+ parser.defineEntityReplacementText("thinsp", "\u2009");
+ parser.defineEntityReplacementText("zwnj", "\u200c");
+ parser.defineEntityReplacementText("zwj", "\u200d");
+ parser.defineEntityReplacementText("lrm", "\u200e");
+ parser.defineEntityReplacementText("rlm", "\u200f");
+ parser.defineEntityReplacementText("ndash", "\u2013");
+ parser.defineEntityReplacementText("mdash", "\u2014");
+ parser.defineEntityReplacementText("lsquo", "\u2018");
+ parser.defineEntityReplacementText("rsquo", "\u2019");
+ parser.defineEntityReplacementText("sbquo", "\u201a");
+ parser.defineEntityReplacementText("ldquo", "\u201c");
+ parser.defineEntityReplacementText("rdquo", "\u201d");
+ parser.defineEntityReplacementText("bdquo", "\u201e");
+ parser.defineEntityReplacementText("dagger", "\u2020");
+ parser.defineEntityReplacementText("Dagger", "\u2021");
+ parser.defineEntityReplacementText("permil", "\u2030");
+ parser.defineEntityReplacementText("lsaquo", "\u2039");
+ parser.defineEntityReplacementText("rsaquo", "\u203a");
+ parser.defineEntityReplacementText("euro", "\u20ac");
+ // ----------------------------------------------------------------------
+ // Symbol entities
+ // ----------------------------------------------------------------------
+ parser.defineEntityReplacementText("fnof", "\u0192");
+ parser.defineEntityReplacementText("Alpha", "\u0391");
+ parser.defineEntityReplacementText("Beta", "\u0392");
+ parser.defineEntityReplacementText("Gamma", "\u0393");
+ parser.defineEntityReplacementText("Delta", "\u0394");
+ parser.defineEntityReplacementText("Epsilon", "\u0395");
+ parser.defineEntityReplacementText("Zeta", "\u0396");
+ parser.defineEntityReplacementText("Eta", "\u0397");
+ parser.defineEntityReplacementText("Theta", "\u0398");
+ parser.defineEntityReplacementText("Iota", "\u0399");
+ parser.defineEntityReplacementText("Kappa", "\u039a");
+ parser.defineEntityReplacementText("Lambda", "\u039b");
+ parser.defineEntityReplacementText("Mu", "\u039c");
+ parser.defineEntityReplacementText("Nu", "\u039d");
+ parser.defineEntityReplacementText("Xi", "\u039e");
+ parser.defineEntityReplacementText("Omicron", "\u039f");
+ parser.defineEntityReplacementText("Pi", "\u03a0");
+ parser.defineEntityReplacementText("Rho", "\u03a1");
+ parser.defineEntityReplacementText("Sigma", "\u03a3");
+ parser.defineEntityReplacementText("Tau", "\u03a4");
+ parser.defineEntityReplacementText("Upsilon", "\u03a5");
+ parser.defineEntityReplacementText("Phi", "\u03a6");
+ parser.defineEntityReplacementText("Chi", "\u03a7");
+ parser.defineEntityReplacementText("Psi", "\u03a8");
+ parser.defineEntityReplacementText("Omega", "\u03a9");
+ parser.defineEntityReplacementText("alpha", "\u03b1");
+ parser.defineEntityReplacementText("beta", "\u03b2");
+ parser.defineEntityReplacementText("gamma", "\u03b3");
+ parser.defineEntityReplacementText("delta", "\u03b4");
+ parser.defineEntityReplacementText("epsilon", "\u03b5");
+ parser.defineEntityReplacementText("zeta", "\u03b6");
+ parser.defineEntityReplacementText("eta", "\u03b7");
+ parser.defineEntityReplacementText("theta", "\u03b8");
+ parser.defineEntityReplacementText("iota", "\u03b9");
+ parser.defineEntityReplacementText("kappa", "\u03ba");
+ parser.defineEntityReplacementText("lambda", "\u03bb");
+ parser.defineEntityReplacementText("mu", "\u03bc");
+ parser.defineEntityReplacementText("nu", "\u03bd");
+ parser.defineEntityReplacementText("xi", "\u03be");
+ parser.defineEntityReplacementText("omicron", "\u03bf");
+ parser.defineEntityReplacementText("pi", "\u03c0");
+ parser.defineEntityReplacementText("rho", "\u03c1");
+ parser.defineEntityReplacementText("sigmaf", "\u03c2");
+ parser.defineEntityReplacementText("sigma", "\u03c3");
+ parser.defineEntityReplacementText("tau", "\u03c4");
+ parser.defineEntityReplacementText("upsilon", "\u03c5");
+ parser.defineEntityReplacementText("phi", "\u03c6");
+ parser.defineEntityReplacementText("chi", "\u03c7");
+ parser.defineEntityReplacementText("psi", "\u03c8");
+ parser.defineEntityReplacementText("omega", "\u03c9");
+ parser.defineEntityReplacementText("thetasym", "\u03d1");
+ parser.defineEntityReplacementText("upsih", "\u03d2");
+ parser.defineEntityReplacementText("piv", "\u03d6");
+ parser.defineEntityReplacementText("bull", "\u2022");
+ parser.defineEntityReplacementText("hellip", "\u2026");
+ parser.defineEntityReplacementText("prime", "\u2032");
+ parser.defineEntityReplacementText("Prime", "\u2033");
+ parser.defineEntityReplacementText("oline", "\u203e");
+ parser.defineEntityReplacementText("frasl", "\u2044");
+ parser.defineEntityReplacementText("weierp", "\u2118");
+ parser.defineEntityReplacementText("image", "\u2111");
+ parser.defineEntityReplacementText("real", "\u211c");
+ parser.defineEntityReplacementText("trade", "\u2122");
+ parser.defineEntityReplacementText("alefsym", "\u2135");
+ parser.defineEntityReplacementText("larr", "\u2190");
+ parser.defineEntityReplacementText("uarr", "\u2191");
+ parser.defineEntityReplacementText("rarr", "\u2192");
+ parser.defineEntityReplacementText("darr", "\u2193");
+ parser.defineEntityReplacementText("harr", "\u2194");
+ parser.defineEntityReplacementText("crarr", "\u21b5");
+ parser.defineEntityReplacementText("lArr", "\u21d0");
+ parser.defineEntityReplacementText("uArr", "\u21d1");
+ parser.defineEntityReplacementText("rArr", "\u21d2");
+ parser.defineEntityReplacementText("dArr", "\u21d3");
+ parser.defineEntityReplacementText("hArr", "\u21d4");
+ parser.defineEntityReplacementText("forall", "\u2200");
+ parser.defineEntityReplacementText("part", "\u2202");
+ parser.defineEntityReplacementText("exist", "\u2203");
+ parser.defineEntityReplacementText("empty", "\u2205");
+ parser.defineEntityReplacementText("nabla", "\u2207");
+ parser.defineEntityReplacementText("isin", "\u2208");
+ parser.defineEntityReplacementText("notin", "\u2209");
+ parser.defineEntityReplacementText("ni", "\u220b");
+ parser.defineEntityReplacementText("prod", "\u220f");
+ parser.defineEntityReplacementText("sum", "\u2211");
+ parser.defineEntityReplacementText("minus", "\u2212");
+ parser.defineEntityReplacementText("lowast", "\u2217");
+ parser.defineEntityReplacementText("radic", "\u221a");
+ parser.defineEntityReplacementText("prop", "\u221d");
+ parser.defineEntityReplacementText("infin", "\u221e");
+ parser.defineEntityReplacementText("ang", "\u2220");
+ parser.defineEntityReplacementText("and", "\u2227");
+ parser.defineEntityReplacementText("or", "\u2228");
+ parser.defineEntityReplacementText("cap", "\u2229");
+ parser.defineEntityReplacementText("cup", "\u222a");
+ parser.defineEntityReplacementText("int", "\u222b");
+ parser.defineEntityReplacementText("there4", "\u2234");
+ parser.defineEntityReplacementText("sim", "\u223c");
+ parser.defineEntityReplacementText("cong", "\u2245");
+ parser.defineEntityReplacementText("asymp", "\u2248");
+ parser.defineEntityReplacementText("ne", "\u2260");
+ parser.defineEntityReplacementText("equiv", "\u2261");
+ parser.defineEntityReplacementText("le", "\u2264");
+ parser.defineEntityReplacementText("ge", "\u2265");
+ parser.defineEntityReplacementText("sub", "\u2282");
+ parser.defineEntityReplacementText("sup", "\u2283");
+ parser.defineEntityReplacementText("nsub", "\u2284");
+ parser.defineEntityReplacementText("sube", "\u2286");
+ parser.defineEntityReplacementText("supe", "\u2287");
+ parser.defineEntityReplacementText("oplus", "\u2295");
+ parser.defineEntityReplacementText("otimes", "\u2297");
+ parser.defineEntityReplacementText("perp", "\u22a5");
+ parser.defineEntityReplacementText("sdot", "\u22c5");
+ parser.defineEntityReplacementText("lceil", "\u2308");
+ parser.defineEntityReplacementText("rceil", "\u2309");
+ parser.defineEntityReplacementText("lfloor", "\u230a");
+ parser.defineEntityReplacementText("rfloor", "\u230b");
+ parser.defineEntityReplacementText("lang", "\u2329");
+ parser.defineEntityReplacementText("rang", "\u232a");
+ parser.defineEntityReplacementText("loz", "\u25ca");
+ parser.defineEntityReplacementText("spades", "\u2660");
+ parser.defineEntityReplacementText("clubs", "\u2663");
+ parser.defineEntityReplacementText("hearts", "\u2665");
+ parser.defineEntityReplacementText("diams", "\u2666");
+ }
+
+ /**
+ *
+ * @return all the {@link Xpp3Reader} registred via a {@link ServiceLoader}
+ * on the contract {@link Xpp3Reader}.
+ *
+ */
+ protected static Map<Class<?>, Xpp3Reader> getReaders() {
+ if (readers == null) {
+ readers = new HashMap<Class<?>, Xpp3Reader>();
+ ServiceLoader<Xpp3Reader> load = ServiceLoader.load(Xpp3Reader.class);
+ for (Xpp3Reader r : load) {
+ readers.put(r.getType(), r);
+ }
+ }
+ return readers;
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Helper.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java
===================================================================
--- trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java (rev 0)
+++ trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java 2009-09-07 22:54:20 UTC (rev 569)
@@ -0,0 +1,89 @@
+package org.nuiton.io.xpp3;
+
+import java.io.IOException;
+import java.io.Reader;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * A simple contract to mark all xpp readers.
+ *
+ * a such reader is associated to a {@link #getType()}.
+ *
+ * The implementations of such readers must be register in a file
+ * <pre>
+ * META-INF/services.org.nuiton.io.xpp3.Xpp3Reader
+ * </pre>
+ *
+ * to make possible auto-discovering of availables reader at runtime.
+ *
+ * See {@link Xpp3Helper#getReader(java.lang.Class)}.
+ *
+ *
+ * @author chemit
+ * @since 1.0.3
+ */
+public interface Xpp3Reader {
+
+ /**
+ *
+ * @return the type of main object to read
+ */
+ Class<?> getType();
+
+ /**
+ * @see ReaderFactory#newXmlReader
+ *
+ * @param reader
+ * @throws IOException
+ * @throws XmlPullParserException
+ * @return Settings
+ */
+ Object read(Reader reader) throws IOException, XmlPullParserException;
+
+ /**
+ * @see ReaderFactory#newXmlReader
+ *
+ * @param reader
+ * @param strict
+ * @throws IOException
+ * @throws XmlPullParserException
+ * @return Settings
+ */
+ Object read(Reader reader, boolean strict) throws IOException, XmlPullParserException;
+
+ /**
+ * @see ReaderFactory#newXmlReader
+ *
+ * @param reader
+ * @throws IOException
+ * @throws XmlPullParserException
+ * @return Settings
+ */
+ Object[] readArray(Reader reader) throws IOException, XmlPullParserException;
+
+ /**
+ * @see ReaderFactory#newXmlReader
+ *
+ * @param reader
+ * @param strict
+ * @throws IOException
+ * @throws XmlPullParserException
+ * @return Settings
+ */
+ Object[] readArray(Reader reader, boolean strict) throws IOException, XmlPullParserException;
+
+ /**
+ * Returns the state of the "add default entities" flag.
+ *
+ * @return boolean
+ */
+ boolean isAddDefaultEntities();
+
+ /**
+ * Sets the state of the "add default entities" flag.
+ *
+ * @param addDefaultEntities
+ */
+ void setAddDefaultEntities(boolean addDefaultEntities);
+}
Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
1
0
Author: tchemit
Date: 2009-09-06 22:27:59 +0200 (Sun, 06 Sep 2009)
New Revision: 568
Modified:
trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
Log:
automatic tests discovering
Modified: trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-06 13:31:48 UTC (rev 567)
+++ trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-06 20:27:59 UTC (rev 568)
@@ -32,6 +32,8 @@
import java.util.List;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusTestCase;
+import org.junit.Ignore;
+import org.junit.Test;
import org.nuiton.AbstractPlugin;
/**
@@ -70,6 +72,29 @@
testDir = new File(f, rep);
System.out.println("test dir : " + testDir);
+ if (testNames.length == 0) {
+
+ // auto looking up for tests names, methods which respect
+ // with @PluginConfig
+ // with @Test
+ // without @Ignore
+
+ List<String> testNamesList = new ArrayList<String>();
+ for (Method m : klass.getMethods()) {
+ PluginConfig annotation = m.getAnnotation(PluginConfig.class);
+ if (annotation != null) {
+ Test t = m.getAnnotation(Test.class);
+ if (t != null) {
+ Ignore i = m.getAnnotation(Ignore.class);
+ if (i==null) {
+ testNamesList.add(m.getName());
+ }
+ }
+ }
+ }
+ testNames = testNamesList.toArray(new String[testNamesList.size()]);
+ }
+
for (String testName : testNames) {
Method m = klass.getMethod(testName);
if (m == null) {
1
0
r567 - in trunk: . src/test/java/org/nuiton/license/plugin src/test/java/org/nuiton/util
by tchemit@users.nuiton.org 06 Sep '09
by tchemit@users.nuiton.org 06 Sep '09
06 Sep '09
Author: tchemit
Date: 2009-09-06 15:31:48 +0200 (Sun, 06 Sep 2009)
New Revision: 567
Modified:
trunk/changelog.txt
trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java
trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
Log:
[FEATURE #45] utiliser des generics dans le framework de test de mojos
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2009-08-29 21:37:23 UTC (rev 566)
+++ trunk/changelog.txt 2009-09-06 13:31:48 UTC (rev 567)
@@ -1,10 +1,16 @@
+maven-helper-plugin (1.0.3) stable; urgency=high
+
+ * [FEATURE #45] utiliser des generics dans le framework de test de mojos
+
+ -- chemit --
+
maven-helper-plugin (1.0.2) stable; urgency=high
- * [FIX] #36 protect emails
+ * [FIX #36] protect emails
* [FEATURE] use maven.file.license
* [FEATURE] improve code + add some usefull methods for plugin
* [FEATURE] add some documentation on site + use apt format (no deps to jrst)
- * [FEATURE] #26 add a check-project-files goal to detect existence of the changelog.txt file for root module of project.
+ * [FEATURE #26] add a check-project-files goal to detect existence of the changelog.txt file for root module of project.
-- chemit -- Sat, 29 Aug 2009 19:45:05 +0200
Modified: trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java
===================================================================
--- trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-08-29 21:37:23 UTC (rev 566)
+++ trunk/src/test/java/org/nuiton/license/plugin/LicensePluginTest.java 2009-09-06 13:31:48 UTC (rev 567)
@@ -34,7 +34,7 @@
import org.nuiton.util.BasePluginTestCase;
/** @author chemit */
-public class LicensePluginTest extends BasePluginTestCase {
+public class LicensePluginTest extends BasePluginTestCase<LicensePlugin> {
@BeforeClass
public static void initClass() throws Exception {
@@ -51,14 +51,13 @@
@Override
public void setUp() throws Exception {
super.setUp();
- LicensePlugin plugin = (LicensePlugin) mojo;
- plugin.setOutputDirectory(new File(getBaseDir(), plugin.getOutputDirectory().toString()));
- if (!plugin.getOutputDirectory().exists()) {
- if (!plugin.getOutputDirectory().mkdirs()) {
- throw new IOException("could not create directory : " + plugin.getOutputDirectory());
+ mojo.setOutputDirectory(new File(getBaseDir(), mojo.getOutputDirectory().toString()));
+ if (!mojo.getOutputDirectory().exists()) {
+ if (!mojo.getOutputDirectory().mkdirs()) {
+ throw new IOException("could not create directory : " + mojo.getOutputDirectory());
}
}
- plugin.setLicenseFile(new File(pomFile.getParentFile(), plugin.getLicenseFile().toString()));
+ mojo.setLicenseFile(new File(pomFile.getParentFile(), mojo.getLicenseFile().toString()));
}
@Test
@@ -66,24 +65,22 @@
public void testOne() throws MojoExecutionException, MojoFailureException {
assertNotNull(mojo);
- LicensePlugin p = (LicensePlugin) mojo;
+ long t0 = mojo.getLicenseFile().lastModified();
- long t0 = p.getLicenseFile().lastModified();
-
// always assume pom is older than any file
// since we can not ensure order of copy test resources
- p.getProject().getFile().setLastModified(0);
+ mojo.getProject().getFile().setLastModified(0);
- p.execute();
+ mojo.execute();
- long t1 = p.getLicenseFile().lastModified();
+ long t1 = mojo.getLicenseFile().lastModified();
assertEquals(t0, t1);
- p.setForce(true);
+ mojo.setForce(true);
- p.execute();
- t1 = p.getLicenseFile().lastModified();
+ mojo.execute();
+ t1 = mojo.getLicenseFile().lastModified();
assertTrue(t1 > t0);
}
Modified: trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java
===================================================================
--- trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-08-29 21:37:23 UTC (rev 566)
+++ trunk/src/test/java/org/nuiton/util/BasePluginTestCase.java 2009-09-06 13:31:48 UTC (rev 567)
@@ -34,8 +34,10 @@
import org.codehaus.plexus.PlexusTestCase;
import org.nuiton.AbstractPlugin;
-/** @author chemit */
-public abstract class BasePluginTestCase {
+/**
+ * @param <P> le mojo a test
+ * @author chemit */
+public abstract class BasePluginTestCase<P extends AbstractPlugin> {
protected static File basedir;
protected static File testDir;
@@ -43,7 +45,7 @@
protected static MyAbstractMojoTestCase delegate;
protected String goalName;
protected File pomFile;
- protected AbstractPlugin mojo;
+ protected P mojo;
protected static File getBaseDir() {
if (basedir == null) {
@@ -58,7 +60,7 @@
return testDir;
}
- protected static void initConfigs(Class<? extends BasePluginTestCase> klass, String... testNames) throws Exception {
+ protected static <P extends AbstractPlugin> void initConfigs(Class<? extends BasePluginTestCase<P>> klass, String... testNames) throws Exception {
List<PluginConfig> configs = new ArrayList<PluginConfig>();
String rep = klass.getName();
rep = rep.replaceAll("\\.", File.separator);
@@ -94,7 +96,7 @@
protected void initPomFile(PluginConfig pluginConfig) throws Exception {
this.goalName = pluginConfig.goalName();
this.pomFile = new File(getTestDir(), pluginConfig.pomName());
- this.mojo = (AbstractPlugin) delegate.lookupMojo(goalName, pomFile);
+ this.mojo = (P) delegate.lookupMojo(goalName, pomFile);
MavenProject project = mojo.getProject();
if (project == null) {
1
0
Author: tchemit
Date: 2009-08-29 23:37:23 +0200 (Sat, 29 Aug 2009)
New Revision: 566
Modified:
trunk/pom.xml
Log:
[maven-release-plugin] prepare for next development iteration
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-08-29 21:37:21 UTC (rev 565)
+++ trunk/pom.xml 2009-08-29 21:37:23 UTC (rev 566)
@@ -10,7 +10,7 @@
<groupId>org.nuiton</groupId>
<artifactId>maven-helper-plugin</artifactId>
- <version>1.0.2</version>
+ <version>1.0.3-SNAPSHOT</version>
<dependencies>
@@ -441,9 +441,9 @@
<!--Source control management-->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/tags/maven-helper-plu…</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/tags/maven-helper-plu…</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/maven-helper-plugin/tags/maven-he…</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/trunk</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/trunk</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/maven-helper-plugin/trunk</url>
</scm>
<issueManagement>
1
0
Author: tchemit
Date: 2009-08-29 23:37:21 +0200 (Sat, 29 Aug 2009)
New Revision: 565
Added:
tags/maven-helper-plugin-1.0.2/
Log:
[maven-scm] copy for tag maven-helper-plugin-1.0.2
Property changes on: tags/maven-helper-plugin-1.0.2
___________________________________________________________________
Added: svn:ignore
+ target
Added: svn:mergeinfo
+
1
0
Author: tchemit
Date: 2009-08-29 23:37:18 +0200 (Sat, 29 Aug 2009)
New Revision: 564
Modified:
trunk/pom.xml
Log:
[maven-release-plugin] prepare release maven-helper-plugin-1.0.2
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-08-29 20:41:09 UTC (rev 563)
+++ trunk/pom.xml 2009-08-29 21:37:18 UTC (rev 564)
@@ -10,7 +10,7 @@
<groupId>org.nuiton</groupId>
<artifactId>maven-helper-plugin</artifactId>
- <version>1.0.2-SNAPSHOT</version>
+ <version>1.0.2</version>
<dependencies>
@@ -441,9 +441,9 @@
<!--Source control management-->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/trunk</connection>
- <developerConnection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/trunk</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/maven-helper-plugin/trunk</url>
+ <connection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/tags/maven-helper-plu…</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/maven-helper-plugin/tags/maven-helper-plu…</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/maven-helper-plugin/tags/maven-he…</url>
</scm>
<issueManagement>
1
0
Author: tchemit
Date: 2009-08-29 22:41:09 +0200 (Sat, 29 Aug 2009)
New Revision: 563
Modified:
trunk/changelog.txt
trunk/pom.xml
Log:
[FIX] #36 protect emails
[FEATURE] use maven.file.license
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2009-08-29 18:23:17 UTC (rev 562)
+++ trunk/changelog.txt 2009-08-29 20:41:09 UTC (rev 563)
@@ -1,5 +1,7 @@
maven-helper-plugin (1.0.2) stable; urgency=high
+ * [FIX] #36 protect emails
+ * [FEATURE] use maven.file.license
* [FEATURE] improve code + add some usefull methods for plugin
* [FEATURE] add some documentation on site + use apt format (no deps to jrst)
* [FEATURE] #26 add a check-project-files goal to detect existence of the changelog.txt file for root module of project.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-08-29 18:23:17 UTC (rev 562)
+++ trunk/pom.xml 2009-08-29 20:41:09 UTC (rev 563)
@@ -114,34 +114,37 @@
<licenses>
<license>
- <name>LGPL</name>
- <url>http://www.gnu.org/licenses/lgpl.txt</url>
- <distribution>repo</distribution>
+ <name>Lesser General Public License (LGPL)</name>
+ <!--<url>http://www.gnu.org/licenses/lgpl.txt</url>-->
+ <url>${project.basedir}/LICENSE.txt</url>
+ <distribution>local</distribution>
</license>
</licenses>
<developers>
-
+
<developer>
- <id>chatellier</id>
<name>Eric Chatellier</name>
- <email>chatellier(a)codelutin.com</email>
+ <id>echatellier</id>
+ <!--<email>chatellier(a)codelutin.com</email>-->
+ <email>http://mailhide.recaptcha.net/d?k=01qLvyYlchVJ90Gg2lfYg-5A==&c=8mzC6s-m…</email>
<organization>CodeLutin</organization>
<timezone>+2</timezone>
<roles>
<role>Développeur</role>
</roles>
</developer>
-
+
<developer>
+ <name>Tony Chemit</name>
<id>tchemit</id>
- <name>Tony Chemit</name>
- <email>chemit(a)codelutin.com</email>
+ <!--<email>chemit(a)codelutin.com</email>-->
+ <email>http://mailhide.recaptcha.net/d?k=01qLvyYlchVJ90Gg2lfYg-5A==&c=Dg32g6wa…</email>
<organization>CodeLutin</organization>
+ <timezone>+2</timezone>
<roles>
<role>Développeur</role>
</roles>
- <timezone>+2</timezone>
</developer>
</developers>
1
0
r562 - in trunk: . src/main/java/org/nuiton src/site src/site/apt
by tchemit@users.nuiton.org 29 Aug '09
by tchemit@users.nuiton.org 29 Aug '09
29 Aug '09
Author: tchemit
Date: 2009-08-29 20:23:17 +0200 (Sat, 29 Aug 2009)
New Revision: 562
Added:
trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java
Removed:
trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java
Modified:
trunk/changelog.txt
trunk/pom.xml
trunk/src/site/apt/index.apt
trunk/src/site/site.xml
Log:
- evolution #26 add a check-project-files goal
- fix hudson url in reports
- update documentation
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2009-08-29 17:33:31 UTC (rev 561)
+++ trunk/changelog.txt 2009-08-29 18:23:17 UTC (rev 562)
@@ -2,9 +2,9 @@
* [FEATURE] improve code + add some usefull methods for plugin
* [FEATURE] add some documentation on site + use apt format (no deps to jrst)
- * [FEATURE] add a check-changelog-file goal to detect existence of the changelog.txt file for root module of project.
+ * [FEATURE] #26 add a check-project-files goal to detect existence of the changelog.txt file for root module of project.
- -- chemit -- ???
+ -- chemit -- Sat, 29 Aug 2009 19:45:05 +0200
maven-helper-plugin (1.0.1) stable; urgency=low
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2009-08-29 17:33:31 UTC (rev 561)
+++ trunk/pom.xml 2009-08-29 18:23:17 UTC (rev 562)
@@ -465,7 +465,7 @@
<ciManagement>
<system>hudson</system>
- <url>http://hudson.nuiton.org/job/${project.artifactId}</url>
+ <url>http://hudson.nuiton.org/hudson/job/${project.artifactId}</url>
</ciManagement>
<!--Any mailing lists for the project-->
Deleted: trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java 2009-08-29 17:33:31 UTC (rev 561)
+++ trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java 2009-08-29 18:23:17 UTC (rev 562)
@@ -1,63 +0,0 @@
-/*
- * *##%
- * Maven helper plugin
- * Copyright (C) 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package org.nuiton;
-
-import java.io.File;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-
-/**
- * Check that the changelog exists on standalone module or root module of a
- * multi-module project.
- *
- * @goal check-changelog-file
- * @requiresProject true
- * @phase validate
- * @author chemit
- * @since 1.0.2
- */
-public class CheckChangelogPlugin extends AbstractMojo {
-
- /**
- * Dependance du projet.
- *
- * @parameter default-value="${project}"
- * @required
- * @since 1.0.2
- */
- protected MavenProject project;
-
- @Override
- public void execute() throws MojoExecutionException, MojoFailureException {
- if (project.isExecutionRoot()) {
- File f = new File(project.getBasedir(), "changelog.txt");
- if (!f.exists()) {
- throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
- } else {
- getLog().info("changelog file dectected : " + f.getAbsolutePath());
- }
- } else {
- getLog().info("skip for module " + project.getName() + " (not a root module)");
- }
- }
-}
Copied: trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java (from rev 561, trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java)
===================================================================
--- trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java (rev 0)
+++ trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java 2009-08-29 18:23:17 UTC (rev 562)
@@ -0,0 +1,103 @@
+/*
+ * *##%
+ * Maven helper plugin
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package org.nuiton;
+
+import java.io.File;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Check that :
+ *
+ * 1) the changelog exists on standalone module or root module of a
+ * multi-module project.
+ * 2) any project module has a README.txt and LICENSE.txt file
+ *
+ * @goal check-project-files
+ * @requiresProject true
+ * @phase validate
+ * @author chemit
+ * @since 1.0.2
+ */
+public class CheckProjectFilesPlugin extends AbstractMojo {
+
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @since 1.0.2
+ */
+ protected MavenProject project;
+ /**
+ * Un flag pour activer le mode verbeux.
+ *
+ * @parameter expression="${helper.verbose}" default-value="${maven.verbose}"
+ * @since 1.0.2
+ */
+ protected boolean verbose;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ checkChangelogFile();
+ checkReadmeFile();
+ checkLicenseFile();
+ }
+
+ protected void checkChangelogFile() throws MojoExecutionException {
+ if (project.isExecutionRoot()) {
+ File f = new File(project.getBasedir(), "changelog.txt");
+ if (!f.exists()) {
+ throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
+ } else {
+ if (verbose) {
+ getLog().info("changelog file dectected : " + f.getAbsolutePath());
+ }
+ }
+ } else {
+ getLog().info("changelog.txt is not required for module " + project.getName() + " (not a root module)");
+ }
+ }
+
+ protected void checkReadmeFile() throws MojoExecutionException {
+ File f = new File(project.getBasedir(), "README.txt");
+ if (!f.exists()) {
+ throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
+ } else {
+ if (verbose) {
+ getLog().info("readme file dectected : " + f.getAbsolutePath());
+ }
+ }
+ }
+
+ protected void checkLicenseFile() throws MojoExecutionException {
+ File f = new File(project.getBasedir(), "LICENSE.txt");
+ if (!f.exists()) {
+ throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
+ } else {
+ if (verbose) {
+ getLog().info("license file dectected : " + f.getAbsolutePath());
+ }
+ }
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/CheckProjectFilesPlugin.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Modified: trunk/src/site/apt/index.apt
===================================================================
--- trunk/src/site/apt/index.apt 2009-08-29 17:33:31 UTC (rev 561)
+++ trunk/src/site/apt/index.apt 2009-08-29 18:23:17 UTC (rev 562)
@@ -27,7 +27,7 @@
* {{{add-third-party-mojo.html} helper:add-third-party}} write the licenses of all third-party libraries used in project.
- * {{{check-changelog-file-mojo.html} helper:check-changelog-file}} check the root module of project has a changelog.txt file.
+ * {{{check-project-files-mojo.html} helper:check-project-files}} check the root module of project has a changelog.txt file.
* {{{help-mojo.html} helper:help}} display help about the plugin (goals, usage).
Modified: trunk/src/site/site.xml
===================================================================
--- trunk/src/site/site.xml 2009-08-29 17:33:31 UTC (rev 561)
+++ trunk/src/site/site.xml 2009-08-29 18:23:17 UTC (rev 562)
@@ -43,7 +43,7 @@
<item name="add-license" href="add-license-mojo.html"/>
<item name="add-third-party" href="add-third-party-mojo.html"/>
<item name="available-licenses" href="available-licenses-mojo.html"/>
- <item name="check-changelog-file" href="check-changelog-file-mojo.html"/>
+ <item name="check-project-files" href="check-project-files-mojo.html"/>
<item name="help" href="help-mojo.html"/>
<item name="runJava" href="runJava-mojo.html"/>
</item>
1
0
r561 - in trunk: . src/main/java/org/nuiton src/main/java/org/nuiton/util src/site src/site/apt
by tchemit@users.nuiton.org 29 Aug '09
by tchemit@users.nuiton.org 29 Aug '09
29 Aug '09
Author: tchemit
Date: 2009-08-29 19:33:31 +0200 (Sat, 29 Aug 2009)
New Revision: 561
Added:
trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java
Modified:
trunk/changelog.txt
trunk/src/main/java/org/nuiton/util/SourceEntry.java
trunk/src/site/apt/index.apt
trunk/src/site/site.xml
Log:
add a check-changelog-file goal to detect existence of the changelog.txt file for root module of project.
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2009-08-29 16:50:54 UTC (rev 560)
+++ trunk/changelog.txt 2009-08-29 17:33:31 UTC (rev 561)
@@ -2,6 +2,7 @@
* [FEATURE] improve code + add some usefull methods for plugin
* [FEATURE] add some documentation on site + use apt format (no deps to jrst)
+ * [FEATURE] add a check-changelog-file goal to detect existence of the changelog.txt file for root module of project.
-- chemit -- ???
Added: trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java
===================================================================
--- trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java (rev 0)
+++ trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java 2009-08-29 17:33:31 UTC (rev 561)
@@ -0,0 +1,63 @@
+/*
+ * *##%
+ * Maven helper plugin
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package org.nuiton;
+
+import java.io.File;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Check that the changelog exists on standalone module or root module of a
+ * multi-module project.
+ *
+ * @goal check-changelog-file
+ * @requiresProject true
+ * @phase validate
+ * @author chemit
+ * @since 1.0.2
+ */
+public class CheckChangelogPlugin extends AbstractMojo {
+
+ /**
+ * Dependance du projet.
+ *
+ * @parameter default-value="${project}"
+ * @required
+ * @since 1.0.2
+ */
+ protected MavenProject project;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (project.isExecutionRoot()) {
+ File f = new File(project.getBasedir(), "changelog.txt");
+ if (!f.exists()) {
+ throw new MojoExecutionException("the module " + project.getName() + " requires the file " + f.getAbsolutePath());
+ } else {
+ getLog().info("changelog file dectected : " + f.getAbsolutePath());
+ }
+ } else {
+ getLog().info("skip for module " + project.getName() + " (not a root module)");
+ }
+ }
+}
Property changes on: trunk/src/main/java/org/nuiton/CheckChangelogPlugin.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/src/main/java/org/nuiton/util/SourceEntry.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/SourceEntry.java 2009-08-29 16:50:54 UTC (rev 560)
+++ trunk/src/main/java/org/nuiton/util/SourceEntry.java 2009-08-29 17:33:31 UTC (rev 561)
@@ -1,5 +1,5 @@
/*
- * *##%
+ * *##%
* Maven helper plugin
* Copyright (C) 2009 CodeLutin
*
Modified: trunk/src/site/apt/index.apt
===================================================================
--- trunk/src/site/apt/index.apt 2009-08-29 16:50:54 UTC (rev 560)
+++ trunk/src/site/apt/index.apt 2009-08-29 17:33:31 UTC (rev 561)
@@ -26,6 +26,8 @@
* {{{add-license-mojo.html} helper:add-license}} add license file and third-party files to classpath (generate them if necessary).
* {{{add-third-party-mojo.html} helper:add-third-party}} write the licenses of all third-party libraries used in project.
+
+ * {{{check-changelog-file-mojo.html} helper:check-changelog-file}} check the root module of project has a changelog.txt file.
* {{{help-mojo.html} helper:help}} display help about the plugin (goals, usage).
Modified: trunk/src/site/site.xml
===================================================================
--- trunk/src/site/site.xml 2009-08-29 16:50:54 UTC (rev 560)
+++ trunk/src/site/site.xml 2009-08-29 17:33:31 UTC (rev 561)
@@ -43,6 +43,7 @@
<item name="add-license" href="add-license-mojo.html"/>
<item name="add-third-party" href="add-third-party-mojo.html"/>
<item name="available-licenses" href="available-licenses-mojo.html"/>
+ <item name="check-changelog-file" href="check-changelog-file-mojo.html"/>
<item name="help" href="help-mojo.html"/>
<item name="runJava" href="runJava-mojo.html"/>
</item>
1
0