From 44c3e592eaf2f4313f272337a0f9e7eacce80e5c Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Tue, 1 Nov 2005 22:46:08 +0000 Subject: [PATCH] add a similar deployment hook for uploading to a m1 repo simultaneously git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@330143 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugins/MavenOneRepositoryDeployMojo.java | 133 ++++++++++++++++++ .../src/site/apt/introduction.apt | 32 ++++- 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOneRepositoryDeployMojo.java diff --git a/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOneRepositoryDeployMojo.java b/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOneRepositoryDeployMojo.java new file mode 100644 index 0000000000..555b5c93c2 --- /dev/null +++ b/sandbox/maven-one-plugin/src/main/java/org/apache/maven/plugins/MavenOneRepositoryDeployMojo.java @@ -0,0 +1,133 @@ +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.deployer.ArtifactDeployer; +import org.apache.maven.artifact.deployer.ArtifactDeploymentException; +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 deploy-maven-one-repository + * @phase deploy + */ +public class MavenOneRepositoryDeployMojo + 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 ArtifactDeployer deployer; + + /** + * @component + */ + protected ArtifactRepositoryFactory factory; + + /** + * @parameter expression="${remoteRepositoryId}" default-value="mavenOneRemoteRepository" + * @required + */ + protected String remoteRepositoryId; + + /** + * @parameter expression="${remoteRepositoryUrl}" + * @required + */ + protected String remoteRepositoryUrl; + + /** + * @component roleHint="legacy" + */ + private ArtifactRepositoryLayout legacyLayout; + + /** + * @parameter expression="${localRepository}" + * @required + * @readonly + */ + private ArtifactRepository localRepository; + + public void execute() + throws MojoExecutionException + { + try + { + ArtifactRepository deploymentRepository = factory.createDeploymentArtifactRepository( remoteRepositoryId, + remoteRepositoryUrl, + legacyLayout, false ); + + boolean isPomArtifact = "pom".equals( packaging ); + + if ( isPomArtifact ) + { + deployer.deploy( pomFile, artifact, deploymentRepository, 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" ); + } + deployer.deploy( file, artifact, deploymentRepository, localRepository ); + } + + } + catch ( ArtifactDeploymentException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } +} diff --git a/sandbox/maven-one-plugin/src/site/apt/introduction.apt b/sandbox/maven-one-plugin/src/site/apt/introduction.apt index 5803cd0505..ff235cc8ea 100644 --- a/sandbox/maven-one-plugin/src/site/apt/introduction.apt +++ b/sandbox/maven-one-plugin/src/site/apt/introduction.apt @@ -63,5 +63,35 @@ Maven One Plugin This will read the local repository location from <<<~/build.properties>>>, defaulting to <<<~/.maven/repository>>>. - For more information, see the {{{index.html} Goal Reference}} +* Maven 1.x Remote Repository Deployment + + To have your artifact deployed into an additional remote Maven 1.x repository, add the following lifecycle binding to + your POM: + +------- + + ... + + maven-one-plugin + + + + scp://cvs.apache.org/repository + + + deploy-maven-one-repository + + + + + ... + +------- + + This will not read any settings from the Maven 1.x properties, so the URL is required. + + If configuring server settings in your local configuration, use the ID of <<>>. This can be + overridden using the <<>> configuration element. + + For more information, see the {{{index.html} Goal Reference}}.