lin-yichang opened a new issue, #968:
URL: https://github.com/apache/maven-archetype/issues/968
### Affected version
this bug has been around for more than a decade
### Bug description
# Steps to reproduce the bug
* System properties provide `archetypeGroupId` (G) and `archetypeArtifactId`
(A), but not `archetypeVersion` (V),
* G:A is not found in the aggregate archetype catalog, and
* The command runs in the interactive mode.
For example, I tried to use
`org.apache.maven.archetypes:maven-archetype-webapp`, but the artifactId was
misspelled:
```
mvn archetype:generate "-DarchetypeGroupId=org.apache.maven.archetypes"
"-DarchetypeArtifactId=maven-archetype-web"
```
# Expected behavior
The goal keeps the original coordinates, and fails with G:A:1.0 immediately.
1.0 is the default version.
# Current behavior
The goal substitutes G:A with
`org.apache.maven.archetypes:maven-archetype-quickstart`, which is then used as
the default answer for the prompt:
```
Choose a number or apply filter (format: [groupId:]artifactId, case
sensitive contains): 2293:
```
2293 is the number for
`org.apache.maven.archetypes:maven-archetype-quickstart`. The name, however, is
not shown.
If the problem is caused by a typo, a typical user may not realize that the
archetype has been changed. And the huge list makes it difficult to scroll back
and forth. As a result, the user will believe the number represents the
intended archetype and hit the Enter/Return key. At this point, the new name is
shown, but since there is no way to recover, the user has to terminate the
execution.
If the problem is not caused by a typo - that is, the intended archetype is
simply not in the catalogs, this behavior is completely useless.
# Details
The following schematic shows what happens in
`org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector`'s
`selectArchetype()` method. `m` is short for `org.apache.maven.archetypes`, `q`
is for `maven-archetype-quickstart`, and `f` is for the version of the first
result found.
```
G A V
---------------------------------------------------------------------------> G
A V
G:A found
G A 0
---------------------------------------------------------------------------> G
A f
|
| G:A not found batch mode
-------------------------------------------------------------------------> G A
1.0
|
| interactive mode
---------------------> 000 --> m 0 1.0 --> [m q
1.0]
0 A V
---------------------------------------------------------------------------> m
A V
0 A 0
---------------------------------------------------------------------------> m
A 1.0
batch mode
G 0 V --------------> G q V
-----------------------------------------------------> G q V
|
| interactive mode
---------------------------> [G q V]
batch mode
G 0 0 --> G 0 1.0 --> G q 1.0
---------------------------------------------------> G q 1.0
|
| interactive mode
---------------------------> [G q
1.0]
batch mode
0 0 V --> m 0 V ----> m q V
-----------------------------------------------------> m q V
|
| interactive mode
---------------------------> [m q V]
batch mode
0 0 0 --> m 0 1.0 --> m q 1.0
---------------------------------------------------> m q 1.0
|
| interactive mode
---------------------------> [m q
1.0]
```
All other cases respect the original G and A, using
`org.apache.maven.archetypes` if G is missing and `maven-archetype-quickstart`
if A is missing. When the archetype is not found in the catalogs, the goal
fails immediately, reporting the coordinates to the user.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]