Skip to content

Commit

Permalink
[JENKINS-8651] Maven deployment with uniqueVersion == true creating "…
Browse files Browse the repository at this point in the history
…new" versions for attached artifacts

Originally-Committed-As: b3b4ccb0f23bf1769d91ee7535d054ef1937953e
  • Loading branch information
olamy committed Feb 9, 2011
1 parent 768fd5d commit 595199a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -179,9 +179,9 @@ THE SOFTWARE.
<artifactId>plexus-classworlds</artifactId>
</dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>hudson-maven-artifact-manager</artifactId>
<version>1.0</version>
<groupId>org.jenkins-ci.lib</groupId>
<artifactId>lib-jenkins-maven-artifact-manager</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/hudson/maven/reporters/MavenArtifact.java
Expand Up @@ -30,6 +30,8 @@
import hudson.model.BuildListener;
import hudson.model.FingerprintMap;
import hudson.model.Hudson;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.ArtifactHandler;
Expand Down Expand Up @@ -148,6 +150,7 @@ public Artifact toArtifact(ArtifactHandlerManager handlerManager, ArtifactFactor
final String canonicalExtension = canonicalName.substring(canonicalName.lastIndexOf('.')+1);
ArtifactHandler ah = handlerManager.getArtifactHandler(type);
Map<String,ArtifactHandler> handlers = Maps.newHashMap();

handlers.put( type, new DefaultArtifactHandler(type) {
public String getExtension() {
return canonicalExtension;
Expand All @@ -159,6 +162,7 @@ public String getExtension() {

Artifact a = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
a.setFile(getFile(build));

return a;
}

Expand Down
30 changes: 19 additions & 11 deletions src/main/java/hudson/maven/reporters/MavenArtifactRecord.java
Expand Up @@ -113,8 +113,15 @@ public void deploy(MavenEmbedder embedder, ArtifactRepository deploymentReposito
ArtifactFactory factory = embedder.lookup(ArtifactFactory.class);
PrintStream logger = listener.getLogger();
boolean maven3orLater = MavenUtil.maven3orLater(parent.getModuleSetBuild().getMavenVersionUsed());
if (!deploymentRepository.isUniqueVersion() && maven3orLater) {
logger.println("uniqueVersion == false is not anymore supported in maven 3");
boolean uniqueVersion = true;
if (!deploymentRepository.isUniqueVersion()) {
if (maven3orLater) {
logger.println("uniqueVersion == false is not anymore supported in maven 3");
} else {
((WrappedArtifactRepository) deploymentRepository).setUniqueVersion( false );
uniqueVersion = false;
}
} else {
((WrappedArtifactRepository) deploymentRepository).setUniqueVersion( true );
}
Artifact main = mainArtifact.toArtifact(handlerManager,factory,parent);
Expand All @@ -123,21 +130,22 @@ public void deploy(MavenEmbedder embedder, ArtifactRepository deploymentReposito

// deploy the main artifact. This also deploys the POM
logger.println(Messages.MavenArtifact_DeployingMainArtifact(main.getFile().getName()));
deployMavenArtifact( main, deploymentRepository, embedder );

ArtifactDeployer deployer = embedder.lookup(ArtifactDeployer.class,uniqueVersion ? "default":"maven2");

deployer.deploy( main.getFile(), main, deploymentRepository, embedder.getLocalRepository() );

//deployMavenArtifact( main, deploymentRepository, embedder, uniqueVersion );

for (MavenArtifact aa : attachedArtifacts) {
Artifact a = aa.toArtifact(handlerManager,factory, parent);
logger.println(Messages.MavenArtifact_DeployingAttachedArtifact(a.getFile().getName()));
deployMavenArtifact( a, deploymentRepository, embedder );
deployer.deploy( a.getFile(), a, deploymentRepository, embedder.getLocalRepository() );
}
}

protected void deployMavenArtifact(Artifact artifact, ArtifactRepository deploymentRepository, MavenEmbedder embedder)
throws ArtifactDeploymentException, ComponentLookupException {

ArtifactDeployer deployer = embedder.lookup(ArtifactDeployer.class,"maven2");
deployer.deploy(artifact.getFile(),artifact,deploymentRepository,embedder.getLocalRepository());
}



/**
* Installs the artifact to the local Maven repository.
*/
Expand Down

0 comments on commit 595199a

Please sign in to comment.