diff --git a/modello-core/pom.xml b/modello-core/pom.xml
index 00ff85cfc..b31466b4d 100644
--- a/modello-core/pom.xml
+++ b/modello-core/pom.xml
@@ -3,7 +3,7 @@
modello
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-maven-plugin/pom.xml b/modello-maven-plugin/pom.xml
index cad07f48c..51fd2d1fd 100644
--- a/modello-maven-plugin/pom.xml
+++ b/modello-maven-plugin/pom.xml
@@ -3,7 +3,7 @@
modello
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
@@ -112,4 +112,67 @@
+
+
+
+ run-its
+
+
+
+ org.apache.maven.plugins
+ maven-invoker-plugin
+ 1.3
+
+ src/it
+ ${project.build.directory}/it
+
+ */pom.xml
+
+ verify.bsh
+ src/it/settings.xml
+ ${project.build.directory}/local-repo
+ true
+
+ 1.5.8
+ 3.8.2
+
+
+ clean
+ test
+
+
+
+
+ integration-test
+
+ install
+ run
+
+
+
+
+
+
+
+
+ run-its-java14
+
+ 1.4
+
+
+
+
+ org.apache.maven.plugins
+ maven-invoker-plugin
+ 1.3
+
+
+ clone-java5/**
+
+
+
+
+
+
+
diff --git a/modello-maven-plugin/src/it/clone-java5/pom.xml b/modello-maven-plugin/src/it/clone-java5/pom.xml
new file mode 100644
index 000000000..83f32c6ea
--- /dev/null
+++ b/modello-maven-plugin/src/it/clone-java5/pom.xml
@@ -0,0 +1,72 @@
+
+
+
+ 4.0.0
+
+ org.codehaus.modello.its
+ clone
+ 0.1-SNAPSHOT
+
+ Clone IT
+
+ Test the generation of clone() methods.
+
+
+
+
+ org.codehaus.plexus
+ plexus-utils
+ @plexusUtilsVersion@
+
+
+ junit
+ junit
+ @junitVersion@
+
+
+
+
+ test
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+ 1.5
+ 1.5
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.4.3
+
+
+ org.codehaus.modello
+ modello-maven-plugin
+ @project.version@
+
+ 1.0.0
+ true
+
+ src/main/mdo/thing.mdo
+
+
+
+
+ standard
+
+ java
+
+
+
+
+
+
+
diff --git a/modello-maven-plugin/src/it/clone-java5/src/main/mdo/thing.mdo b/modello-maven-plugin/src/it/clone-java5/src/main/mdo/thing.mdo
new file mode 100644
index 000000000..aa8a806d2
--- /dev/null
+++ b/modello-maven-plugin/src/it/clone-java5/src/main/mdo/thing.mdo
@@ -0,0 +1,203 @@
+
+
+
+ thing
+ Thing
+
+
+ package
+ test
+
+
+
+
+
+ SuperThing
+ 1.0.0
+
+
+ Thing
+ SuperThing
+ 1.0.0
+
+
+
+ someBoolean
+ 1.0.0
+ boolean
+
+
+ someChar
+ 1.0.0
+ char
+
+
+ someByte
+ 1.0.0
+ byte
+
+
+ someShort
+ 1.0.0
+ short
+
+
+ someInt
+ 1.0.0
+ int
+
+
+ someLong
+ 1.0.0
+ long
+
+
+ someFloat
+ 1.0.0
+ float
+
+
+ someDouble
+ 1.0.0
+ double
+
+
+ someString
+ 1.0.0
+ String
+
+
+ someDate
+ 1.0.0
+ Date
+
+
+ someDom
+ 1.0.0
+ DOM
+
+
+
+ someProperties
+ 1.0.0
+ Properties
+
+ String
+ *
+
+
+
+ someStringList
+ 1.0.0
+ List
+
+ String
+ *
+
+
+
+ someStringSet
+ 1.0.0
+ Set
+
+ String
+ *
+
+
+
+
+ deepThingy
+ 1.0.0
+
+ Thingy
+ 1
+
+
+
+ deepThingyList
+ 1.0.0
+ List
+
+ Thingy
+ *
+
+
+
+ deepThingySet
+ 1.0.0
+ Set
+
+ Thingy
+ *
+
+
+
+
+ shallowThingy
+ 1.0.0
+
+ Thingy
+ 1
+
+
+
+ shallowThingyList
+ 1.0.0
+ List
+
+ Thingy
+ *
+
+
+
+ shallowThingySet
+ 1.0.0
+ Set
+
+ Thingy
+ *
+
+
+
+
+
+ 1.0.0
+
+
+
+
+
+
+ Thingy
+ SuperThing
+ 1.0.0
+
+
+
diff --git a/modello-maven-plugin/src/it/clone-java5/src/test/java/test/CloneTest.java b/modello-maven-plugin/src/it/clone-java5/src/test/java/test/CloneTest.java
new file mode 100644
index 000000000..15d2f0e15
--- /dev/null
+++ b/modello-maven-plugin/src/it/clone-java5/src/test/java/test/CloneTest.java
@@ -0,0 +1,92 @@
+package test;
+
+import java.util.Date;
+
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+import junit.framework.TestCase;
+
+public class CloneTest
+ extends TestCase
+{
+
+ public void testNullSafe()
+ throws Exception
+ {
+ Thing orig = new Thing();
+
+ Thing copy = (Thing) orig.clone();
+
+ assertNotNull( copy );
+ assertNotSame( orig, copy );
+ }
+
+ public void testClone()
+ throws Exception
+ {
+ Thing orig = new Thing();
+ orig.setSomeBoolean( true );
+ orig.setSomeChar( 'X' );
+ orig.setSomeByte( (byte) 7 );
+ orig.setSomeShort( (short) 11 );
+ orig.setSomeInt( 13 );
+ orig.setSomeLong( 17 );
+ orig.setSomeFloat( -2.5f );
+ orig.setSomeDouble( 3.14 );
+ orig.setSomeString( "test" );
+ orig.setSomeDate( new Date() );
+ orig.setSomeDom( new Xpp3Dom( "test" ) );
+ orig.addSomeStringList( "string" );
+ orig.addSomeStringSet( "string" );
+ orig.setDeepThingy( new Thingy() );
+ orig.addDeepThingyList( new Thingy() );
+ orig.addDeepThingySet( new Thingy() );
+ orig.setShallowThingy( new Thingy() );
+ orig.addShallowThingyList( new Thingy() );
+ orig.addShallowThingySet( new Thingy() );
+ orig.addSomeProperty( "key", "value" );
+ orig.customProperties.setProperty( "key", "value" );
+
+ // NOTE: This has no cast and checks for covariant return value
+ Thing copy = orig.clone();
+
+ assertNotNull( copy );
+ assertNotSame( orig, copy );
+
+ assertEquals( orig.isSomeBoolean(), copy.isSomeBoolean() );
+ assertEquals( orig.getSomeChar(), copy.getSomeChar() );
+ assertEquals( orig.getSomeByte(), copy.getSomeByte() );
+ assertEquals( orig.getSomeShort(), copy.getSomeShort() );
+ assertEquals( orig.getSomeInt(), copy.getSomeInt() );
+ assertEquals( orig.getSomeLong(), copy.getSomeLong() );
+ assertEquals( orig.getSomeFloat(), copy.getSomeFloat(), 0.1 );
+ assertEquals( orig.getSomeDouble(), copy.getSomeDouble(), 0.1 );
+ assertEquals( orig.getSomeString(), copy.getSomeString() );
+
+ assertEquals( orig.getSomeDate(), copy.getSomeDate() );
+ assertNotSame( orig.getSomeDate(), copy.getSomeDate() );
+ assertEquals( orig.getSomeDom(), copy.getSomeDom() );
+ assertNotSame( orig.getSomeDom(), copy.getSomeDom() );
+
+ assertEquals( orig.getSomeStringList(), copy.getSomeStringList() );
+ assertNotSame( orig.getSomeStringList(), copy.getSomeStringList() );
+ assertEquals( orig.getSomeStringSet(), copy.getSomeStringSet() );
+ assertNotSame( orig.getSomeStringSet(), copy.getSomeStringSet() );
+
+ assertNotSame( orig.getDeepThingy(), copy.getDeepThingy() );
+ assertNotSame( orig.getDeepThingyList(), copy.getDeepThingyList() );
+ assertNotSame( orig.getDeepThingyList().iterator().next(), copy.getDeepThingyList().iterator().next() );
+ assertNotSame( orig.getDeepThingySet(), copy.getDeepThingySet() );
+ assertNotSame( orig.getDeepThingySet().iterator().next(), copy.getDeepThingySet().iterator().next() );
+
+ assertSame( orig.getShallowThingy(), copy.getShallowThingy() );
+ assertNotSame( orig.getShallowThingyList(), copy.getShallowThingyList() );
+ assertSame( orig.getShallowThingyList().iterator().next(), copy.getShallowThingyList().iterator().next() );
+ assertNotSame( orig.getShallowThingySet(), copy.getShallowThingySet() );
+ assertSame( orig.getShallowThingySet().iterator().next(), copy.getShallowThingySet().iterator().next() );
+
+ assertEquals( orig.customProperties, copy.customProperties );
+ assertNotSame( orig.customProperties, copy.customProperties );
+ }
+
+}
diff --git a/modello-maven-plugin/src/it/clone/pom.xml b/modello-maven-plugin/src/it/clone/pom.xml
new file mode 100644
index 000000000..e3e73755d
--- /dev/null
+++ b/modello-maven-plugin/src/it/clone/pom.xml
@@ -0,0 +1,71 @@
+
+
+
+ 4.0.0
+
+ org.codehaus.modello.its
+ clone
+ 0.1-SNAPSHOT
+
+ Clone IT
+
+ Test the generation of clone() methods.
+
+
+
+
+ org.codehaus.plexus
+ plexus-utils
+ @plexusUtilsVersion@
+
+
+ junit
+ junit
+ @junitVersion@
+
+
+
+
+ test
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+ 1.4
+ 1.4
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.4.3
+
+
+ org.codehaus.modello
+ modello-maven-plugin
+ @project.version@
+
+ 1.0.0
+
+ src/main/mdo/thing.mdo
+
+
+
+
+ standard
+
+ java
+
+
+
+
+
+
+
diff --git a/modello-maven-plugin/src/it/clone/src/main/mdo/thing.mdo b/modello-maven-plugin/src/it/clone/src/main/mdo/thing.mdo
new file mode 100644
index 000000000..aa8a806d2
--- /dev/null
+++ b/modello-maven-plugin/src/it/clone/src/main/mdo/thing.mdo
@@ -0,0 +1,203 @@
+
+
+
+ thing
+ Thing
+
+
+ package
+ test
+
+
+
+
+
+ SuperThing
+ 1.0.0
+
+
+ Thing
+ SuperThing
+ 1.0.0
+
+
+
+ someBoolean
+ 1.0.0
+ boolean
+
+
+ someChar
+ 1.0.0
+ char
+
+
+ someByte
+ 1.0.0
+ byte
+
+
+ someShort
+ 1.0.0
+ short
+
+
+ someInt
+ 1.0.0
+ int
+
+
+ someLong
+ 1.0.0
+ long
+
+
+ someFloat
+ 1.0.0
+ float
+
+
+ someDouble
+ 1.0.0
+ double
+
+
+ someString
+ 1.0.0
+ String
+
+
+ someDate
+ 1.0.0
+ Date
+
+
+ someDom
+ 1.0.0
+ DOM
+
+
+
+ someProperties
+ 1.0.0
+ Properties
+
+ String
+ *
+
+
+
+ someStringList
+ 1.0.0
+ List
+
+ String
+ *
+
+
+
+ someStringSet
+ 1.0.0
+ Set
+
+ String
+ *
+
+
+
+
+ deepThingy
+ 1.0.0
+
+ Thingy
+ 1
+
+
+
+ deepThingyList
+ 1.0.0
+ List
+
+ Thingy
+ *
+
+
+
+ deepThingySet
+ 1.0.0
+ Set
+
+ Thingy
+ *
+
+
+
+
+ shallowThingy
+ 1.0.0
+
+ Thingy
+ 1
+
+
+
+ shallowThingyList
+ 1.0.0
+ List
+
+ Thingy
+ *
+
+
+
+ shallowThingySet
+ 1.0.0
+ Set
+
+ Thingy
+ *
+
+
+
+
+
+ 1.0.0
+
+
+
+
+
+
+ Thingy
+ SuperThing
+ 1.0.0
+
+
+
diff --git a/modello-maven-plugin/src/it/clone/src/test/java/test/CloneTest.java b/modello-maven-plugin/src/it/clone/src/test/java/test/CloneTest.java
new file mode 100644
index 000000000..41f8e167c
--- /dev/null
+++ b/modello-maven-plugin/src/it/clone/src/test/java/test/CloneTest.java
@@ -0,0 +1,91 @@
+package test;
+
+import java.util.Date;
+
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+import junit.framework.TestCase;
+
+public class CloneTest
+ extends TestCase
+{
+
+ public void testNullSafe()
+ throws Exception
+ {
+ Thing orig = new Thing();
+
+ Thing copy = (Thing) orig.clone();
+
+ assertNotNull( copy );
+ assertNotSame( orig, copy );
+ }
+
+ public void testClone()
+ throws Exception
+ {
+ Thing orig = new Thing();
+ orig.setSomeBoolean( true );
+ orig.setSomeChar( 'X' );
+ orig.setSomeByte( (byte) 7 );
+ orig.setSomeShort( (short) 11 );
+ orig.setSomeInt( 13 );
+ orig.setSomeLong( 17 );
+ orig.setSomeFloat( -2.5f );
+ orig.setSomeDouble( 3.14 );
+ orig.setSomeString( "test" );
+ orig.setSomeDate( new Date() );
+ orig.setSomeDom( new Xpp3Dom( "test" ) );
+ orig.addSomeStringList( "string" );
+ orig.addSomeStringSet( "string" );
+ orig.setDeepThingy( new Thingy() );
+ orig.addDeepThingyList( new Thingy() );
+ orig.addDeepThingySet( new Thingy() );
+ orig.setShallowThingy( new Thingy() );
+ orig.addShallowThingyList( new Thingy() );
+ orig.addShallowThingySet( new Thingy() );
+ orig.addSomeProperty( "key", "value" );
+ orig.customProperties.setProperty( "key", "value" );
+
+ Thing copy = (Thing) orig.clone();
+
+ assertNotNull( copy );
+ assertNotSame( orig, copy );
+
+ assertEquals( orig.isSomeBoolean(), copy.isSomeBoolean() );
+ assertEquals( orig.getSomeChar(), copy.getSomeChar() );
+ assertEquals( orig.getSomeByte(), copy.getSomeByte() );
+ assertEquals( orig.getSomeShort(), copy.getSomeShort() );
+ assertEquals( orig.getSomeInt(), copy.getSomeInt() );
+ assertEquals( orig.getSomeLong(), copy.getSomeLong() );
+ assertEquals( orig.getSomeFloat(), copy.getSomeFloat(), 0.1 );
+ assertEquals( orig.getSomeDouble(), copy.getSomeDouble(), 0.1 );
+ assertEquals( orig.getSomeString(), copy.getSomeString() );
+
+ assertEquals( orig.getSomeDate(), copy.getSomeDate() );
+ assertNotSame( orig.getSomeDate(), copy.getSomeDate() );
+ assertEquals( orig.getSomeDom(), copy.getSomeDom() );
+ assertNotSame( orig.getSomeDom(), copy.getSomeDom() );
+
+ assertEquals( orig.getSomeStringList(), copy.getSomeStringList() );
+ assertNotSame( orig.getSomeStringList(), copy.getSomeStringList() );
+ assertEquals( orig.getSomeStringSet(), copy.getSomeStringSet() );
+ assertNotSame( orig.getSomeStringSet(), copy.getSomeStringSet() );
+
+ assertNotSame( orig.getDeepThingy(), copy.getDeepThingy() );
+ assertNotSame( orig.getDeepThingyList(), copy.getDeepThingyList() );
+ assertNotSame( orig.getDeepThingyList().iterator().next(), copy.getDeepThingyList().iterator().next() );
+ assertNotSame( orig.getDeepThingySet(), copy.getDeepThingySet() );
+ assertNotSame( orig.getDeepThingySet().iterator().next(), copy.getDeepThingySet().iterator().next() );
+
+ assertSame( orig.getShallowThingy(), copy.getShallowThingy() );
+ assertNotSame( orig.getShallowThingyList(), copy.getShallowThingyList() );
+ assertSame( orig.getShallowThingyList().iterator().next(), copy.getShallowThingyList().iterator().next() );
+ assertNotSame( orig.getShallowThingySet(), copy.getShallowThingySet() );
+ assertSame( orig.getShallowThingySet().iterator().next(), copy.getShallowThingySet().iterator().next() );
+
+ assertEquals( orig.customProperties, copy.customProperties );
+ assertNotSame( orig.customProperties, copy.customProperties );
+ }
+
+}
diff --git a/modello-maven-plugin/src/it/settings.xml b/modello-maven-plugin/src/it/settings.xml
new file mode 100644
index 000000000..c8f77f0b7
--- /dev/null
+++ b/modello-maven-plugin/src/it/settings.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+ it-repo
+
+ true
+
+
+
+ local.central
+ @localRepositoryUrl@
+
+ true
+
+
+ true
+
+
+
+
+
+ local.central
+ @localRepositoryUrl@
+
+ true
+
+
+ true
+
+
+
+
+
+
diff --git a/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jReaderMojo.java b/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jReaderMojo.java
index cfb4b3f17..ce2833dc0 100644
--- a/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jReaderMojo.java
+++ b/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jReaderMojo.java
@@ -5,7 +5,7 @@
/**
* Creates a DOM4J reader from the model.
*
- * @version $Id:$
+ * @version $Id$
* @goal dom4j-reader
* @phase generate-sources
*/
diff --git a/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jWriterMojo.java b/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jWriterMojo.java
index b67cd27e8..47b7ce9ff 100644
--- a/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jWriterMojo.java
+++ b/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloDom4jWriterMojo.java
@@ -5,7 +5,7 @@
/**
* Creates a DOM4J writer from the model.
*
- * @version $Id:$
+ * @version $Id$
* @goal dom4j-writer
* @phase generate-sources
*/
diff --git a/modello-plugins/modello-plugin-converters/pom.xml b/modello-plugins/modello-plugin-converters/pom.xml
index 7c3b81fcb..9be1e7469 100644
--- a/modello-plugins/modello-plugin-converters/pom.xml
+++ b/modello-plugins/modello-plugin-converters/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-dom4j/pom.xml b/modello-plugins/modello-plugin-dom4j/pom.xml
index 107a4e611..d355623a9 100644
--- a/modello-plugins/modello-plugin-dom4j/pom.xml
+++ b/modello-plugins/modello-plugin-dom4j/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-dom4j/src/test/verifiers/features/Dom4jFeaturesVerifier.java b/modello-plugins/modello-plugin-dom4j/src/test/verifiers/features/Dom4jFeaturesVerifier.java
index ecdd2c40f..49faf6b2a 100644
--- a/modello-plugins/modello-plugin-dom4j/src/test/verifiers/features/Dom4jFeaturesVerifier.java
+++ b/modello-plugins/modello-plugin-dom4j/src/test/verifiers/features/Dom4jFeaturesVerifier.java
@@ -42,7 +42,7 @@
import java.io.StringWriter;
/**
- * @author Hervé Boutemy
+ * @author Herve Boutemy
* @version $Id$
*/
public class Dom4jFeaturesVerifier
diff --git a/modello-plugins/modello-plugin-java/pom.xml b/modello-plugins/modello-plugin-java/pom.xml
index 93bb00e07..3c8327777 100644
--- a/modello-plugins/modello-plugin-java/pom.xml
+++ b/modello-plugins/modello-plugin-java/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java
index 5834282b1..5d28b1adf 100644
--- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java
+++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java
@@ -50,6 +50,9 @@
import java.io.IOException;
import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@@ -61,6 +64,11 @@
public class JavaModelloGenerator
extends AbstractJavaModelloGenerator
{
+
+ private Collection immutableTypes =
+ new HashSet( Arrays.asList( new String[] { "boolean", "Boolean", "byte", "Byte", "char", "Character", "short",
+ "Short", "int", "Integer", "long", "Long", "float", "Float", "double", "Double", "String" } ) );
+
public void generate( Model model, Properties parameters )
throws ModelloException
{
@@ -227,6 +235,13 @@ private void generateJava()
jClass.addMethod( toString );
}
+ JMethod[] cloneMethods = generateClone( modelClass );
+ if ( cloneMethods.length > 0 )
+ {
+ jClass.addInterface( Cloneable.class.getName() );
+ jClass.addMethods( cloneMethods );
+ }
+
if ( modelClass.getCodeSegments( getGeneratedVersion() ) != null )
{
for ( Iterator iterator = modelClass.getCodeSegments( getGeneratedVersion() ).iterator();
@@ -419,6 +434,239 @@ private JMethod generateHashCode( ModelClass modelClass )
return hashCode;
}
+ private JMethod[] generateClone( ModelClass modelClass )
+ throws ModelloException
+ {
+ String cloneModeClass = getCloneMode( modelClass );
+
+ if ( JavaClassMetadata.CLONE_NONE.equals( cloneModeClass ) )
+ {
+ return new JMethod[0];
+ }
+
+ JType returnType;
+ if ( useJava5 )
+ {
+ returnType = new JClass( modelClass.getName() );
+ }
+ else
+ {
+ returnType = new JClass( "Object" );
+ }
+
+ JMethod cloneMethod = new JMethod( "clone", returnType, null );
+
+ JSourceCode sc = cloneMethod.getSourceCode();
+
+ sc.add( "try" );
+ sc.add( "{" );
+ sc.indent();
+
+ sc.add( modelClass.getName() + " copy = (" + modelClass.getName() + ") super.clone();" );
+
+ sc.add( "" );
+
+ for ( Iterator j = modelClass.getFields( getGeneratedVersion() ).iterator(); j.hasNext(); )
+ {
+ ModelField modelField = (ModelField) j.next();
+
+ String thisField = "this." + modelField.getName();
+ String copyField = "copy." + modelField.getName();
+
+ if ( "DOM".equals( modelField.getType() ) )
+ {
+ sc.add( "if ( " + thisField + " != null )" );
+ sc.add( "{" );
+ sc.addIndented( copyField
+ + " = new org.codehaus.plexus.util.xml.Xpp3Dom( (org.codehaus.plexus.util.xml.Xpp3Dom) "
+ + thisField + " );" );
+ sc.add( "}" );
+ sc.add( "" );
+ }
+ else if ( "Date".equalsIgnoreCase( modelField.getType() ) || "java.util.Date".equals( modelField.getType() ) )
+ {
+ sc.add( "if ( " + thisField + " != null )" );
+ sc.add( "{" );
+ sc.addIndented( copyField + " = (java.util.Date) " + thisField + ".clone();" );
+ sc.add( "}" );
+ sc.add( "" );
+ }
+ else if ( ModelDefault.PROPERTIES.equals( modelField.getType() ) )
+ {
+ sc.add( "if ( " + thisField + " != null )" );
+ sc.add( "{" );
+ sc.addIndented( copyField + " = (" + ModelDefault.PROPERTIES + ") " + thisField + ".clone();" );
+ sc.add( "}" );
+ sc.add( "" );
+ }
+ else if ( modelField instanceof ModelAssociation )
+ {
+ ModelAssociation modelAssociation = (ModelAssociation) modelField;
+
+ String cloneModeAssoc = getCloneMode( modelAssociation, cloneModeClass );
+
+ boolean deepClone =
+ JavaAssociationMetadata.CLONE_DEEP.equals( cloneModeAssoc )
+ && !immutableTypes.contains( modelAssociation.getTo() );
+
+ if ( modelAssociation.isOneMultiplicity() )
+ {
+ if ( deepClone )
+ {
+ sc.add( "if ( " + thisField + " != null )" );
+ sc.add( "{" );
+ sc.addIndented( copyField + " = (" + modelAssociation.getTo() + ") " + thisField + ".clone();" );
+ sc.add( "}" );
+ sc.add( "" );
+ }
+ }
+ else
+ {
+ sc.add( "if ( " + thisField + " != null )" );
+ sc.add( "{" );
+ sc.indent();
+ sc.add( copyField + " = " + getDefaultValue( modelAssociation ) + ";" );
+
+ if ( isCollection( modelField.getType() ) )
+ {
+ if ( deepClone )
+ {
+ if ( useJava5 )
+ {
+ sc.add( "for ( " + modelAssociation.getTo() + " item : " + thisField + " )" );
+ }
+ else
+ {
+ sc.add( "for ( java.util.Iterator it = " + thisField + ".iterator(); it.hasNext(); )" );
+ }
+ sc.add( "{" );
+ sc.indent();
+ if ( useJava5 )
+ {
+ sc.add( copyField + ".add( item.clone() );" );
+ }
+ else
+ {
+ sc.add( copyField + ".add( ( (" + modelAssociation.getTo() + ") it.next() ).clone() );" );
+ }
+ sc.unindent();
+ sc.add( "}" );
+ }
+ else
+ {
+ sc.add( copyField + ".addAll( " + thisField + " );" );
+ }
+ }
+ else if ( isMap( modelField.getType() ) )
+ {
+ sc.add( copyField + ".clear();" );
+ sc.add( copyField + ".putAll( " + thisField + " );" );
+ }
+
+ sc.unindent();
+ sc.add( "}" );
+ sc.add( "" );
+ }
+ }
+ }
+
+ String cloneHook = getCloneHook( modelClass );
+
+ if ( StringUtils.isNotEmpty( cloneHook ) && !"false".equalsIgnoreCase( cloneHook ) )
+ {
+ if ( "true".equalsIgnoreCase( cloneHook ) )
+ {
+ cloneHook = "cloneHook";
+ }
+
+ sc.add( cloneHook + "( copy );" );
+ sc.add( "" );
+ }
+
+ sc.add( "return copy;" );
+
+ sc.unindent();
+ sc.add( "}" );
+ sc.add( "catch ( " + Exception.class.getName() + " ex )" );
+ sc.add( "{" );
+ sc.indent();
+ sc.add( "throw (" + RuntimeException.class.getName() + ") new " + UnsupportedOperationException.class.getName()
+ + "( getClass().getName()" );
+ sc.addIndented( "+ \" does not support clone()\" ).initCause( ex );" );
+ sc.unindent();
+ sc.add( "}" );
+
+ return new JMethod[] { cloneMethod };
+ }
+
+ private String getCloneMode( ModelClass modelClass )
+ throws ModelloException
+ {
+ String cloneMode = null;
+
+ for ( ModelClass currentClass = modelClass;; )
+ {
+ JavaClassMetadata javaClassMetadata = (JavaClassMetadata) currentClass.getMetadata( JavaClassMetadata.ID );
+
+ cloneMode = javaClassMetadata.getCloneMode();
+
+ if ( cloneMode != null )
+ {
+ break;
+ }
+
+ String superClass = currentClass.getSuperClass();
+ if ( StringUtils.isEmpty( superClass ) || !isClassInModel( superClass, getModel() ) )
+ {
+ break;
+ }
+
+ currentClass = getModel().getClass( superClass, getGeneratedVersion() );
+ }
+
+ if ( cloneMode == null )
+ {
+ cloneMode = JavaClassMetadata.CLONE_NONE;
+ }
+ else if ( !JavaClassMetadata.CLONE_MODES.contains( cloneMode ) )
+ {
+ throw new ModelloException( "The Java Modello Generator cannot use '" + cloneMode
+ + "' as a value for , " + "only the following values are acceptable "
+ + JavaClassMetadata.CLONE_MODES );
+ }
+
+ return cloneMode;
+ }
+
+ private String getCloneMode( ModelAssociation modelAssociation, String cloneModeClass )
+ throws ModelloException
+ {
+ JavaAssociationMetadata javaAssociationMetadata =
+ (JavaAssociationMetadata) modelAssociation.getAssociationMetadata( JavaAssociationMetadata.ID );
+
+ String cloneModeAssoc = javaAssociationMetadata.getCloneMode();
+ if ( cloneModeAssoc == null )
+ {
+ cloneModeAssoc = cloneModeClass;
+ }
+ else if ( !JavaAssociationMetadata.CLONE_MODES.contains( cloneModeAssoc ) )
+ {
+ throw new ModelloException( "The Java Modello Generator cannot use '" + cloneModeAssoc
+ + "' as a value for , " + "only the following values are acceptable "
+ + JavaAssociationMetadata.CLONE_MODES );
+ }
+
+ return cloneModeAssoc;
+ }
+
+ private String getCloneHook( ModelClass modelClass )
+ throws ModelloException
+ {
+ JavaClassMetadata javaClassMetadata = (JavaClassMetadata) modelClass.getMetadata( JavaClassMetadata.ID );
+
+ return javaClassMetadata.getCloneHook();
+ }
+
/**
* Utility method that adds a period to the end of a string, if the last
* non-whitespace character of the string is not a punctuation mark or an
diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.java
index 9939f8582..fbfee977d 100644
--- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.java
+++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.java
@@ -50,6 +50,18 @@ public class JavaAssociationMetadata
INIT_TYPES.add( FIELD_INIT );
}
+ public static final String CLONE_SHALLOW = "shallow";
+ public static final String CLONE_DEEP = "deep";
+
+ public final static List CLONE_MODES;
+
+ static
+ {
+ CLONE_MODES = new ArrayList();
+ CLONE_MODES.add( CLONE_SHALLOW );
+ CLONE_MODES.add( CLONE_DEEP );
+ }
+
private boolean adder = true;
private boolean bidi;
@@ -58,6 +70,8 @@ public class JavaAssociationMetadata
private String initializationMode;
+ private String cloneMode;
+
public boolean isAdder()
{
return adder;
@@ -104,4 +118,15 @@ public void setInitializationMode( String initializationMode )
this.initializationMode = initializationMode;
}
}
+
+ public String getCloneMode()
+ {
+ return cloneMode;
+ }
+
+ public void setCloneMode( String cloneMode )
+ {
+ this.cloneMode = cloneMode;
+ }
+
}
diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.java
index 98cbef8a4..ca1632712 100644
--- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.java
+++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.java
@@ -22,6 +22,9 @@
* SOFTWARE.
*/
+import java.util.ArrayList;
+import java.util.List;
+
import org.codehaus.modello.metadata.ClassMetadata;
/**
@@ -33,10 +36,28 @@ public class JavaClassMetadata
{
public static final String ID = JavaClassMetadata.class.getName();
+ public static final String CLONE_NONE = "none";
+ public static final String CLONE_SHALLOW = "shallow";
+ public static final String CLONE_DEEP = "deep";
+
+ public final static List CLONE_MODES;
+
+ static
+ {
+ CLONE_MODES = new ArrayList();
+ CLONE_MODES.add( CLONE_NONE );
+ CLONE_MODES.add( CLONE_SHALLOW );
+ CLONE_MODES.add( CLONE_DEEP );
+ }
+
private boolean abstractMode;
private boolean enabled;
+ private String cloneMode;
+
+ private String cloneHook;
+
public void setAbstract( boolean abstractMode )
{
this.abstractMode = abstractMode;
@@ -56,4 +77,25 @@ public void setEnabled( boolean generate )
{
this.enabled = generate;
}
+
+ public String getCloneMode()
+ {
+ return cloneMode;
+ }
+
+ public void setCloneMode( String cloneMode )
+ {
+ this.cloneMode = cloneMode;
+ }
+
+ public String getCloneHook()
+ {
+ return cloneHook;
+ }
+
+ public void setCloneHook( String cloneHook )
+ {
+ this.cloneHook = cloneHook;
+ }
+
}
diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaMetadataPlugin.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaMetadataPlugin.java
index 4da5e4542..1658ea182 100644
--- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaMetadataPlugin.java
+++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaMetadataPlugin.java
@@ -59,6 +59,10 @@ public class JavaMetadataPlugin
public static final String JAVA_USE_INTERFACE = "java.useInterface";
+ public static final String JAVA_CLONE = "java.clone";
+
+ public static final String JAVA_CLONE_HOOK = "java.clone.hook";
+
// ----------------------------------------------------------------------
// Map to Metadata
// ----------------------------------------------------------------------
@@ -76,6 +80,10 @@ public ClassMetadata getClassMetadata( ModelClass clazz, Map data )
metadata.setAbstract( getBoolean( data, JAVA_ABSTRACT, false ) );
+ metadata.setCloneMode( getString( data, JAVA_CLONE ) );
+
+ metadata.setCloneHook( getString( data, JAVA_CLONE_HOOK ) );
+
return metadata;
}
@@ -83,7 +91,7 @@ public FieldMetadata getFieldMetadata( ModelField field, Map data )
{
JavaFieldMetadata metadata = new JavaFieldMetadata();
- metadata.setSetter( getBoolean( data, JAVA_GETTER, true ) );
+ metadata.setGetter( getBoolean( data, JAVA_GETTER, true ) );
String fieldType = field.getType();
metadata.setBooleanGetter( ( fieldType != null ) && fieldType.endsWith( "oolean" ) );
@@ -105,6 +113,8 @@ public AssociationMetadata getAssociationMetadata( ModelAssociation association,
metadata.setInitializationMode( getString( data, JAVA_INIT ) );
+ metadata.setCloneMode( getString( data, JAVA_CLONE ) );
+
return metadata;
}
}
diff --git a/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/FeaturesJava5GeneratorTest.java b/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/FeaturesJava5GeneratorTest.java
new file mode 100644
index 000000000..e38820714
--- /dev/null
+++ b/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/FeaturesJava5GeneratorTest.java
@@ -0,0 +1,74 @@
+package org.codehaus.modello.plugin.java;
+
+/*
+ * Copyright (c) 2004, Codehaus.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import org.codehaus.modello.AbstractModelloJavaGeneratorTest;
+import org.codehaus.modello.ModelloParameterConstants;
+import org.codehaus.modello.core.ModelloCore;
+import org.codehaus.modello.model.Model;
+
+import java.util.Properties;
+
+/**
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class FeaturesJava5GeneratorTest
+ extends AbstractModelloJavaGeneratorTest
+{
+
+ public FeaturesJava5GeneratorTest()
+ {
+ super( "features" );
+ }
+
+ public void testJavaGenerator()
+ throws Throwable
+ {
+ String javaVersion = System.getProperty( "java.specification.version", "1.5" );
+
+ if ( "1.5".compareTo( javaVersion ) > 0 )
+ {
+ System.out.println( "Skipped Java 5 feature test, not supported by current test environment ("
+ + javaVersion + ")" );
+ return;
+ }
+
+ ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE );
+
+ Properties parameters = new Properties();
+ parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() );
+ parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) );
+ parameters.setProperty( ModelloParameterConstants.VERSION, "2.0.0" );
+ parameters.setProperty( ModelloParameterConstants.USE_JAVA5, Boolean.toString( true ) );
+
+ Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) );
+
+ modello.generate( model, "java", parameters );
+
+ compile( getOutputDirectory(), getOutputClasses(), true );
+
+ verify( "JavaVerifier", "java" );
+ }
+
+}
diff --git a/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/JavaVerifier.java b/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/JavaVerifier.java
index 71cd955cc..8405ed0e4 100644
--- a/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/JavaVerifier.java
+++ b/modello-plugins/modello-plugin-java/src/test/verifiers/features-version/JavaVerifier.java
@@ -26,7 +26,7 @@
import junit.framework.Assert;
/**
- * @author Hervé Boutemy
+ * @author Herve Boutemy
* @version $Id$
*/
public class JavaVerifier
diff --git a/modello-plugins/modello-plugin-java/src/test/verifiers/features/JavaVerifier.java b/modello-plugins/modello-plugin-java/src/test/verifiers/features/JavaVerifier.java
index 6ed97e8a7..a434d2600 100644
--- a/modello-plugins/modello-plugin-java/src/test/verifiers/features/JavaVerifier.java
+++ b/modello-plugins/modello-plugin-java/src/test/verifiers/features/JavaVerifier.java
@@ -39,10 +39,14 @@
import org.codehaus.modello.test.features.SubClassLevel2;
import org.codehaus.modello.test.features.SubClassLevel3;
import org.codehaus.modello.test.features.SubInterface;
+import org.codehaus.modello.test.features.Thing;
+import org.codehaus.modello.test.features.Thingy;
import org.codehaus.modello.test.features.XmlAttributes;
import org.codehaus.modello.test.features.XmlFeatures;
import org.codehaus.modello.test.features.other.SubInterfaceInPackage;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -56,7 +60,7 @@
import junit.framework.Assert;
/**
- * @author Hervé Boutemy
+ * @author Herve Boutemy
* @version $Id$
*/
public class JavaVerifier
@@ -83,6 +87,8 @@ public void verify()
verifyInterfaces();
verifyMisc();
+
+ verifyClone();
}
/**
@@ -103,7 +109,7 @@ private void checkField( Class clazz, String attributeName, Class type, String g
Assert.assertEquals( attributeName + " attribute type", type, field.getType() );
Assert.assertTrue( attributeName + " attribute should be private", Modifier.isPrivate( field.getModifiers() ) );
- Method getter = clazz.getMethod( getterName, null );
+ Method getter = clazz.getMethod( getterName, (Class[]) null );
Assert.assertNotNull( getterName + "() method", getter );
Assert.assertEquals( getterName + "() method return type", type, getter.getReturnType() );
Assert.assertTrue( getterName + "() method should be public", Modifier.isPublic( getter.getModifiers() ) );
@@ -338,4 +344,91 @@ public void verifyMisc()
throw new VerifierException( "java.util.Properties model default value was ignored" );
}
}
+
+ /**
+ * Verify generated clone() methods.
+ */
+ public void verifyClone()
+ {
+ checkCloneNullSafe();
+
+ checkClone();
+ }
+
+ private void checkCloneNullSafe()
+ {
+ Thing orig = new Thing();
+
+ Thing copy = (Thing) orig.clone();
+
+ assertNotNull( copy );
+ assertNotSame( orig, copy );
+ }
+
+ private void checkClone()
+ {
+ Thing orig = new Thing();
+ orig.setSomeBoolean( true );
+ orig.setSomeChar( 'X' );
+ orig.setSomeByte( (byte) 7 );
+ orig.setSomeShort( (short) 11 );
+ orig.setSomeInt( 13 );
+ orig.setSomeLong( 17 );
+ orig.setSomeFloat( -2.5f );
+ orig.setSomeDouble( 3.14 );
+ orig.setSomeString( "test" );
+ orig.setSomeDate( new Date() );
+ orig.setSomeDom( new Xpp3Dom( "test" ) );
+ orig.addSomeStringList( "string" );
+ orig.addSomeStringSet( "string" );
+ orig.setDeepThingy( new Thingy() );
+ orig.addDeepThingyList( new Thingy() );
+ orig.addDeepThingySet( new Thingy() );
+ orig.setShallowThingy( new Thingy() );
+ orig.addShallowThingyList( new Thingy() );
+ orig.addShallowThingySet( new Thingy() );
+ orig.addSomeProperty( "key", "value" );
+ orig.customProperties.setProperty( "key", "value" );
+
+ Thing copy = (Thing) orig.clone();
+
+ assertNotNull( copy );
+ assertNotSame( orig, copy );
+
+ assertEquals( orig.isSomeBoolean(), copy.isSomeBoolean() );
+ assertEquals( orig.getSomeChar(), copy.getSomeChar() );
+ assertEquals( orig.getSomeByte(), copy.getSomeByte() );
+ assertEquals( orig.getSomeShort(), copy.getSomeShort() );
+ assertEquals( orig.getSomeInt(), copy.getSomeInt() );
+ assertEquals( orig.getSomeLong(), copy.getSomeLong() );
+ assertEquals( orig.getSomeFloat(), copy.getSomeFloat(), 0.1 );
+ assertEquals( orig.getSomeDouble(), copy.getSomeDouble(), 0.1 );
+ assertEquals( orig.getSomeString(), copy.getSomeString() );
+
+ assertEquals( orig.getSomeDate(), copy.getSomeDate() );
+ assertNotSame( orig.getSomeDate(), copy.getSomeDate() );
+ assertEquals( orig.getSomeDom(), copy.getSomeDom() );
+ assertNotSame( orig.getSomeDom(), copy.getSomeDom() );
+
+ assertEquals( orig.getSomeStringList(), copy.getSomeStringList() );
+ assertNotSame( orig.getSomeStringList(), copy.getSomeStringList() );
+ assertEquals( orig.getSomeStringSet(), copy.getSomeStringSet() );
+ assertNotSame( orig.getSomeStringSet(), copy.getSomeStringSet() );
+
+ assertNotSame( orig.getDeepThingy(), copy.getDeepThingy() );
+ assertNotSame( orig.getDeepThingyList(), copy.getDeepThingyList() );
+ assertNotSame( orig.getDeepThingyList().iterator().next(), copy.getDeepThingyList().iterator().next() );
+ assertNotSame( orig.getDeepThingySet(), copy.getDeepThingySet() );
+ assertNotSame( orig.getDeepThingySet().iterator().next(), copy.getDeepThingySet().iterator().next() );
+
+ assertSame( orig.getShallowThingy(), copy.getShallowThingy() );
+ assertNotSame( orig.getShallowThingyList(), copy.getShallowThingyList() );
+ assertSame( orig.getShallowThingyList().iterator().next(), copy.getShallowThingyList().iterator().next() );
+ assertNotSame( orig.getShallowThingySet(), copy.getShallowThingySet() );
+ assertSame( orig.getShallowThingySet().iterator().next(), copy.getShallowThingySet().iterator().next() );
+
+ assertEquals( orig.customProperties, copy.customProperties );
+ assertNotSame( orig.customProperties, copy.customProperties );
+ }
+
}
diff --git a/modello-plugins/modello-plugin-jdom/pom.xml b/modello-plugins/modello-plugin-jdom/pom.xml
index 7bce8a1f2..6ce13a41c 100644
--- a/modello-plugins/modello-plugin-jdom/pom.xml
+++ b/modello-plugins/modello-plugin-jdom/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-jdom/src/test/verifiers/features/JDOMFeaturesVerifier.java b/modello-plugins/modello-plugin-jdom/src/test/verifiers/features/JDOMFeaturesVerifier.java
index 7f9cd99f5..e31bf25cc 100644
--- a/modello-plugins/modello-plugin-jdom/src/test/verifiers/features/JDOMFeaturesVerifier.java
+++ b/modello-plugins/modello-plugin-jdom/src/test/verifiers/features/JDOMFeaturesVerifier.java
@@ -44,7 +44,7 @@
import java.io.StringWriter;
/**
- * @author Hervé Boutemy
+ * @author Herve Boutemy
* @version $Id$
*/
public class JDOMFeaturesVerifier
diff --git a/modello-plugins/modello-plugin-stax/pom.xml b/modello-plugins/modello-plugin-stax/pom.xml
index aae926f58..fa22dfbbd 100644
--- a/modello-plugins/modello-plugin-stax/pom.xml
+++ b/modello-plugins/modello-plugin-stax/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-stax/src/test/verifiers/features/StaxFeaturesVerifier.java b/modello-plugins/modello-plugin-stax/src/test/verifiers/features/StaxFeaturesVerifier.java
index d7bdc1049..86594af7b 100644
--- a/modello-plugins/modello-plugin-stax/src/test/verifiers/features/StaxFeaturesVerifier.java
+++ b/modello-plugins/modello-plugin-stax/src/test/verifiers/features/StaxFeaturesVerifier.java
@@ -44,7 +44,7 @@
import javax.xml.stream.XMLStreamException;
/**
- * @author Hervé Boutemy
+ * @author Herve Boutemy
* @version $Id$
*/
public class StaxFeaturesVerifier
diff --git a/modello-plugins/modello-plugin-xdoc/pom.xml b/modello-plugins/modello-plugin-xdoc/pom.xml
index 93fb54047..c611d6471 100644
--- a/modello-plugins/modello-plugin-xdoc/pom.xml
+++ b/modello-plugins/modello-plugin-xdoc/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-xml/pom.xml b/modello-plugins/modello-plugin-xml/pom.xml
index 60052c1ac..5274660f7 100644
--- a/modello-plugins/modello-plugin-xml/pom.xml
+++ b/modello-plugins/modello-plugin-xml/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-xpp3/pom.xml b/modello-plugins/modello-plugin-xpp3/pom.xml
index b4a2528e6..41409e9a3 100644
--- a/modello-plugins/modello-plugin-xpp3/pom.xml
+++ b/modello-plugins/modello-plugin-xpp3/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-xpp3/src/test/verifiers/features/Xpp3FeaturesVerifier.java b/modello-plugins/modello-plugin-xpp3/src/test/verifiers/features/Xpp3FeaturesVerifier.java
index 62c25d27a..faf7b98a1 100644
--- a/modello-plugins/modello-plugin-xpp3/src/test/verifiers/features/Xpp3FeaturesVerifier.java
+++ b/modello-plugins/modello-plugin-xpp3/src/test/verifiers/features/Xpp3FeaturesVerifier.java
@@ -42,7 +42,7 @@
import java.io.StringWriter;
/**
- * @author Hervé Boutemy
+ * @author Herve Boutemy
* @version $Id$
*/
public class Xpp3FeaturesVerifier
diff --git a/modello-plugins/modello-plugin-xsd/pom.xml b/modello-plugins/modello-plugin-xsd/pom.xml
index 1b3544646..ad9d67703 100644
--- a/modello-plugins/modello-plugin-xsd/pom.xml
+++ b/modello-plugins/modello-plugin-xsd/pom.xml
@@ -3,7 +3,7 @@
modello-plugins
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/XsdGenerator.java b/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/XsdGenerator.java
index ad6c3ca04..75369179d 100644
--- a/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/XsdGenerator.java
+++ b/modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/XsdGenerator.java
@@ -382,7 +382,8 @@ else if ( hasContentField )
}
writeFieldDocumentation( w, field );
- if ( List.class.getName().equals( field.getType() ) )
+ if ( List.class.getName().equals( field.getType() )
+ || Set.class.getName().equals( field.getType() ) )
{
ModelAssociation association = (ModelAssociation) field;
diff --git a/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/ModelloXsdGeneratorTest.java b/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/ModelloXsdGeneratorTest.java
index c136e638d..82379d8fe 100644
--- a/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/ModelloXsdGeneratorTest.java
+++ b/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/ModelloXsdGeneratorTest.java
@@ -59,7 +59,7 @@ public void testXsdGenerator()
Properties parameters = new Properties();
parameters.setProperty( ModelloParameterConstants.OUTPUT_DIRECTORY, getOutputDirectory().getAbsolutePath() );
parameters.setProperty( ModelloParameterConstants.PACKAGE_WITH_VERSION, Boolean.toString( false ) );
- parameters.setProperty( ModelloParameterConstants.VERSION, "1.0.0" );
+ parameters.setProperty( ModelloParameterConstants.VERSION, "1.1.0" );
Model model = modello.loadModel( getTestFile( "../../src/main/mdo/modello.mdo" ) );
@@ -82,7 +82,7 @@ public void testXsdGenerator()
saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema" );
saxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource",
- new File( getOutputDirectory(), "modello-1.0.0.xsd" ) );
+ new File( getOutputDirectory(), "modello-1.1.0.xsd" ) );
// first self-test: validate Modello model with xsd generated from it
saxParser.parse( getTestFile( "../../src/main/mdo/modello.mdo" ), new Handler() );
diff --git a/modello-plugins/pom.xml b/modello-plugins/pom.xml
index e0c7dd211..b612ab46f 100644
--- a/modello-plugins/pom.xml
+++ b/modello-plugins/pom.xml
@@ -3,7 +3,7 @@
modello
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-test/pom.xml b/modello-test/pom.xml
index f49e7f2cf..099d400e6 100644
--- a/modello-test/pom.xml
+++ b/modello-test/pom.xml
@@ -3,7 +3,7 @@
modello
org.codehaus.modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
4.0.0
diff --git a/modello-test/src/main/java/org/codehaus/modello/AbstractModelloJavaGeneratorTest.java b/modello-test/src/main/java/org/codehaus/modello/AbstractModelloJavaGeneratorTest.java
index 2b533a53e..3cf27e79b 100755
--- a/modello-test/src/main/java/org/codehaus/modello/AbstractModelloJavaGeneratorTest.java
+++ b/modello-test/src/main/java/org/codehaus/modello/AbstractModelloJavaGeneratorTest.java
@@ -156,7 +156,13 @@ protected String getModelloVersion()
protected void compile( File generatedSources, File destinationDirectory )
throws IOException, CompilerException
{
- addDependency( "junit", "junit", "3.8.1" );
+ compile( generatedSources, destinationDirectory, false );
+ }
+
+ protected void compile( File generatedSources, File destinationDirectory, boolean useJava5 )
+ throws IOException, CompilerException
+ {
+ addDependency( "junit", "junit", "3.8.2" );
addDependency( "org.codehaus.plexus", "plexus-utils", "1.5.8" ); // version must be the same as in pom.xml
addDependency( "org.codehaus.modello", "modello-test", getModelloVersion() );
@@ -179,6 +185,16 @@ protected void compile( File generatedSources, File destinationDirectory )
configuration.setSourceLocations( Arrays.asList( sourceDirectories ) );
configuration.setOutputLocation( destinationDirectory.getAbsolutePath() );
configuration.setDebug( true );
+ if ( useJava5 )
+ {
+ configuration.setSourceVersion( "1.5" );
+ configuration.setTargetVersion( "1.5" );
+ }
+ else
+ {
+ configuration.setSourceVersion( "1.4" );
+ configuration.setTargetVersion( "1.4" );
+ }
List messages = compiler.compile( configuration );
diff --git a/modello-test/src/main/resources/features.mdo b/modello-test/src/main/resources/features.mdo
index 0b4e8aa50..3dfefa552 100644
--- a/modello-test/src/main/resources/features.mdo
+++ b/modello-test/src/main/resources/features.mdo
@@ -1,7 +1,7 @@
-
features
@@ -139,6 +139,13 @@
NodeItem
+
+ cloneable
+ 1.0.0+
+
+ Thing
+
+
@@ -441,13 +448,22 @@
- stringReferences
+ listStrings
1.0.0+
String
*
+
+ setStrings
+ 1.0.0+
+ Set
+
+ String
+ *
+
+
map
2.0.0+
@@ -1127,6 +1143,178 @@
+
+
+ SuperThing
+ 1.0.0+
+
+
+ Thing
+ SuperThing
+ 1.0.0+
+
+
+
+ someBoolean
+ 1.0.0+
+ boolean
+
+
+ someChar
+ 1.0.0+
+ char
+
+
+ someByte
+ 1.0.0+
+ byte
+
+
+ someShort
+ 1.0.0+
+ short
+
+
+ someInt
+ 1.0.0+
+ int
+
+
+ someLong
+ 1.0.0+
+ long
+
+
+ someFloat
+ 1.0.0+
+ float
+
+
+ someDouble
+ 1.0.0+
+ double
+
+
+ someString
+ 1.0.0+
+ String
+
+
+ someDate
+ 1.0.0+
+ Date
+
+
+ someDom
+ 1.0.0+
+ DOM
+
+
+
+ someProperties
+ 1.0.0+
+ Properties
+
+ String
+ *
+
+
+
+ someStringList
+ 1.0.0+
+ List
+
+ String
+ *
+
+
+
+ someStringSet
+ 1.0.0+
+ Set
+
+ String
+ *
+
+
+
+
+ deepThingy
+ 1.0.0+
+
+ Thingy
+ 1
+
+
+
+ deepThingyList
+ 1.0.0+
+ List
+
+ Thingy
+ *
+
+
+
+ deepThingySet
+ 1.0.0+
+ Set
+
+ Thingy
+ *
+
+
+
+
+ shallowThingy
+ 1.0.0+
+
+ Thingy
+ 1
+
+
+
+ shallowThingyList
+ 1.0.0+
+ List
+
+ Thingy
+ *
+
+
+
+ shallowThingySet
+ 1.0.0+
+ Set
+
+ Thingy
+ *
+
+
+
+
+
+ 1.0.0+
+
+
+
+
+
+
+ Thingy
+ SuperThing
+ 1.0.0+
+
diff --git a/modello-test/src/main/resources/features.xml b/modello-test/src/main/resources/features.xml
index 2956107a9..1abc5d538 100644
--- a/modello-test/src/main/resources/features.xml
+++ b/modello-test/src/main/resources/features.xml
@@ -41,11 +41,14 @@
first
-
- first
- second
- third
-
+
+ first
+ second
+ third
+
+
+ first
+
theValue
diff --git a/pom.xml b/pom.xml
index de4f92932..6dfdbb972 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
modello
pom
Modello
- 1.0.2-SNAPSHOT
+ 1.1-SNAPSHOT
http://modello.codehaus.org/
Modello is a framework for code generation from a simple model.
@@ -245,7 +245,7 @@
maven-release-plugin
- 2.0-beta-7
+ 2.0-beta-9
https://svn.codehaus.org/modello/tags
@@ -317,7 +317,7 @@
junit
junit
- 3.8.1
+ 3.8.2
test
@@ -493,7 +493,7 @@
src/main/mdo/modello.mdo
- 1.0.0
+ 1.1.0
diff --git a/src/main/mdo/modello.mdo b/src/main/mdo/modello.mdo
index 6958bd82e..f7e703904 100644
--- a/src/main/mdo/modello.mdo
+++ b/src/main/mdo/modello.mdo
@@ -1,7 +1,7 @@
-
modello
@@ -10,7 +10,7 @@
This is a reference for the Modello descriptor used to describe a model with Modello.
An XSD is available at
- http://modello.codehaus.org/xsd/modello-1.0.0.xsd .
+ http://modello.codehaus.org/xsd/modello-1.1.0.xsd .
]]>
@@ -27,17 +27,17 @@
Common attributes for most of the elements.
- 1.0.0
+ 1.0.0+
name
- 1.0.0
+ 1.0.0+
String
The name of the element.
description
- 1.0.0
+ 1.0.0+
String
A user-level description of the element.
@@ -45,7 +45,7 @@
comment
- 1.0.0
+ 1.0.0+
String
A private comment about the element.
@@ -53,7 +53,7 @@
versionRange
- 1.0.0
+ 1.0.0+
String
deprecatedVersion
- 1.0.0
+ 1.0.0+
String
@@ -75,12 +75,12 @@
Root tag for the description of a model.
- 1.0.0
+ 1.0.0+
BaseElement
namespace
- 1.0.0
+ 1.0.0+
String
schemaLocation
- 1.0.0
+ 1.0.0+
String
xsdNamespace
- 1.0.0
+ 1.0.0+
String
@@ -114,7 +114,7 @@
xsdTargetNamespace
- 1.0.0
+ 1.0.0+
String
@@ -126,14 +126,14 @@
id
- 1.0.0
+ 1.0.0+
true
String
Unique identifier of this model.
defaults
- 1.0.0
+ 1.0.0+
ModelDefault
*
@@ -144,14 +144,14 @@
versionDefinition
- 1.0.0
+ 1.0.0+
VersionDefinition
interfaces
- 1.0.0
+ 1.0.0+
ModelInterface
*
@@ -162,7 +162,7 @@
classes
- 1.0.0
+ 1.0.0+
true
ModelClass
@@ -177,14 +177,14 @@
ModelDefault
- 1.0.0
+ 1.0.0+
A default setting for some of the property of this model.
key
- 1.0.0
+ 1.0.0+
true
String
checkDeprecation,
@@ -193,7 +193,7 @@
value
- 1.0.0
+ 1.0.0+
true
String
The value of this property.
@@ -203,11 +203,11 @@
VersionDefinition
- 1.0.0
+ 1.0.0+
type
- 1.0.0
+ 1.0.0+
true
String
field,
@@ -215,7 +215,7 @@
value
- 1.0.0
+ 1.0.0+
String
field, the name of the field containing the model
version.]]>
@@ -225,13 +225,13 @@
ModelInterface
- 1.0.0
+ 1.0.0+
An interface provided by the model.
BaseElement
superInterface
- 1.0.0
+ 1.0.0+
String
The name of the super interface for this interface.
@@ -239,7 +239,7 @@
packageName
- 1.0.0
+ 1.0.0+
String
The destination package name for this interface.
@@ -247,7 +247,7 @@
codeSegments
- 1.0.0
+ 1.0.0+
CodeSegment
*
@@ -261,7 +261,7 @@
CodeSegment
- 1.0.0
+ 1.0.0+
A segment of code to be appended to this element.
@@ -269,7 +269,7 @@
code
- 1.0.0
+ 1.0.0+
String
The code block.
@@ -278,13 +278,13 @@
ModelClass
- 1.0.0
+ 1.0.0+
A class for this model.
BaseElement
rootElement
- 1.0.0
+ 1.0.0+
boolean
Indicates that this class is the root of the model (only one class in a model can have this attribute set
@@ -294,7 +294,7 @@
tagName
- 1.0.0
+ 1.0.0+
String
Define a tag name to be used in XML content, which can be different from the class name.
@@ -303,7 +303,7 @@
enabled
- 1.0.0
+ 1.0.0+
boolean
true
@@ -313,16 +313,42 @@
abstractMode
- 1.0.0
+ 1.0.0+
boolean
Mark this class as abstract.
see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin
+
+ javaClone
+ 1.1.0+
+ String
+ clone() method for this class. Allowed values are
+ none
, shallow
and deep
. The value is inherited from super classes
+ and defaults to none
if no super class declares otherwise. Since Modello 1.1 ]]>
+
+ see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin
+
+
+ javaCloneHook
+ 1.1.0+
+ String
+ clone() method.
+ The value of this attribute specifies the simple name of the hook method which is assumed to be provided as
+ part of some code segment. For convenience, the boolean literal true
can also be given to use
+ the default method name cloneHook
. The hook method itself must have a single parameter whose
+ type matches this class in order to receive the cloned object for further manipulation before completion of
+ the clone operation. Besides, the hook method must not have a return value and must not throw a checked
+ exception. Since Modello 1.1 ]]>
+
+ see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin
+
compositor
- 1.0.0
+ 1.0.0+
String
all
interfaces
- 1.0.0
+ 1.0.0+
String
*
@@ -343,7 +369,7 @@
superClass
- 1.0.0
+ 1.0.0+
String
The name of the super class for this class.
@@ -351,7 +377,7 @@
packageName
- 1.0.0
+ 1.0.0+
String
The destination package name for this class.
@@ -359,7 +385,7 @@
fields
- 1.0.0
+ 1.0.0+
ModelField
*
@@ -370,7 +396,7 @@
codeSegments
- 1.0.0
+ 1.0.0+
CodeSegment
*
@@ -384,7 +410,7 @@
ModelField
- 1.0.0
+ 1.0.0+
A field to be defined in a class.
@@ -392,7 +418,7 @@
getter
- 1.0.0
+ 1.0.0+
boolean
true
@@ -402,7 +428,7 @@
setter
- 1.0.0
+ 1.0.0+
boolean
true
@@ -412,7 +438,7 @@
separator
- 1.0.0
+ 1.0.0+
String
blank.]]>
@@ -421,7 +447,7 @@
attribute
- 1.0.0
+ 1.0.0+
boolean
Consider this field as an XML attribute instead of an element.
@@ -430,7 +456,7 @@
trim
- 1.0.0
+ 1.0.0+
boolean
true
@@ -440,7 +466,7 @@
tagName
- 1.0.0
+ 1.0.0+
String
Define a tag name to be used in XML content, which can be different from the field name.
@@ -449,7 +475,7 @@
format
- 1.0.0
+ 1.0.0+
String
The date format to use when parsing/writing a date (see java SimpleDateFormat).
@@ -458,7 +484,7 @@
alias
- 1.0.0
+ 1.0.0+
String
Alias name for this field (a parser should allow for this name instead of the given name).
@@ -466,7 +492,7 @@
type
- 1.0.0
+ 1.0.0+
true
String
defaultValue
- 1.0.0
+ 1.0.0+
String
The default value for this field.
required
- 1.0.0
+ 1.0.0+
boolean
Whether this field is required in model or not.
@@ -500,7 +526,7 @@
identifier
- 1.0.0
+ 1.0.0+
boolean
Whether this field is part of the identification of the object or not.
@@ -508,7 +534,7 @@
association
- 1.0.0
+ 1.0.0+
ModelAssociation
@@ -522,7 +548,7 @@
ModelAssociation
- 1.0.0
+ 1.0.0+
An association allows for mapping of a field to a complex type,
or to a many-multiplicity field.
@@ -530,7 +556,7 @@
adder
- 1.0.0
+ 1.0.0+
boolean
true
bidi
- 1.0.0
+ 1.0.0+
boolean
true
interfaceName
- 1.0.0
+ 1.0.0+
String
add, remove
,
@@ -565,7 +591,7 @@
initializationMode
- 1.0.0
+ 1.0.0+
String
lazy
see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin
+
+ javaClone
+ 1.1.0+
+ String
+ shallow and
+ deep
. If the value is not specified, the clone mode of the container class will be used.
+ Since Modello 1.1 ]]>
+
+ see org.codehaus.modello.plugin.java.metadata.JavaMetadataPlugin
+
associationTagName
- 1.0.0
+ 1.0.0+
String
Define a tag name to be used for every element inside a multiple association. By default, the name is
@@ -585,7 +622,7 @@
itemsStyle
- 1.0.0
+ 1.0.0+
String
wrapped
mapStyle
- 1.0.0
+ 1.0.0+
String
inline
reference
- 1.0.0
+ 1.0.0+
boolean
see org.codehaus.modello.plugins.xml.metadata.XmlMetadataPlugin
to
- 1.0.0
+ 1.0.0+
true
String
multiplicity
- 1.0.0
+ 1.0.0+
String
Can be 1 if only one such child is allowed, or * if any
diff --git a/src/site/apt/release-notes.apt b/src/site/apt/release-notes.apt
index a24d40654..2db476a59 100644
--- a/src/site/apt/release-notes.apt
+++ b/src/site/apt/release-notes.apt
@@ -8,6 +8,25 @@
Modello
+* 1.0.2 Release Notes (2009-06-11)
+
+ The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=15080&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below.
+
+
+** Bug
+
+ * [MODELLO-88] - converters goal generates wrong class names for continuum-model - won't compile
+
+ * [MODELLO-188] - Modello plugins are not available from ModelloCli or a standalone Modello instance
+
+ * [MODELLO-189] - Generated Xpp3Reader does not reconstruct modelEncoding
+
+ * [MODELLO-199] - java.getter attribute for field not initialize at all
+
+** Improvement
+
+ * [MODELLO-190] - Use StringBuilder for toString() when Java 1.5 is enabled
+
* 1.0.1 Release Notes (2009-03-09)
The full list of changes can be found in our {{{http://jira.codehaus.org/secure/IssueNavigator.jspa?fixfor=14892&sorter/field=issuekey&sorter/order=DESC&reset=true}issue management system}}, and is reproduced below.