Author: brett Date: Mon Oct 31 20:18:32 2005 New Revision: 329968 URL: http://svn.apache.org/viewcvs?rev=329968&view=rev Log: add a plugin that creates maven 1.x plugins
Added: maven/components/trunk/sandbox/maven-one-plugin/ (with props) maven/components/trunk/sandbox/maven-one-plugin/pom.xml (with props) maven/components/trunk/sandbox/maven-one-plugin/src/ maven/components/trunk/sandbox/maven-one-plugin/src/main/ maven/components/trunk/sandbox/maven-one-plugin/src/main/java/ maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/ maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/ maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/ maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/ maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java (with props) maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/ maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/ maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/ maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml (with props) Propchange: maven/components/trunk/sandbox/maven-one-plugin/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Mon Oct 31 20:18:32 2005 @@ -0,0 +1,4 @@ +target +*.iml +*.ipr +*.iws Added: maven/components/trunk/sandbox/maven-one-plugin/pom.xml URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-one-plugin/pom.xml?rev=329968&view=auto ============================================================================== --- maven/components/trunk/sandbox/maven-one-plugin/pom.xml (added) +++ maven/components/trunk/sandbox/maven-one-plugin/pom.xml Mon Oct 31 20:18:32 2005 @@ -0,0 +1,42 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-one-plugin</artifactId> + <packaging>maven-plugin</packaging> + <version>1.0-SNAPSHOT</version> + <name>Maven 1.x Plugin</name> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-archiver</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-archiver</artifactId> + <version>1.0-alpha-3</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>1.0.4</version> + </dependency> + </dependencies> +</project> Propchange: maven/components/trunk/sandbox/maven-one-plugin/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/trunk/sandbox/maven-one-plugin/pom.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java?rev=329968&view=auto ============================================================================== --- maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java (added) +++ maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java Mon Oct 31 20:18:32 2005 @@ -0,0 +1,159 @@ +package org.apache.maven.plugins; + +/* + * 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.archiver.MavenArchiveConfiguration; +import org.apache.maven.archiver.MavenArchiver; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; + +/** + * Create a Maven 1.x plugin. + * + * @goal maven-one-plugin + * @phase package + */ +public class MavenOnePluginMojo + extends AbstractMojo +{ + + private static final String[] DEFAULT_EXCLUDES = new String[]{"**/package.html"}; + + private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"}; + + /** + * Directory containing the generated JAR. + * + * @parameter expression="${project.build.directory}" + * @required + * @readonly + */ + private File basedir; + + /** + * Name of the generated JAR. + * + * @parameter expression="${project.build.finalName}" + * @required + */ + private String finalName; + + /** + * The Jar archiver. + * + * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}" + * @required + */ + private JarArchiver jarArchiver; + + /** + * The maven project. + * + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * @component + */ + private MavenProjectHelper projectHelper; + + /** + * @parameter expression="${project.build.outputDirectory}" + * @required + */ + private File contentDirectory; + + /** + * Generates the JAR. + * + * @todo Add license files in META-INF directory. + */ + public File createArchive() + throws MojoExecutionException + { + File jarFile = new File( basedir, finalName + ".jar" ); + + MavenArchiver archiver = new MavenArchiver(); + + archiver.setArchiver( jarArchiver ); + + archiver.setOutputFile( jarFile ); + + try + { + archiver.getArchiver().addDirectory( contentDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES ); + + addFile( archiver, new File( "plugin.jelly" ) ); + addFile( archiver, new File( "plugin.properties" ) ); + addFile( archiver, new File( "project.properties" ) ); + addFile( archiver, new File( "build.properties" ) ); + addFile( archiver, new File( "project.xml" ) ); + addDirectory( archiver, new File( "src/plugin-resources" ) ); + + archiver.createArchive( project, new MavenArchiveConfiguration() ); + + return jarFile; + } + catch ( Exception e ) + { + // TODO: improve error handling + throw new MojoExecutionException( "Error assembling JAR", e ); + } + } + + private static void addDirectory( MavenArchiver archiver, File file ) + throws ArchiverException + { + if ( file.exists() ) + { + archiver.getArchiver().addDirectory( file, file.getName() + "/", DEFAULT_INCLUDES, + FileUtils.getDefaultExcludes() ); + } + } + + private static void addFile( MavenArchiver archiver, File file ) + throws ArchiverException + { + if ( file.exists() ) + { + archiver.getArchiver().addFile( file, file.getName() ); + } + } + + /** + * Generates the JAR. + * + * @todo Add license files in META-INF directory. + */ + public void execute() + throws MojoExecutionException + { + File jarFile = createArchive(); + + project.getArtifact().setFile( jarFile ); + } +} Propchange: maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/trunk/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml URL: http://svn.apache.org/viewcvs/maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml?rev=329968&view=auto ============================================================================== --- maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml (added) +++ maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml Mon Oct 31 20:18:32 2005 @@ -0,0 +1,30 @@ +<component-set> + <components> + <component> + <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> + <role-hint>maven-one-plugin</role-hint> + <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> + <configuration> + <lifecycles> + <lifecycle> + <id>default</id> + <phases> + <process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources> + <compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile> + <process-test-resources> + org.apache.maven.plugins:maven-resources-plugin:testResources</process-test-resources> + <test-compile>org.apache.maven.plugins:maven-compiler-plugin:testCompile</test-compile> + <test>org.apache.maven.plugins:maven-surefire-plugin:test</test> + <package> + org.apache.maven.plugins:maven-one-plugin:maven-one-plugin + </package> + <install>org.apache.maven.plugins:maven-install-plugin:install</install> + <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy> + </phases> + </lifecycle> + </lifecycles> + </configuration> + </component> + + </components> +</component-set> \ No newline at end of file Propchange: maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/components/trunk/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"