o Adding group id and version when creating a archetype.

o Adding licenses.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163293 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Trygve Laugstol 2005-01-06 13:03:10 +00:00
parent b5add4d660
commit f5052b6d5a
11 changed files with 261 additions and 46 deletions

View File

@ -1,13 +1,25 @@
/*
* Copyright (c) 2004 Your Corporation. All Rights Reserved.
*/
package org.apache.maven.archetype; package org.apache.maven.archetype;
import org.apache.maven.artifact.repository.ArtifactRepository; /*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.io.File;
import org.apache.maven.artifact.repository.ArtifactRepository;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -23,6 +35,7 @@ public interface Archetype
String ARCHETYPE_POM = "pom.xml"; String ARCHETYPE_POM = "pom.xml";
void createArchetype( String archetypeId, ArtifactRepository localRepository, Set remoteRepositories, Map parameters ) void createArchetype( String archetypeGroupId, String archetypeArtifactId, String archetypeVersion,
ArtifactRepository localRepository, Set remoteRepositories, Map parameters )
throws ArchetypeNotFoundException, ArchetypeDescriptorException, ArchetypeTemplateProcessingException; throws ArchetypeNotFoundException, ArchetypeDescriptorException, ArchetypeTemplateProcessingException;
} }

View File

@ -1,8 +1,21 @@
/*
* Copyright (c) 2004 Your Corporation. All Rights Reserved.
*/
package org.apache.maven.archetype; package org.apache.maven.archetype;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$

View File

@ -1,8 +1,21 @@
/*
* Copyright (c) 2004 Your Corporation. All Rights Reserved.
*/
package org.apache.maven.archetype; package org.apache.maven.archetype;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$

View File

@ -1,8 +1,21 @@
/*
* Copyright (c) 2004 Your Corporation. All Rights Reserved.
*/
package org.apache.maven.archetype; package org.apache.maven.archetype;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$

View File

@ -1,27 +1,45 @@
package org.apache.maven.archetype; package org.apache.maven.archetype;
import org.apache.maven.archetype.descriptor.ArchetypeDescriptor; /*
import org.apache.maven.archetype.descriptor.ArchetypeDescriptorBuilder; * Copyright 2001-2004 The Apache Software Foundation.
import org.apache.maven.artifact.Artifact; *
import org.apache.maven.artifact.resolver.ArtifactResolver; * Licensed under the Apache License, Version 2.0 (the "License");
import org.apache.maven.artifact.manager.WagonManager; * you may not use this file except in compliance with the License.
import org.apache.maven.artifact.repository.ArtifactRepository; * You may obtain a copy of the License at
import org.apache.velocity.VelocityContext; *
import org.apache.velocity.context.Context; * http://www.apache.org/licenses/LICENSE-2.0
import org.codehaus.plexus.util.FileUtils; *
import org.codehaus.plexus.velocity.VelocityComponent; * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Writer; import java.io.Writer;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.net.URLClassLoader;
import java.net.URL; import org.apache.maven.archetype.descriptor.ArchetypeDescriptor;
import org.apache.maven.archetype.descriptor.ArchetypeDescriptorBuilder;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.velocity.VelocityComponent;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -48,20 +66,30 @@ public class DefaultArchetype
// artifactId = maven-foo-archetype // artifactId = maven-foo-archetype
// version = latest // version = latest
public void createArchetype( String archetypeId, ArtifactRepository localRepository, Set remoteRepositories, Map parameters ) public void createArchetype( String archetypeGroupId, String archetypeArtifactId, String archetypeVersion,
ArtifactRepository localRepository, Set remoteRepositories, Map parameters )
throws ArchetypeNotFoundException, ArchetypeDescriptorException, ArchetypeTemplateProcessingException throws ArchetypeNotFoundException, ArchetypeDescriptorException, ArchetypeTemplateProcessingException
{ {
Artifact archetypeJar = wagonManager.createArtifact( "maven", "maven-archetype-" + archetypeId, "1.0-alpha-1-SNAPSHOT", "jar" ); // ----------------------------------------------------------------------
// Download the archetype
// ----------------------------------------------------------------------
Artifact archetypeJar =
wagonManager.createArtifact( archetypeGroupId, archetypeArtifactId, archetypeVersion, "jar" );
try try
{ {
artifactResolver.resolve( archetypeJar, remoteRepositories, localRepository ); artifactResolver.resolve( archetypeJar, remoteRepositories, localRepository );
} }
catch ( Exception e ) catch ( ArtifactResolutionException e )
{ {
throw new ArchetypeNotFoundException( "Cannot download archetype.", e ); throw new ArchetypeNotFoundException( "Cannot download archetype.", e );
} }
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
String outputDirectory = (String) parameters.get( "outputDirectory" ); String outputDirectory = (String) parameters.get( "outputDirectory" );
String packageName = (String) parameters.get( "package" ); String packageName = (String) parameters.get( "package" );
@ -109,25 +137,31 @@ public class DefaultArchetype
context.put( key, value ); context.put( key, value );
} }
try
{
ClassLoader old = Thread.currentThread().getContextClassLoader(); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( archetypeJarLoader ); Thread.currentThread().setContextClassLoader( archetypeJarLoader );
try
{
processTemplate( outputDirectory, context, ARCHETYPE_POM, null ); processTemplate( outputDirectory, context, ARCHETYPE_POM, null );
processSources( outputDirectory, context, descriptor.getSources(), packageName ); processSources( outputDirectory, context, descriptor.getSources(), packageName );
processSources( outputDirectory, context, descriptor.getTestSources(), packageName ); processSources( outputDirectory, context, descriptor.getTestSources(), packageName );
Thread.currentThread().setContextClassLoader( old );
} }
catch ( Exception e ) catch ( Exception e )
{ {
throw new ArchetypeTemplateProcessingException( "Error processing templates.", e ); throw new ArchetypeTemplateProcessingException( "Error processing templates.", e );
} }
finally
{
Thread.currentThread().setContextClassLoader( old );
} }
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
protected void processSources( String outputDirectory, Context context, List sources, String packageName ) protected void processSources( String outputDirectory, Context context, List sources, String packageName )
throws Exception throws Exception

View File

@ -1,5 +1,21 @@
package org.apache.maven.archetype.descriptor; package org.apache.maven.archetype.descriptor;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,5 +1,21 @@
package org.apache.maven.archetype.descriptor; package org.apache.maven.archetype.descriptor;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.Reader; import java.io.Reader;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.Xpp3DomBuilder;

View File

@ -1,8 +1,21 @@
/*
* Copyright (c) 2004 Your Corporation. All Rights Reserved.
*/
package org.apache.maven.archetype.descriptor; package org.apache.maven.archetype.descriptor;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* Pass over the directory containing the sources of the archetype and create * Pass over the directory containing the sources of the archetype and create
* the appropriate descriptor. * the appropriate descriptor.

View File

@ -1,5 +1,21 @@
package org.apache.maven.archetype; package org.apache.maven.archetype;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
@ -55,6 +71,7 @@ public class ArchetypeTest
remoteRepositories.add( remoteRepository ); remoteRepositories.add( remoteRepository );
archetype.createArchetype( "quickstart", localRepository, remoteRepositories, parameters); archetype.createArchetype( "maven", "maven-archetype-quickstart", "1.0-alpha-1-SNAPSHOT",
localRepository, remoteRepositories, parameters);
} }
} }

View File

@ -1,5 +1,21 @@
package org.apache.maven.archetype.descriptor; package org.apache.maven.archetype.descriptor;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.StringReader; import java.io.StringReader;

View File

@ -1,5 +1,21 @@
package org.apache.maven.plugin.archetype; package org.apache.maven.plugin.archetype;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.archetype.Archetype; import org.apache.maven.archetype.Archetype;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractPlugin; import org.apache.maven.plugin.AbstractPlugin;
@ -31,6 +47,33 @@ import java.util.Set;
* description="" * description=""
* *
* @parameter * @parameter
* name="archetypeGroupId"
* type="String"
* required="true"
* validator=""
* expression="#archetypeGroupId"
* default="maven"
* description=""
*
* @parameter
* name="archetypeArtifactId"
* type="String"
* required="true"
* validator=""
* expression="#archetypeArtifactId"
* default="maven"
* description=""
*
* @parameter
* name="archetypeVersion"
* type="String"
* required="true"
* validator=""
* expression="#archetypeVersion"
* default="maven"
* description=""
*
* @parameter
* name="groupId" * name="groupId"
* type="String" * type="String"
* required="true" * required="true"
@ -73,7 +116,10 @@ public class MavenArchetypePlugin
throws Exception throws Exception
{ {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// archetypeId // archetypeGroupId
// archetypeArtifactId
// archetypeVersion
//
// localRepository // localRepository
// remoteRepository // remoteRepository
// parameters // parameters
@ -91,12 +137,17 @@ public class MavenArchetypePlugin
remoteRepositories.add( remoteRepository ); remoteRepositories.add( remoteRepository );
String archetypeId = (String) request.getParameter( "archetypeId" ); String archetypeGroupId = (String) request.getParameter( "archetypeGroupId" );
String archetypeArtifactId = (String) request.getParameter( "archetypeArtifactId" );
String archetypeVersion = (String) request.getParameter( "archetypeVersion" );
Archetype archetype = (Archetype) request.getParameter( "archetype" ); Archetype archetype = (Archetype) request.getParameter( "archetype" );
request.getParameters().put( "outputDirectory", System.getProperty( "user.dir" ) ); request.getParameters().put( "outputDirectory", System.getProperty( "user.dir" ) );
archetype.createArchetype( "quickstart", localRepository, remoteRepositories, request.getParameters() ); archetype.createArchetype( archetypeGroupId, archetypeArtifactId, archetypeVersion,
localRepository, remoteRepositories, request.getParameters() );
} }
} }