Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0
-
Fix Version/s: 2.1
-
Component/s: Plugin
-
Labels:None
-
Environment:HideApache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/local/maven
Java version: 1.6.0_24, vendor: Sun Microsystems Inc.
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux", version: "2.6.35.12-90.fc14.x86_64", arch: "amd64", family: "unix"ShowApache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100) Maven home: /usr/local/maven Java version: 1.6.0_24, vendor: Sun Microsystems Inc. Default locale: fr_FR, platform encoding: UTF-8 OS name: "linux", version: "2.6.35.12-90.fc14.x86_64", arch: "amd64", family: "unix"
-
Number of attachments :
Description
Currently, running mvn archetype:generate returns 390 archetypes, on my machine.
By default, th window buffer of my terminal isn't set big enough so I can see the first archetypes in the list.
So, I think it would be really useful to have a CLI arg allowing us to filter the archetypes containing a string.
Ex: running
mvn archetype:generate -Dfilter=webapp
would return only the archetypes having webapp in their artifactId.
What do you think?
After a bit of hacking, I managed to get the following results :
Basically, the code in org.apache.maven.archetype.ui.DefaultArchetypeSelector looks like :
public void selectArchetype( ArchetypeGenerationRequest request, Boolean interactiveMode, String catalogs ) throws ArchetypeNotDefined, UnknownArchetype, UnknownGroup, IOException, PrompterException, ArchetypeSelectionFailure { ... Map<String, List<Archetype>> archetypes = getFilteredArchetypes(getArchetypesByCatalog( catalogs ), request.getFilter() ); ...private Map<String, List<Archetype>> getFilteredArchetypes( Map<String, List<Archetype>> archetypesByCatalog, final String filter) { if (StringUtils.isNotEmpty(filter) && !archetypesByCatalog.isEmpty()) { Iterator<Map.Entry<String, List<Archetype>>> ite = archetypesByCatalog.entrySet().iterator(); while (ite.hasNext()) { Map.Entry<String, List<Archetype>> entry = ite.next(); List<Archetype> archetypes = entry.getValue(); CollectionUtils.filter(archetypes, new Predicate() { public boolean evaluate(Object archetype) { return ((Archetype) archetype).getArtifactId().contains(filter); } }); if (archetypes.isEmpty()) { ite.remove(); } } } return archetypesByCatalog; }This implementation has a minimum impact on the code. However, doing the actual filtering would probably be more appropriate directly in the ArchetypeCatalog class, but that would require more code change. It's debatable.
If this implementation suits you, I can add some test cases and attach a patch here. You tell me