mirror of https://github.com/apache/maven.git
added jar:install goal - needs more testing
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6f700af1c2
commit
1b24da6163
|
@ -10,5 +10,15 @@
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<name>Maven Jar Plugin</name>
|
<name>Maven Jar Plugin</name>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<package>org.apache.maven</package>
|
<package>org.apache.maven.plugin.jar</package>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>maven</groupId>
|
||||||
|
<artifactId>maven-core</artifactId>
|
||||||
|
<version>2.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -19,12 +19,14 @@ package org.apache.maven.plugin.jar;
|
||||||
import org.apache.maven.plugin.AbstractPlugin;
|
import org.apache.maven.plugin.AbstractPlugin;
|
||||||
import org.apache.maven.plugin.PluginExecutionRequest;
|
import org.apache.maven.plugin.PluginExecutionRequest;
|
||||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
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;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @goalXX install
|
* @goal jar:install
|
||||||
*
|
*
|
||||||
* @description install a jar in local repository
|
* @description install a jar in local repository
|
||||||
*
|
*
|
||||||
|
@ -37,56 +39,32 @@ import java.io.File;
|
||||||
* validator=""
|
* validator=""
|
||||||
* expression="#maven.final.name"
|
* expression="#maven.final.name"
|
||||||
* description=""
|
* description=""
|
||||||
|
*
|
||||||
* @parameter
|
* @parameter
|
||||||
* name="outputDirectory"
|
* name="outputDirectory"
|
||||||
* type="String"
|
* type="String"
|
||||||
* required="true"
|
* required="true"
|
||||||
* validator=""
|
* validator=""
|
||||||
* expression="#project.build.directory"
|
* expression="#maven.build.dir"
|
||||||
* description=""
|
* description=""
|
||||||
|
*
|
||||||
* @parameter
|
* @parameter
|
||||||
* name="basedir"
|
* name="project"
|
||||||
* type="String"
|
* type="org.apache.maven.project.MavenProject"
|
||||||
* required="true"
|
* required="true"
|
||||||
* validator=""
|
* validator=""
|
||||||
* expression="#project.build.directory"
|
* expression="#project"
|
||||||
* description=""
|
* description=""
|
||||||
|
*
|
||||||
* @parameter
|
* @parameter
|
||||||
* name="groupId"
|
* name="installer"
|
||||||
* type="String"
|
* type="org.apache.maven.artifact.installer.ArtifactInstaller"
|
||||||
* required="true"
|
* required="true"
|
||||||
* validator=""
|
* validator=""
|
||||||
* expression="#project.groupId"
|
* expression="#component.org.apache.maven.artifact.installer.ArtifactInstaller"
|
||||||
* description=""
|
|
||||||
* @parameter
|
|
||||||
* name="artifactId"
|
|
||||||
* type="String"
|
|
||||||
* required="true"
|
|
||||||
* validator=""
|
|
||||||
* expression="#project.artifactId"
|
|
||||||
* description=""
|
|
||||||
* @parameter
|
|
||||||
* name="version"
|
|
||||||
* type="String"
|
|
||||||
* required="true"
|
|
||||||
* validator=""
|
|
||||||
* expression="#project.version"
|
|
||||||
* description=""
|
|
||||||
* @parameter
|
|
||||||
* name="localRepository"
|
|
||||||
* type="String"
|
|
||||||
* required="true"
|
|
||||||
* validator=""
|
|
||||||
* expression="#project.localRepository"
|
|
||||||
* description=""
|
|
||||||
* @parameter
|
|
||||||
* name="pomFile"
|
|
||||||
* type="java.io.File"
|
|
||||||
* required="true"
|
|
||||||
* validator=""
|
|
||||||
* expression="#project.file"
|
|
||||||
* description=""
|
* description=""
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
@ -96,99 +74,19 @@ public class JarInstallMojo
|
||||||
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
|
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
String outputDirectory = ( String ) request.getParameter( "outputDirectory" );
|
String outputDirectory = ( String ) request.getParameter( "outputDirectory" );
|
||||||
|
|
||||||
String jarName = ( String ) request.getParameter( "jarName" );
|
String jarName = ( String ) request.getParameter( "jarName" );
|
||||||
|
|
||||||
String groupId = ( String ) request.getParameter( "groupId" );
|
|
||||||
|
|
||||||
String artifactId = ( String ) request.getParameter( "artifactId" );
|
|
||||||
|
|
||||||
//@todo if we have SNAPSHOT version should we do something special?
|
|
||||||
|
|
||||||
String version = ( String ) request.getParameter( "version" );
|
|
||||||
|
|
||||||
File pomFile = ( File ) request.getParameter( "pomFile" );
|
|
||||||
|
|
||||||
String localRepository = ( String ) request.getParameter( "localRepository" );
|
|
||||||
|
|
||||||
File jarFile = new File( outputDirectory , jarName + ".jar" );
|
File jarFile = new File( outputDirectory , jarName + ".jar" );
|
||||||
|
|
||||||
try
|
MavenProject project = ( MavenProject ) request.getParameter( "project" );
|
||||||
{
|
|
||||||
String jarPath = groupId + "/poms/" + artifactId + "-" + version + ".pom";
|
|
||||||
|
|
||||||
//here I imagine that also something like this can be made
|
ArtifactInstaller artifactInstaller = ( ArtifactInstaller ) request.getParameter( "component.org.apache.maven.artifact.installer.ArtifactInstaller" );
|
||||||
//
|
|
||||||
// Dependecy = new Dependecy();
|
|
||||||
// dependecy.setGroupid( groupId )
|
|
||||||
// ....
|
|
||||||
// MavenArtifact artifact = artifactFactory.createArtifact( dependecy )
|
|
||||||
//
|
|
||||||
// so maven artifact factory will be centralized service for creating
|
|
||||||
// repository paths
|
|
||||||
//
|
|
||||||
// I am not sure if this is good option but it is something which might be considered
|
|
||||||
installArtifact( jarPath, jarFile, localRepository );
|
|
||||||
|
|
||||||
}
|
artifactInstaller.install( jarFile, "jar", project );
|
||||||
catch ( Exception e )
|
|
||||||
{
|
|
||||||
response.setException( e );
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String pomPath = groupId + "/poms/" + artifactId + "-" + version + ".pom";
|
|
||||||
|
|
||||||
installArtifact( pomPath, pomFile, localRepository );
|
|
||||||
}
|
|
||||||
catch ( Exception e )
|
|
||||||
{
|
|
||||||
// @todo what shall we do when jar was installed but we failed to install pom?
|
|
||||||
|
|
||||||
// response.setException ( e );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//@todo do we need to crate md5 checksums in local repsitory?
|
|
||||||
//I think it would be nice if any local repository could be
|
|
||||||
// and at any moment in time used as remote repository
|
|
||||||
// so content of both repositories should be symetrical
|
|
||||||
private void installArtifact( String path, File source, String localRepository ) throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
File destination = new File( localRepository, path );
|
|
||||||
|
|
||||||
|
|
||||||
// @todo should we use plexus classes?
|
|
||||||
FileUtils.fileCopy( source.getPath(), destination.getPath() );
|
|
||||||
|
|
||||||
// @todo we can use as well file wagon here.
|
|
||||||
|
|
||||||
// FileWagon wagon = new FileWagon();
|
|
||||||
//
|
|
||||||
// TransferObserver observer = new ChecksumObserver()
|
|
||||||
//
|
|
||||||
// wagon.addTransferObserver( observer );
|
|
||||||
//
|
|
||||||
// Repository repository = new Repository( "file://xxxx" );
|
|
||||||
//
|
|
||||||
// wagon.connect( repository );
|
|
||||||
//
|
|
||||||
// wagon.put( path, file );
|
|
||||||
|
|
||||||
// and wagon has also built-in support for <<artifacts>> which is not used
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue