Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from lordofthejars/pr63_manualmerge
Browse files Browse the repository at this point in the history
removes unused code
  • Loading branch information
centic9 committed Feb 5, 2016
2 parents a41a986 + 4e4fb1b commit 28a7f26
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 68 deletions.
6 changes: 2 additions & 4 deletions src/main/java/hudson/plugins/jacoco/JacocoBuildAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ public final class JacocoBuildAction extends CoverageObject<JacocoBuildAction> i

/**
*
* @param owner
* @param ratios
* The available coverage ratios in the report. Null is treated
* the same as an empty map.
* @param thresholds
*/
public JacocoBuildAction(Run<?,?> owner,
public JacocoBuildAction(
Map<CoverageElement.Type, Coverage> ratios,
JacocoHealthReportThresholds thresholds, TaskListener listener, String[] inclusions, String[] exclusions) {
logger = listener.getLogger();
Expand All @@ -71,7 +70,6 @@ public JacocoBuildAction(Run<?,?> owner,
}
this.inclusions = inclusions;
this.exclusions = exclusions;
this.owner = owner;
this.clazz = getOrCreateRatio(ratios, CoverageElement.Type.CLASS);
this.method = getOrCreateRatio(ratios, CoverageElement.Type.METHOD);
this.line = getOrCreateRatio(ratios, CoverageElement.Type.LINE);
Expand Down Expand Up @@ -298,7 +296,7 @@ public static JacocoBuildAction load(Run<?,?> owner, JacocoHealthReportThreshold
Map<CoverageElement.Type,Coverage> ratios = null;

ratios = loadRatios(layout, ratios, includes, excludes);
return new JacocoBuildAction(owner, ratios, thresholds, listener, includes, excludes);
return new JacocoBuildAction(ratios, thresholds, listener, includes, excludes);
}


Expand Down
104 changes: 44 additions & 60 deletions src/main/java/hudson/plugins/jacoco/JacocoPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -392,109 +393,96 @@ protected static FilePath[] resolveDirPaths(FilePath workspace, TaskListener lis
}
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 {
return publishReports(build, build.getBuildVariables(), build.getRootDir(), build.getWorkspace(), launcher, listener);
}


@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull Launcher launcher, @Nonnull TaskListener taskListener) throws InterruptedException, IOException {
publishReports(run, new HashMap<String, String>(), run.getRootDir(), filePath, launcher, taskListener);
}

private boolean publishReports(Run<?, ?> build, Map<String, String> envs, File rootDir, FilePath workspace, Launcher launcher, TaskListener listener) throws IOException, InterruptedException {
Map<String, String> envs = new HashMap<String, String>();

healthReports = createJacocoHealthReportThresholds();

final PrintStream logger = listener.getLogger();
FilePath[] matchedClassDirs = null;
FilePath[] matchedSrcDirs = null;
final PrintStream logger = taskListener.getLogger();
FilePath[] matchedClassDirs = null;
FilePath[] matchedSrcDirs = null;

if (build.getResult() == Result.FAILURE || build.getResult() == Result.ABORTED) {
return true;
}
logger.println("[JaCoCo plugin] Collecting JaCoCo coverage data...");
EnvVars env = build.getEnvironment(listener);
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 ((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(rootDir);
JacocoReportDir dir = new JacocoReportDir(run.getRootDir());

List<FilePath> matchedExecFiles = Arrays.asList(workspace.list(resolveFilePaths(build, listener, execPattern)));
List<FilePath> matchedExecFiles = Arrays.asList(filePath.list(resolveFilePaths(run, taskListener, execPattern)));
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(workspace, 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(workspace, 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, 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 true;
return;
}

private JacocoHealthReportThresholds createJacocoHealthReportThresholds() {
Expand Down Expand Up @@ -586,7 +574,7 @@ public Publisher newInstance(StaplerRequest req, JSONObject json) throws FormExc

}

private static class ResolveDirPaths implements FilePath.FileCallable<FilePath[]> {
private static class ResolveDirPaths extends MasterToSlaveFileCallable<FilePath[]> {
static final long serialVersionUID = 1552178457453558870L;
private final String input;

Expand All @@ -612,10 +600,6 @@ public FilePath[] invoke(File f, VirtualChannel channel) throws IOException {
FilePath[] lfp = {};//trick to have an empty array as a parameter, so the returned array will contain the elements
return localDirectoryPaths.toArray(lfp);
}

public void checkRoles(RoleChecker checker) throws SecurityException {

}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public PrintWriter fatalError(String s, Object... objects) {
}
};

JacocoBuildAction action = new JacocoBuildAction(null, null, null, taskListener, null, null);
JacocoBuildAction action = new JacocoBuildAction(null, null, taskListener, null, null);
report.getParent().getParent().setParent(new CoverageReport(action, null));
assertNull(report.getBuild());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testThresholds() throws Exception {
report.setThresholds(new JacocoHealthReportThresholds());
}

private JacocoBuildAction action = new JacocoBuildAction(null, null, null, new TaskListener() {
private JacocoBuildAction action = new JacocoBuildAction(null, null, new TaskListener() {

public void hyperlink(String url, String text) throws IOException {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testGetPercentWithBuildAndAction() {
public Run<?,?> getLastSuccessfulBuild() {
try {
Run<?,?> newBuild = newBuild();
newBuild.getActions().add(new JacocoBuildAction(null, null, null, new TaskListener() {
newBuild.getActions().add(new JacocoBuildAction(null, null, new TaskListener() {
private static final long serialVersionUID = 1L;

public void hyperlink(String url, String text) throws IOException {
Expand Down Expand Up @@ -231,7 +231,7 @@ public Run<?,?> getLastSuccessfulBuild() {
try {
Run<?,?> run = newBuild();
Map<Type, Coverage> map = Collections.<CoverageElement.Type, Coverage>emptyMap();
run.addAction(new JacocoBuildAction(null, map, null, listener, null, null));
run.addAction(new JacocoBuildAction(map, null, listener, null, null));
return run;
} catch (IOException e) {
throw new IllegalStateException(e);
Expand Down

0 comments on commit 28a7f26

Please sign in to comment.