Skip to content

Commit

Permalink
[JENKINS-43094] Add Maven Dependencies Fingerprint Publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrille Le Clerc committed Jun 9, 2017
1 parent a1ad158 commit 3c9ab16
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
Expand Up @@ -169,7 +169,7 @@ public String getScope() {
}

public void setScope(String scope) {
this.scope = scope;
this.scope = scope == null || scope.isEmpty() ? null : scope;
}

@Override
Expand Down
Expand Up @@ -13,6 +13,8 @@
import org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor;
import org.jenkinsci.plugins.pipeline.maven.util.XmlUtils;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.w3c.dom.Element;

import java.io.IOException;
Expand Down Expand Up @@ -49,6 +51,11 @@ public class DependenciesFingerprintPublisher extends MavenPublisher {

private boolean includeScopeProvided = true;

@DataBoundConstructor
public DependenciesFingerprintPublisher() {
super();
}

protected Set<String> getIncludedScopes() {
Set<String> includedScopes = new TreeSet<>();
if (includeScopeCompile)
Expand Down Expand Up @@ -179,8 +186,9 @@ public List<MavenSpyLogProcessor.MavenDependency> listDependencies(Element maven
Element fileElt = XmlUtils.getUniqueChildElementOrNull(dependencyElt, "file");
if (fileElt == null | fileElt.getTextContent() == null || fileElt.getTextContent().isEmpty()) {
LOGGER.log(Level.WARNING, "listDependencies: no associated file found for " + dependencyArtifact + " in " + XmlUtils.toString(dependencyElt));
} else {
dependencyArtifact.file = StringUtils.trim(fileElt.getTextContent());
}
dependencyArtifact.file = StringUtils.trim(fileElt.getTextContent());

result.add(dependencyArtifact);
}
Expand All @@ -189,6 +197,60 @@ public List<MavenSpyLogProcessor.MavenDependency> listDependencies(Element maven
return result;
}

public boolean isIncludeSnapshotVersions() {
return includeSnapshotVersions;
}

@DataBoundSetter
public void setIncludeSnapshotVersions(boolean includeSnapshotVersions) {
this.includeSnapshotVersions = includeSnapshotVersions;
}

public boolean isIncludeReleaseVersions() {
return includeReleaseVersions;
}

@DataBoundSetter
public void setIncludeReleaseVersions(boolean includeReleaseVersions) {
this.includeReleaseVersions = includeReleaseVersions;
}

public boolean isIncludeScopeCompile() {
return includeScopeCompile;
}

@DataBoundSetter
public void setIncludeScopeCompile(boolean includeScopeCompile) {
this.includeScopeCompile = includeScopeCompile;
}

public boolean isIncludeScopeRuntime() {
return includeScopeRuntime;
}

@DataBoundSetter
public void setIncludeScopeRuntime(boolean includeScopeRuntime) {
this.includeScopeRuntime = includeScopeRuntime;
}

public boolean isIncludeScopeTest() {
return includeScopeTest;
}

@DataBoundSetter
public void setIncludeScopeTest(boolean includeScopeTest) {
this.includeScopeTest = includeScopeTest;
}

public boolean isIncludeScopeProvided() {
return includeScopeProvided;
}

@DataBoundSetter
public void setIncludeScopeProvided(boolean includeScopeProvided) {
this.includeScopeProvided = includeScopeProvided;
}

@Symbol("dependenciesFingerprintPublisher")
@Extension
public static class DescriptorImpl extends MavenPublisher.DescriptorImpl {
Expand Down
Expand Up @@ -67,7 +67,7 @@ public static MavenSpyLogProcessor.MavenArtifact newMavenArtifact(Element artifa
public static MavenSpyLogProcessor.MavenDependency newMavenDependency(Element dependencyElt) {
MavenSpyLogProcessor.MavenDependency dependency = new MavenSpyLogProcessor.MavenDependency();
loadMavenArtifact(dependencyElt, dependency);
dependency.scope = dependencyElt.getAttribute("scope");
dependency.setScope(dependencyElt.getAttribute("scope"));
dependency.optional = Boolean.valueOf(dependencyElt.getAttribute("optional"));

return dependency;
Expand Down
Expand Up @@ -27,5 +27,17 @@ THE SOFTWARE.
xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<st:include page="maven-publisher" class="${descriptor.clazz}"/>
<f:section title="Dependencies filtering">
<f:entry title="${%Include versions}">
<f:checkbox title="${%Snapshots}" field="includeSnapshotVersions"/>
<f:checkbox title="${%Releases}" field="includeReleaseVersions"/>
</f:entry>

<f:entry title="${%Include Scopes}">
<f:checkbox title="${%Compile}" field="includeScopeCompile"/>
<f:checkbox title="${%Runtime}" field="includeScopeRuntime"/>
<f:checkbox title="${%Provided}" field="includeScopeProvided"/>
<f:checkbox title="${%Test}" field="includeScopeTest"/>
</f:entry>
</f:section>
</j:jelly>

0 comments on commit 3c9ab16

Please sign in to comment.