Skip to content

Commit

Permalink
Merge pull request #72 from lordofthejars/pr63_manualmerge
Browse files Browse the repository at this point in the history
fixes code review issues
  • Loading branch information
centic9 committed Apr 15, 2016
2 parents 08bdee6 + 249bd6d commit adc858d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 103 deletions.
30 changes: 25 additions & 5 deletions src/main/java/hudson/plugins/jacoco/JacocoPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,34 @@ protected static void saveCoverageReports(FilePath destFolder, FilePath sourceFo
sourceFolder.copyRecursiveTo(destFolder);
}

protected String resolveFilePaths(Run<?, ?> build, TaskListener listener, String input) {
protected String resolveFilePaths(Run<?, ?> build, TaskListener listener, String input, Map<String, String> 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 \""+
input+"\" due to following error:\n"+e.getMessage());
}
return 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;
Expand Down Expand Up @@ -431,7 +447,11 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull

JacocoReportDir dir = new JacocoReportDir(run.getRootDir());

List<FilePath> matchedExecFiles = Arrays.asList(filePath.list(resolveFilePaths(run, taskListener, execPattern)));
if (run instanceof AbstractBuild) {
execPattern = resolveFilePaths((AbstractBuild) run, taskListener, execPattern);
}

List<FilePath> 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);
Expand Down
30 changes: 2 additions & 28 deletions src/test/java/hudson/plugins/jacoco/report/AbstractReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.PrintWriter;
import java.util.List;

import hudson.util.StreamTaskListener;
import org.junit.Test;


Expand All @@ -28,35 +29,8 @@ public void test() throws Exception {
report.setParent(new ClassReport());
report.getParent().setParent(new PackageReport());

TaskListener taskListener = new TaskListener() {
public PrintStream getLogger() {
return null;
}

public void annotate(ConsoleNote consoleNote) throws IOException {

}

public void hyperlink(String s, String s1) throws IOException {

}

public PrintWriter error(String s) {
return null;
}

public PrintWriter error(String s, Object... objects) {
return null;
}

public PrintWriter fatalError(String s) {
return null;
}

public PrintWriter fatalError(String s, Object... objects) {
return null;
}
};
TaskListener taskListener = StreamTaskListener.fromStdout();

JacocoBuildAction action = new JacocoBuildAction(null, null, taskListener, null, null);
report.getParent().getParent().setParent(new CoverageReport(action, null));
Expand Down
36 changes: 2 additions & 34 deletions src/test/java/hudson/plugins/jacoco/report/CoverageReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.PrintWriter;
import java.util.List;

import hudson.util.StreamTaskListener;
import org.junit.Test;


Expand Down Expand Up @@ -45,38 +46,5 @@ public void testThresholds() throws Exception {
report.setThresholds(new JacocoHealthReportThresholds());
}

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

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<Cause> causes) {
}

public void finished(Result result) {
}
}, null, null);
private JacocoBuildAction action = new JacocoBuildAction(null, null, StreamTaskListener.fromStdout(), null, null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.servlet.ServletContext;

import hudson.util.StreamTaskListener;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -86,42 +87,7 @@ public void testGetPercentWithBuildAndAction() {
public Run<?,?> getLastSuccessfulBuild() {
try {
Run<?,?> newBuild = newBuild();
newBuild.getActions().add(new JacocoBuildAction(null, null, new TaskListener() {
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<Cause> 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) {
Expand Down

0 comments on commit adc858d

Please sign in to comment.