[ 
https://issues.apache.org/jira/browse/ARCHETYPE-613?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17223420#comment-17223420
 ] 

Liu Shilong commented on ARCHETYPE-613:
---------------------------------------

I solve the problem, In fact ,it occurs not because of the maven version but 
the jdk version, it needs jdk14 rather than jdk8

> Different gererating result with user defined parameters
> --------------------------------------------------------
>
>                 Key: ARCHETYPE-613
>                 URL: https://issues.apache.org/jira/browse/ARCHETYPE-613
>             Project: Maven Archetype
>          Issue Type: Bug
>          Components: Plugin
>    Affects Versions: 3.2.0
>         Environment: maven 3.6.3(right), maven3.6.1(wrong), IDEA2020.1(wrong)
>            Reporter: Liu Shilong
>            Priority: Major
>
> Happend in two different maven version 3.6.1 and 3.6.3,
> I defined my archetype-metadata.xml as following:
> {code:java}
> //代码占位符
> <requiredProperties>
>     <requiredProperty key="groupId"/>
>     <requiredProperty key="artifactId"/>
>     <requiredProperty key="version">
>         <defaultValue>1.0.0-SNAPSHOT</defaultValue>
>     </requiredProperty>
>     <requiredProperty key="package"/>
>     <requiredProperty key="projectName"/>
>     <requiredProperty key="xxxx1"/> //user defined parameter
>     <requiredProperty key="xxxx2"> // user defined parameter
>    
> <defaultValue>${package.getClass().forName("org.apache.velocity.util.StringUtils").nullTrim("")}</defaultValue>
>  //default is null;
>     </requiredProperty>
>     {code}
>  and following are some others parameter tansformed by abover parameters
> {code:java}
> //代码占位符
> <requiredProperty key="xxxx3" >
>     <defaultValue>${xxxx1.toUpperCase()}</defaultValue>
> </requiredProperty>
> <requiredProperty key="xxxx4" >
>     
> <defaultValue>${xxxx1.toLowerCase().substring(0,1).toUpperCase()}${xxxx1.toLowerCase().substring(1)}</defaultValue>
> </requiredProperty>
> <requiredProperty key="xxxx5" >
>     
> <defaultValue>${package.getClass().forName("org.apache.velocity.util.StringUtils").nullTrim("$xxxx2").toUpperCase()}</defaultValue>
> </requiredProperty>
> <requiredProperty key="xxxx6" >
>     
> <defaultValue>${package.getClass().forName("org.apache.velocity.util.StringUtils").firstLetterCaps("${xxxx2}_").replaceAll("_","")}</defaultValue>
> </requiredProperty>
> <requiredProperty key="xxxx7" >
>     <defaultValue>${xxxx4}${xxxx6}</defaultValue>
> </requiredProperty>
> ....
> {code}
> when I use command "mvn archetype : generate ...." in maven 3.6.3, i got the 
> right generated project ,and all the parameters are as my expected including 
> parameters which need to be evaluated. But in maven 3.6.1(In fact , I'm not 
> sure whether the version cause the difference"), it's different, some 
> parameters are not evaluatedd correctly like following:
> {code:java}
> //代码占位符
> ...
> Parameter: xxxx3, Value: ${xxxx1.toUpperCase()}
> [INFO] Parameter: xxxxx6, Value: _${xxxx}_
> [INFO] Parameter: xxxxx,  Value: _xxxx_
> ...{code}
> as you see, some parameters are evaluated, but some are not.  In fact , I 
> found this happened also in 'mvn command' and 'maven archetype generating 
> process in IDEA'. And I found following source code in maven-archetype plugin:
> {code:java}
> //代码占位符
> private Context prepareVelocityContext(ArchetypeGenerationRequest request) {
>     Context context = new VelocityContext();
>     context.put(Constants.GROUP_ID, request.getGroupId());
>     context.put(Constants.ARTIFACT_ID, request.getArtifactId());
>     context.put(Constants.VERSION, request.getVersion());
>     context.put(Constants.PACKAGE, request.getPackage());
>     final String packageInPathFormat = 
> getPackageInPathFormat(request.getPackage());
>     context.put(Constants.PACKAGE_IN_PATH_FORMAT, packageInPathFormat);
>     if (getLogger().isInfoEnabled()) {
>         
> getLogger().info("----------------------------------------------------------------------------");
>         getLogger().info(
>                 "Using following parameters for creating project from 
> Archetype: " + request
>                         .getArchetypeArtifactId()
>                         + ":" + request.getArchetypeVersion());
>         
> getLogger().info("----------------------------------------------------------------------------");
>         getLogger().info("Parameter: " + Constants.GROUP_ID + ", Value: " + 
> request.getGroupId());
>         getLogger().info("Parameter: " + Constants.ARTIFACT_ID + ", Value: " 
> + request.getArtifactId());
>         getLogger().info("Parameter: " + Constants.VERSION + ", Value: " + 
> request.getVersion());
>         getLogger().info("Parameter: " + Constants.PACKAGE + ", Value: " + 
> request.getPackage());
>         getLogger().info("Parameter: " + Constants.PACKAGE_IN_PATH_FORMAT + 
> ", Value: " + packageInPathFormat);
>     }
>     for (Iterator<?> iterator = request.getProperties().keySet().iterator(); 
> iterator.hasNext(); ) { // here,the result of request.getProperties() is a 
> hashtable
>         String key = (String) iterator.next();
>         String value = request.getProperties().getProperty(key);
>         if (maybeVelocityExpression(value)) {
>             value = evaluateExpression(context, key, value);
>         }
>         context.put(key, value);
>         if (getLogger().isInfoEnabled()) {
>             getLogger().info("Parameter: " + key + ", Value: " + value);
>         }
>     }
>     return context;
> }
> {code}
> As above comment, the result of request.getProperties() is a HashTable, the 
> fact is that the parameter order is not what we input but hash value, so it 
> cause that some parameters are not evaluated because some parameters are 
> relied on others.
> But the question is "how difference happens?" . In fact ,once the parameter 
> are determined, the result will be determined, why it will be different in 
> some case?
> {color:#808080}IDEA use the java command to start the process of generating 
> like: {color}
> {code:java}
> //代码占位符
> java -Dxxx=xxx 
> org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate
> {code}
> {color:#808080}also, some parameters are not evaluated correctly.{color}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to