String.replace() used in an inconsistent (and unnecessary) way
--------------------------------------------------------------

                 Key: ARCHETYPE-361
                 URL: http://jira.codehaus.org/browse/ARCHETYPE-361
             Project: Maven Archetype
          Issue Type: Bug
          Components: Generator
    Affects Versions: 2.0
            Reporter: Marc Wirth
            Priority: Minor
         Attachments: unnecessary_stringreplace.patch

See attached patch. Sorry, no specific test case, but the existing testcases do 
not complain if this change is applied.

First one:

{code}
processFilesetProject( archetypeDescriptor,
                                           StringUtils.replace( artifactId, 
"${rootArtifactId}", rootArtifactId ),
                                           archetypeResources, pom, 
archetypeZipFile, moduleOffset, context, packageName,
                                           outputDirectoryFile, basedirPom );
{code}
replaced with:
{code}
processFilesetProject( archetypeDescriptor,
                                           artifactId,
                                           archetypeResources, pom, 
archetypeZipFile, moduleOffset, context, packageName,
                                           outputDirectoryFile, basedirPom );
{code}

On the first call to the method the artifactId is the id from the request, so 
it cannot really contain "$\{rootArtifactId\}" unless somebody typed that on 
the console. If there are modules and the method recurses the parameter is 
replaced with {{StringUtils.replace( project.getDir(), "__rootArtifactId__", 
rootArtifactId )}} and the ModuleDescriptor dir uses the underscores for 
escaping, not the dollar and the braces, so I assume this replacement is not 
necessary at all. (None of the existing tests breaks).

Second one:

{code}
processFilesetModule( rootArtifactId,
                                          StringUtils.replace( 
project.getDir(), "__rootArtifactId__", rootArtifactId ),
                                          archetypeResources,
                                          new File( moduleOutputDirectoryFile, 
Constants.ARCHETYPE_POM ), archetypeZipFile,
                                          ( StringUtils.isEmpty( moduleOffset ) 
? "" : ( moduleOffset + "/" ) )
                                                  + StringUtils.replace( 
project.getDir(), "${rootArtifactId}", rootArtifactId ),
                                          pom, moduleOutputDirectoryFile, 
packageName, project, context );
{code}
replaced with:
{code}
processFilesetModule( rootArtifactId,
                                          StringUtils.replace( 
project.getDir(), "__rootArtifactId__", rootArtifactId ),
                                          archetypeResources,
                                          new File( moduleOutputDirectoryFile, 
Constants.ARCHETYPE_POM ), archetypeZipFile,
                                          ( StringUtils.isEmpty( moduleOffset ) 
? "" : ( moduleOffset + "/" ) )
                                                  + project.getDir(),
                                          pom, moduleOutputDirectoryFile, 
packageName, project, context );
{code}

The dir of the Module descriptor uses underscores, not dollar plus braces for 
escaping. At least that's the way it is also created in 
org.apache.maven.archetype.creator.FilesetArchetypeCreator#createModule. Thus 
replacing a {{"$\{...\}"}} expression in ModuleDescriptor#getDir() should never 
actually do anything.

Is that analysis correct?


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to