From 880648435f8d5ce85afea56b85bf44b5339f0809 Mon Sep 17 00:00:00 2001 From: Trygve Laugstol Date: Fri, 25 Jun 2004 02:35:08 +0000 Subject: [PATCH] o Adding plugin:install mojo. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162835 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/plugin/InstallMojo.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/InstallMojo.java diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/InstallMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/InstallMojo.java new file mode 100644 index 0000000000..79bc7f3483 --- /dev/null +++ b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/InstallMojo.java @@ -0,0 +1,120 @@ +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 install + * + * @description Installs a plugin into the maven installation. + * + * @prereq plugin:descriptor + * @prereq jar:jar + * + * @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 Trygve Laugstøl + * @version $Id$ + */ +public class InstallMojo + extends AbstractPlugin +{ + public void execute( PluginExecutionRequest request, PluginExecutionResponse response ) + throws Exception + { + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + String outputDirectory = (String) request.getParameter( "outputDirectory" ); + + String jarName = (String) request.getParameter( "jarName" ); + + String pluginHomeName = (String) request.getParameter( "pluginHome" ); + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + File jarFile = new File( new File( outputDirectory ), jarName + ".jar" ); + + 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 ); + } + + System.out.println( "Installing " + jarFile + " in " + pluginHome ); + + FileUtils.copyFileToDirectory( jarFile, pluginHome ); + } +}