Skip to content

Commit 347c4b6

Browse files
authored
Merge pull request #881 from alecharp/feature/removes-jacoco-integration
Removes Jacoco integration
2 parents 94d4ce9 + 0179a6e commit 347c4b6

File tree

8 files changed

+77
-279
lines changed

8 files changed

+77
-279
lines changed

README.adoc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,6 @@ Requires the https://plugins.jenkins.io/jgiven/[Jenkins JGiven Plugin]
347347
+
348348
Publish http://jgiven.org/[JGiven] test reports
349349

350-
JaCoCo Code Coverage::
351-
Requires the https://plugins.jenkins.io/jacoco/[Jenkins JaCoCo Plugin]
352-
+
353-
Publish JaCoCo Code Coverage
354-
355350
Maven Linker Publisher::
356351
Publish the Maven report on the pipeline build GUI (list of dependencies, produced artifacts, downstream & upstream pipelines). +
357352
This publisher should be renamed "Maven Build Report Publisher". +
@@ -417,10 +412,6 @@ Since 3.11.0 more fine granular options: +
417412
|`withMaven(options: [jgivenPublisher(disabled: true)],...)`
418413
|`.skip-publish-jgiven-results`
419414

420-
|JaCoCo Code Coverage
421-
|`withMaven(options: [jacocoPublisher(disabled: true)],...)`
422-
|
423-
424415
|Maven Linker Publisher
425416
|`withMaven(options: [mavenLinkerPublisher(disabled: true)],...)`
426417
|`skip-maven-linker-publisher`
@@ -501,7 +492,7 @@ withMaven() {
501492
The API for Maven reporters is still experimental.
502493
Please open a Request for Enhancement Jira issue to discuss how to add Maven reporters.
503494

504-
We want to quickly add reporters for CheckStyle, Jacoco...
495+
We want to quickly add reporters for CheckStyle...
505496

506497
[#db-setup]
507498
== Database Setup

pipeline-maven/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,6 @@
144144
<artifactId>htmlpublisher</artifactId>
145145
<optional>true</optional>
146146
</dependency>
147-
<dependency>
148-
<groupId>org.jenkins-ci.plugins</groupId>
149-
<artifactId>jacoco</artifactId>
150-
<optional>true</optional>
151-
<exclusions>
152-
<exclusion>
153-
<groupId>org.apache.httpcomponents</groupId>
154-
<artifactId>httpcore</artifactId>
155-
</exclusion>
156-
</exclusions>
157-
</dependency>
158147
<dependency>
159148
<groupId>org.jenkins-ci.plugins</groupId>
160149
<artifactId>jgiven</artifactId>

pipeline-maven/src/main/java/org/jenkinsci/plugins/pipeline/maven/MavenPublisherStrategy.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.logging.Level;
1515
import java.util.logging.Logger;
1616
import jenkins.model.Jenkins;
17+
import org.jenkinsci.plugins.pipeline.maven.publishers.JacocoReportPublisher;
1718

1819
/**
1920
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
@@ -71,7 +72,18 @@ public List<MavenPublisher> buildPublishersList(
7172
Jenkins.get().getDescriptorList(MavenPublisher.class);
7273
for (Descriptor<MavenPublisher> descriptor : descriptorList) {
7374
try {
74-
defaultPublishersById.put(descriptor.getId(), descriptor.clazz.newInstance());
75+
if (JacocoReportPublisher.DescriptorImpl.class.isAssignableFrom(descriptor.getClass())) {
76+
listener.getLogger()
77+
.println(
78+
"""
79+
[withMaven] JacocoPublisher is no longer implicitly used with `withMaven` step.
80+
[withMaven] Jacoco plugin has been deprecated and should not be used anymore.
81+
[withMaven] Usage of Coverage plugin is recommended.
82+
[withMaven] See https://plugins.jenkins.io/coverage/#plugin-content-pipeline-example.
83+
""");
84+
} else {
85+
defaultPublishersById.put(descriptor.getId(), descriptor.clazz.newInstance());
86+
}
7587
} catch (InstantiationException | IllegalAccessException e) {
7688
PrintWriter error =
7789
listener.error("[withMaven] Exception instantiation default config for Maven Publisher '"

pipeline-maven/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/JacocoReportPublisher.java

Lines changed: 10 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,23 @@
2525
package org.jenkinsci.plugins.pipeline.maven.publishers;
2626

2727
import edu.umd.cs.findbugs.annotations.NonNull;
28+
import hudson.AbortException;
2829
import hudson.Extension;
29-
import hudson.FilePath;
30-
import hudson.Launcher;
31-
import hudson.model.Run;
32-
import hudson.model.TaskListener;
33-
import hudson.plugins.jacoco.JacocoPublisher;
3430
import java.io.IOException;
35-
import java.util.ArrayList;
36-
import java.util.List;
37-
import java.util.logging.Level;
38-
import java.util.logging.Logger;
39-
import java.util.stream.Collectors;
4031
import org.jenkinsci.Symbol;
41-
import org.jenkinsci.plugins.pipeline.maven.MavenArtifact;
4232
import org.jenkinsci.plugins.pipeline.maven.MavenPublisher;
43-
import org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor;
4433
import org.jenkinsci.plugins.pipeline.maven.Messages;
45-
import org.jenkinsci.plugins.pipeline.maven.util.XmlUtils;
4634
import org.jenkinsci.plugins.workflow.steps.StepContext;
4735
import org.kohsuke.stapler.DataBoundConstructor;
4836
import org.w3c.dom.Element;
4937

5038
/**
5139
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
40+
*
41+
* @deprecated since TODO
5242
*/
43+
@Deprecated
5344
public class JacocoReportPublisher extends MavenPublisher {
54-
private static final Logger LOGGER = Logger.getLogger(JacocoReportPublisher.class.getName());
55-
5645
private static final long serialVersionUID = 1L;
5746

5847
@DataBoundConstructor
@@ -123,184 +112,12 @@ public JacocoReportPublisher() {}
123112
@Override
124113
public void process(@NonNull StepContext context, @NonNull Element mavenSpyLogsElt)
125114
throws IOException, InterruptedException {
126-
127-
TaskListener listener = context.get(TaskListener.class);
128-
FilePath workspace = context.get(FilePath.class);
129-
Run run = context.get(Run.class);
130-
Launcher launcher = context.get(Launcher.class);
131-
132-
List<Element> jacocoPrepareAgentEvents = XmlUtils.getExecutionEventsByPlugin(
133-
mavenSpyLogsElt, "org.jacoco", "jacoco-maven-plugin", "prepare-agent", "MojoSucceeded", "MojoFailed");
134-
List<Element> jacocoPrepareAgentIntegrationEvents = XmlUtils.getExecutionEventsByPlugin(
135-
mavenSpyLogsElt,
136-
"org.jacoco",
137-
"jacoco-maven-plugin",
138-
"prepare-agent-integration",
139-
"MojoSucceeded",
140-
"MojoFailed");
141-
jacocoPrepareAgentEvents.addAll(jacocoPrepareAgentIntegrationEvents); // add prepare-agent-integration goals
142-
143-
if (jacocoPrepareAgentEvents.isEmpty()) {
144-
LOGGER.log(Level.FINE, "No org.jacoco:jacoco-maven-plugin:prepare-agent[-integration] execution found");
145-
return;
146-
}
147-
148-
try {
149-
Class.forName("hudson.plugins.jacoco.JacocoPublisher");
150-
} catch (ClassNotFoundException e) {
151-
listener.getLogger().print("[withMaven] Jenkins ");
152-
listener.hyperlink("https://wiki.jenkins.io/display/JENKINS/JaCoCo+Plugin", "JaCoCo Plugin");
153-
listener.getLogger()
154-
.println(
155-
" not found, don't display org.jacoco:jacoco-maven-plugin:prepare-agent[-integration] results in pipeline screen.");
156-
return;
157-
}
158-
159-
List<JacocoReportDetails> jacocoReportDetails = new ArrayList<>();
160-
161-
for (Element jacocoPrepareAgentEvent : jacocoPrepareAgentEvents) {
162-
163-
Element buildElement = XmlUtils.getUniqueChildElementOrNull(jacocoPrepareAgentEvent, "project", "build");
164-
if (buildElement == null) {
165-
if (LOGGER.isLoggable(Level.FINE))
166-
LOGGER.log(
167-
Level.FINE,
168-
"Ignore execution event with missing 'build' child:"
169-
+ XmlUtils.toString(jacocoPrepareAgentEvent));
170-
continue;
171-
}
172-
173-
Element pluginElt = XmlUtils.getUniqueChildElement(jacocoPrepareAgentEvent, "plugin");
174-
Element destFileElt = XmlUtils.getUniqueChildElementOrNull(pluginElt, "destFile");
175-
Element projectElt = XmlUtils.getUniqueChildElement(jacocoPrepareAgentEvent, "project");
176-
MavenArtifact mavenArtifact = XmlUtils.newMavenArtifact(projectElt);
177-
MavenSpyLogProcessor.PluginInvocation pluginInvocation = XmlUtils.newPluginInvocation(pluginElt);
178-
179-
if (destFileElt == null) {
180-
listener.getLogger()
181-
.println("[withMaven] No <destFile> element found for <plugin> in "
182-
+ XmlUtils.toString(jacocoPrepareAgentEvent));
183-
continue;
184-
}
185-
String destFile = destFileElt.getTextContent().trim();
186-
if (destFile.equals("${jacoco.destFile}")) {
187-
destFile = "${project.build.directory}/jacoco.exec";
188-
if ("prepare-agent-integration".equals(pluginInvocation.goal))
189-
destFile = "${project.build.directory}/jacoco-it.exec";
190-
String projectBuildDirectory = XmlUtils.getProjectBuildDirectory(projectElt);
191-
if (projectBuildDirectory == null || projectBuildDirectory.isEmpty()) {
192-
listener.getLogger()
193-
.println("[withMaven] '${project.build.directory}' found for <project> in "
194-
+ XmlUtils.toString(jacocoPrepareAgentEvent));
195-
continue;
196-
}
197-
198-
destFile = destFile.replace("${project.build.directory}", projectBuildDirectory);
199-
} else if (destFile.contains("${project.build.directory}")) {
200-
String projectBuildDirectory = XmlUtils.getProjectBuildDirectory(projectElt);
201-
if (projectBuildDirectory == null || projectBuildDirectory.isEmpty()) {
202-
listener.getLogger()
203-
.println("[withMaven] '${project.build.directory}' found for <project> in "
204-
+ XmlUtils.toString(jacocoPrepareAgentEvent));
205-
continue;
206-
}
207-
destFile = destFile.replace("${project.build.directory}", projectBuildDirectory);
208-
209-
} else if (destFile.contains("${basedir}")) {
210-
String baseDir = projectElt.getAttribute("baseDir");
211-
if (baseDir.isEmpty()) {
212-
listener.getLogger()
213-
.println("[withMaven] '${basedir}' found for <project> in "
214-
+ XmlUtils.toString(jacocoPrepareAgentEvent));
215-
continue;
216-
}
217-
destFile = destFile.replace("${basedir}", baseDir);
218-
}
219-
220-
destFile = XmlUtils.getPathInWorkspace(destFile, workspace);
221-
222-
String sourceDirectory = buildElement.getAttribute("sourceDirectory");
223-
String classesDirectory = buildElement.getAttribute("directory") + "/classes";
224-
225-
String sourceDirectoryRelativePath = XmlUtils.getPathInWorkspace(sourceDirectory, workspace);
226-
String classesDirectoryRelativePath = XmlUtils.getPathInWorkspace(classesDirectory, workspace);
227-
228-
String excludes = null;
229-
Element excludesElt = XmlUtils.getUniqueChildElementOrNull(pluginElt, "excludes");
230-
if (excludesElt != null) {
231-
List<Element> excludeElements = XmlUtils.getChildrenElements(excludesElt, "exclude");
232-
excludes = excludeElements.stream()
233-
.map(e -> e.getTextContent().trim())
234-
.collect(Collectors.joining(","));
235-
}
236-
237-
listener.getLogger()
238-
.println("[withMaven] jacocoPublisher - Archive JaCoCo analysis results for Maven artifact "
239-
+ mavenArtifact.toString() + " generated by " + pluginInvocation + ": execFile: " + destFile
240-
+ ", sources: " + sourceDirectoryRelativePath + ", classes: "
241-
+ classesDirectoryRelativePath + ", excludes: "
242-
+ excludes);
243-
jacocoReportDetails.add(new JacocoReportDetails(
244-
destFile,
245-
sourceDirectoryRelativePath,
246-
classesDirectoryRelativePath,
247-
excludes,
248-
mavenArtifact.toString() + " " + pluginInvocation));
249-
}
250-
251-
JacocoPublisher jacocoPublisher = new JacocoPublisher();
252-
253-
String aggregatedDestFile =
254-
jacocoReportDetails.stream().map(details -> details.execFile).collect(Collectors.joining(","));
255-
String aggregatedSourceDirectory = jacocoReportDetails.stream()
256-
.map(details -> details.sourceDirectory)
257-
.collect(Collectors.joining(","));
258-
String aggregatedClassesDirectory = jacocoReportDetails.stream()
259-
.map(details -> details.classesDirectory)
260-
.collect(Collectors.joining(","));
261-
String aggregatedExclusionPattern = jacocoReportDetails.stream()
262-
.map(details -> details.excludes)
263-
.filter(e -> e != null && !e.isEmpty())
264-
.distinct()
265-
.collect(Collectors.joining(","));
266-
267-
jacocoPublisher.setExecPattern(aggregatedDestFile);
268-
jacocoPublisher.setSourcePattern(aggregatedSourceDirectory);
269-
jacocoPublisher.setClassPattern(aggregatedClassesDirectory);
270-
jacocoPublisher.setExclusionPattern(aggregatedExclusionPattern);
271-
272-
try {
273-
jacocoPublisher.perform(run, workspace, launcher, listener);
274-
} catch (Exception e) {
275-
listener.error("[withMaven] jacocoPublisher - exception archiving JaCoCo results for " + jacocoReportDetails
276-
+ ": " + e);
277-
LOGGER.log(Level.WARNING, "Exception processing JaCoCo results", e);
278-
throw new MavenPipelinePublisherException(
279-
"jacocoPublisher", "archiving JaCoCo results for " + jacocoReportDetails, e);
280-
}
281-
}
282-
283-
public static class JacocoReportDetails {
284-
final String execFile, sourceDirectory, classesDirectory, excludes, description;
285-
286-
public JacocoReportDetails(
287-
String execFile, String sourceDirectory, String classesDirectory, String excludes, String description) {
288-
this.execFile = execFile;
289-
this.sourceDirectory = sourceDirectory;
290-
this.classesDirectory = classesDirectory;
291-
this.excludes = excludes;
292-
this.description = description;
293-
}
294-
295-
@Override
296-
public String toString() {
297-
return "JacocoReportDetails{" + "execFile='"
298-
+ execFile + '\'' + ", sourceDirectory='"
299-
+ sourceDirectory + '\'' + ", classesDirectory='"
300-
+ classesDirectory + '\'' + ", excludes='"
301-
+ excludes + '\'' + ", description='"
302-
+ description + '\'' + '}';
303-
}
115+
throw new AbortException(
116+
"""
117+
The jacocoPublisher is deprecated as is the Jacoco plugin and you should not use it.
118+
Alternatively, you should rely on Coverage plugin and see the configuration required at https://plugins.jenkins.io/coverage/#plugin-content-pipeline-example.
119+
Or, if continuing to use the JaCoCo plugin for now, run it explicitly rather than expecting withMaven to run it implicitly.
120+
""");
304121
}
305122

306123
@Symbol("jacocoPublisher")

pipeline-maven/src/test/java/org/jenkinsci/plugins/pipeline/maven/MavenPublisherStrategyTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.jenkinsci.plugins.pipeline.maven.publishers.GeneratedArtifactsPublisher;
1515
import org.jenkinsci.plugins.pipeline.maven.publishers.InvokerRunsPublisher;
1616
import org.jenkinsci.plugins.pipeline.maven.publishers.JGivenTestsPublisher;
17-
import org.jenkinsci.plugins.pipeline.maven.publishers.JacocoReportPublisher;
1817
import org.jenkinsci.plugins.pipeline.maven.publishers.JunitTestsPublisher;
1918
import org.jenkinsci.plugins.pipeline.maven.publishers.MavenLinkerPublisher2;
2019
import org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher;
@@ -38,7 +37,7 @@ public void listMavenPublishers(JenkinsRule r) throws Exception {
3837

3938
List<MavenPublisher> mavenPublishers = MavenPublisherStrategy.IMPLICIT.buildPublishersList(
4039
Collections.emptyList(), new StreamTaskListener(baos));
41-
assertThat(mavenPublishers).hasSize(12);
40+
assertThat(mavenPublishers).hasSize(11);
4241

4342
Map<String, MavenPublisher> reportersByDescriptorId = new HashMap<>();
4443
for (MavenPublisher mavenPublisher : mavenPublishers) {
@@ -51,7 +50,6 @@ public void listMavenPublishers(JenkinsRule r) throws Exception {
5150
assertThat(reportersByDescriptorId).containsKey(new DependenciesFingerprintPublisher.DescriptorImpl().getId());
5251
assertThat(reportersByDescriptorId).containsKey(new GeneratedArtifactsPublisher.DescriptorImpl().getId());
5352
assertThat(reportersByDescriptorId).containsKey(new InvokerRunsPublisher.DescriptorImpl().getId());
54-
assertThat(reportersByDescriptorId).containsKey(new JacocoReportPublisher.DescriptorImpl().getId());
5553
assertThat(reportersByDescriptorId).containsKey(new JGivenTestsPublisher.DescriptorImpl().getId());
5654
assertThat(reportersByDescriptorId).containsKey(new JunitTestsPublisher.DescriptorImpl().getId());
5755
assertThat(reportersByDescriptorId).containsKey(new MavenLinkerPublisher2.DescriptorImpl().getId());

0 commit comments

Comments
 (0)