URL: http://svn.apache.org/repos/asf/maven/plugins/tags/maven-deploy-plugin-2.6 Repository Root: http://svn.apache.org/repos/asf Repository UUID: 13f79535-47bb-0310-9956-ffa450edef68 Revision: 1387514
Index: pom.xml =================================================================== --- pom.xml (revision 1387514) +++ pom.xml (working copy) @@ -30,7 +30,7 @@ </parent> <artifactId>maven-deploy-plugin</artifactId> - <version>2.6</version> + <version>2.6-SNAPSHOT</version> <packaging>maven-plugin</packaging> <name>Maven Deploy Plugin</name> @@ -76,10 +76,16 @@ <artifactId>maven-artifact</artifactId> <version>${mavenVersion}</version> </dependency> + <!-- The plexus container --> <dependency> <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-container-default</artifactId> + <version>1.0-alpha-9</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> - <version>1.5.6</version> + <version>2.1</version> </dependency> <dependency> <groupId>org.apache.maven.plugin-testing</groupId> @@ -93,6 +99,12 @@ <version>3.8.2</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-filtering</artifactId> + <version>1.0</version> + <type>jar</type> + </dependency> </dependencies> <profiles> Index: src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java =================================================================== --- src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java (revision 1387514) +++ src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java (working copy) @@ -19,6 +19,10 @@ * under the License. */ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Reader; import java.util.Map; import org.apache.maven.artifact.deployer.ArtifactDeployer; @@ -26,9 +30,16 @@ 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.model.Model; +import org.apache.maven.model.Resource; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.validation.ModelValidationResult; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * @version $Id$ @@ -128,4 +139,27 @@ return layout; } + /** + * Extract the model from the specified POM file. + * + * @param pomFile The path of the POM file to parse, must not be <code>null</code>. + * @return The model from the POM file, never <code>null</code>. + * @throws MojoExecutionException If the file doesn't exist of cannot be read. + */ + Model readModel(File pomFile) throws MojoExecutionException { + Reader reader = null; + try { + reader = ReaderFactory.newXmlReader(pomFile); + return new MavenXpp3Reader().read(reader); + } catch (FileNotFoundException e) { + throw new MojoExecutionException("POM not found " + pomFile, e); + } catch (IOException e) { + throw new MojoExecutionException("Error reading POM " + pomFile, e); + } catch (XmlPullParserException e) { + throw new MojoExecutionException("Error parsing POM " + pomFile, e); + } finally { + IOUtil.close(reader); } + } + +} Index: src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java =================================================================== --- src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java (revision 1387514) +++ src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java (working copy) @@ -170,6 +170,8 @@ */ private File pomFile; + private File deployPomFile; + /** * Upload a POM for this artifact. Will generate a default POM if none is * supplied with the pomFile argument. @@ -360,40 +362,6 @@ } } - /** - * Extract the model from the specified POM file. - * - * @param pomFile The path of the POM file to parse, must not be <code>null</code>. - * @return The model from the POM file, never <code>null</code>. - * @throws MojoExecutionException If the file doesn't exist of cannot be read. - */ - Model readModel( File pomFile ) - throws MojoExecutionException - { - Reader reader = null; - try - { - reader = ReaderFactory.newXmlReader( pomFile ); - return new MavenXpp3Reader().read( reader ); - } - catch ( FileNotFoundException e ) - { - throw new MojoExecutionException( "POM not found " + pomFile, e ); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error reading POM " + pomFile, e ); - } - catch ( XmlPullParserException e ) - { - throw new MojoExecutionException( "Error parsing POM " + pomFile, e ); - } - finally - { - IOUtil.close( reader ); - } - } - private File generatePomFile() throws MojoExecutionException { @@ -425,20 +393,14 @@ * * @throws MojoExecutionException If any artifact coordinate is invalid. */ - private void validateArtifactInformation() - throws MojoExecutionException - { + private void validateArtifactInformation() throws MojoExecutionException { Model model = generateModel(); - ModelValidationResult result = modelValidator.validate( model ); - if ( result.getMessageCount() > 0 ) - { - throw new MojoExecutionException( "The artifact information is incomplete or not valid:\n" - + result.render( " " ) ); + throw new MojoExecutionException("The artifact information is incomplete or not valid:\n" + result.render(" ")); } - } + /** * Generates a minimal model from the user-supplied artifact information. * @@ -519,4 +481,6 @@ { this.classifier = classifier; } + } + Index: src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java =================================================================== --- src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java (revision 1387514) +++ src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java (working copy) @@ -18,22 +18,31 @@ * specific language governing permissions and limitations * under the License. */ - import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.deployer.ArtifactDeploymentException; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.model.DeploymentRepository; +import org.apache.maven.model.Model; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.ProjectArtifactMetadata; - import java.io.File; +import java.io.IOException; +import java.net.URLConnection; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.shared.filtering.MavenFileFilter; +import org.apache.maven.shared.filtering.MavenFileFilterRequest; +import org.apache.maven.shared.filtering.MavenFilteringException; +import org.sonatype.plexus.build.incremental.ThreadBuildContext; /** * Deploys an artifact to remote repository. @@ -45,40 +54,52 @@ * @phase deploy */ public class DeployMojo - extends AbstractDeployMojo -{ + extends AbstractDeployMojo { + /** + * @plexus.requirement + */ + private ThreadBuildContext buildContext; private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.+)::(.+)" ); - /** + * @parameter default-value="${session}" + * @required + * @readonly + */ + private MavenSession session; + /** * @parameter default-value="${project}" * @required * @readonly */ private MavenProject project; - /** * @parameter default-value="${project.artifact}" * @required * @readonly */ private Artifact artifact; - /** * @parameter default-value="${project.packaging}" * @required * @readonly */ private String packaging; - /** * @parameter default-value="${project.file}" * @required * @readonly */ private File pomFile; - /** + * @parameter default-value="${deployPomFile} + */ + private File deployPomFile; + /** + * @parameter default-value="${interpolatePom} + */ + private boolean interpolatePom; + /** * Specifies an alternative repository to which the project artifacts should be deployed ( other * than those specified in <distributionManagement> ). * <br/> @@ -87,27 +108,30 @@ * @parameter expression="${altDeploymentRepository}" */ private String altDeploymentRepository; - /** * @parameter default-value="${project.attachedArtifacts} * @required * @readonly */ private List attachedArtifacts; - /** * Set this to 'true' to bypass artifact deploy * * @parameter expression="${maven.deploy.skip}" default-value="false" + * * @since 2.4 */ private boolean skip; + private Model model; + /** + * @component + */ + protected MavenFileFilter dmff; + public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( skip ) - { + throws MojoExecutionException, MojoFailureException { + if (skip) { getLog().info( "Skipping artifact deployment" ); return; } @@ -118,99 +142,116 @@ String protocol = repo.getProtocol(); - if ( protocol.equalsIgnoreCase( "scp" ) ) - { + if (protocol.equalsIgnoreCase("scp")) { File sshFile = new File( System.getProperty( "user.home" ), ".ssh" ); if ( !sshFile.exists() ) - { sshFile.mkdirs(); } - } // Deploy the POM boolean isPomArtifact = "pom".equals( packaging ); - if ( !isPomArtifact ) - { - ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pomFile ); - artifact.addMetadata( metadata ); + + + if (!isPomArtifact) { + + ArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, (deployPomFile != null) ? deployPomFile : pomFile); + + if (deployPomFile == null) + artifact.getMetadataList().add(metadata); + else { + File file = artifact.getFile(); + artifact = new DefaultArtifact(model.getGroupId(), model.getArtifactId(), artifact.getVersionRange(), artifact.getScope(), artifact.getType(), artifact.getClassifier(), artifact.getArtifactHandler()); + artifact.setFile(file); } + } if ( updateReleaseInfo ) - { artifact.setRelease( true ); - } + org.apache.maven.shared.filtering.MavenFileFilterRequest r = new MavenFileFilterRequest(); - try - { - if ( isPomArtifact ) - { - getDeployer().deploy( pomFile, artifact, repo, getLocalRepository() ); + try { + if (isPomArtifact) { + + if (deployPomFile != null) + artifact.setFile(deployPomFile); + + deployPomArtifact(artifact, repo); + + } else { + + File file = null; + + if (attachedArtifacts.isEmpty() || project.getAttachedArtifacts().contains(artifact)) { + //single attached/non-attached case + file = artifact.getFile(); + + if (file != null && file.isFile()) { + getLog().warn("deploying file " + file); + + if (deployPomFile != null) { + artifact.setVersion(model.getVersion()); + artifact.setResolvedVersion(model.getVersion()); + artifact.setBaseVersion(model.getVersion()); } - else - { - File file = artifact.getFile(); - if ( file != null && file.isFile() ) - { getDeployer().deploy( file, artifact, repo, getLocalRepository() ); } - else if ( !attachedArtifacts.isEmpty() ) + } + + if (file == null && !attachedArtifacts.isEmpty()) + getLog().warn("No primary artifact to deploy, deploying attached artifacts instead."); + else if (file == null && attachedArtifacts.isEmpty()) { + String message = "The packaging for this project did not assign a file to the build artifact"; + throw new MojoExecutionException(message); + } + + { - getLog().info( "No primary artifact to deploy, deploying attached artifacts instead." ); Artifact pomArtifact = - artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getBaseVersion() ); - pomArtifact.setFile( pomFile ); - if ( updateReleaseInfo ) - { + artifactFactory.createProjectArtifact(model.getGroupId(), model.getArtifactId(), + model.getVersion()); + + if (updateReleaseInfo) { + project.getArtifact().setRelease(true); pomArtifact.setRelease( true ); } + // propagate the timestamped version to the main artifact for the attached artifacts to pick it up + artifact.setResolvedVersion(pomArtifact.getVersion()); - getDeployer().deploy( pomFile, pomArtifact, repo, getLocalRepository() ); - // propagate the timestamped version to the main artifact for the attached artifacts to pick it up - artifact.setResolvedVersion( pomArtifact.getVersion() ); + deployPomArtifact(pomArtifact, repo); + } - else - { - String message = "The packaging for this project did not assign a file to the build artifact"; - throw new MojoExecutionException( message ); } - } - for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); ) - { + for (Iterator i = attachedArtifacts.iterator(); i.hasNext();) { Artifact attached = ( Artifact ) i.next(); + if (updateReleaseInfo) + artifact.setRelease(true); + getDeployer().deploy( attached.getFile(), attached, repo, getLocalRepository() ); } - } - catch ( ArtifactDeploymentException e ) - { + } catch (ArtifactDeploymentException e) { throw new MojoExecutionException( e.getMessage(), e ); } } private ArtifactRepository getDeploymentRepository() - throws MojoExecutionException, MojoFailureException - { + throws MojoExecutionException, MojoFailureException { ArtifactRepository repo = null; - if ( altDeploymentRepository != null ) - { + if (altDeploymentRepository != null) { getLog().info( "Using alternate deployment repository " + altDeploymentRepository ); Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepository ); if ( !matcher.matches() ) - { throw new MojoFailureException( altDeploymentRepository, "Invalid syntax for repository.", "Invalid syntax for alternative repository. Use \"id::layout::url\"." ); - } - else - { + else { String id = matcher.group( 1 ).trim(); String layout = matcher.group( 2 ).trim(); String url = matcher.group( 3 ).trim(); @@ -221,13 +262,27 @@ } } + if (deployPomFile != null) { + getLog().warn("using repo configuration from " + deployPomFile.getAbsolutePath()); + + model = super.readModel(deployPomFile); + this.artifact.setVersion(model.getVersion()); + DeploymentRepository deployRepo = null; + + if (!updateReleaseInfo) + deployRepo = model.getDistributionManagement().getSnapshotRepository(); + else + deployRepo = model.getDistributionManagement().getRepository(); + + ArtifactRepositoryLayout layout = getLayout(deployRepo.getLayout()); + repo = repositoryFactory.createDeploymentArtifactRepository( + deployRepo.getId(), deployRepo.getUrl(), layout, deployRepo.isUniqueVersion()); + } + if ( repo == null ) - { repo = project.getDistributionManagementArtifactRepository(); - } - if ( repo == null ) - { + if (repo == null) { String msg = "Deployment failed: repository element was not specified in the POM inside" + " distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter"; @@ -237,4 +292,50 @@ return repo; } + public File getDeployPomFile() { + return deployPomFile; } + + public void setDeployPomFile(File deployPomFile) { + this.deployPomFile = deployPomFile; + } + + private void deployPomArtifact(Artifact artifact, ArtifactRepository repo) throws ArtifactDeploymentException { + + if (deployPomFile != null) { + getLog().warn("setting deploy artifact " + deployPomFile.getAbsolutePath()); + artifact.setFile(deployPomFile); + } else + artifact.setFile(pomFile); + + File file = artifact.getFile(); + if (interpolatePom) { + getLog().info("interpolating pom " + interpolatePom); + try { + file = interpolatePom(artifact); + } catch (Exception ex) { + getLog().error(ex); + } + } + + getDeployer().deploy(file, artifact, repo, getLocalRepository()); + } + + private File interpolatePom(Artifact artifact) throws IOException, MavenFilteringException { + File tempFile = File.createTempFile("mvndeploy-interpolated", ".pom"); + + getLog().info(tempFile.getAbsolutePath()); + + ThreadBuildContext.setThreadBuildContext(ThreadBuildContext.getContext()); + tempFile.deleteOnExit(); + + MavenFileFilterRequest ffr = new MavenFileFilterRequest(artifact.getFile(), tempFile, true, this.project, new ArrayList(), false, "UTF-8", session, model.getProperties()); + + dmff.copyFile(ffr); + + URLConnection c = tempFile.toURI().toURL().openConnection(); + + return tempFile; + + } +}
--------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org For additional commands, e-mail: dev-h...@maven.apache.org