-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-65757] only use pluginFirst classloader when you have no oth…
…er option (and never for guice!) (#151) Remove a number of unused dependencies to avoid issues with jar-hell in Jenkins itself and add a full e2e test. * Add a full e2e test using realistic class loading * remove the need for maven / guice FileFilter just joined the passed in excludes as a comma separated list and added defaults if the list was empty or null, But the code already handles this so just call the Plex util directly * httpcomponents was declared as a dependency but unused and bundled * xml-apis was declared bundled and unused * final clean up of unrequired stuff * skip the instruction coverage as it is compiler specific JDK11 and JDK8 compilers generate different bytecode and so asserting the bytecode instruction coverage would need to be different on potentially different compilers (e.g eclipse vs jdk 8 vs jdk11 vs ...) * remove shade configuration - it did nothing. the shade plugin was bound to a phase that did not exist in the hpi packaging type. even if it did it would be completely unclear what it did as the shade plugin does not play nicely with hpis.
- Loading branch information
Showing
3 changed files
with
115 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package hudson.plugins.jacoco.e2e; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.TypeSafeDiagnosingMatcher; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.RealJenkinsRule; | ||
|
||
import hudson.Functions; | ||
import hudson.model.Descriptor; | ||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.plugins.jacoco.JacocoBuildAction; | ||
import hudson.plugins.jacoco.JacocoPublisher; | ||
import hudson.plugins.jacoco.model.Coverage; | ||
import hudson.tasks.BatchFile; | ||
import hudson.tasks.Builder; | ||
import hudson.tasks.Publisher; | ||
import hudson.tasks.Shell; | ||
import hudson.util.DescribableList; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import static hudson.plugins.jacoco.e2e.E2ETest.CoverageMatcher.withCoverage; | ||
|
||
public class E2ETest { | ||
|
||
@Rule | ||
public RealJenkinsRule rjr = new RealJenkinsRule(); | ||
|
||
@Test | ||
public void simpleTest() throws Throwable { | ||
rjr.then(r -> { | ||
FreeStyleProject project = r.createFreeStyleProject(); | ||
project.getBuildersList().addAll(createJacocoProjectBuilders()); | ||
project.getPublishersList().add(new JacocoPublisher()); | ||
|
||
FreeStyleBuild build = r.buildAndAssertSuccess(project); | ||
|
||
assertThat("plugin collected data", build.getLog(), containsString("Collecting JaCoCo coverage data")); | ||
|
||
JacocoBuildAction action = build.getAction(JacocoBuildAction.class); | ||
assertThat("Build has the Jacoco Action", action, notNullValue()); | ||
|
||
assertThat("incorrect branch coverage reported", action.getBranchCoverage(), withCoverage(0, 621, 621)); | ||
assertThat("incorrect class coverage reported", action.getClassCoverage(), withCoverage(7, 59, 66)); | ||
assertThat("incorrect complexity coverage reported", action.getComplexityScore(), withCoverage(19, 835, 854)); | ||
// different compilers can generate different instructions (e.g. java8 vs java 11. | ||
// so just skip this for now as it seems brittle | ||
// assertThat("incorrect instruction coverage reported", action.getInstructionCoverage(), withCoverage(229, 9013, 9242)); /* java 8* / | ||
// assertThat("incorrect instruction coverage reported", action.getInstructionCoverage(), withCoverage(229, 9010 , 9239)); /* java 11 */ | ||
assertThat("incorrect line coverage reported", action.getLineCoverage(), withCoverage(53, 1860, 1913)); | ||
} | ||
); | ||
} | ||
|
||
private static List<Builder> createJacocoProjectBuilders() { | ||
String[] commands = { "git clone --branch jacoco-3.2.0 https://github.com/jenkinsci/jacoco-plugin.git .", | ||
"mvn -P enable-jacoco -B -Dtest=ClassReportTest test" }; | ||
List<Builder> builders = new ArrayList<>(); | ||
if (Functions.isWindows()) { | ||
for (String command : commands) { | ||
builders.add(new BatchFile(command)); | ||
} | ||
} else { | ||
for (String command : commands) { | ||
builders.add(new Shell(command)); | ||
} | ||
} | ||
return builders; | ||
} | ||
|
||
public static class CoverageMatcher extends TypeSafeDiagnosingMatcher<Coverage> { | ||
|
||
private final int covered; | ||
private final int missed; | ||
private final int total; | ||
|
||
private CoverageMatcher(int covered, int missed, int total) { | ||
this.covered = covered; | ||
this.missed = missed; | ||
this.total = total; | ||
} | ||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText(" with covered="+ covered); | ||
description.appendText(" and missed="+ missed); | ||
description.appendText(" and total="+ total); | ||
|
||
} | ||
|
||
@Override | ||
protected boolean matchesSafely(Coverage coverage, Description mismatchDescription) { | ||
mismatchDescription.appendText("Coverage with covered="+ coverage.getCovered()); | ||
mismatchDescription.appendText(" and missed="+ coverage.getMissed()); | ||
mismatchDescription.appendText(" and total="+ coverage.getTotal()); | ||
|
||
return coverage.getCovered() == covered && | ||
coverage.getMissed() == missed && | ||
coverage.getTotal() == total; | ||
} | ||
|
||
public static CoverageMatcher withCoverage(int covered, int missed, int total) { | ||
return new CoverageMatcher(covered, missed, total); | ||
} | ||
} | ||
} |