PR: MNG-1160

fix up some deployment repository determination logic, and avoid NPE in the process


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@312810 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-11 04:58:13 +00:00
parent d3f5c3d755
commit 8a6aae6db4
3 changed files with 47 additions and 21 deletions

View File

@ -0,0 +1,6 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.test</groupId>
<artifactId>sample-build-test</artifactId>
<version>2.0-beta-4-SNAPSHOT</version>
</project>

View File

@ -70,7 +70,7 @@
<target name="foo" depends="initTaskDefs">
<artifact:dependencies pathId="dependency.classpath" filesetId="dependency.fileset">
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-2">
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-4">
<exclusion groupId="junit" artifactId="junit"/>
</dependency>
<dependency groupId="plexus" artifactId="plexus-container-default" version="1.0-alpha-6-SNAPSHOT"/>
@ -164,7 +164,7 @@
<artifact:remoteRepository id="deploy.repository" url="scm:svn:${scm.url}" layout="default"/>
<artifact:dependencies pathId="dependency.classpath">
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-2"/>
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-4"/>
<dependency groupId="plexus" artifactId="plexus-container-default" version="1.0-alpha-6-SNAPSHOT"/>
<localRepository refid="local.repository"/>
</artifact:dependencies>
@ -183,7 +183,7 @@
<artifact:localRepository id="local.repository.scm" location="${basedir}/target/local-repo-scm" layout="default"/>
<artifact:dependencies pathId="dependency.classpath.scm">
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-2"/>
<dependency groupId="org.apache.maven.wagon" artifactId="wagon-provider-test" version="1.0-alpha-4"/>
<dependency groupId="plexus" artifactId="plexus-container-default" version="1.0-alpha-6-SNAPSHOT"/>
<localRepository refid="local.repository.scm"/>
<remoteRepository refid="deploy.repository"/>
@ -202,5 +202,12 @@
<pom refid="invalid-ref" />
</artifact:dependencies>
</target>
<target name="test-no-dist-mgmt" depends="initTaskDefs">
<artifact:deploy file="sample-build-test.pom">
<pom file="sample-build-test.pom" />
<remoteRepository refid="deploy.repository" />
</artifact:deploy>
</target>
</project>

View File

@ -21,6 +21,7 @@ import org.apache.maven.artifact.deployer.ArtifactDeployer;
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.model.DistributionManagement;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.tools.ant.BuildException;
@ -54,35 +55,47 @@ public class DeployTask
throw new BuildException( "A POM element is required to deploy to the repository" );
}
if ( remoteRepository == null )
{
if ( pom.getDistributionManagement() == null || pom.getDistributionManagement().getRepository() == null )
{
throw new BuildException( "A distributionManagement element is required in your POM to deploy" );
}
Artifact artifact = createArtifact( pom );
remoteRepository = createAntRemoteRepositoryBase( pom.getDistributionManagement().getRepository() );
DistributionManagement distributionManagement = pom.getDistributionManagement();
if ( remoteSnapshotRepository == null && remoteRepository == null )
{
if ( distributionManagement != null )
{
if ( distributionManagement.getSnapshotRepository() != null )
{
remoteSnapshotRepository = createAntRemoteRepositoryBase(
distributionManagement.getSnapshotRepository() );
}
if ( distributionManagement.getRepository() != null )
{
remoteRepository = createAntRemoteRepositoryBase( distributionManagement.getRepository() );
}
}
}
if ( remoteSnapshotRepository == null )
{
if ( pom.getDistributionManagement().getSnapshotRepository() != null )
{
remoteSnapshotRepository = createAntRemoteRepositoryBase(
pom.getDistributionManagement().getSnapshotRepository() );
}
remoteSnapshotRepository = remoteRepository;
}
// Deploy the POM
Artifact artifact = createArtifact( pom );
ArtifactRepository deploymentRepository = createRemoteArtifactRepository( remoteRepository );
if ( remoteSnapshotRepository != null && artifact.isSnapshot() )
ArtifactRepository deploymentRepository = null;
if ( artifact.isSnapshot() && remoteSnapshotRepository != null )
{
deploymentRepository = createRemoteArtifactRepository( remoteSnapshotRepository );
}
else if ( remoteRepository != null )
{
deploymentRepository = createRemoteArtifactRepository( remoteRepository );
}
else
{
throw new BuildException(
"A distributionManagement element or remoteRepository element is required to deploy" );
}
// Deploy the POM
boolean isPomArtifact = "pom".equals( pom.getPackaging() );
if ( !isPomArtifact )
{