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
This commit is contained in:
Brett Leslie Porter 2005-11-01 04:57:24 +00:00
parent 373492ddac
commit 1287dc32c7
6 changed files with 271 additions and 1 deletions

View File

@ -39,4 +39,14 @@
<version>1.0.4</version>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<configuration>
<goalPrefix>maven-one-plugin</goalPrefix>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

View File

@ -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" ) );

View File

@ -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 );
}
}
}

View File

@ -26,5 +26,18 @@
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>maven-one-plugin</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>maven-one-plugin</type>
<directory>plugins</directory>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
</components>
</component-set>

View File

@ -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
<<<packaging>>> of <<<maven-one-plugin>>>. The following is an example of such a POM:
-------
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>maven-site-plugin</artifactId>
<packaging>maven-one-plugin</packaging>
<version>1.6-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-one-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
-------
* 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:
-------
<project>
...
<plugin>
<artifactId>maven-one-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>install-maven-one-repository</goal>
</goals>
</execution>
</executions>
</plugin>
...
</project>
-------
<<Note:>> 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}}

View File

@ -0,0 +1,22 @@
<project name="Maven One plugin">
<bannerLeft>
<name>Maven One plugin</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<body>
<links>
<item name="Maven 2" href="http://maven.apache.org"/>
</links>
<menu name="Maven One Plugin">
<item name="Introduction" href="introduction.html"/>
</menu>
${reports}
</body>
</project>