You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2007/10/18 22:58:18 UTC
svn commit: r586133 - in /maven/ant-tasks/trunk: ./
src/main/java/org/apache/maven/artifact/ant/
Author: hboutemy
Date: Thu Oct 18 13:58:17 2007
New Revision: 586133
URL: http://svn.apache.org/viewvc?rev=586133&view=rev
Log:
[MANTTASKS-67] artifact:deploy - fix build number when deploying an artifact with attachment
Modified:
maven/ant-tasks/trunk/pom.xml
maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java
maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java
maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java
maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java
maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallWagonProviderTask.java
maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/Pom.java
maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/VersionMapper.java
Modified: maven/ant-tasks/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/pom.xml?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/pom.xml (original)
+++ maven/ant-tasks/trunk/pom.xml Thu Oct 18 13:58:17 2007
@@ -1,20 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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
~
- ~ 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
~
- ~ 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.
- -->
+ ~ 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.
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java Thu Oct 18 13:58:17 2007
@@ -373,8 +373,7 @@
return container;
}
- public Pom buildPom( MavenProjectBuilder projectBuilder,
- ArtifactRepository localArtifactRepository )
+ public Pom buildPom( ArtifactRepository localArtifactRepository )
{
if ( pomRefId != null && pom != null )
{
@@ -393,6 +392,7 @@
if ( pom != null )
{
+ MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
pom.initialise( projectBuilder, localArtifactRepository );
}
return pom;
@@ -416,6 +416,15 @@
return pom;
}
+ protected Artifact createDummyArtifact()
+ {
+ Pom pom = createDummyPom();
+ ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
+ return factory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(),
+ pom.getPackaging() );
+ }
+
public String[] getSupportedProtocols()
{
try
@@ -496,14 +505,6 @@
log( "Profiles not yet supported, ignoring profiles '" + profiles + "'", Project.MSG_WARN );
// System.setProperty( ProfileActivationUtils.ACTIVE_PROFILE_IDS, profiles );
}
- }
-
- protected Artifact createArtifact( Pom pom )
- {
- ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
- // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
- return factory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(),
- pom.getPackaging() );
}
private static RepositoryPolicy convertRepositoryPolicy( org.apache.maven.model.RepositoryPolicy pomRepoPolicy )
Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java Thu Oct 18 13:58:17 2007
@@ -34,7 +34,6 @@
import org.apache.maven.artifact.resolver.filter.TypeArtifactFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Repository;
-import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.tools.ant.BuildException;
@@ -89,13 +88,12 @@
log( "Using local repository: " + localRepo.getBasedir(), Project.MSG_VERBOSE );
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
- MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
List dependencies = this.dependencies;
- Pom pom = buildPom( projectBuilder, localRepo );
+ Pom pom = buildPom( localRepo );
if ( pom != null )
{
if ( !dependencies.isEmpty() )
Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DeployTask.java Thu Oct 18 13:58:17 2007
@@ -25,7 +25,6 @@
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.DistributionManagement;
-import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.tools.ant.BuildException;
@@ -47,17 +46,60 @@
protected void doExecute()
{
ArtifactRepository localRepo = createLocalArtifactRepository();
- MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
- Pom pom = buildPom( builder, localRepo );
+ Pom pom = buildPom( localRepo );
if ( pom == null )
{
throw new BuildException( "A POM element is required to deploy to the repository" );
}
+
+ Artifact artifact = pom.getArtifact();
- Artifact artifact = createArtifact( pom );
+ // Deploy the POM
+ boolean isPomArtifact = "pom".equals( pom.getPackaging() );
+ if ( !isPomArtifact )
+ {
+ ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
+ artifact.addMetadata( metadata );
+ }
+
+ ArtifactRepository deploymentRepository = getDeploymentRepository( pom, artifact );
+
+ log( "Deploying to " + deploymentRepository.getUrl() );
+ ArtifactDeployer deployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE );
+ try
+ {
+ if ( !isPomArtifact )
+ {
+ deployer.deploy( file, artifact, deploymentRepository, localRepo );
+ }
+ else
+ {
+ deployer.deploy( pom.getFile(), artifact, deploymentRepository, localRepo );
+ }
+ // Deploy any attached artifacts
+ if ( attachedArtifacts != null )
+ {
+ Iterator iter = pom.getAttachedArtifacts().iterator();
+
+ while ( iter.hasNext() )
+ {
+ Artifact attachedArtifact = (Artifact) iter.next();
+ deployer.deploy( attachedArtifact.getFile(), attachedArtifact, deploymentRepository, localRepo );
+ }
+ }
+ }
+ catch ( ArtifactDeploymentException e )
+ {
+ throw new BuildException(
+ "Error deploying artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
+ }
+ }
+
+ private ArtifactRepository getDeploymentRepository( Pom pom, Artifact artifact )
+ {
DistributionManagement distributionManagement = pom.getDistributionManagement();
if ( remoteSnapshotRepository == null && remoteRepository == null )
@@ -96,50 +138,7 @@
"A distributionManagement element or remoteRepository element is required to deploy" );
}
- // Deploy the POM
- boolean isPomArtifact = "pom".equals( pom.getPackaging() );
- if ( !isPomArtifact )
- {
- ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
- artifact.addMetadata( metadata );
- }
-
- log( "Deploying to " + deploymentRepository.getUrl() );
- ArtifactDeployer deployer = (ArtifactDeployer) lookup( ArtifactDeployer.ROLE );
- try
- {
- if ( !isPomArtifact )
- {
- deployer.deploy( file, artifact, deploymentRepository, localRepo );
- }
- else
- {
- deployer.deploy( pom.getFile(), artifact, deploymentRepository, localRepo );
- }
- }
- catch ( ArtifactDeploymentException e )
- {
- throw new BuildException(
- "Error deploying artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
- }
-
- // Deploy any attached artifacts
- if (attachedArtifacts != null) {
- Iterator iter = attachedArtifacts.iterator();
-
- while (iter.hasNext()) {
- AttachedArtifact attached = (AttachedArtifact)iter.next();
- Artifact attachedArtifact = createArtifactFromAttached(attached, artifact);
-
- try {
- deployer.deploy( attachedArtifact.getFile(), attachedArtifact, deploymentRepository, localRepo );
- }
- catch (ArtifactDeploymentException e) {
- throw new BuildException(
- "Error deploying attached artifact '" + attachedArtifact.getDependencyConflictId() + "': " + e.getMessage(), e );
- }
- }
- }
+ return deploymentRepository;
}
public RemoteRepository getRemoteRepository()
Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java Thu Oct 18 13:58:17 2007
@@ -20,11 +20,11 @@
*/
import java.io.File;
+import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* Support for install/deploy tasks.
@@ -48,34 +48,22 @@
{
this.file = file;
}
-
- protected Artifact createArtifactFromAttached(final AttachedArtifact attached, final Artifact parent)
+
+ public Pom buildPom( ArtifactRepository localArtifactRepository )
{
- ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ Pom pom = super.buildPom( localArtifactRepository );
- Artifact artifact;
- if (attached.getClassifier() != null) {
- artifact = factory.createArtifactWithClassifier(
- parent.getGroupId(),
- parent.getArtifactId(),
- parent.getVersion(),
- attached.getType(),
- attached.getClassifier()
- );
- }
- else {
- artifact = factory.createArtifact(
- parent.getGroupId(),
- parent.getArtifactId(),
- parent.getVersion(),
- null, // scope
- attached.getType()
- );
+ // attach artifacts
+ if (attachedArtifacts != null) {
+ Iterator iter = attachedArtifacts.iterator();
+
+ while (iter.hasNext()) {
+ AttachedArtifact attached = (AttachedArtifact)iter.next();
+ pom.attach( attached );
+ }
}
-
- artifact.setFile( attached.getFile() );
-
- return artifact;
+
+ return pom;
}
public AttachedArtifact createAttach()
Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallTask.java Thu Oct 18 13:58:17 2007
@@ -24,7 +24,6 @@
import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.tools.ant.BuildException;
@@ -44,10 +43,9 @@
{
ArtifactRepository localRepo = createLocalArtifactRepository();
- MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
- Pom pom = buildPom( builder, localRepo );
+ Pom pom = buildPom( localRepo );
- Artifact artifact = createArtifact( pom );
+ Artifact artifact = pom.getArtifact();
boolean isPomArtifact = "pom".equals( pom.getPackaging() );
if ( !isPomArtifact )
@@ -67,29 +65,23 @@
{
installer.install( pom.getFile(), artifact, localRepo );
}
- }
- catch ( ArtifactInstallationException e )
- {
- throw new BuildException(
- "Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
- }
- // Install any attached artifacts
- if (attachedArtifacts != null) {
- Iterator iter = attachedArtifacts.iterator();
-
- while (iter.hasNext()) {
- AttachedArtifact attached = (AttachedArtifact)iter.next();
- Artifact attachedArtifact = createArtifactFromAttached(attached, artifact);
+ // Install any attached artifacts
+ if ( attachedArtifacts != null )
+ {
+ Iterator iter = pom.getAttachedArtifacts().iterator();
- try {
+ while ( iter.hasNext() )
+ {
+ Artifact attachedArtifact = (Artifact) iter.next();
installer.install( attachedArtifact.getFile(), attachedArtifact, localRepo );
}
- catch (ArtifactInstallationException e) {
- throw new BuildException(
- "Error installing attached artifact '" + attachedArtifact.getDependencyConflictId() + "': " + e.getMessage(), e );
- }
}
+ }
+ catch ( ArtifactInstallationException e )
+ {
+ throw new BuildException(
+ "Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
}
}
}
Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallWagonProviderTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallWagonProviderTask.java?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallWagonProviderTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/InstallWagonProviderTask.java Thu Oct 18 13:58:17 2007
@@ -109,7 +109,7 @@
List remoteRepositories = createRemoteArtifactRepositories();
result = resolver.resolveTransitively( Collections.singleton( providerArtifact ),
- createArtifact( createDummyPom() ), createLocalArtifactRepository(),
+ createDummyArtifact(), createLocalArtifactRepository(),
remoteRepositories, metadataSource, null );
}
catch ( ArtifactResolutionException e )
Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/Pom.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/Pom.java?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/Pom.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/Pom.java Thu Oct 18 13:58:17 2007
@@ -39,6 +39,7 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.tools.ant.BuildException;
@@ -130,19 +131,41 @@
this.file = file;
}
+ public Artifact getArtifact()
+ {
+ return getMavenProject().getArtifact();
+ }
+
+ public void attach( AttachedArtifact attached )
+ {
+ MavenProjectHelper helper = (MavenProjectHelper) lookup( MavenProjectHelper.ROLE );
+ MavenProject project = getMavenProject();
+ if (attached.getClassifier() != null) {
+ helper.attachArtifact( project, attached.getType(), attached.getClassifier(), attached.getFile() );
+ }
+ else {
+ helper.attachArtifact( project, attached.getType(), attached.getFile() );
+ }
+ }
+
+ public List getAttachedArtifacts()
+ {
+ return getMavenProject().getAttachedArtifacts();
+ }
+
void initialise( MavenProjectBuilder builder, ArtifactRepository localRepository )
{
if ( mavenProject != null )
{
log( "POM is already initialized for: " + mavenProject.getId(), Project.MSG_DEBUG );
-
+
return;
}
// TODO: should this be in execute() too? Would that work when it is used as a type?
if ( file != null )
{
checkParentPom();
-
+
try
{
// TODO: should the profiles be constructed and passed in here? From Ant, or perhaps settings?
@@ -158,7 +181,7 @@
getInstance().initialise( builder, localRepository );
}
}
-
+
private void checkParentPom()
{
Model model = null;
@@ -195,7 +218,7 @@
List remoteRepositories = createRemoteArtifactRepositories();
resolver.resolveTransitively( Collections.singleton( parentArtifact ),
- createArtifact( createDummyPom() ), createLocalArtifactRepository(),
+ createDummyArtifact(), createLocalArtifactRepository(),
remoteRepositories, metadataSource, null );
}
catch ( ArtifactResolutionException e )
@@ -389,7 +412,6 @@
// else handle the property resolution
String expression = name.substring( prefix.length() );
return getPOMValue( "project." + expression );
-
}
catch ( Exception ex )
{
Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/VersionMapper.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/VersionMapper.java?rev=586133&r1=586132&r2=586133&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/VersionMapper.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/VersionMapper.java Thu Oct 18 13:58:17 2007
@@ -1,19 +1,22 @@
package org.apache.maven.artifact.ant;
/*
- * Copyright 2001-2007 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
*
- * 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
*
- * 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.
+ * 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 java.io.File;