update the archetypes

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163837 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-07 15:42:46 +00:00
parent 9408e4607d
commit f4ecf6bf08
16 changed files with 192 additions and 223 deletions

View File

@ -11,25 +11,20 @@
<dependencies>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<artifactId>plexus-utils</artifactId>
<version>1.0-alpha-2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!--
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
@ -37,5 +32,6 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
-->
</dependencies>
</model>

View File

@ -17,15 +17,14 @@ package org.apache.maven.archetype;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -51,27 +50,28 @@ public class ArchetypeTest
parameters.put( "package", "org.apache.maven.quickstart" );
parameters.put( "outputDirectory",new File( getBasedir(), "target/archetype" ).getPath() );
parameters.put( "outputDirectory", new File( getBasedir(), "target/archetype" ).getPath() );
// ----------------------------------------------------------------------
// This needs to be encapsulated in a maven test case.
// ----------------------------------------------------------------------
File mavenPropertiesFile = new File( System.getProperty( "user.home" ), ".m2/maven.properties" );
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE,
"default" );
Properties mavenProperties = new Properties();
mavenProperties.load( new FileInputStream( mavenPropertiesFile ) );
ArtifactRepository localRepository = new ArtifactRepository( "local", "file://" + mavenProperties.getProperty( "maven.repo.local" ) );
String mavenRepoLocal = getTestFile( "target/local-repository" ).toURL().toString();
ArtifactRepository localRepository = new ArtifactRepository( "local", mavenRepoLocal, layout );
List remoteRepositories = new ArrayList();
ArtifactRepository remoteRepository = new ArtifactRepository( "remote", "http://repo1.maven.org" );
String mavenRepoRemote = getTestFile( "src/test/repository" ).toURL().toString();
ArtifactRepository remoteRepository = new ArtifactRepository( "remote", mavenRepoRemote, layout );
remoteRepositories.add( remoteRepository );
archetype.createArchetype( "maven", "maven-archetype-quickstart", "1.0-alpha-1-SNAPSHOT",
localRepository, remoteRepositories, parameters);
archetype.createArchetype( "org.apache.maven.archetypes", "maven-archetype-quickstart", "1.0-alpha-1-SNAPSHOT",
localRepository, remoteRepositories, parameters );
// TODO: validate output
}
}
}

View File

@ -1,7 +1,7 @@
<model>
<parent>
<artifactId>maven-plugin-parent</artifactId>
<groupId>org.apache.maven</groupId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -1,7 +1,7 @@
package org.apache.maven.plugin.archetype;
/*
* Copyright 2001-2004 The Apache Software Foundation.
* Copyright 2001-2005 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.
@ -19,95 +19,81 @@ package org.apache.maven.plugin.archetype;
import org.apache.maven.archetype.Archetype;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import java.util.ArrayList;
import java.io.File;
import java.util.List;
/**
* @goal create
*
* @description Builds archetype containers.
*
* @parameter
* name="archetype"
* type="org.apache.maven.archetype.Archetype"
* required="true"
* validator=""
* expression="#component.org.apache.maven.archetype.Archetype"
* description=""
*
* @parameter
* name="localRepository"
* type="org.apache.maven.artifact.ArtifactRepository"
* required="true"
* validator=""
* expression="#localRepository"
* description=""
*
* @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"
* type="String"
* required="true"
* validator=""
* expression="#groupId"
* default="maven"
* description=""
*
* @parameter
* name="artifactId"
* type="String"
* required="true"
* validator=""
* expression="#artifactId"
* default="quickstart"
* description=""
*
* @parameter
* name="version"
* type="String"
* required="true"
* validator=""
* expression="#version"
* default="1.0"
* description=""
*
* @parameter
* name="package"
* type="String"
* required="true"
* validator=""
* expression="#package"
* default="org.apache.maven.quickstart"
* description=""
* @parameter name="archetype"
* type="org.apache.maven.archetype.Archetype"
* required="true"
* validator=""
* expression="#component.org.apache.maven.archetype.Archetype"
* description=""
* @parameter name="localRepository"
* type="org.apache.maven.artifact.ArtifactRepository"
* required="true"
* validator=""
* expression="#localRepository"
* description=""
* @parameter name="archetypeGroupId"
* type="String"
* required="true"
* validator=""
* expression="#archetypeGroupId"
* default="org.apache.maven.archetypes"
* description=""
* @parameter name="archetypeArtifactId"
* type="String"
* required="true"
* validator=""
* expression="#archetypeArtifactId"
* default="maven-archetype-quickstart"
* description=""
* @parameter name="archetypeVersion"
* type="String"
* required="true"
* validator=""
* expression="#archetypeVersion"
* default="1.0-alpha-1-SNAPSHOT"
* description=""
* @parameter name="groupId"
* type="String"
* required="true"
* validator=""
* expression="#groupId"
* description=""
* @parameter name="artifactId"
* type="String"
* required="true"
* validator=""
* expression="#artifactId"
* description=""
* @parameter name="version"
* type="String"
* required="true"
* validator=""
* expression="#version"
* default="1.0-SNAPSHOT"
* description=""
* @parameter name="package"
* type="String"
* required="true"
* validator=""
* expression="#package"
* default="com.mycompany.app"
* description=""
* @parameter name="remoteRepositories"
* type="java.util.List"
* required="true"
* validator=""
* expression="#project.remoteArtifactRepositories"
* description=""
*/
public class MavenArchetypePlugin
extends AbstractPlugin
@ -115,6 +101,10 @@ public class MavenArchetypePlugin
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
// TODO: prompt for missing values
// TODO: use new plugin type
// TODO: configurable license
// ----------------------------------------------------------------------
// archetypeGroupId
// archetypeArtifactId
@ -125,17 +115,10 @@ public class MavenArchetypePlugin
// parameters
// ----------------------------------------------------------------------
// When there is no project how do we get the local repository and remote repos.
// The local repository will always be present but the remote is in the POM except
// for the super POM ...
ArtifactRepository localRepository = (ArtifactRepository) request.getParameter( "localRepository" );
List remoteRepositories = new ArrayList();
ArtifactRepository remoteRepository = new ArtifactRepository( "remote", "http://repo1.maven.org" );
remoteRepositories.add( remoteRepository );
// From the super POM
List remoteRepositories = (List) request.getParameter( "remoteRepositories" );
String archetypeGroupId = (String) request.getParameter( "archetypeGroupId" );
@ -145,9 +128,19 @@ public class MavenArchetypePlugin
Archetype archetype = (Archetype) request.getParameter( "archetype" );
request.getParameters().put( "outputDirectory", System.getProperty( "user.dir" ) );
String basedir = System.getProperty( "user.dir" );
archetype.createArchetype( archetypeGroupId, archetypeArtifactId, archetypeVersion,
localRepository, remoteRepositories, request.getParameters() );
// TODO: allow this to be configured
File outputDirectory = new File( basedir, (String) request.getParameter( "artifactId" ) );
request.getParameters().put( "outputDirectory", outputDirectory.getAbsolutePath() );
if ( outputDirectory.exists() )
{
throw new PluginExecutionException(
outputDirectory.getName() + " already exists - please run from a clean directory" );
}
archetype.createArchetype( archetypeGroupId, archetypeArtifactId, archetypeVersion, localRepository,
remoteRepositories, request.getParameters() );
}
}

View File

@ -1,7 +1,7 @@
<model>
<parent>
<artifactId>maven-archetypes</artifactId>
<groupId>org.apache.maven</groupId>
<groupId>org.apache.maven.archetypes</groupId>
<version>1.0-alpha-1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -2,15 +2,20 @@
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<packaging>jar</packaging>
<packaging>maven-plugin</packaging>
<version>${version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<scope>compile</scope>
<scope>test</scope>
</dependency>
</dependencies>
</model>

View File

@ -1,78 +1,84 @@
package $package;
/*
* Copyright 2001-2005 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.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.plugin.PluginExecutionException;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* @goal touch
*
* @phase process-sources
*
* @description Goal which cleans the build
* @description Goal which touches a timestamp file
*
* @parameter
* name="outputDirectory"
* type="String"
* required="true"
* validator=""
* expression="#project.build.directory"
* description=""
*
* @parameter
* name="basedirAlignmentDirectory"
* type="java.io.File"
* required="true"
* validator=""
* expression="target/test-basedir-alignment"
* expression="#project.build.directory"
* description=""
*/
public class MyMojo
extends AbstractPlugin
{
private static final int DELETE_RETRY_SLEEP_MILLIS = 10;
private String outputDirectory;
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute()
throws PluginExecutionException
{
String outputDirectory = (String) request.getParameter( "outputDirectory" );
File f = new File( outputDirectory );
if ( !f.exists() )
{
f.mkdirs();
}
File touch = new File( f, "touch.txt" );
FileWriter w = new FileWriter( touch );
w.write( "touch.txt" );
w.close();
// This parameter should be aligned to the basedir as the parameter type is specified
// as java.io.File
String basedirAlignmentDirectory = (String) request.getParameter( "basedirAlignmentDirectory" );
f = new File( basedirAlignmentDirectory );
if ( !f.exists() )
File touch = new File( f, "touch.txt" );
FileWriter w = null;
try
{
f.mkdirs();
}
touch = new File( f, "touch.txt" );
w = new FileWriter( touch );
w.write( "touch.txt" );
w.close();
w = new FileWriter( touch );
w.write( "touch.txt" );
}
catch ( IOException e )
{
throw new PluginExecutionException( "Error creating file " + touch );
}
finally
{
if ( w != null )
{
try
{
w.close();
}
catch ( IOException e )
{
// ignore
}
}
}
}
}

View File

@ -1,7 +1,7 @@
<model>
<parent>
<artifactId>maven-archetypes</artifactId>
<groupId>org.apache.maven</groupId>
<groupId>org.apache.maven.archetypes</groupId>
<version>1.0-alpha-1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -9,8 +9,7 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<scope>compile</scope>
<scope>test</scope>
</dependency>
</dependencies>
</model>
</model>

View File

@ -3,8 +3,6 @@ package $package;
/**
* Hello world!
*
* @author <a href="jason@zenplex.com">Jason van Zyl</a>
*
*/
public class App
{

View File

@ -1,40 +0,0 @@
package $package;
import java.io.File;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Abstract base class for test cases.
*
* @author <a href="jason@zenplex.com">Jason van Zyl</a>
*/
public abstract class AbstractTestCase
extends TestCase
{
/**
* Basedir for all file I/O. Important when running tests from
* the reactor.
*/
public String basedir = System.getProperty("basedir");
/**
* Constructor.
*/
public AbstractTestCase(String testName)
{
super(testName);
}
/**
* Get test input file.
*
* @param path Path to test input file.
*/
public String getTestFile(String path)
{
return new File(basedir,path).getAbsolutePath();
}
}

View File

@ -6,11 +6,9 @@ import junit.framework.TestSuite;
/**
* Unit test for simple App.
*
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
*/
public class AppTest
extends AbstractTestCase
extends TestCase
{
/**
* Create the test case
@ -35,6 +33,6 @@ public class AppTest
*/
public void testApp()
{
assertEquals( "maven kicks ass", "maven kicks ass" );
assertTrue( true );
}
}

View File

@ -1,7 +1,7 @@
<model>
<parent>
<artifactId>maven-archetypes</artifactId>
<groupId>org.apache.maven</groupId>
<groupId>org.apache.maven.archetypes</groupId>
<version>1.0-alpha-1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -2,22 +2,25 @@
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<packaging>jar</packaging>
<packaging>war</packaging>
<version>${version}</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<scope>compile</scope>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>1.0-alpha-1</version>
<configuration>
<warName>${artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>
</model>
</model>

View File

@ -5,7 +5,13 @@
<version>1.0-alpha-1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.archetypes</groupId>
<artifactId>maven-archetypes</artifactId>
<packaging>pom</packaging>
<version>1.0-alpha-1-SNAPSHOT</version>
<modules>
<module>maven-archetype-mojo</module>
<module>maven-archetype-quickstart</module>
<module>maven-archetype-webapp</module>
</modules>
</model>

View File

@ -8,4 +8,9 @@
<artifactId>maven-archetype</artifactId>
<packaging>pom</packaging>
<version>1.0-alpha-1-SNAPSHOT</version>
<modules>
<module>maven-archetype-core</module>
<module>maven-archetype-plugin</module>
<module>maven-archetypes</module>
</modules>
</model>