Skip to content
Permalink
Browse files

[JENKINS-45024] Use org.eclipse.aether.artifact.Artifact#isSnapshot()…

… to identify snapshot versions

[JENKINS-45024] Use org.eclipse.aether.artifact.Artifact#isSnapshot() to identify snapshot versions instead of looking at the pattern of the version string
  • Loading branch information
Cyrille Le Clerc committed Jun 21, 2017
2 parents 608fd29 + dd61093 commit 96e922fca238fae2f23c7014cedee949453556ba
@@ -137,15 +137,12 @@ public void processMavenSpyLogs(StepContext context, FilePath mavenSpyLogFolder,
public static class MavenArtifact {
public String groupId, artifactId, version, type, classifier, extension;
public String file;
public boolean snapshot;

public String getFileName() {
return artifactId + "-" + version + ((classifier == null || classifier.isEmpty()) ? "" : "-" + classifier) + "." + extension;
}

public boolean isSnapshot() {
return version != null && version.endsWith("-SNAPSHOT");
}

@Override
public String toString() {
return "MavenArtifact{" +
@@ -182,6 +179,7 @@ public String toString() {
version + ", " +
"scope: " + scope + ", " +
" optional: " + optional +
" snapshot: " + snapshot +
(file == null ? "" : " " + file) +
'}';
}
@@ -86,7 +86,7 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE

Map<String, String> artifactsToFingerPrint = new HashMap<>(); // artifactPathInFingerprintZone -> artifactMd5
for (MavenSpyLogProcessor.MavenDependency dependency : dependencies) {
if (dependency.isSnapshot()) {
if (dependency.snapshot) {
if (!includeSnapshotVersions) {
if (LOGGER.isLoggable(Level.FINER)) {
listener.getLogger().println("[withMaven] Skip fingerprinting snapshot dependency: " + dependency);
@@ -69,6 +69,7 @@
loadMavenArtifact(dependencyElt, dependency);
dependency.setScope(dependencyElt.getAttribute("scope"));
dependency.optional = Boolean.valueOf(dependencyElt.getAttribute("optional"));
dependency.snapshot = Boolean.valueOf(dependencyElt.getAttribute("snapshot"));

return dependency;
}
@@ -10,45 +10,4 @@
*/
public class MavenSpyLogProcessorTest {

@Test
public void test_mavenArtifact_is_snapshot() {

// <artifact
// extension="jar"
// groupId="org.jmxtrans.embedded"
// artifactId="embedded-jmxtrans"
// id="org.jmxtrans.embedded:embedded-jmxtrans:jar:1.2.2-SNAPSHOT"
// type="jar"
// version="1.2.2-SNAPSHOT">

MavenSpyLogProcessor.MavenArtifact artifact = new MavenSpyLogProcessor.MavenArtifact();
artifact.groupId = "org.jmxtrans.embedded";
artifact.artifactId = "embedded-jmxtrans";
artifact.version = "1.2.2-SNAPSHOT";
artifact.type = "jar";
artifact.extension = "jar";

assertThat(artifact.isSnapshot(), is(true));
}

@Test
public void test_mavenArtifact_is_not_snapshot() {

// <artifact
// extension="jar"
// groupId="org.jmxtrans.embedded"
// artifactId="embedded-jmxtrans"
// id="org.jmxtrans.embedded:embedded-jmxtrans:jar:1.2.1"
// type="jar"
// version="1.2.1">

MavenSpyLogProcessor.MavenArtifact artifact = new MavenSpyLogProcessor.MavenArtifact();
artifact.groupId = "org.jmxtrans.embedded";
artifact.artifactId = "embedded-jmxtrans";
artifact.version = "1.2.1";
artifact.type = "jar";
artifact.extension = "jar";

assertThat(artifact.isSnapshot(), is(false));
}
}
@@ -100,6 +100,7 @@ protected boolean _handle(DependencyResolutionResult result) {
dependencyElt.setAttribute("extension", artifact.getExtension());
dependencyElt.setAttribute("scope", dependency.getScope());
dependencyElt.setAttribute("optional", Boolean.toString(dependency.isOptional()));
dependencyElt.setAttribute("snapshot", Boolean.toString(artifact.isSnapshot()));

dependenciesElt.addChild(dependencyElt);
}

0 comments on commit 96e922f

Please sign in to comment.