r622 - in trunk: . src/main/java/org/nuiton/io/xpp3 src/test/java/org/nuiton/io src/test/java/org/nuiton/io/xpp3 src/test/java/org/nuiton/plugin src/test/resources src/test/resources/META-INF src/test/resources/META-INF/services src/test/resources/org/nuiton/io src/test/resources/org/nuiton/io/xpp3
Author: tchemit Date: 2009-11-01 20:59:23 +0100 (Sun, 01 Nov 2009) New Revision: 622 Added: trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java trunk/src/test/java/org/nuiton/io/xpp3/ trunk/src/test/java/org/nuiton/io/xpp3/Identity.java trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java trunk/src/test/java/org/nuiton/io/xpp3/Xpp3HelperTest.java trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java trunk/src/test/resources/META-INF/ trunk/src/test/resources/META-INF/services/ trunk/src/test/resources/META-INF/services/org.nuiton.io.xpp3.Xpp3Reader trunk/src/test/resources/org/nuiton/io/xpp3/ trunk/src/test/resources/org/nuiton/io/xpp3/identities.xml trunk/src/test/resources/org/nuiton/io/xpp3/identity.xml Modified: trunk/pom.xml 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/Xpp3Reader.java trunk/src/test/java/org/nuiton/plugin/TestHelper.java Log: - integrate jredmine (for releases) - add tests for org.nuiton.io.xpp3 package Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-11-01 17:01:34 UTC (rev 621) +++ trunk/pom.xml 2009-11-01 19:59:23 UTC (rev 622) @@ -329,6 +329,7 @@ <properties> <license.version>2.0.0</license.version> + <jredmine.version>1.0.0-rc-2</jredmine.version> <maven.version>2.2.1</maven.version> <plexusMailSender.version>1.0-alpha-2</plexusMailSender.version> <javadoc.version>2.6</javadoc.version> @@ -350,6 +351,15 @@ <repository.home.url>http://maven.nuiton.org/release</repository.home.url> + <!-- redmine configuration --> + <platform>nuiton.org</platform> + <redmine.safe>false</redmine.safe> + <redmine.url>http://www.${platform}</redmine.url> + <redmine.projectId>maven-helper-plugin</redmine.projectId> + <redmine.xmlPath>${basedir}/target/generated-sources/changes/changes.xml</redmine.xmlPath> + <redmine.issueLinkTemplate>${redmine.url}/issues/show/%ISSUE%</redmine.issueLinkTemplate> + <redmine.versionLinkTemplate>${redmine.url}/versions/show/%VERSION%</redmine.versionLinkTemplate> + <redmine.collectedFiles>target/collect.properties</redmine.collectedFiles> </properties> <build> @@ -651,6 +661,12 @@ <version>${license.version}</version> </plugin> + <plugin> + <groupId>org.nuiton.jredmine</groupId> + <artifactId>maven-jredmine-plugin</artifactId> + <version>${jredmine.version}</version> + </plugin> + </plugins> </pluginManagement> </build> @@ -894,6 +910,12 @@ <plugin> <artifactId>maven-changes-plugin</artifactId> <version>2.1</version> + <configuration> + <issueLinkTemplatePerSystem> + <redmine>${redmine.issueLinkTemplate}</redmine> + </issueLinkTemplatePerSystem> + <xmlPath>${redmine.xmlPath}</xmlPath> + </configuration> <reportSets> <reportSet> <reports> @@ -1008,6 +1030,239 @@ </build> </profile> + <!-- perform only on a release stage when using the maven-release-plugin --> + <profile> + <id>redmine-pre-release-profile</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + <properties> + <redmine.safe>true</redmine.safe> + </properties> + + <reporting> + <plugins> + + <plugin> + <groupId>org.nuiton.jredmine</groupId> + <artifactId>maven-jredmine-plugin</artifactId> + <version>${jredmine.version}</version> + <configuration> + <columnNames>key,summary,status,assignee,tracker,priority,version,category,createdOn + </columnNames> + </configuration> + <reportSets> + <reportSet> + <reports> + <report>issues-report</report> + </reports> + </reportSet> + </reportSets> + </plugin> + + </plugins> + </reporting> + <build> + + <plugins> + + <!-- + - obtain redmine login + - collect files for jredmine release + --> + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-helper-plugin</artifactId> + <version>1.0.3</version> + <executions> + <execution> + <id>get-redmine-login</id> + <goals> + <goal>share-server-secret</goal> + </goals> + <phase>initialize</phase> + <configuration> + <serverId>redmine-${platform}</serverId> + <passwordOut>redmine.password</passwordOut> + <usernameOut>redmine.username</usernameOut> + </configuration> + </execution> + <execution> + <id>get-redmine-login-site</id> + <goals> + <goal>share-server-secret</goal> + </goals> + <phase>pre-site</phase> + <configuration> + <serverId>redmine-${platform}</serverId> + <passwordOut>redmine.password</passwordOut> + <usernameOut>redmine.username</usernameOut> + </configuration> + </execution> + <execution> + <id>collect-files</id> + <goals> + <goal>collect-files</goal> + </goals> + <phase>install</phase> + <configuration> + <extraFiles/> + <descriptionFile>${redmine.collectedFiles}</descriptionFile> + </configuration> + </execution> + </executions> + </plugin> + + <!-- generate the changes.xml from redmine --> + <plugin> + <groupId>org.nuiton.jredmine</groupId> + <artifactId>maven-jredmine-plugin</artifactId> + <executions> + <execution> + <id>jredmine-generate</id> + <goals> + <goal>generate-changes</goal> + <goal>generate-news-announcement</goal> + <goal>generate-email-announcement</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + <configuration> + + <!-- generate-changes --> + <generateOnce>true</generateOnce> + <actionMapping>fix:1, add:2</actionMapping> + <statusIds>3,4,5</statusIds> + + <!-- generate announcements --> + <urlDownload>${redmine.url}/projects/list_files/maven-helper-plugin</urlDownload> + + <!--<changesTitle>Release note of Maven pom project</changesTitle>--> + <!--<releaseDescription>Description of first release</releaseDescription>--> + <!--<verbose>true</verbose>--> + </configuration> + </plugin> + + </plugins> + + </build> + </profile> + + <!-- perform a redmine release after a successfull release --> + <profile> + <id>redmine-release-profile</id> + <activation> + <property> + <name>performRedmineRelease</name> + <value>true</value> + </property> + </activation> + + <properties> + <dryRun>true</dryRun> + <redmine.dryRun>${dryRun}</redmine.dryRun> + </properties> + <build> + + <plugins> + + <!-- + - obtain redmine login + - send release email + --> + <plugin> + <groupId>org.nuiton</groupId> + <artifactId>maven-helper-plugin</artifactId> + <executions> + <execution> + <id>get-redmine-login</id> + <goals> + <goal>share-server-secret</goal> + </goals> + <phase>initialize</phase> + <configuration> + <serverId>redmine-${platform}</serverId> + <passwordOut>redmine.password</passwordOut> + <usernameOut>redmine.username</usernameOut> + </configuration> + </execution> + <execution> + <id>send-release-email</id> + <goals> + <goal>send-email</goal> + </goals> + <phase>validate</phase> + </execution> + </executions> + <configuration> + + <!-- for a multi-module just run on root project --> + <runOnce>true</runOnce> + + <emailTitle>[ANNOUNCEMENT] - ${project.name} ${project.version} released</emailTitle> + <emailContentFile>target/generated-sources/announcement/release-email-announcement.vm + </emailContentFile> + <mailSender> + <name>${platform} Release Notification</name> + <email>noreply@${platform}</email> + </mailSender> + <toAddresses> + <item>${listId}-users@list.${platform}</item> + <item>${listId}-devel@list.${platform}</item> + <item>dev@codelutin.com</item> + </toAddresses> + <smtpHost>smtp</smtpHost> + </configuration> + </plugin> + + <!-- + - update version in redmine + - publish release files to redmine + - publish a release news in redmine + --> + <plugin> + <groupId>org.nuiton.jredmine</groupId> + <artifactId>maven-jredmine-plugin</artifactId> + <executions> + <execution> + <id>jredmine-release</id> + <goals> + <goal>update-version</goal> + <goal>publish-attachments</goal> + <goal>publish-news</goal> + </goals> + <phase>validate</phase> + </execution> + </executions> + <configuration> + + <!-- for a multi-module just run on root project --> + <runOnce>true</runOnce> + + <!-- update-version --> + <closeVersion>true</closeVersion> + + <!-- publish-attachments --> + <filesFromProperties>${redmine.collectedFiles}</filesFromProperties> + + <!-- publish-news --> + <newsContentFile>target/generated-sources/announcement/release-news-announcement.vm + </newsContentFile> + <newsSummary>${project.description}</newsSummary> + <newsTitle>${project.name} ${project.version} released</newsTitle> + + </configuration> + </plugin> + + </plugins> + + </build> + </profile> + <!-- do not execute tests (generaly a bad idea...) --> <profile> <id>notests</id> Modified: trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java =================================================================== --- trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2009-11-01 17:01:34 UTC (rev 621) +++ trunk/src/main/java/org/nuiton/io/xpp3/AbstractXpp3Reader.java 2009-11-01 19:59:23 UTC (rev 622) @@ -20,44 +20,40 @@ */ package org.nuiton.io.xpp3; +import org.codehaus.plexus.util.xml.pull.MXParser; +import org.codehaus.plexus.util.xml.pull.XmlPullParser; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + 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.*; 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; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * An abstract xpp3Reader based on {@link PropertyMapper} to set properties of * the objects to build. - * + * <p/> * To implements a new parser, just implements method {@link #initMappers()} to * see authorized mapping from tag to pojo properties. - * + * <p/> * The logic of setting properties from xml (tag and attributes) is done in - * + * <p/> * <ul> * <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> - * + * <p/> * The default implementation is to map tag text to a pojo's property. - * + * <p/> * 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 + * @param <O> the type of object to be build by the reader * @see PropertyMapper * @see Xpp3Reader + * @since 1.0.0 */ public abstract class AbstractXpp3Reader<O> implements Xpp3Reader<O> { @@ -78,7 +74,6 @@ protected final Class<O> type; /** * the root tag of an object to retreave from xml streams. - * */ protected String rootTagName; /** @@ -87,10 +82,10 @@ protected String arrayRootTagName; /** * the univers of mappers availables, initialized in {@link #initMappers()}. - * + * <p/> * Each mapper of the dictionary is associated to the fully qualified name * of the target class # the tag name or attribute name. - * + * <p/> * Example : * <pre> * org.nuiton.util.MyPojo#my-tag @@ -101,9 +96,9 @@ protected abstract void initMappers() throws IntrospectionException; - protected AbstractXpp3Reader(Class<O> type) { - this(type, null, null); - } +// protected AbstractXpp3Reader(Class<O> type) { +// this(type, null, null); +// } protected AbstractXpp3Reader(Class<O> type, String rootTagName) { this(type, null, rootTagName); @@ -218,9 +213,9 @@ /** * Obtain all mappers for a given type. - * + * <p/> * In the result, the keys are now the tag-name of attribute-name. - * + * <p/> * Example : * <pre> * my-tag @@ -243,15 +238,15 @@ /** * Parse the xml stream from the given parser and a build the associated object. - * + * <p/> * This default implementation just match a tag text content to a pojo property. - * + * <p/> * No work is done on attribute values here. - * + * <p/> * Note: The parser must accept as a next open tag the required one . - * + * <p/> * the next node name is given by <code>getRootTagName()</code> - * + * <p/> * Example : * <pre> * ... @@ -260,13 +255,13 @@ * </my-pojo> * </pre> * - * @param <T> the type of object to build + * @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 + * @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 IOException if any io pb * @throws XmlPullParserException if any parsing pb */ protected <T> T read(String rootTagName, Class<T> type, XmlPullParser parser, boolean strict) throws XmlPullParserException, IOException { @@ -324,14 +319,14 @@ /** * Parse the xml stream from the given parser and a build an array of associated object. - * + * <p/> * This default implementation just match a tag text content to a pojo property. - * + * <p/> * No work is done on attribute values here. - * + * <p/> * Note: The next node of the parser must be the one given by * {@code parentRootTagName} and sub nodes with names {@code rootTagName}. - * + * <p/> * Example : * <pre> * ... @@ -345,14 +340,14 @@ * </my-pojos> * </pre> * - * @param <T> the type of objects to build + * @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 + * @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 IOException if any io pb * @throws XmlPullParserException if any parsing pb */ protected <T> T[] readArray(String parentRootTagName, String rootTagName, Class<T> type, XmlPullParser parser, boolean strict) throws XmlPullParserException, IOException { @@ -436,7 +431,7 @@ /** * Checks that a given parser is not at the end of the xml document. * - * @param parser the parser to check + * @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 */ @@ -449,7 +444,7 @@ /** * 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. */ Added: trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java =================================================================== --- trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java (rev 0) +++ trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java 2009-11-01 19:59:23 UTC (rev 622) @@ -0,0 +1,81 @@ +/* + * *##% + * JRedmine client + * 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.io.xpp3; + +/** + * A enumaration to convert some data from a string representation. + * <p/> + * + * @author chemit + * @since 1.0.0 + */ +public enum DefaultDataConverter implements DataConverter { + + Boolean { + + @Override + public Object convert(String t) throws Exception { + Object r = java.lang.Boolean.valueOf(t); + return r; + } + }, Short { + + @Override + public Object convert(String t) throws Exception { + Object r = java.lang.Short.valueOf(t); + return r; + } + }, Integer { + + @Override + public Object convert(String t) throws Exception { + Object r = java.lang.Integer.valueOf(t); + return r; + } + }, Long { + + @Override + public Object convert(String t) throws Exception { + Object r = java.lang.Long.valueOf(t); + return r; + } + }, Float { + + @Override + public Object convert(String t) throws Exception { + Object r = java.lang.Float.valueOf(t); + return r; + } + }, Double { + + @Override + public Object convert(String t) throws Exception { + Object r = java.lang.Double.valueOf(t); + return r; + } + }, Text { + + @Override + public Object convert(String t) throws Exception { + return t; + } + }; +} \ No newline at end of file Property changes on: trunk/src/main/java/org/nuiton/io/xpp3/DefaultDataConverter.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java =================================================================== --- trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2009-11-01 17:01:34 UTC (rev 621) +++ trunk/src/main/java/org/nuiton/io/xpp3/PropertyMapper.java 2009-11-01 19:59:23 UTC (rev 622) @@ -20,31 +20,32 @@ */ package org.nuiton.io.xpp3; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.codehaus.plexus.util.xml.pull.XmlPullParser; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + import java.beans.PropertyDescriptor; 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; /** * A abstract object to map an xml value (tag or attribute, or esle?) to a pojo property. - * + * <p/> * Two implementations are given : - * + * <p/> * <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> - * + * <p/> * 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> + * <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 */ @@ -74,7 +75,7 @@ } @Override - protected Object getDataFromXml(XmlPullParser parser) throws XmlPullParserException, Exception { + protected Object getDataFromXml(XmlPullParser parser) throws Exception { String t = parser.getAttributeValue("", name); Object result = null; if (t != null && !(t = t.trim()).isEmpty()) { @@ -83,6 +84,7 @@ return result; } } + /** * name of tag (or attribute to deal with) */ @@ -120,7 +122,7 @@ 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 { + public void setProperty(Object src, XmlPullParser parser, Set<String> parsed, boolean strict) throws XmlPullParserException, IOException { if (onlyOne && parsed.contains(name)) { throw new XmlPullParserException("Duplicated tag: \'" + parser.getName() + "\'", parser, null); } Modified: trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java =================================================================== --- trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java 2009-11-01 17:01:34 UTC (rev 621) +++ trunk/src/main/java/org/nuiton/io/xpp3/Xpp3Reader.java 2009-11-01 19:59:23 UTC (rev 622) @@ -20,47 +20,45 @@ */ package org.nuiton.io.xpp3; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + import java.io.IOException; import java.io.Reader; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * A simple contract to mark all xpp readers. - * + * <p/> * a such reader is associated to a {@link #getType()}. - * + * <p/> * The implementations of such readers must be register in a file * <pre> * META-INF/services.org.nuiton.io.xpp3.Xpp3Reader * </pre> - * + * <p/> * to make possible auto-discovering of availables reader at runtime. - * - * See {@link Xpp3Helper#getReader(java.lang.Class)} and + * <p/> + * 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 + * @param <O> the type of object to be build by the reader. * @since 1.0.3 */ public interface Xpp3Reader<O> { /** - * - * @return the type of main object to read + * @return the type of main object to read */ Class<O> getType(); /** * Read a single instance of the typed object and return it. - * + * <p/> * Note : this is a convinient method to call * {@link #read(java.io.Reader, boolean)} in strict mode. - * + * <p/> * In the xml stream, the root tag must be the {@link #getRootTagName()}. - * + * <p/> * Example : * <pre> * <issue>: @@ -68,18 +66,18 @@ * </issue>: * </pre> * - * @param reader - * @throws IOException - * @throws XmlPullParserException + * @param reader the xml input reader * @return Settings + * @throws IOException if any io pb + * @throws XmlPullParserException if parsing error */ O read(Reader reader) throws IOException, XmlPullParserException; /** * Read a single instance of the typed object and return it. - * + * <p/> * In the xml stream, the root tag must be the {@link #getRootTagName()}. - * + * <p/> * Example : * <pre> * <issue>: @@ -89,20 +87,20 @@ * * @param reader the xml input reader * @param strict flag to be strict while parsing - * @throws IOException if any io pb + * @return the read object + * @throws IOException if any io pb * @throws XmlPullParserException if any parsing pb - * @return the */ O read(Reader reader, boolean strict) throws IOException, XmlPullParserException; /** * Read some instances of the typed object and return it. - * + * <p/> * In the xml stream, the root tag must be the {@link #getArrayRootTagName()}. - * + * <p/> * Note : this is a convinient method to call : * {@link #readArray(java.io.Reader, boolean)} in stritc mode. - * + * <p/> * Example : * <pre> * <issues>: @@ -113,17 +111,17 @@ * </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. + * @throws IOException if any io pb + * @throws XmlPullParserException if any parsing pb */ O[] readArray(Reader reader) throws IOException, XmlPullParserException; /** * Read some instances of the typed object and return it. - * + * <p/> * In the xml stream, the root tag must be the {@link #getArrayRootTagName()}. - * + * <p/> * Example : * <pre> * <issues>: @@ -135,14 +133,13 @@ * * @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. + * @throws IOException if any io pb + * @throws XmlPullParserException if any parsing pb */ O[] readArray(Reader reader, boolean strict) throws IOException, XmlPullParserException; /** - * * @return the name of the root tag of a object to read */ String getRootTagName(); @@ -155,21 +152,20 @@ 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. + * <code>false</code> otherwise. */ boolean isAddDefaultEntities(); Added: trunk/src/test/java/org/nuiton/io/xpp3/Identity.java =================================================================== --- trunk/src/test/java/org/nuiton/io/xpp3/Identity.java (rev 0) +++ trunk/src/test/java/org/nuiton/io/xpp3/Identity.java 2009-11-01 19:59:23 UTC (rev 622) @@ -0,0 +1,85 @@ +package org.nuiton.io.xpp3; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +/** + * User: chemit + * Date: 1 nov. 2009 + * Time: 19:49:59 + */ +public class Identity { + + + protected String firstName = ""; + + protected String lastName = ""; + + protected String email = "dummy@codelutin.com"; + + protected int age = 51; + + + PropertyChangeSupport p; + + public Identity() { + p = new PropertyChangeSupport(this); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + p.addPropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + p.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + p.removePropertyChangeListener(listener); + } + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + p.removePropertyChangeListener(propertyName, listener); + } + + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getEmail() { + return email; + } + + public int getAge() { + return age; + } + + public void setFirstName(String firstName) { + String oldFirstName = this.firstName; + this.firstName = firstName; + p.firePropertyChange("firstName", oldFirstName, firstName); + } + + public void setLastName(String lastName) { + String oldLastName = this.lastName; + this.lastName = lastName; + p.firePropertyChange("lastName", oldLastName, lastName); + } + + public void setEmail(String email) { + String oldEmail = this.email; + this.email = email; + p.firePropertyChange("email", oldEmail, email); + } + + public void setAge(int age) { + int oldAge = this.age; + this.age = age; + p.firePropertyChange("age", oldAge, age); + } +} Property changes on: trunk/src/test/java/org/nuiton/io/xpp3/Identity.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java =================================================================== --- trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java (rev 0) +++ trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java 2009-11-01 19:59:23 UTC (rev 622) @@ -0,0 +1,27 @@ +package org.nuiton.io.xpp3; + +import java.beans.IntrospectionException; + +/** + * User: chemit + * Date: 1 nov. 2009 + * Time: 20:37:56 + */ +public class IdentityXpp3Reader extends AbstractXpp3Reader<Identity> { + public IdentityXpp3Reader() { + super(Identity.class, "identities", "identity"); + } + + @Override + protected void initMappers() throws IntrospectionException { + + org.nuiton.io.xpp3.Xpp3Helper.addTagTextContentMappers(Identity.class, DefaultDataConverter.Text, true, allMappers, + "firstName", + "lastName", + "email"); + + org.nuiton.io.xpp3.Xpp3Helper.addTagTextContentMappers(Identity.class, DefaultDataConverter.Integer, true, allMappers, + "age"); + + } +} Property changes on: trunk/src/test/java/org/nuiton/io/xpp3/IdentityXpp3Reader.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/test/java/org/nuiton/io/xpp3/Xpp3HelperTest.java =================================================================== --- trunk/src/test/java/org/nuiton/io/xpp3/Xpp3HelperTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/io/xpp3/Xpp3HelperTest.java 2009-11-01 19:59:23 UTC (rev 622) @@ -0,0 +1,92 @@ +package org.nuiton.io.xpp3; + +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.plugin.TestHelper; + +import java.io.File; +import java.io.FileReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * User: chemit + * Date: 1 nov. 2009 + * Time: 20:34:34 + */ +public class Xpp3HelperTest { + + @Test + public void testGetReader() throws Exception { + Xpp3Reader<Identity> r = Xpp3Helper.getReader(Identity.class); + Assert.assertNotNull(r); + } + + @Test + public void testGetReaderIterator() throws Exception { + Iterator<Xpp3Reader<?>> r = Xpp3Helper.getReaderItetator(); + Assert.assertNotNull(r); + Assert.assertTrue(r.hasNext()); + Xpp3Reader<?> reader = r.next(); + Assert.assertNotNull(reader); + } + + @Test + public void testReadObject() throws Exception { + List<String> paths = new ArrayList<String>(); + paths.add("target"); + paths.add("test-classes"); + paths.addAll(Arrays.asList(getClass().getPackage().getName().split("\\."))); + File file = TestHelper.getFile(TestHelper.getBasedir(), paths.toArray(new String[paths.size()])); + file = new File(file, "identity.xml"); + Reader input = new FileReader(file); + + Identity result = Xpp3Helper.readObject(Identity.class, input); + + Assert.assertNotNull(result); + Identity expected = new Identity(); + expected.setFirstName("first name"); + expected.setLastName("last name"); + expected.setEmail("noway@bishop.uk"); + expected.setAge(29); + + Xpp3ReaderTest.assertEqualsIdentity(result, expected); + + + } + + @Test + public void testReadObjects() throws Exception { + List<String> paths = new ArrayList<String>(); + paths.add("target"); + paths.add("test-classes"); + paths.addAll(Arrays.asList(getClass().getPackage().getName().split("\\."))); + File file = TestHelper.getFile(TestHelper.getBasedir(), paths.toArray(new String[paths.size()])); + file = new File(file, "identities.xml"); + Reader input = new FileReader(file); + Assert.assertNotNull(input); + Identity[] result = Xpp3Helper.readObjects(Identity.class, input); + Assert.assertNotNull(result); + Assert.assertEquals(2, result.length); + Identity expected = new Identity(); + expected.setFirstName("first name"); + expected.setLastName("last name"); + expected.setEmail("noway@bishop.uk"); + expected.setAge(29); + + Xpp3ReaderTest.assertEqualsIdentity(result[0], expected); + + expected = new Identity(); + expected.setFirstName("first name2"); + expected.setLastName("last name2"); + expected.setEmail("noway2@bishop.uk"); + expected.setAge(31); + + Xpp3ReaderTest.assertEqualsIdentity(result[1], expected); + + + } +} Property changes on: trunk/src/test/java/org/nuiton/io/xpp3/Xpp3HelperTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java =================================================================== --- trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java 2009-11-01 19:59:23 UTC (rev 622) @@ -0,0 +1,85 @@ +package org.nuiton.io.xpp3; + +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.plugin.TestHelper; + +import java.io.File; +import java.io.FileReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * User: chemit + * Date: 1 nov. 2009 + * Time: 19:50:39 + */ +public class Xpp3ReaderTest { + + protected Xpp3Reader<Identity> r = new IdentityXpp3Reader(); + + @Test + public void testRead() throws Exception { + + List<String> paths = new ArrayList<String>(); + paths.add("target"); + paths.add("test-classes"); + paths.addAll(Arrays.asList(getClass().getPackage().getName().split("\\."))); + File file = TestHelper.getFile(TestHelper.getBasedir(), paths.toArray(new String[paths.size()])); + file = new File(file, "identity.xml"); + Reader input = new FileReader(file); + Assert.assertNotNull(input); + Identity result = r.read(input); + Assert.assertNotNull(result); + Identity expected = new Identity(); + expected.setFirstName("first name"); + expected.setLastName("last name"); + expected.setEmail("noway@bishop.uk"); + expected.setAge(29); + + assertEqualsIdentity(result, expected); + + } + + + @Test + public void testReadArray() throws Exception { + + List<String> paths = new ArrayList<String>(); + paths.add("target"); + paths.add("test-classes"); + paths.addAll(Arrays.asList(getClass().getPackage().getName().split("\\."))); + File file = TestHelper.getFile(TestHelper.getBasedir(), paths.toArray(new String[paths.size()])); + file = new File(file, "identities.xml"); + Reader input = new FileReader(file); + Assert.assertNotNull(input); + Identity[] result = r.readArray(input); + Assert.assertNotNull(result); + Assert.assertEquals(2, result.length); + Identity expected = new Identity(); + expected.setFirstName("first name"); + expected.setLastName("last name"); + expected.setEmail("noway@bishop.uk"); + expected.setAge(29); + + assertEqualsIdentity(result[0], expected); + + expected = new Identity(); + expected.setFirstName("first name2"); + expected.setLastName("last name2"); + expected.setEmail("noway2@bishop.uk"); + expected.setAge(31); + + assertEqualsIdentity(result[1], expected); + } + + protected static void assertEqualsIdentity(Identity result, Identity expected) { + Assert.assertEquals(expected.getFirstName(), result.getFirstName()); + Assert.assertEquals(expected.getLastName(), result.getLastName()); + Assert.assertEquals(expected.getEmail(), result.getEmail()); + Assert.assertEquals(expected.getAge(), result.getAge()); + } + +} Property changes on: trunk/src/test/java/org/nuiton/io/xpp3/Xpp3ReaderTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/src/test/java/org/nuiton/plugin/TestHelper.java =================================================================== --- trunk/src/test/java/org/nuiton/plugin/TestHelper.java 2009-11-01 17:01:34 UTC (rev 621) +++ trunk/src/test/java/org/nuiton/plugin/TestHelper.java 2009-11-01 19:59:23 UTC (rev 622) @@ -24,11 +24,12 @@ import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusTestCase; -import java.io.File; import org.junit.Assert; +import org.junit.Ignore; +import java.io.File; + /** - * * @author chemit * @since 1.0.3 */ @@ -39,7 +40,6 @@ protected static DelegateMojoTestCase delegateMojoTest; /** - * * @return the basedir for all tests * @see PlexusTestCase#getBasedir() */ @@ -94,6 +94,7 @@ TestHelper.delegateMojoTest = delegateMojoTest; } + @Ignore public static class DelegateMojoTestCase extends AbstractMojoTestCase { @Override Added: trunk/src/test/resources/META-INF/services/org.nuiton.io.xpp3.Xpp3Reader =================================================================== --- trunk/src/test/resources/META-INF/services/org.nuiton.io.xpp3.Xpp3Reader (rev 0) +++ trunk/src/test/resources/META-INF/services/org.nuiton.io.xpp3.Xpp3Reader 2009-11-01 19:59:23 UTC (rev 622) @@ -0,0 +1 @@ +org.nuiton.io.xpp3.IdentityXpp3Reader \ No newline at end of file Added: trunk/src/test/resources/org/nuiton/io/xpp3/identities.xml =================================================================== --- trunk/src/test/resources/org/nuiton/io/xpp3/identities.xml (rev 0) +++ trunk/src/test/resources/org/nuiton/io/xpp3/identities.xml 2009-11-01 19:59:23 UTC (rev 622) @@ -0,0 +1,14 @@ +<identities> + <identity> + <firstName>first name</firstName> + <lastName>last name</lastName> + <email>noway@bishop.uk</email> + <age>29</age> + </identity> + <identity> + <firstName>first name2</firstName> + <lastName>last name2</lastName> + <email>noway2@bishop.uk</email> + <age>31</age> + </identity> +</identities> \ No newline at end of file Added: trunk/src/test/resources/org/nuiton/io/xpp3/identity.xml =================================================================== --- trunk/src/test/resources/org/nuiton/io/xpp3/identity.xml (rev 0) +++ trunk/src/test/resources/org/nuiton/io/xpp3/identity.xml 2009-11-01 19:59:23 UTC (rev 622) @@ -0,0 +1,6 @@ +<identity> + <firstName>first name</firstName> + <lastName>last name</lastName> + <email>noway@bishop.uk</email> + <age>29</age> +</identity> \ No newline at end of file
participants (1)
-
tchemit@users.nuiton.org