[
http://jira.codehaus.org/browse/ARCHETYPE-371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=265316#action_265316
]
Fred Bricon edited comment on ARCHETYPE-371 at 4/30/11 5:48 PM:
----------------------------------------------------------------
After a bit of hacking, I managed to get the following results :
{noformat}
[fbricon@fbricon Temp]$ mvn
org.apache.maven.plugins:maven-archetype-plugin:2.1-SNAPSHOT:generate
-Dfilter=jee
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.1-SNAPSHOT:generate (default-cli) @
standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.1-SNAPSHOT:generate (default-cli) @
standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.1-SNAPSHOT:generate (default-cli) @
standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart
(org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: remote -> ear-jee5 (-)
2: remote -> ejb-jee5 (-)
3: remote -> webapp-jee5 (-)
4: remote -> jee6-basic-archetype (-)
5: remote -> jee6-minimal-archetype (-)
6: remote -> jee6-sandbox-archetype (-)
7: remote -> jee6-sandbox-demo-archetype (-)
8: remote -> jee6-servlet-basic-archetype (-)
9: remote -> jee6-servlet-demo-archetype (-)
10: remote -> jee6-servlet-minimal-archetype (-)
11: remote -> jee6-servlet-sandbox-archetype (-)
12: remote -> imixs-workflow-jee-archetype (Imixs Workflow JEE Archetype
provides a JEE Sample Application)
13: remote -> weld-jsf-jee (Weld archetype for creating a Java EE 6 application
using JSF 2.0, CDI 1.0, EJB 3.1 and JPA 2.0 (persistence unit included))
14: remote -> weld-jsf-jee-minimal (Weld archetype for creating a minimal Java
EE 6 application using JSF 2.0, CDI 1.0 and EJB 3.1 (persistence unit not
included))
Choose a number: : 13
Downloading:
http://repo1.maven.org/maven2/org/jboss/weld/archetypes/weld-jsf-jee/1.0.0-BETA1/weld-jsf-jee-1.0.0-BETA1.jar
Downloaded:
http://repo1.maven.org/maven2/org/jboss/weld/archetypes/weld-jsf-jee/1.0.0-BETA1/weld-jsf-jee-1.0.0-BETA1.jar
(138 KB at 121.2 KB/sec)
Downloading:
http://repo1.maven.org/maven2/org/jboss/weld/archetypes/weld-jsf-jee/1.0.0-BETA1/weld-jsf-jee-1.0.0-BETA1.pom
Downloaded:
http://repo1.maven.org/maven2/org/jboss/weld/archetypes/weld-jsf-jee/1.0.0-BETA1/weld-jsf-jee-1.0.0-BETA1.pom
(2 KB at 1.9 KB/sec)
Define value for property 'groupId': : foo.bar
Define value for property 'artifactId': : weldy
[INFO] Using property: version = 1.0.0-SNAPSHOT
Define value for property 'package': foo.bar: :
Confirm properties configuration:
groupId: foo.bar
artifactId: weldy
version: 1.0.0-SNAPSHOT
package: foo.bar
Y: :
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 31.635s
[INFO] Finished at: Sun May 01 00:09:10 CEST 2011
[INFO] Final Memory: 6M/245M
[INFO] ------------------------------------------------------------------------
{noformat}
Basically, the code in org.apache.maven.archetype.ui.DefaultArchetypeSelector
looks like :
{noformat}
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() );
...
{noformat}
{noformat}
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;
}
{noformat}
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 :-)
was (Author: fbricon):
After a bit of hacking, I managed to get the following results :
{noformat}
[fbricon@fbricon Temp]$ mvn
org.apache.maven.plugins:maven-archetype-plugin:2.1-SNAPSHOT:generate
-Dfilter=jee
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.1-SNAPSHOT:generate (default-cli) @
standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.1-SNAPSHOT:generate (default-cli) @
standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.1-SNAPSHOT:generate (default-cli) @
standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart
(org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: remote -> ear-jee5 (-)
2: remote -> ejb-jee5 (-)
3: remote -> webapp-jee5 (-)
4: remote -> jee6-basic-archetype (-)
5: remote -> jee6-minimal-archetype (-)
6: remote -> jee6-sandbox-archetype (-)
7: remote -> jee6-sandbox-demo-archetype (-)
8: remote -> jee6-servlet-basic-archetype (-)
9: remote -> jee6-servlet-demo-archetype (-)
10: remote -> jee6-servlet-minimal-archetype (-)
11: remote -> jee6-servlet-sandbox-archetype (-)
12: remote -> imixs-workflow-jee-archetype (Imixs Workflow JEE Archetype
provides a JEE Sample Application)
13: remote -> weld-jsf-jee (Weld archetype for creating a Java EE 6 application
using JSF 2.0, CDI 1.0, EJB 3.1 and JPA 2.0 (persistence unit included))
14: remote -> weld-jsf-jee-minimal (Weld archetype for creating a minimal Java
EE 6 application using JSF 2.0, CDI 1.0 and EJB 3.1 (persistence unit not
included))
Choose a number: : 13
Downloading:
http://repo1.maven.org/maven2/org/jboss/weld/archetypes/weld-jsf-jee/1.0.0-BETA1/weld-jsf-jee-1.0.0-BETA1.jar
Downloaded:
http://repo1.maven.org/maven2/org/jboss/weld/archetypes/weld-jsf-jee/1.0.0-BETA1/weld-jsf-jee-1.0.0-BETA1.jar
(138 KB at 121.2 KB/sec)
Downloading:
http://repo1.maven.org/maven2/org/jboss/weld/archetypes/weld-jsf-jee/1.0.0-BETA1/weld-jsf-jee-1.0.0-BETA1.pom
Downloaded:
http://repo1.maven.org/maven2/org/jboss/weld/archetypes/weld-jsf-jee/1.0.0-BETA1/weld-jsf-jee-1.0.0-BETA1.pom
(2 KB at 1.9 KB/sec)
Define value for property 'groupId': : foo.bar
Define value for property 'artifactId': : weldy
[INFO] Using property: version = 1.0.0-SNAPSHOT
Define value for property 'package': foo.bar: :
Confirm properties configuration:
groupId: foo.bar
artifactId: weldy
version: 1.0.0-SNAPSHOT
package: foo.bar
Y: :
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 31.635s
[INFO] Finished at: Sun May 01 00:09:10 CEST 2011
[INFO] Final Memory: 6M/245M
[INFO] ------------------------------------------------------------------------
{noformat}
Basically, the code in org.apache.maven.archetype.ui.DefaultArchetypeSelector
looks like :
{noformat}
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() );
...
{noformat}
{noformat}
private Map<String, List<Archetype>> getFilteredArchetypes( Map<String,
List<Archetype>> archetypesByCatalog,
final String filter) {
if (StringUtils.isNotEmpty(filter) && !archetypesByCatalog.isEmpty())
{
for (Map.Entry<String, List<Archetype>> entry :
archetypesByCatalog.entrySet())
{
CollectionUtils.filter(entry.getValue(), new Predicate()
{
public boolean evaluate(Object
archetype)
{
return ((Archetype)
archetype).getArtifactId().contains(filter);
}
});
}
}
return archetypesByCatalog;
}
{noformat}
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 :-)
> Add a command line argument to filter/limit the archetypes returned by mvn
> archetype:generate
> ---------------------------------------------------------------------------------------------
>
> Key: ARCHETYPE-371
> URL: http://jira.codehaus.org/browse/ARCHETYPE-371
> Project: Maven Archetype
> Issue Type: New Feature
> Components: Plugin
> Affects Versions: 2.0
> Environment: Apache 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"
> Reporter: Fred Bricon
>
> 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 {code}mvn archetype:generate -Dfilter=webapp{code} would return
> only the archetypes having webapp in their artifactId.
> What do you think?
--
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