Author: vsiveton Date: Thu Oct 12 15:40:44 2006 New Revision: 463479 URL: http://svn.apache.org/viewvc?view=rev&rev=463479 Log: MINSTALL-35: Possibility to install an artifact on a given repository directory
o added localRepositoryPath and localRepositoryId parameters in InstallFileMojo o updated doc and javadoc Added: maven/plugins/trunk/maven-install-plugin/src/site/apt/examples/specific-local-repo.apt (with props) Modified: maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java maven/plugins/trunk/maven-install-plugin/src/site/apt/index.apt Modified: maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java?view=diff&rev=463479&r1=463478&r2=463479 ============================================================================== --- maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java (original) +++ maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java Thu Oct 12 15:40:44 2006 @@ -148,7 +148,7 @@ } protected String getChecksum( File file, String algo ) - throws NoSuchAlgorithmException, IOException, DigesterException + throws NoSuchAlgorithmException, DigesterException { if ( "MD5".equals( algo ) ) { Modified: maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java?view=diff&rev=463479&r1=463478&r2=463479 ============================================================================== --- maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java (original) +++ maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java Thu Oct 12 15:40:44 2006 @@ -20,6 +20,8 @@ import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.installer.ArtifactInstallationException; import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; @@ -28,6 +30,7 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.artifact.ProjectArtifactMetadata; import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; @@ -36,6 +39,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.Reader; +import java.net.MalformedURLException; /** * Installs a file in local repository. @@ -116,9 +120,50 @@ */ private ArtifactFactory artifactFactory; + /** + * Default repository layout + * + * @component roleHint="default" + */ + private ArtifactRepositoryLayout repositoryLayout; + + /** + * The path for a specific local repository directory. It will wrap into an <code>ArtifactRepository</code> + * with <code>localRepoId</code> as <code>id</code> and with default <code>repositoryLayout</code> + * + * @parameter expression="${localRepositoryPath}" + */ + private File localRepositoryPath; + + /** + * The <code>id</code> for the <code>localRepo</code> + * + * @parameter expression="${localRepositoryId}" + */ + private String localRepositoryId; + + /** + * @see org.apache.maven.plugin.Mojo#execute() + */ public void execute() throws MojoExecutionException, MojoFailureException { + // ---------------------------------------------------------------------- + // Override the default localRepository variable + // ---------------------------------------------------------------------- + if ( StringUtils.isNotEmpty( localRepositoryId ) && ( localRepositoryPath != null ) ) + { + try + { + localRepository = new DefaultArtifactRepository( localRepositoryId, localRepositoryPath.toURL() + .toString(), repositoryLayout ); + } + catch ( MalformedURLException e ) + { + throw new MojoExecutionException( "MalformedURLException: " + e.getMessage(), e ); + } + } + ArtifactMetadata metadata = null; Artifact pomArtifact = null; @@ -224,13 +269,18 @@ } } - private Model readPom( File file ) + /** + * @param aFile + * @return the model from a file + * @throws MojoExecutionException if any + */ + private Model readPom( File aFile ) throws MojoExecutionException { Reader reader = null; try { - reader = new FileReader( file ); + reader = new FileReader( aFile ); MavenXpp3Reader mavenReader = new MavenXpp3Reader(); @@ -238,7 +288,7 @@ } catch ( FileNotFoundException e ) { - throw new MojoExecutionException( "File not found " + file, e ); + throw new MojoExecutionException( "File not found " + aFile, e ); } catch ( IOException e ) { Added: maven/plugins/trunk/maven-install-plugin/src/site/apt/examples/specific-local-repo.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/site/apt/examples/specific-local-repo.apt?view=auto&rev=463479 ============================================================================== --- maven/plugins/trunk/maven-install-plugin/src/site/apt/examples/specific-local-repo.apt (added) +++ maven/plugins/trunk/maven-install-plugin/src/site/apt/examples/specific-local-repo.apt Thu Oct 12 15:40:44 2006 @@ -0,0 +1,42 @@ + ------ + Install an artifact on a specific local repository path + ------ + Vincent Siveton + ------ + October 2006 + ------ + +~~ Copyright 2006 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/guides/mini/guide-apt-format.html + +Install on a specific local repository path + + By default, Maven Install Plugin uses the local repository defined in the settings.xml to install an artifact. + + You could install an artifact on a specific local repository by setting the <<localRepositoryPath>> and <<localRepositoryId>> + parameters when installing. + ++---+ +mvn install:install-file -Dfile=path-to-your-artifact-jar \ + -DgroupId=your.groupId \ + -DartifactId=your-artifactId \ + -Dversion=version \ + -Dpackaging=jar \ + -DpomFile=path-to-pom \ + -DlocalRepositoryPath=path-to-specific-local-repo \ + -DlocalRepositoryId=id-for-specific-local-repo ++---+ Propchange: maven/plugins/trunk/maven-install-plugin/src/site/apt/examples/specific-local-repo.apt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-install-plugin/src/site/apt/examples/specific-local-repo.apt ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Modified: maven/plugins/trunk/maven-install-plugin/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/site/apt/index.apt?view=diff&rev=463479&r1=463478&r2=463479 ============================================================================== --- maven/plugins/trunk/maven-install-plugin/src/site/apt/index.apt (original) +++ maven/plugins/trunk/maven-install-plugin/src/site/apt/index.apt Thu Oct 12 15:40:44 2006 @@ -30,7 +30,7 @@ the user's home directory <<<(~/.m2/repository)>>> but the location can be configured in <<<~/.m2/settings.xml>>> using the \<localRepository\> element. - The install plugin is used during the install phase to add + The install plugin is used during the install phase to add artifact(s) to the local repository. The install plugin uses the information in the POM (groupId, artifactId, version) to determine the proper location for the artifact within the local repository. @@ -44,8 +44,8 @@ (sources, javadoc, etc) produced by a particular project. * {{{install-file-mojo.html}install:install-file}} is mostly used to install an externally - created artifact into the local repository, along with its pom. In that case - the project information can be taken from an optionally specified pomFile, but can + created artifact into the local repository, along with its pom. In that case + the project information can be taken from an optionally specified pomFile, but can be given using command line parameters. * Usage @@ -65,5 +65,7 @@ * {{{examples/installing-checksums.html}Installing Checksums}} * {{{examples/update-release-info.html}Updating Release Info}} + + * {{{examples/specific-local-repo.html}Installing an artifact on a specific local repository path}} []