diff --git a/pom.xml b/pom.xml index 9c81ae0b..c2530dc1 100644 --- a/pom.xml +++ b/pom.xml @@ -28,8 +28,8 @@ THE SOFTWARE. org.jenkins-ci.plugins plugin - 1.424.6 - + 1.609.3 + jacoco @@ -154,6 +154,41 @@ THE SOFTWARE. jacoco-maven-plugin ${jacoco.version} + + org.apache.maven.plugins + maven-plugin-plugin + 3.2 + test + + + org.apache.maven + maven-plugin-api + 3.3.9 + test + + + org.apache.maven + maven-artifact + 3.3.9 + test + + + org.apache.maven + maven-model + 3.3.9 + test + + + org.apache.maven + maven-settings + 3.3.9 + test + + + org.codehaus.plexus + plexus-utils + 3.0.15 + @@ -191,8 +226,8 @@ THE SOFTWARE. maven-compiler-plugin 2.3.2 - 1.5 - 1.5 + 1.6 + 1.6 diff --git a/src/main/java/hudson/plugins/jacoco/JacocoBuildAction.java b/src/main/java/hudson/plugins/jacoco/JacocoBuildAction.java index 7d9c3065..6ce1de3d 100644 --- a/src/main/java/hudson/plugins/jacoco/JacocoBuildAction.java +++ b/src/main/java/hudson/plugins/jacoco/JacocoBuildAction.java @@ -9,6 +9,9 @@ import java.util.LinkedHashMap; import java.util.Map; +import hudson.model.Run; +import hudson.model.TaskListener; +import jenkins.model.RunAction2; import org.jacoco.core.analysis.IBundleCoverage; import org.jvnet.localizer.Localizable; import org.kohsuke.stapler.StaplerProxy; @@ -33,9 +36,9 @@ * @author Jonathan Fuerth * @author Ognjen Bubalo */ -public final class JacocoBuildAction extends CoverageObject implements HealthReportingAction, StaplerProxy, Serializable { +public final class JacocoBuildAction extends CoverageObject implements HealthReportingAction, StaplerProxy, Serializable, RunAction2 { - public final AbstractBuild owner; + public transient Run owner; @Deprecated public transient AbstractBuild build; @@ -45,11 +48,6 @@ public final class JacocoBuildAction extends CoverageObject i private final String[] inclusions; private final String[] exclusions; - /** - * Non-null if the coverage has pass/fail rules. - */ - private final Rule rule; - /** * The thresholds that applied when this build was built. * TODO: add ability to trend thresholds on the graph @@ -58,24 +56,20 @@ public final class JacocoBuildAction extends CoverageObject i /** * - * @param owner - * @param rule * @param ratios * The available coverage ratios in the report. Null is treated * the same as an empty map. * @param thresholds */ - public JacocoBuildAction(AbstractBuild owner, Rule rule, + public JacocoBuildAction( Map ratios, - JacocoHealthReportThresholds thresholds, BuildListener listener, String[] inclusions, String[] exclusions) { + JacocoHealthReportThresholds thresholds, TaskListener listener, String[] inclusions, String[] exclusions) { logger = listener.getLogger(); if (ratios == null) { ratios = Collections.emptyMap(); } this.inclusions = inclusions; this.exclusions = exclusions; - this.owner = owner; - this.rule = rule; this.clazz = getOrCreateRatio(ratios, CoverageElement.Type.CLASS); this.method = getOrCreateRatio(ratios, CoverageElement.Type.METHOD); this.line = getOrCreateRatio(ratios, CoverageElement.Type.LINE); @@ -202,12 +196,12 @@ public Object getTarget() { } @Override - public AbstractBuild getBuild() { + public Run getBuild() { return owner; } public JacocoReportDir getJacocoReport() { - return new JacocoReportDir(owner); + return new JacocoReportDir(owner.getRootDir()); } /** @@ -275,8 +269,8 @@ public Map getCoverageRatios(){ /** * Gets the previous {@link JacocoBuildAction} of the given build. */ - /*package*/ static JacocoBuildAction getPreviousResult(AbstractBuild start) { - AbstractBuild b = start; + /*package*/ static JacocoBuildAction getPreviousResult(Run start) { + Run b = start; while(true) { b = b.getPreviousBuild(); if(b==null) { @@ -298,12 +292,12 @@ public Map getCoverageRatios(){ * @throws IOException * if failed to parse the file. */ - public static JacocoBuildAction load(AbstractBuild owner, Rule rule, JacocoHealthReportThresholds thresholds, BuildListener listener, JacocoReportDir layout, String[] includes, String[] excludes) throws IOException { + public static JacocoBuildAction load(Run owner, JacocoHealthReportThresholds thresholds, TaskListener listener, JacocoReportDir layout, String[] includes, String[] excludes) throws IOException { //PrintStream logger = listener.getLogger(); Map ratios = null; ratios = loadRatios(layout, ratios, includes, excludes); - return new JacocoBuildAction(owner, rule, ratios, thresholds, listener, includes, excludes); + return new JacocoBuildAction(ratios, thresholds, listener, includes, excludes); } @@ -360,4 +354,14 @@ public final PrintStream getLogger() { // does not run the construct and thus leaves the transient variables empty return System.out; } + + @Override + public void onAttached(Run run) { + this.owner = run; + } + + @Override + public void onLoad(Run run) { + this.owner = run; + } } diff --git a/src/main/java/hudson/plugins/jacoco/JacocoPublisher.java b/src/main/java/hudson/plugins/jacoco/JacocoPublisher.java index 2c54ebc1..eada8d55 100644 --- a/src/main/java/hudson/plugins/jacoco/JacocoPublisher.java +++ b/src/main/java/hudson/plugins/jacoco/JacocoPublisher.java @@ -10,6 +10,8 @@ import hudson.model.Result; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; +import hudson.model.Run; +import hudson.model.TaskListener; import hudson.plugins.jacoco.report.CoverageReport; import hudson.remoting.VirtualChannel; import hudson.tasks.BuildStepDescriptor; @@ -22,11 +24,20 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import jenkins.MasterToSlaveFileCallable; +import jenkins.tasks.SimpleBuildStep; import org.apache.tools.ant.DirectoryScanner; +import org.jenkinsci.remoting.RoleChecker; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; /** * {@link Publisher} that captures jacoco coverage reports. @@ -36,16 +47,18 @@ * @author Ognjen Bubalo * */ -public class JacocoPublisher extends Recorder { - +public class JacocoPublisher extends Recorder implements SimpleBuildStep { + /** * Rule to be enforced. Can be null. - * + *

* TODO: define a configuration mechanism. */ public Rule rule; - @Deprecated public transient String includes; - @Deprecated public transient int moduleNum; + @Deprecated + public transient String includes; + @Deprecated + public transient int moduleNum; /** * {@link hudson.model.HealthReport} thresholds to apply. */ @@ -55,33 +68,54 @@ public class JacocoPublisher extends Recorder { /** * Variables containing the configuration set by the user. */ - private final String execPattern; - private final String classPattern; - private final String sourcePattern; - private final String inclusionPattern; - private final String exclusionPattern; - - - private final String minimumInstructionCoverage; - private final String minimumBranchCoverage; - private final String minimumComplexityCoverage; - private final String minimumLineCoverage; - private final String minimumMethodCoverage; - private final String minimumClassCoverage; - private final String maximumInstructionCoverage; - private final String maximumBranchCoverage; - private final String maximumComplexityCoverage; - private final String maximumLineCoverage; - private final String maximumMethodCoverage; - private final String maximumClassCoverage; - private final boolean changeBuildStatus; + private String execPattern; + private String classPattern; + private String sourcePattern; + private String inclusionPattern; + private String exclusionPattern; + + private String minimumInstructionCoverage; + private String minimumBranchCoverage; + private String minimumComplexityCoverage; + private String minimumLineCoverage; + private String minimumMethodCoverage; + private String minimumClassCoverage; + private String maximumInstructionCoverage; + private String maximumBranchCoverage; + private String maximumComplexityCoverage; + private String maximumLineCoverage; + private String maximumMethodCoverage; + private String maximumClassCoverage; + private boolean changeBuildStatus; private static final String DIR_SEP = "\\s*,\\s*"; + @DataBoundConstructor + public JacocoPublisher() { + this.execPattern = "**/**.exec"; + this.classPattern = "**/classes"; + this.sourcePattern = "**/src/main/java"; + this.inclusionPattern = ""; + this.exclusionPattern = ""; + this.minimumInstructionCoverage = "0"; + this.minimumBranchCoverage = "0"; + this.minimumComplexityCoverage = "0"; + this.minimumLineCoverage = "0"; + this.minimumMethodCoverage = "0"; + this.minimumClassCoverage = "0"; + this.maximumInstructionCoverage = "0"; + this.maximumBranchCoverage = "0"; + this.maximumComplexityCoverage = "0"; + this.maximumLineCoverage = "0"; + this.maximumMethodCoverage = "0"; + this.maximumClassCoverage = "0"; + this.changeBuildStatus = false; + } + /** * Loads the configuration set by user. */ - @DataBoundConstructor + @Deprecated public JacocoPublisher(String execPattern, String classPattern, String sourcePattern, String inclusionPattern, String exclusionPattern, String maximumInstructionCoverage, String maximumBranchCoverage , String maximumComplexityCoverage, String maximumLineCoverage, String maximumMethodCoverage, String maximumClassCoverage, String minimumInstructionCoverage, String minimumBranchCoverage , String minimumComplexityCoverage, String minimumLineCoverage, String minimumMethodCoverage, String minimumClassCoverage, boolean changeBuildStatus) { @@ -240,17 +274,108 @@ public boolean isChangeBuildStatus() { public boolean getChangeBuildStatus() { return changeBuildStatus; } - + @DataBoundSetter + public void setExecPattern(String execPattern) { + this.execPattern = execPattern; + } + + @DataBoundSetter + public void setClassPattern(String classPattern) { + this.classPattern = classPattern; + } + + @DataBoundSetter + public void setSourcePattern(String sourcePattern) { + this.sourcePattern = sourcePattern; + } + + @DataBoundSetter + public void setMinimumInstructionCoverage(String minimumInstructionCoverage) { + this.minimumInstructionCoverage = checkThresholdInput(minimumInstructionCoverage); + } + + @DataBoundSetter + public void setMinimumBranchCoverage(String minimumBranchCoverage) { + this.minimumBranchCoverage = checkThresholdInput(minimumBranchCoverage); + } + + @DataBoundSetter + public void setMinimumComplexityCoverage(String minimumComplexityCoverage) { + this.minimumComplexityCoverage = checkThresholdInput(minimumComplexityCoverage); + } + + @DataBoundSetter + public void setMinimumLineCoverage(String minimumLineCoverage) { + this.minimumLineCoverage = checkThresholdInput(minimumLineCoverage); + } + + @DataBoundSetter + public void setMinimumMethodCoverage(String minimumMethodCoverage) { + this.minimumMethodCoverage = checkThresholdInput(minimumMethodCoverage); + } + + @DataBoundSetter + public void setMinimumClassCoverage(String minimumClassCoverage) { + this.minimumClassCoverage = checkThresholdInput(minimumClassCoverage); + } + + @DataBoundSetter + public void setMaximumInstructionCoverage(String maximumInstructionCoverage) { + this.maximumInstructionCoverage = checkThresholdInput(maximumInstructionCoverage); + } + + @DataBoundSetter + public void setMaximumBranchCoverage(String maximumBranchCoverage) { + this.maximumBranchCoverage = checkThresholdInput(maximumBranchCoverage); + } + + @DataBoundSetter + public void setMaximumComplexityCoverage(String maximumComplexityCoverage) { + this.maximumComplexityCoverage = checkThresholdInput(maximumComplexityCoverage); + } + + @DataBoundSetter + public void setMaximumLineCoverage(String maximumLineCoverage) { + this.maximumLineCoverage = checkThresholdInput(maximumLineCoverage); + } + + @DataBoundSetter + public void setMaximumMethodCoverage(String maximumMethodCoverage) { + this.maximumMethodCoverage = checkThresholdInput(maximumMethodCoverage); + } + + @DataBoundSetter + public void setMaximumClassCoverage(String maximumClassCoverage) { + this.maximumClassCoverage = checkThresholdInput(maximumClassCoverage); + } + + @DataBoundSetter + public void setChangeBuildStatus(boolean changeBuildStatus) { + this.changeBuildStatus = changeBuildStatus; + } + + @DataBoundSetter + public void setInclusionPattern(String inclusionPattern) { + this.inclusionPattern = inclusionPattern; + } + + @DataBoundSetter + public void setExclusionPattern(String exclusionPattern) { + this.exclusionPattern = exclusionPattern; + } + protected static void saveCoverageReports(FilePath destFolder, FilePath sourceFolder) throws IOException, InterruptedException { destFolder.mkdirs(); sourceFolder.copyRecursiveTo(destFolder); } - protected static String resolveFilePaths(AbstractBuild build, BuildListener listener, String input) { + protected String resolveFilePaths(Run build, TaskListener listener, String input, Map env) { try { - - return build.getEnvironment(listener).expand(input); + + final EnvVars environment = build.getEnvironment(listener); + environment.overrideAll(env); + return environment.expand(input); } catch (Exception e) { listener.getLogger().println("Failed to resolve parameters in string \""+ @@ -258,35 +383,26 @@ protected static String resolveFilePaths(AbstractBuild build, BuildListene } return input; } - - protected static FilePath[] resolveDirPaths(AbstractBuild build, BuildListener listener, final String input) { + + protected String resolveFilePaths(AbstractBuild build, TaskListener listener, String input) { + try { + + final EnvVars environment = build.getEnvironment(listener); + environment.overrideAll(build.getBuildVariables()); + return environment.expand(input); + + } catch (Exception e) { + listener.getLogger().println("Failed to resolve parameters in string \""+ + input+"\" due to following error:\n"+e.getMessage()); + } + return input; + } + + protected static FilePath[] resolveDirPaths(FilePath workspace, TaskListener listener, final String input) { //final PrintStream logger = listener.getLogger(); FilePath[] directoryPaths = null; try { - directoryPaths = build.getWorkspace().act(new FilePath.FileCallable() - { - static final long serialVersionUID = 1552178457453558870L; - - public FilePath[] invoke(File f, VirtualChannel channel) throws IOException { - FilePath base = new FilePath(f); - ArrayList localDirectoryPaths= new ArrayList(); - String[] includes = input.split(DIR_SEP); - DirectoryScanner ds = new DirectoryScanner(); - - ds.setIncludes(includes); - ds.setCaseSensitive(false); - ds.setBasedir(f); - ds.scan(); - String[] dirs = ds.getIncludedDirectories(); - - for (String dir : dirs) { - localDirectoryPaths.add(base.child(dir)); - } - FilePath[] lfp = {};//trick to have an empty array as a parameter, so the returned array will contain the elements - return localDirectoryPaths.toArray(lfp); - } - }); - + directoryPaths = workspace.act(new ResolveDirPaths(input)); } catch(InterruptedException ie) { ie.printStackTrace(); } catch(IOException io) { @@ -294,107 +410,113 @@ public FilePath[] invoke(File f, VirtualChannel channel) throws IOException { } return directoryPaths; } - - /* - * Entry point of this report plugin. - * - * @see hudson.tasks.BuildStepCompatibilityLayer#perform(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.BuildListener) - */ - @SuppressWarnings("resource") + + @Override - public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { - - final PrintStream logger = listener.getLogger(); - FilePath[] matchedClassDirs = null; - FilePath[] matchedSrcDirs = null; + public void perform(@Nonnull Run run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener taskListener) throws InterruptedException, IOException { + Map envs = run instanceof AbstractBuild ? ((AbstractBuild) run).getBuildVariables() : Collections.emptyMap(); + + healthReports = createJacocoHealthReportThresholds(); + + final PrintStream logger = taskListener.getLogger(); + FilePath[] matchedClassDirs = null; + FilePath[] matchedSrcDirs = null; + + if (run.getResult() == Result.FAILURE || run.getResult() == Result.ABORTED) { + return; + } + + + logger.println("[JaCoCo plugin] Collecting JaCoCo coverage data..."); + + + EnvVars env = run.getEnvironment(taskListener); + env.overrideAll(envs); - if (build.getResult() == Result.FAILURE || build.getResult() == Result.ABORTED) { - return true; - } - - - logger.println("[JaCoCo plugin] Collecting JaCoCo coverage data..."); - - - EnvVars env = build.getEnvironment(listener); - env.overrideAll(build.getBuildVariables()); - try { - healthReports = new JacocoHealthReportThresholds(Integer.parseInt(minimumClassCoverage), Integer.parseInt(maximumClassCoverage), Integer.parseInt(minimumMethodCoverage), Integer.parseInt(maximumMethodCoverage), Integer.parseInt(minimumLineCoverage), Integer.parseInt(maximumLineCoverage) - ,Integer.parseInt(minimumBranchCoverage), Integer.parseInt(maximumBranchCoverage), Integer.parseInt(minimumInstructionCoverage), Integer.parseInt(maximumInstructionCoverage), Integer.parseInt(minimumComplexityCoverage), Integer.parseInt(maximumComplexityCoverage)); - } catch(NumberFormatException nfe) { - healthReports = new JacocoHealthReportThresholds(0,0,0,0,0,0,0,0,0,0,0,0); - } - if ((execPattern==null) || (classPattern==null) || (sourcePattern==null)) { - if(build.getResult().isWorseThan(Result.UNSTABLE)) { - return true; + if(run.getResult().isWorseThan(Result.UNSTABLE)) { + return; } - + logger.println("[JaCoCo plugin] ERROR: Missing configuration!"); - build.setResult(Result.FAILURE); - return true; + run.setResult(Result.FAILURE); + return; } - + logger.println("[JaCoCo plugin] " + execPattern + ";" + classPattern + ";" + sourcePattern + ";" + " locations are configured"); - JacocoReportDir dir = new JacocoReportDir(build); + JacocoReportDir dir = new JacocoReportDir(run.getRootDir()); + + if (run instanceof AbstractBuild) { + execPattern = resolveFilePaths((AbstractBuild) run, taskListener, execPattern); + } - List matchedExecFiles = Arrays.asList(build.getWorkspace().list(resolveFilePaths(build, listener, execPattern))); + List matchedExecFiles = Arrays.asList(filePath.list(resolveFilePaths(run, taskListener, execPattern, env))); logger.println("[JaCoCo plugin] Number of found exec files for pattern " + execPattern + ": " + matchedExecFiles.size()); logger.print("[JaCoCo plugin] Saving matched execfiles: "); dir.addExecFiles(matchedExecFiles); logger.print(" " + Util.join(matchedExecFiles," ")); - matchedClassDirs = resolveDirPaths(build, listener, classPattern); + matchedClassDirs = resolveDirPaths(filePath, taskListener, classPattern); logger.print("\n[JaCoCo plugin] Saving matched class directories for class-pattern: " + classPattern + ": "); for (FilePath file : matchedClassDirs) { dir.saveClassesFrom(file); - logger.print(" " + file); + logger.print(" " + file); } - matchedSrcDirs = resolveDirPaths(build, listener, sourcePattern); + matchedSrcDirs = resolveDirPaths(filePath, taskListener, sourcePattern); logger.print("\n[JaCoCo plugin] Saving matched source directories for source-pattern: " + sourcePattern + ": "); for (FilePath file : matchedSrcDirs) { dir.saveSourcesFrom(file); - logger.print(" " + file); + logger.print(" " + file); } - + logger.println("\n[JaCoCo plugin] Loading inclusions files.."); String[] includes = {}; if (inclusionPattern != null) { - includes = inclusionPattern.split(DIR_SEP); - logger.println("[JaCoCo plugin] inclusions: " + Arrays.toString(includes)); + includes = inclusionPattern.split(DIR_SEP); + logger.println("[JaCoCo plugin] inclusions: " + Arrays.toString(includes)); } String[] excludes = {}; if (exclusionPattern != null) { - excludes = exclusionPattern.split(DIR_SEP); - logger.println("[JaCoCo plugin] exclusions: " + Arrays.toString(excludes)); + excludes = exclusionPattern.split(DIR_SEP); + logger.println("[JaCoCo plugin] exclusions: " + Arrays.toString(excludes)); } - - final JacocoBuildAction action = JacocoBuildAction.load(build, rule, healthReports, listener, dir, includes, excludes); + + final JacocoBuildAction action = JacocoBuildAction.load(run, healthReports, taskListener, dir, includes, excludes); action.getThresholds().ensureValid(); logger.println("[JaCoCo plugin] Thresholds: " + action.getThresholds()); - build.getActions().add(action); - + run.getActions().add(action); + logger.println("[JaCoCo plugin] Publishing the results.."); final CoverageReport result = action.getResult(); - + if (result == null) { logger.println("[JaCoCo plugin] Could not parse coverage results. Setting Build to failure."); - build.setResult(Result.FAILURE); + run.setResult(Result.FAILURE); } else { logger.println("[JaCoCo plugin] Overall coverage: class: " + result.getClassCoverage().getPercentage() + ", method: " + result.getMethodCoverage().getPercentage() + ", line: " + result.getLineCoverage().getPercentage() + ", branch: " + result.getBranchCoverage().getPercentage() + ", instruction: " + result.getInstructionCoverage().getPercentage()); - result.setThresholds(healthReports); - if (changeBuildStatus) { - build.setResult(checkResult(action)); - } + result.setThresholds(healthReports); + if (changeBuildStatus) { + run.setResult(checkResult(action)); + } + } + return; + } + + private JacocoHealthReportThresholds createJacocoHealthReportThresholds() { + try { + return healthReports = new JacocoHealthReportThresholds(Integer.parseInt(minimumClassCoverage), Integer.parseInt(maximumClassCoverage), Integer.parseInt(minimumMethodCoverage), Integer.parseInt(maximumMethodCoverage), Integer.parseInt(minimumLineCoverage), Integer.parseInt(maximumLineCoverage) + , Integer.parseInt(minimumBranchCoverage), Integer.parseInt(maximumBranchCoverage), Integer.parseInt(minimumInstructionCoverage), Integer.parseInt(maximumInstructionCoverage), Integer.parseInt(minimumComplexityCoverage), Integer.parseInt(maximumComplexityCoverage)); + } catch (NumberFormatException nfe) { + return healthReports = new JacocoHealthReportThresholds(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } - return true; } - public Result checkResult(JacocoBuildAction action) { + + public static Result checkResult(JacocoBuildAction action) { if ((action.getBranchCoverage().getPercentageFloat() < action.getThresholds().getMinBranch()) || (action.getInstructionCoverage().getPercentageFloat() < action.getThresholds().getMinInstruction()) || (action.getClassCoverage().getPercentageFloat() < action.getThresholds().getMinClass()) || (action.getLineCoverage().getPercentageFloat() < action.getThresholds().getMinLine()) || (action.getComplexityScore().getPercentageFloat() < action.getThresholds().getMinComplexity()) || (action.getMethodCoverage().getPercentageFloat() < action.getThresholds().getMinMethod())) { return Result.FAILURE; } @@ -472,6 +594,35 @@ public Publisher newInstance(StaplerRequest req, JSONObject json) throws FormExc }*/ } - + + private static class ResolveDirPaths extends MasterToSlaveFileCallable { + static final long serialVersionUID = 1552178457453558870L; + private final String input; + + public ResolveDirPaths(String input) { + this.input = input; + } + + public FilePath[] invoke(File f, VirtualChannel channel) throws IOException { + FilePath base = new FilePath(f); + ArrayList localDirectoryPaths= new ArrayList(); + String[] includes = input.split(DIR_SEP); + DirectoryScanner ds = new DirectoryScanner(); + + ds.setIncludes(includes); + ds.setCaseSensitive(false); + ds.setBasedir(f); + ds.scan(); + String[] dirs = ds.getIncludedDirectories(); + + for (String dir : dirs) { + localDirectoryPaths.add(base.child(dir)); + } + FilePath[] lfp = {};//trick to have an empty array as a parameter, so the returned array will contain the elements + return localDirectoryPaths.toArray(lfp); + } + + } + //private static final Logger logger = Logger.getLogger(JacocoPublisher.class.getName()); } diff --git a/src/main/java/hudson/plugins/jacoco/JacocoReportDir.java b/src/main/java/hudson/plugins/jacoco/JacocoReportDir.java index ef088fe8..820419fa 100644 --- a/src/main/java/hudson/plugins/jacoco/JacocoReportDir.java +++ b/src/main/java/hudson/plugins/jacoco/JacocoReportDir.java @@ -16,8 +16,8 @@ public class JacocoReportDir { private final File root; - public JacocoReportDir(AbstractBuild build) { - root = new File(build.getRootDir(), "jacoco"); + public JacocoReportDir(File rootDir) { + root = new File(rootDir, "jacoco"); } /** diff --git a/src/main/java/hudson/plugins/jacoco/model/CoverageObject.java b/src/main/java/hudson/plugins/jacoco/model/CoverageObject.java index 639c73fd..6fc47cd4 100644 --- a/src/main/java/hudson/plugins/jacoco/model/CoverageObject.java +++ b/src/main/java/hudson/plugins/jacoco/model/CoverageObject.java @@ -3,6 +3,7 @@ import hudson.Util; import hudson.model.AbstractBuild; import hudson.model.Api; +import hudson.model.Run; import hudson.plugins.jacoco.Messages; import hudson.plugins.jacoco.Rule; import hudson.plugins.jacoco.report.AggregatedReport; @@ -203,7 +204,7 @@ public Coverage getLineCoverage() { /** * Gets the build object that owns the whole coverage report tree. */ - public abstract AbstractBuild getBuild(); + public abstract Run getBuild(); /** * Gets the corresponding coverage report object in the previous @@ -362,7 +363,7 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException return; } - AbstractBuild build = getBuild(); + Run build = getBuild(); Calendar t = build.getTimestamp(); String w = Util.fixEmptyAndTrim(req.getParameter("width")); diff --git a/src/main/java/hudson/plugins/jacoco/report/AbstractReport.java b/src/main/java/hudson/plugins/jacoco/report/AbstractReport.java index 1a3ed6b3..dca2c0f9 100644 --- a/src/main/java/hudson/plugins/jacoco/report/AbstractReport.java +++ b/src/main/java/hudson/plugins/jacoco/report/AbstractReport.java @@ -2,6 +2,7 @@ import hudson.model.AbstractBuild; import hudson.model.ModelObject; +import hudson.model.Run; import hudson.plugins.jacoco.model.CoverageElement; import hudson.plugins.jacoco.model.CoverageObject; @@ -66,7 +67,7 @@ public SELF getPreviousResult() { } @Override - public AbstractBuild getBuild() { + public Run getBuild() { return parent.getBuild(); } diff --git a/src/main/java/hudson/plugins/jacoco/report/CoverageReport.java b/src/main/java/hudson/plugins/jacoco/report/CoverageReport.java index 725f17e9..7a606013 100644 --- a/src/main/java/hudson/plugins/jacoco/report/CoverageReport.java +++ b/src/main/java/hudson/plugins/jacoco/report/CoverageReport.java @@ -11,6 +11,7 @@ import javax.servlet.ServletException; +import hudson.model.Run; import org.jacoco.core.analysis.IClassCoverage; import org.jacoco.core.analysis.IMethodCoverage; import org.jacoco.core.analysis.IPackageCoverage; @@ -218,7 +219,7 @@ public CoverageReport getPreviousResult() { } @Override - public AbstractBuild getBuild() { + public Run getBuild() { return action.owner; } diff --git a/src/test/java/hudson/plugins/jacoco/report/AbstractReportTest.java b/src/test/java/hudson/plugins/jacoco/report/AbstractReportTest.java index 7799b029..5c825489 100644 --- a/src/test/java/hudson/plugins/jacoco/report/AbstractReportTest.java +++ b/src/test/java/hudson/plugins/jacoco/report/AbstractReportTest.java @@ -5,6 +5,7 @@ import hudson.model.BuildListener; import hudson.model.Result; import hudson.model.Cause; +import hudson.model.TaskListener; import hudson.plugins.jacoco.JacocoBuildAction; import java.io.IOException; @@ -12,6 +13,7 @@ import java.io.PrintWriter; import java.util.List; +import hudson.util.StreamTaskListener; import org.junit.Test; @@ -26,41 +28,11 @@ public void test() throws Exception { report.setParent(new ClassReport()); report.getParent().setParent(new PackageReport()); - - JacocoBuildAction action = new JacocoBuildAction(null, null, null, null, new BuildListener() { - - public void hyperlink(String url, String text) throws IOException { - } - - public PrintStream getLogger() { - return null; - } - - public PrintWriter fatalError(String format, Object... args) { - return null; - } - - public PrintWriter fatalError(String msg) { - return null; - } - - public PrintWriter error(String format, Object... args) { - return null; - } - - public PrintWriter error(String msg) { - return null; - } - - public void annotate(@SuppressWarnings("rawtypes") ConsoleNote ann) throws IOException { - } - - public void started(List causes) { - } - - public void finished(Result result) { - } - }, null, null); + + + TaskListener taskListener = StreamTaskListener.fromStdout(); + + JacocoBuildAction action = new JacocoBuildAction(null, null, taskListener, null, null); report.getParent().getParent().setParent(new CoverageReport(action, null)); assertNull(report.getBuild()); diff --git a/src/test/java/hudson/plugins/jacoco/report/CoverageReportTest.java b/src/test/java/hudson/plugins/jacoco/report/CoverageReportTest.java index 76935c1d..4f12d999 100644 --- a/src/test/java/hudson/plugins/jacoco/report/CoverageReportTest.java +++ b/src/test/java/hudson/plugins/jacoco/report/CoverageReportTest.java @@ -5,6 +5,7 @@ import hudson.model.BuildListener; import hudson.model.Result; import hudson.model.Cause; +import hudson.model.TaskListener; import hudson.plugins.jacoco.ExecutionFileLoader; import hudson.plugins.jacoco.JacocoBuildAction; import hudson.plugins.jacoco.JacocoHealthReportThresholds; @@ -14,6 +15,7 @@ import java.io.PrintWriter; import java.util.List; +import hudson.util.StreamTaskListener; import org.junit.Test; @@ -44,38 +46,5 @@ public void testThresholds() throws Exception { report.setThresholds(new JacocoHealthReportThresholds()); } - private JacocoBuildAction action = new JacocoBuildAction(null, null, null, null, new BuildListener() { - - public void hyperlink(String url, String text) throws IOException { - } - - public PrintStream getLogger() { - return System.out; - } - - public PrintWriter fatalError(String format, Object... args) { - return null; - } - - public PrintWriter fatalError(String msg) { - return null; - } - - public PrintWriter error(String format, Object... args) { - return null; - } - - public PrintWriter error(String msg) { - return null; - } - - public void annotate(@SuppressWarnings("rawtypes") ConsoleNote ann) throws IOException { - } - - public void started(List causes) { - } - - public void finished(Result result) { - } - }, null, null); + private JacocoBuildAction action = new JacocoBuildAction(null, null, StreamTaskListener.fromStdout(), null, null); } diff --git a/src/test/java/hudson/plugins/jacococoveragecolumn/JaCoCoColumnTest.java b/src/test/java/hudson/plugins/jacococoveragecolumn/JaCoCoColumnTest.java index c377f80c..4c6731dc 100644 --- a/src/test/java/hudson/plugins/jacococoveragecolumn/JaCoCoColumnTest.java +++ b/src/test/java/hudson/plugins/jacococoveragecolumn/JaCoCoColumnTest.java @@ -9,6 +9,7 @@ import hudson.model.Descriptor.FormException; import hudson.model.Job; import hudson.model.Run; +import hudson.model.TaskListener; import hudson.plugins.jacoco.JacocoBuildAction; import hudson.plugins.jacoco.model.Coverage; import hudson.plugins.jacoco.model.CoverageElement; @@ -26,6 +27,7 @@ import javax.servlet.ServletContext; +import hudson.util.StreamTaskListener; import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; @@ -85,42 +87,7 @@ public void testGetPercentWithBuildAndAction() { public Run getLastSuccessfulBuild() { try { Run newBuild = newBuild(); - newBuild.getActions().add(new JacocoBuildAction(null, null, null, null, new BuildListener() { - private static final long serialVersionUID = 1L; - - public void hyperlink(String url, String text) throws IOException { - } - - public PrintStream getLogger() { - return null; - } - - public PrintWriter fatalError(String format, Object... args) { - return null; - } - - public PrintWriter fatalError(String msg) { - return null; - } - - public PrintWriter error(String format, Object... args) { - return null; - } - - public PrintWriter error(String msg) { - return null; - } - - public void annotate(@SuppressWarnings("rawtypes") ConsoleNote ann) throws IOException { - - } - - public void started(List causes) { - } - - public void finished(Result result) { - } - }, null, null)); + newBuild.getActions().add(new JacocoBuildAction(null, null, StreamTaskListener.fromStdout(), null, null)); assertEquals(1, newBuild.getActions().size()); return newBuild; } catch (IOException e) { @@ -230,7 +197,7 @@ public Run getLastSuccessfulBuild() { try { Run run = newBuild(); Map map = Collections.emptyMap(); - run.addAction(new JacocoBuildAction(null, null, map, null, listener, null, null)); + run.addAction(new JacocoBuildAction(map, null, listener, null, null)); return run; } catch (IOException e) { throw new IllegalStateException(e);