From 1287dc32c7996d9aca52f6177a448b683a53be4e Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Tue, 1 Nov 2005 04:57:24 +0000 Subject: [PATCH] add mojo for copying the artifact to the Maven 1.x repo, and add docs git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@329973 13f79535-47bb-0310-9956-ffa450edef68 --- sandbox/maven-one-plugin/pom.xml | 10 ++ .../maven/plugins/MavenOnePluginMojo.java | 5 +- .../MavenOneRepositoryInstallMojo.java | 155 ++++++++++++++++++ .../resources/META-INF/plexus/components.xml | 13 ++ .../src/site/apt/introduction.apt | 67 ++++++++ sandbox/maven-one-plugin/src/site/site.xml | 22 +++ 6 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOneRepositoryInstallMojo.java create mode 100644 sandbox/maven-one-plugin/src/site/apt/introduction.apt create mode 100644 sandbox/maven-one-plugin/src/site/site.xml diff --git a/sandbox/maven-one-plugin/pom.xml b/sandbox/maven-one-plugin/pom.xml index 6dbb133df8..8dd9873087 100644 --- a/sandbox/maven-one-plugin/pom.xml +++ b/sandbox/maven-one-plugin/pom.xml @@ -39,4 +39,14 @@ 1.0.4 + + + + maven-plugin-plugin + + maven-one-plugin + + + + diff --git a/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java b/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java index 4e430105ff..84d79c550d 100644 --- a/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java +++ b/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOnePluginMojo.java @@ -105,7 +105,10 @@ public class MavenOnePluginMojo try { - archiver.getArchiver().addDirectory( contentDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES ); + if ( contentDirectory.exists() ) + { + archiver.getArchiver().addDirectory( contentDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES ); + } addFile( archiver, new File( "plugin.jelly" ) ); addFile( archiver, new File( "plugin.properties" ) ); diff --git a/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOneRepositoryInstallMojo.java b/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOneRepositoryInstallMojo.java new file mode 100644 index 0000000000..94745b90b5 --- /dev/null +++ b/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOneRepositoryInstallMojo.java @@ -0,0 +1,155 @@ +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.artifact.Artifact; +import org.apache.maven.artifact.installer.ArtifactInstallationException; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.util.IOUtil; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; + +/** + * Install the artifact in a maven one local repository + * + * @goal install-maven-one-repository + * @phase install + */ +public class MavenOneRepositoryInstallMojo + extends AbstractMojo +{ + /** + * @parameter expression="${project.packaging}" + * @required + * @readonly + */ + protected String packaging; + + /** + * @parameter expression="${project.file}" + * @required + * @readonly + */ + private File pomFile; + + /** + * @parameter expression="${project.artifact}" + * @required + * @readonly + */ + private Artifact artifact; + + /** + * @component + */ + protected ArtifactInstaller installer; + + /** + * @component + */ + protected ArtifactRepositoryFactory factory; + + /** + * @parameter expression="${mavenOneRepository}" + */ + protected String mavenOneRepository; + + /** + * @component roleHint="legacy" + */ + private ArtifactRepositoryLayout legacyLayout; + + public void execute() + throws MojoExecutionException + { + try + { + if ( mavenOneRepository == null ) + { + File f = new File( System.getProperty( "user.home" ), "build.properties" ); + if ( f.exists() ) + { + Properties p = new Properties(); + FileInputStream inStream = new FileInputStream( f ); + try + { + p.load( inStream ); + } + finally + { + IOUtil.close( inStream ); + } + mavenOneRepository = p.getProperty( "maven.repo.local" ); + } + + if ( mavenOneRepository == null ) + { + mavenOneRepository = System.getProperty( "user.home" ) + "/.maven/repository"; + } + } + + File f = new File( mavenOneRepository ); + if ( !f.exists() ) + { + f.mkdirs(); + } + + ArtifactRepository localRepository = factory.createDeploymentArtifactRepository( "mavenOneRepository", + f.toURL().toString(), + legacyLayout, false ); + + boolean isPomArtifact = "pom".equals( packaging ); + + if ( isPomArtifact ) + { + installer.install( pomFile, artifact, localRepository ); + } + else + { + File file = artifact.getFile(); + if ( file == null ) + { + throw new MojoExecutionException( + "The packaging for this project did not assign a file to the build artifact" ); + } + installer.install( file, artifact, localRepository ); + } + + } + catch ( ArtifactInstallationException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( FileNotFoundException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } +} diff --git a/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml b/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml index a032140c4c..4ada2c3b18 100644 --- a/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml +++ b/sandbox/maven-one-plugin/src/main/resources/META-INF/plexus/components.xml @@ -26,5 +26,18 @@ + + org.apache.maven.artifact.handler.ArtifactHandler + maven-one-plugin + org.apache.maven.artifact.handler.DefaultArtifactHandler + + maven-one-plugin + plugins + jar + java + true + + + \ No newline at end of file diff --git a/sandbox/maven-one-plugin/src/site/apt/introduction.apt b/sandbox/maven-one-plugin/src/site/apt/introduction.apt new file mode 100644 index 0000000000..5803cd0505 --- /dev/null +++ b/sandbox/maven-one-plugin/src/site/apt/introduction.apt @@ -0,0 +1,67 @@ + ---------- +Maven One Plugin + ---------- +Brett Porter + ---------- +1 November 2005 + ---------- + +Maven One Plugin + + The Maven One Plugin is a plugin for Maven 2.0 that performs some integration tasks with Maven 1.x: + + * Provides a packaging for Maven 1.x plugins, building using Maven 2.0 + + * Provides a hook for installation that will copy built artifacts into a local Maven 1.x repository, for + concurrent development with Maven 1.x projects + +* Maven 1.x Plugin Packaging + + To build a Maven 1.x plugin using Maven 2.x, you need to include this plugin in the build section, and use a + <<>> of <<>>. The following is an example of such a POM: + +------- + + 4.0.0 + maven + maven-site-plugin + maven-one-plugin + 1.6-SNAPSHOT + + + + maven-one-plugin + true + + + + +------- + +* Maven 1.x Local Repository Installation + + To have your artifact installed into a local Maven 1.x repository, add the following lifecycle binding to your POM: + +------- + + ... + + maven-one-plugin + + + + install-maven-one-repository + + + + + ... + +------- + + <> The plugin section can be shared with the one above in the case of building a Maven 1.x plugin. + + This will read the local repository location from <<<~/build.properties>>>, defaulting to <<<~/.maven/repository>>>. + + For more information, see the {{{index.html} Goal Reference}} + diff --git a/sandbox/maven-one-plugin/src/site/site.xml b/sandbox/maven-one-plugin/src/site/site.xml new file mode 100644 index 0000000000..7f98c6e45f --- /dev/null +++ b/sandbox/maven-one-plugin/src/site/site.xml @@ -0,0 +1,22 @@ + + + Maven One plugin + http://maven.apache.org/images/apache-maven-project.png + http://maven.apache.org/ + + + http://maven.apache.org/images/maven-small.gif + + + + + + + + + + + ${reports} + + +