Skip to content

Commit

Permalink
[JENKINS-49482] Netter display of deployed artifacts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrille Le Clerc committed Feb 12, 2018
1 parent f39c4e6 commit 4bc703f
Show file tree
Hide file tree
Showing 33 changed files with 801 additions and 494 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
@@ -0,0 +1,136 @@
package org.jenkinsci.plugins.pipeline.maven;

import org.apache.commons.lang.builder.CompareToBuilder;

import java.io.Serializable;
import java.util.Objects;

import javax.annotation.Nullable;

/**
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a>
*/
public class MavenArtifact implements Serializable, Comparable<MavenArtifact> {

private static final long serialVersionUID = 1L;

public String groupId, artifactId;
/**
* Gets the version of this artifact, for example "1.0-20100529-1213". Note that in case of meta versions like
* "1.0-SNAPSHOT", the artifact's version depends on the state of the artifact. Artifacts that have been resolved or
* deployed will usually have the meta version expanded.
*
* @see org.eclipse.aether.artifact.Artifact#getVersion()
*/
public String version;
/**
* Gets the base version of this artifact, for example "1.0-SNAPSHOT". In contrast to the org.eclipse.aether.artifact.Artifact#getVersion(), the
* base version will always refer to the unresolved meta version.
*
* @see org.eclipse.aether.artifact.Artifact#getBaseVersion()
*/
public String baseVersion;
public String type, classifier, extension;
public String file;
public boolean snapshot;
/**
* URL on of the Maven repository on which the artifact has been deployed ("mvn deploy")
*/
@Nullable
public String repositoryUrl;

/**
* @see MavenArtifact#version
*/
public String getFileName() {
return artifactId + "-" + version + ((classifier == null || classifier.isEmpty()) ? "" : "-" + classifier) + "." + extension;
}

/**
* @see MavenArtifact#baseVersion
*/
public String getFileNameWithBaseVersion() {
return artifactId + "-" + baseVersion + ((classifier == null || classifier.isEmpty()) ? "" : "-" + classifier) + "." + extension;
}

/**
* @see org.apache.maven.artifact.Artifact#getId()
*/
public String getId() {
return groupId + ":" + artifactId + ":" + (baseVersion) + ((classifier == null || classifier.isEmpty()) ? "" : ":" + classifier);
}

/**
* URL of the artifact on the maven repository on which it has been deployed if it has been deployed.
* @return URL of the artifact or {@code null} if the artifact has not been deployed (if "{@code mvn deploy}" was not invoked)
*/
@Nullable
public String getUrl() {
if (repositoryUrl == null)
return null;
return repositoryUrl + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + getFileNameWithBaseVersion();
}

@Override
public String toString() {
return "MavenArtifact{" +
groupId + ":" +
artifactId + ":" +
type +
(classifier == null ? "" : ":" + classifier) + ":" +
baseVersion + "(version: " + version + ", snapshot:" + snapshot + ") " +
(file == null ? "" : " " + file) +
'}';
}

@Override
public int compareTo(MavenArtifact o) {
return new CompareToBuilder().
append(this.groupId, o.groupId).
append(this.artifactId, o.artifactId).
append(this.version, o.version).
append(this.type, o.type).
append(this.classifier, o.classifier).
toComparison();
}

/**
* Artifact has been deployed to a Maven repository ("mvn deploy")
* @see #getUrl()
*/
public boolean isDeployed() {
return this.repositoryUrl != null && !repositoryUrl.isEmpty();
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId, baseVersion);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MavenArtifact other = (MavenArtifact) obj;
if (groupId == null) {
if (other.groupId != null)
return false;
} else if (!groupId.equals(other.groupId))
return false;
if (artifactId == null) {
if (other.artifactId != null)
return false;
} else if (!artifactId.equals(other.artifactId))
return false;
if (baseVersion == null) {
if (other.baseVersion != null)
return false;
} else if (!baseVersion.equals(other.baseVersion))
return false;
return true;
}
}
Expand Up @@ -153,93 +153,6 @@ public void processMavenSpyLogs(StepContext context, FilePath mavenSpyLogFolder,
}
}

public static class MavenArtifact {
public String groupId, artifactId;
/**
* Gets the version of this artifact, for example "1.0-20100529-1213". Note that in case of meta versions like
* "1.0-SNAPSHOT", the artifact's version depends on the state of the artifact. Artifacts that have been resolved or
* deployed will usually have the meta version expanded.
*
* @see org.eclipse.aether.artifact.Artifact#getVersion()
*/
public String version;
/**
* Gets the base version of this artifact, for example "1.0-SNAPSHOT". In contrast to the org.eclipse.aether.artifact.Artifact#getVersion(), the
* base version will always refer to the unresolved meta version.
*
* @see org.eclipse.aether.artifact.Artifact#getBaseVersion()
*/
public String baseVersion;
public String type, classifier, extension;
public String file;
public boolean snapshot;

/**
* @see MavenArtifact#version
*/
public String getFileName() {
return artifactId + "-" + version + ((classifier == null || classifier.isEmpty()) ? "" : "-" + classifier) + "." + extension;
}

/**
* @see MavenArtifact#baseVersion
*/
public String getFileNameWithBaseVersion() {
return artifactId + "-" + baseVersion + ((classifier == null || classifier.isEmpty()) ? "" : "-" + classifier) + "." + extension;
}

/**
* @see org.apache.maven.artifact.Artifact#getId()
*/
public String getId() {
return groupId + ":" + artifactId + ":" + (baseVersion) + ((classifier == null || classifier.isEmpty()) ? "" : ":" + classifier);
}

@Override
public String toString() {
return "MavenArtifact{" +
groupId + ":" +
artifactId + ":" +
type +
(classifier == null ? "" : ":" + classifier) + ":" +
baseVersion + "(version: " + version + ", snapshot:" + snapshot + ") " +
(file == null ? "" : " " + file) +
'}';
}

@Override
public int hashCode() {
return Objects.hash(groupId, artifactId, baseVersion);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
MavenArtifact other = (MavenArtifact) obj;
if (groupId == null) {
if (other.groupId != null)
return false;
} else if (!groupId.equals(other.groupId))
return false;
if (artifactId == null) {
if (other.artifactId != null)
return false;
} else if (!artifactId.equals(other.artifactId))
return false;
if (baseVersion == null) {
if (other.baseVersion != null)
return false;
} else if (!baseVersion.equals(other.baseVersion))
return false;
return true;
}
}

public static class MavenDependency extends MavenArtifact {

private String scope;
Expand Down
Expand Up @@ -26,12 +26,14 @@

import hudson.model.Item;
import hudson.model.Run;
import org.jenkinsci.plugins.pipeline.maven.MavenArtifact;
import org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher;

import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a>
Expand All @@ -40,19 +42,19 @@ public interface PipelineMavenPluginDao {

/**
* Record a Maven dependency of a build.
*
* @param jobFullName see {@link Item#getFullName()}
* @param jobFullName see {@link Item#getFullName()}
* @param buildNumber see {@link Run#getNumber()}
* @param groupId Maven dependency groupId
* @param artifactId Maven dependency artifactId
* @param version Maven dependency version
* @param type Maven dependency type (e.g. "jar", "war", "pom", hpi"...)
* @param scope Maven dependency scope ("compile", "test", "provided"...)
* @param ignoreUpstreamTriggers see {@link PipelineGraphPublisher#isIgnoreUpstreamTriggers()} ()}
* @param classifier Maven dependency classifier
*/
void recordDependency(@Nonnull String jobFullName, int buildNumber,
@Nonnull String groupId, @Nonnull String artifactId, @Nonnull String version, @Nonnull String type, @Nonnull String scope,
boolean ignoreUpstreamTriggers);
boolean ignoreUpstreamTriggers, String classifier);

/**
* Record a Maven parent project of a pom processed by this build of a build.
Expand All @@ -69,22 +71,34 @@ void recordParentProject(@Nonnull String jobFullName, int buildNumber,
boolean ignoreUpstreamTriggers);
/**
* Record a Maven artifact generated in a build.
*
* @param jobFullName see {@link Item#getFullName()}
* @param buildNumber see {@link Run#getNumber()}
* @param groupId Maven artifact groupId
* @param artifactId Maven artifact artifactId
* @param version Maven artifact version, the "expanded version" for snapshots who have been "mvn deploy" or equivalent
* (e.g. "1.1-20170808.155524-66" for "1.1-SNAPSHOT" deployed to a repo)
* (e.g. "1.1-20170808.155524-66" for "1.1-SNAPSHOT" deployed to a repo)
* @param type Maven artifact type (e.g. "jar", "war", "pom", hpi"...)
* @param baseVersion Maven artifact version, the NOT "expanded version" for snapshots who have been "mvn deploy" or equivalent
* (e.g. baseVersion is "1.1-SNAPSHOT" for a "1.1-SNAPSHOT" artifact that has been deployed to a repo and expanded
* to "1.1-20170808.155524-66")
* (e.g. baseVersion is "1.1-SNAPSHOT" for a "1.1-SNAPSHOT" artifact that has been deployed to a repo and expanded
* to "1.1-20170808.155524-66")
* @param repositoryUrl URL of the Maven repository on which the artifact is deployed ("mvn deploy"). {@code null} if the artifact was not deployed
* @param skipDownstreamTriggers see {@link PipelineGraphPublisher#isSkipDownstreamTriggers()}
* @param extension
* @param classifier
*/
void recordGeneratedArtifact(@Nonnull String jobFullName, int buildNumber,
@Nonnull String groupId, @Nonnull String artifactId, @Nonnull String version, @Nonnull String type, @Nonnull String baseVersion,
boolean skipDownstreamTriggers);
@Nullable String repositoryUrl, boolean skipDownstreamTriggers, String extension, String classifier);

/**
* Return the artifacts generated by the given build.
*
* @param jobFullName see {@link Item#getFullName()}
* @param buildNumber see {@link Run#getNumber()}
* @return sorted list of generated maven artifacts.
*/
@Nonnull
List<MavenArtifact> getGeneratedArtifacts(@Nonnull String jobFullName, int buildNumber);

/**
* Sync database when a job is renamed (see {@link hudson.model.listeners.ItemListener#onRenamed(Item, String, String)})
Expand Down

0 comments on commit 4bc703f

Please sign in to comment.