[ 
https://issues.apache.org/jira/browse/ARCHETYPE-612?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]
David Hutchison updated ARCHETYPE-612:
--------------------------------------
    Description: 
The interactive archetype project generation attempts to be smart in ordering 
required properties so that when a default value for one property includes a 
reference to another, they are asked for in the correct order. This also 
however tries to ask the "core" properties (groupId, archetypeId, version, and 
package) in a fixed order, and any others in alphabetical order, if they do not 
have dependencies. 

 

I was trying to setup an archetype with a couple of prompts which would be 
referenced in the default values for groupId, archetypeId and package. 
Basically attempting to standardise the setup for these based on the 
"application" and "database" the repository was for, so we would have:
 * groupId: {{com.example.${application}.data}}
 * archetypeId: {{${database}}}
 * package: {{com.example.${application}.data.${database}}}

 

When doing this however, the package is prompted for before the value it's 
default depends on. 

 

This snippet from archetype-metadata.xml will trigger the issue as a test
{code:java}
  <requiredProperties>
    <requiredProperty key="a-prop"/>
    <requiredProperty key="groupId">
      <defaultValue>com.devwithimagination</defaultValue>
    </requiredProperty>
    <requiredProperty key="artifactId">
      <defaultValue>test-${a-prop}</defaultValue>
    </requiredProperty>
    <requiredProperty key="package">
      <defaultValue>${groupId}.${artifactId}.${z-prop}</defaultValue>
    </requiredProperty>
    <requiredProperty key="z-prop"/>
  </requiredProperties>
{code}

Running this archetype interactively will output something like this:
{code:java}
$ mvn archetype:generate -DarchetypeArtifactId=archetype-test 
-DarchetypeGroupId=com.devwithimagination.archetypes

[INFO] Generating project in Interactive mode
[INFO] Archetype 
[com.devwithimagination.archetypes:archetype-test:1.0-SNAPSHOT] found in 
catalog local
[INFO] Using property: groupId = com.devwithimagination
Define value for property 'version' 1.0-SNAPSHOT: : 
Define value for property 'package' 
com.devwithimagination.archetypes.archetype-test.${z-prop}: : 
Define value for property 'a-prop': 123
Define value for property 'artifactId' test-123: : 
Define value for property 'z-prop': 
{code}

So {{package}} was prompted for before {{artifactId}} and {{z-prop}} which it 
needed for the default value. In typing this up I just noticed it used the 
{{archetypeArtifactId}} in the default value instead. 

I have got a failing test case for {{RequiredPropertyComparatorTest}} which 
shows the comparator isn't performing the sort correctly. 

A possible solution for this could be what ARCHETYPE-443 proposed, and respect 
the property order defined in the archetype metadata file. Any "core" required 
properties could still be prompted for in their default order, unless the 
archetype author had also included them in {{archetype-metadata.xml}}. With 
that change, it would be up to the archetype author to ensure that properties 
are correctly ordered. ARCHETYPE-562 points to other issues with this sort.

I have been having a look at making the sort smarter, but so far I've not been 
able to keep the name based ordering working while fixing the property 
dependency based sort. 

 

  was:
The interactive archetype project generation attempts to be smart in ordering 
required properties so that when a default value for one property includes a 
reference to another, they are asked for in the correct order. This also 
however tries to ask the "core" properties (groupId, archetypeId, version, and 
package) in a fixed order, and any others in alphabetical order, if they do not 
have dependencies. 

 

I was trying to setup an archetype with a couple of prompts which would be 
referenced in the default values for groupId, archetypeId and package. 
Basically attempting to standardise the setup for these based on the 
"application" and "database" the repository was for, so we would have:
 * groupId: `com.example.${application}.data`
 * archetypeId: `${database}`
 * package: `com.example.${application}.data.${database}`

 

When doing this however, the package is prompted for before the value it's 
default depends on. 

 

This snippet from archetype-metadata.xml will trigger the issue as a test
{code:java}
  <requiredProperties>
    <requiredProperty key="a-prop"/>
    <requiredProperty key="groupId">
      <defaultValue>com.devwithimagination</defaultValue>
    </requiredProperty>
    <requiredProperty key="artifactId">
      <defaultValue>test-${a-prop}</defaultValue>
    </requiredProperty>
    <requiredProperty key="package">
      <defaultValue>${groupId}.${artifactId}.${z-prop}</defaultValue>
    </requiredProperty>
    <requiredProperty key="z-prop"/>
  </requiredProperties>
{code}

Running this archetype interactively will output something like this:
{code:java}
$ mvn archetype:generate -DarchetypeArtifactId=archetype-test 
-DarchetypeGroupId=com.devwithimagination.archetypes

[INFO] Generating project in Interactive mode
[INFO] Archetype 
[com.devwithimagination.archetypes:archetype-test:1.0-SNAPSHOT] found in 
catalog local
[INFO] Using property: groupId = com.devwithimagination
Define value for property 'version' 1.0-SNAPSHOT: : 
Define value for property 'package' 
com.devwithimagination.archetypes.archetype-test.${z-prop}: : 
Define value for property 'a-prop': 123
Define value for property 'artifactId' test-123: : 
Define value for property 'z-prop': 
{code}

So `package` was prompted for before `artifactId` and `z-prop` which it needed 
for the default value. In typing this up I just noticed it used the 
`archetypeArtifactId` in the default value instead. 

I have got a failing test case for `RequiredPropertyComparatorTest` which shows 
the comparator isn't performing the sort correctly. 

A possible solution for this could be what ARCHETYPE-443 proposed, and respect 
the property order defined in the archetype metadata file. Any "core" required 
properties could still be prompted for in their default order, unless the 
archetype author had also included them in `archetype-metadata.xml`. With that 
change, it would be up to the archetype author to ensure that properties are 
correctly ordered. ARCHETYPE-562 points to other issues with this sort.

I have been having a look at making the sort smarter, but so far I've not been 
able to keep the name based ordering working while fixing the property 
dependency based sort. 

 


> Required property interactive prompt ordering incorrect when reassigning 
> default for a "core" property
> ------------------------------------------------------------------------------------------------------
>
>                 Key: ARCHETYPE-612
>                 URL: https://issues.apache.org/jira/browse/ARCHETYPE-612
>             Project: Maven Archetype
>          Issue Type: Bug
>          Components: Plugin
>    Affects Versions: 3.2.0
>            Reporter: David Hutchison
>            Priority: Minor
>
> The interactive archetype project generation attempts to be smart in ordering 
> required properties so that when a default value for one property includes a 
> reference to another, they are asked for in the correct order. This also 
> however tries to ask the "core" properties (groupId, archetypeId, version, 
> and package) in a fixed order, and any others in alphabetical order, if they 
> do not have dependencies. 
>  
> I was trying to setup an archetype with a couple of prompts which would be 
> referenced in the default values for groupId, archetypeId and package. 
> Basically attempting to standardise the setup for these based on the 
> "application" and "database" the repository was for, so we would have:
>  * groupId: {{com.example.${application}.data}}
>  * archetypeId: {{${database}}}
>  * package: {{com.example.${application}.data.${database}}}
>  
> When doing this however, the package is prompted for before the value it's 
> default depends on. 
>  
> This snippet from archetype-metadata.xml will trigger the issue as a test
> {code:java}
>   <requiredProperties>
>     <requiredProperty key="a-prop"/>
>     <requiredProperty key="groupId">
>       <defaultValue>com.devwithimagination</defaultValue>
>     </requiredProperty>
>     <requiredProperty key="artifactId">
>       <defaultValue>test-${a-prop}</defaultValue>
>     </requiredProperty>
>     <requiredProperty key="package">
>       <defaultValue>${groupId}.${artifactId}.${z-prop}</defaultValue>
>     </requiredProperty>
>     <requiredProperty key="z-prop"/>
>   </requiredProperties>
> {code}
> Running this archetype interactively will output something like this:
> {code:java}
> $ mvn archetype:generate -DarchetypeArtifactId=archetype-test 
> -DarchetypeGroupId=com.devwithimagination.archetypes
> [INFO] Generating project in Interactive mode
> [INFO] Archetype 
> [com.devwithimagination.archetypes:archetype-test:1.0-SNAPSHOT] found in 
> catalog local
> [INFO] Using property: groupId = com.devwithimagination
> Define value for property 'version' 1.0-SNAPSHOT: : 
> Define value for property 'package' 
> com.devwithimagination.archetypes.archetype-test.${z-prop}: : 
> Define value for property 'a-prop': 123
> Define value for property 'artifactId' test-123: : 
> Define value for property 'z-prop': 
> {code}
> So {{package}} was prompted for before {{artifactId}} and {{z-prop}} which it 
> needed for the default value. In typing this up I just noticed it used the 
> {{archetypeArtifactId}} in the default value instead. 
> I have got a failing test case for {{RequiredPropertyComparatorTest}} which 
> shows the comparator isn't performing the sort correctly. 
> A possible solution for this could be what ARCHETYPE-443 proposed, and 
> respect the property order defined in the archetype metadata file. Any "core" 
> required properties could still be prompted for in their default order, 
> unless the archetype author had also included them in 
> {{archetype-metadata.xml}}. With that change, it would be up to the archetype 
> author to ensure that properties are correctly ordered. ARCHETYPE-562 points 
> to other issues with this sort.
> I have been having a look at making the sort smarter, but so far I've not 
> been able to keep the name based ordering working while fixing the property 
> dependency based sort. 
>  



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

Reply via email to