o maven-plugin-plugin now uses plugin:setup for integrating plugin with maven installation.

plugin:install and plugin:deploy methods are implemented but some change in the core are needed to make   them work


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162843 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michal Maczka 2004-06-27 17:09:13 +00:00
parent a28ad00561
commit 107fd13e0a
11 changed files with 370 additions and 12 deletions

View File

@ -8,8 +8,18 @@
</parent>
<groupId>maven-plugin-plugin</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<type>plugin</type>
<name>Maven</name>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2001</inceptionYear>
<package>org.apache.maven</package>
<package>org.apache.maven.plugin.plugin</package>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,36 @@
package org.apache.maven.plugin.plugin;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public abstract class AbstractGeneratorMojo
extends AbstractPlugin
{
protected abstract void generate( String sourceDirectory, String outputDirectory, String pom )
throws Exception;
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
String sourceDirectory = (String) request.getParameter( "sourceDirectory" );
String outputDirectory = (String) request.getParameter( "outputDirectory" );
String pom = (String) request.getParameter( "pom" );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
generate( sourceDirectory, outputDirectory, pom );
}
}

View File

@ -4,6 +4,8 @@ import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import java.io.File;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
@ -11,26 +13,27 @@ import org.apache.maven.plugin.PluginExecutionResponse;
public abstract class AbstractPluginMojo
extends AbstractPlugin
{
protected abstract void generate( String sourceDirectory, String outputDirectory, String pom )
throws Exception;
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
protected File getJarFile( PluginExecutionRequest request )
{
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
String sourceDirectory = (String) request.getParameter( "sourceDirectory" );
String outputDirectory = (String) request.getParameter( "outputDirectory" );
String pom = (String) request.getParameter( "pom" );
String jarName = (String) request.getParameter( "jarName" );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
generate( sourceDirectory, outputDirectory, pom );
File jarFile = new File( new File( outputDirectory ), jarName + ".jar" );
return jarFile;
}
}

View File

@ -33,7 +33,7 @@ import org.apache.maven.plugin.generator.BeanGenerator;
* @version $Id$
*/
public class BeanGeneratorMojo
extends AbstractPluginMojo
extends AbstractGeneratorMojo
{
protected void generate( String sourceDirectory, String outputDirectory, String pom )
throws Exception

View File

@ -33,7 +33,7 @@ import org.apache.maven.plugin.generator.PluginDescriptorGenerator;
* @version $Id$
*/
public class DescriptorGenerator
extends AbstractPluginMojo
extends AbstractGeneratorMojo
{
protected void generate( String sourceDirectory, String outputDirectory, String pom )
throws Exception

View File

@ -18,6 +18,7 @@ import org.codehaus.plexus.util.FileUtils;
* @description Installs a plugin into the maven installation.
*
* @prereq plugin:descriptor
*
* @prereq jar:jar
*
* @parameter

View File

@ -33,7 +33,7 @@ import org.apache.maven.plugin.generator.jelly.JellyHarnessGenerator;
* @version $Id$
*/
public class JellyGeneratorMojo
extends AbstractPluginMojo
extends AbstractGeneratorMojo
{
protected void generate( String sourceDirectory, String outputDirectory, String pom )
throws Exception

View File

@ -0,0 +1,79 @@
package org.apache.maven.plugin.plugin;
import java.io.File;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.project.MavenProject;
import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.codehaus.plexus.util.FileUtils;
/*
* LICENSE
*/
/**
* @goal deploy
*
* @description Installs a plugin into local repository
*
* @prereq plugin:plugin
*
* @parameter
* name="outputDirectory"
* type="String"
* required="true"
* validator=""
* expression="#project.build.directory"
* description=""
*
* @parameter
* name="jarName"
* type="String"
* required="true"
* validator=""
* expression="#maven.final.name"
* description=""
*
* @parameter
* name="project"
* type="org.apache.maven.project.MavenProject"
* required="true"
* validator=""
* expression="#project"
* description=""
*
* @parameter
* name="deployer"
* type="org.apache.maven.artifact.deployer.ArtifactDeployer"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.deployer.ArtifactDeployer"
* description=""
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @version $Id$
*/
public class PluginDeployMojo
extends AbstractPluginMojo
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
File jarFile = getJarFile( request );
MavenProject project = (MavenProject) request.getParameter( "project" );
ArtifactDeployer artifactDeployer = ( ArtifactDeployer ) request.getParameter( "deployer" );
artifactDeployer.deploy( jarFile, "plugin", project );
}
}

View File

@ -0,0 +1,81 @@
package org.apache.maven.plugin.plugin;
import java.io.File;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.project.MavenProject;
import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.codehaus.plexus.util.FileUtils;
/*
* LICENSE
*/
/**
* @goal install
*
* @description Installs a plugin into local repository
*
* @prereq plugin:plugin
*
* @parameter
* name="outputDirectory"
* type="String"
* required="true"
* validator=""
* expression="#project.build.directory"
* description=""
*
* @parameter
* name="jarName"
* type="String"
* required="true"
* validator=""
* expression="#maven.final.name"
* description=""
*
* @parameter
* name="project"
* type="org.apache.maven.project.MavenProject"
* required="true"
* validator=""
* expression="#project"
* description=""
*
* @parameter
* name="installer"
* type="org.apache.maven.artifact.installer.ArtifactInstaller"
* required="true"
* validator=""
* expression="#component.org.apache.maven.artifact.installer.ArtifactInstaller"
* description=""
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @version $Id$
*/
public class PluginInstallMojo
extends AbstractPluginMojo
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
File jarFile = getJarFile( request );
MavenProject project = (MavenProject) request.getParameter( "project" );
ArtifactInstaller artifactInstaller = (ArtifactInstaller) request.getParameter( "installer" );
System.out.println( "artifactInstaller: " + artifactInstaller );
artifactInstaller.install( jarFile, "plugin", project );
}
}

View File

@ -0,0 +1,27 @@
package org.apache.maven.plugin.plugin;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
/**
* @goal plugin
*
* @description Creates a plugin jar
*
* @prereq plugin:descriptor
*
* @prereq jar:jar
*
*
* @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @version $Id$
*/
public class PluginMojo extends AbstractPlugin
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) throws Exception
{
}
}

View File

@ -0,0 +1,121 @@
package org.apache.maven.plugin.plugin;
import java.io.File;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.codehaus.plexus.util.FileUtils;
/*
* LICENSE
*/
/**
* @goal setup
*
* @description Installs a plugin into the maven installation.
*
* @prereq plugin:plugin
*
* @parameter
* name="outputDirectory"
* type="String"
* required="true"
* validator=""
* expression="#project.build.directory"
* description=""
*
* @parameter
* name="jarName"
* type="String"
* required="true"
* validator=""
* expression="#maven.final.name"
* description=""
*
* @parameter
* name="pluginHome"
* type="String"
* required="true"
* validator=""
* expression="#maven.plugin.home"
* description=""
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @version $Id$
*/
public class PluginSetupMojo
extends AbstractPluginMojo
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
String pluginHomeName = (String) request.getParameter( "pluginHome" );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
File jarFile = getJarFile( request );
File pluginHome = getPluginHome( pluginHomeName );
System.out.println( "Installing " + jarFile + " in " + pluginHome );
FileUtils.copyFileToDirectory( jarFile, pluginHome );
}
private File getPluginHome( String pluginHomeName )
throws Exception
{
File pluginHome;
if ( pluginHomeName == null ||
pluginHomeName.trim().length() == 0 ||
pluginHomeName.equals( "maven.plugin.home" ) )
{
String mavenHomeName = System.getProperty( "maven.home" );
if ( mavenHomeName == null )
{
String userHomeName = System.getProperty( "user.home" );
System.out.println( "userHomeName: " + userHomeName );
File mavenHome = new File( userHomeName, ".m2" );
if ( !mavenHome.exists() )
{
mavenHome = new File( userHomeName, "m2" );
if ( !mavenHome.exists() )
{
pluginHome = new File( mavenHome, "plugins" );
}
else
{
throw new Exception( "Cannot find the maven plugins directory." );
}
}
else
{
pluginHome = new File( mavenHome, "plugins" );
}
}
else
{
pluginHome = new File( mavenHomeName, "plugins" );
}
}
else
{
pluginHome = new File( pluginHomeName );
}
return pluginHome;
}
}