Sculptor 2.0.0 - Maven Archetypes: StringIndexOutOfBoundsException while merging Velocity templates in "fornax-cartridges-sculptor-archetype-parent"

37 views
Skip to first unread message

Torsten Juergeleit

unread,
Jul 18, 2011, 8:20:15 AM7/18/11
to fornax-...@googlegroups.com
If feeding "fornax-cartridges-sculptor-archetype-parent" with groupId of "com.acme.foo" and artifactId of "bar" then the maven build throws the following exception:

C:\temp>mvn archetype:generate -DarchetypeGroupId=org.fornax.cartridges -DarchetypeArtifactId=fornax-cartridges-sculptor-archetype-parent -DarchetypeVersion=2.0.0 -DarchetypeRepository=http://fornax-platform.org/nexus/content/repositories/public -X
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: c:\DriveD\develop\apache-maven-3.0.3
Java version: 1.6.0_26, vendor: Sun Microsystems Inc.
Java home: C:\Programme\Java\jdk1.6.0_26\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
[INFO] Error stacktraces are turned on.

   :

[DEBUG] Adding requiredProperty groupId
[DEBUG] Setting property groupId=null
[DEBUG] Adding requiredProperty artifactId
[DEBUG] Setting property artifactId=null
[DEBUG] Adding requiredProperty version
[DEBUG] Setting property version=null
[DEBUG] Adding requiredProperty package
[DEBUG] Setting property package=null
[DEBUG] Required properties before content sort: [groupId, artifactId, version, package]
[DEBUG] Required properties after content sort: [groupId, artifactId, version, package]
Define value for property 'groupId': : com.acme.foo
Define value for property 'artifactId': : bar
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  com.acme.foo: :
Confirm properties configuration:
groupId: com.acme.foo
artifactId: bar
version: 1.0-SNAPSHOT
package: com.acme.foo
 Y: :
[DEBUG] Archetype generation configuration confirmed
[DEBUG] Found archetype org.fornax.cartridges:fornax-cartridges-sculptor-archetype-parent:2.0.0 in cache: c:\DriveD\develop\maven-repos\org\fornax\cartridges\fornax-cartridges-sculptor-archetype-parent\2.0.0\fornax-cartridges-sculptor-archetype-parent-2.0.0.jar
[DEBUG] Found archetype org.fornax.cartridges:fornax-cartridges-sculptor-archetype-parent:2.0.0 in cache: c:\DriveD\develop\maven-repos\org\fornax\cartridges\fornax-cartridges-sculptor-archetype-parent\2.0.0\fornax-cartridges-sculptor-archetype-parent-2.0.0.jar
[DEBUG] checking fileset archetype status on c:\DriveD\develop\maven-repos\org\fornax\cartridges\fornax-cartridges-sculptor-archetype-parent\2.0.0\fornax-cartridges-sculptor-archetype-parent-2.0.0.jar
[DEBUG] Searching for META-INF/maven/archetype-metadata.xml inside c:\DriveD\develop\maven-repos\org\fornax\cartridges\fornax-cartridges-sculptor-archetype-parent\2.0.0\fornax-cartridges-sculptor-archetype-parent-2.0.0.jar
[DEBUG]   - archetype-resources/.project
[DEBUG]   - archetype-resources/antbuild-ear.xml
[DEBUG]   - archetype-resources/antbuild-war.xml
[DEBUG]   - archetype-resources/pom.xml
[DEBUG]   - META-INF/archetype.xml
[DEBUG] checking old archetype status on c:\DriveD\develop\maven-repos\org\fornax\cartridges\fornax-cartridges-sculptor-archetype-parent\2.0.0\fornax-cartridges-sculptor-archetype-parent-2.0.0.jar
[DEBUG] Searching for META-INF/maven/archetype.xml inside c:\DriveD\develop\maven-repos\org\fornax\cartridges\fornax-cartridges-sculptor-archetype-parent\2.0.0\fornax-cartridges-sculptor-archetype-parent-2.0.0.jar
[DEBUG]   - archetype-resources/.project
[DEBUG]   - archetype-resources/antbuild-ear.xml
[DEBUG]   - archetype-resources/antbuild-war.xml
[DEBUG]   - archetype-resources/pom.xml
[DEBUG]   - META-INF/archetype.xml
[DEBUG] Searching for META-INF/archetype.xml inside c:\DriveD\develop\maven-repos\org\fornax\cartridges\fornax-cartridges-sculptor-archetype-parent\2.0.0\fornax-cartridges-sculptor-archetype-parent-2.0.0.jar
[DEBUG]   - archetype-resources/.project
[DEBUG]   - archetype-resources/antbuild-ear.xml
[DEBUG]   - archetype-resources/antbuild-war.xml
[DEBUG]   - archetype-resources/pom.xml
[DEBUG]   - META-INF/archetype.xml
[DEBUG] Entry found
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: fornax-cartridges-sculptor-archetype-parent:2.0.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.acme.foo
[INFO] Parameter: packageName, Value: com.acme.foo
[INFO] Parameter: package, Value: com.acme.foo
[INFO] Parameter: artifactId, Value: bar
[INFO] Parameter: basedir, Value: C:\temp
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[ERROR] Method substring threw exception for reference $artifactId in template archetype-resources/pom.xml at  [1,80]
[ERROR] Error merging velocity templates
org.apache.maven.archetype.old.ArchetypeTemplateProcessingException: Error merging velocity templates
        at org.apache.maven.archetype.old.DefaultOldArchetype.processTemplate(DefaultOldArchetype.java:883)
        at org.apache.maven.archetype.old.DefaultOldArchetype.processTemplate(DefaultOldArchetype.java:743)
        at org.apache.maven.archetype.old.DefaultOldArchetype.processTemplates(DefaultOldArchetype.java:488)
        at org.apache.maven.archetype.old.DefaultOldArchetype.createArchetype(DefaultOldArchetype.java:336)
        at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.processOldArchetype(DefaultArchetypeGenerator.java:142)
        at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.generateArchetype(DefaultArchetypeGenerator.java:110)
        at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.generateArchetype(DefaultArchetypeGenerator.java:149)
        at org.apache.maven.archetype.generator.DefaultArchetypeGenerator.generateArchetype(DefaultArchetypeGenerator.java:209)
        at org.apache.maven.archetype.DefaultArchetypeManager.generateProjectFromArchetype(DefaultArchetypeManager.java:71)
        at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute(CreateProjectFromArchetypeMojo.java:190)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'substring' in  class java.lang.String threw exception java.lang.StringIndexOutOfBoundsException: String index out of range: -4 @ archetype-resources/pom.xml[1,92]
        at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:286)
        at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:203)
        at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:419)
        at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:73)
        at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:125)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:318)
        at org.apache.velocity.Template.merge(Template.java:254)
        at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:508)
        at org.apache.maven.archetype.old.DefaultOldArchetype.processTemplate(DefaultOldArchetype.java:873)
        ... 30 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -4
        at java.lang.String.substring(String.java:1937)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:295)
        at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:245)
        ... 38 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33.329s
[INFO] Finished at: Mon Jul 18 13:58:13 CEST 2011
[INFO] Final Memory: 7M/123M
[INFO] ------------------------------------------------------------------------


If replacing "bar" with "foo-parent" then the same mvn build is running properly.

It seems that Sculptors parent archetype expects that the last segment of the groupId is used as a prefix in the artifactId.
This may be true in a kind of "Hello World" environnment or in the Maven Book but not in our environment ;-)

/Torsten

Torsten Juergeleit

unread,
Jul 18, 2011, 6:44:24 PM7/18/11
to fornax-...@googlegroups.com
Hhm, it seems that in the caclulation in the first line of the pom template [1] (used within the archetype) is hard-coded to expect artifactIds postfixed with "-parent":
    #set( $artifactIdBaseLength = $artifactId.length() - 7)
That badly fails if an artifactId is specified which is shorter than 7 characters.

/Torsten

[1] https://fisheye3.atlassian.com/browse/fornax/trunk/cartridges/sculptor/fornax-cartridges-sculptor-archetype-parent/src/main/resources/archetype-resources/pom.xml?r=7594

Patrik Nordwall

unread,
Jul 19, 2011, 2:26:06 AM7/19/11
to fornax-...@googlegroups.com
Correct, the archetypes are based on naming convention of the artifact ids, such as -parent
Reply all
Reply to author
Forward
0 new messages