Skip to content

Commit e359daf

Browse files
committed
#37 allow to disable SimpleCov parser
1 parent e1da7c1 commit e359daf

8 files changed

Lines changed: 34 additions & 8 deletions

File tree

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/CompareCoverageAction.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public void perform(
8888

8989
buildLog.println(BUILD_LOG_PREFIX + "start");
9090

91+
final SettingsRepository settingsRepository = ServiceRegistry.getSettingsRepository();
92+
9193
final int prId = PrIdAndUrlUtils.getPrId(scmVars, build, listener);
9294
final String gitUrl = PrIdAndUrlUtils.getGitUrl(scmVars, build, listener);
9395

@@ -98,18 +100,17 @@ public void perform(
98100
buildLog.println(BUILD_LOG_PREFIX + "master coverage: " + masterCoverage);
99101

100102
buildLog.println(BUILD_LOG_PREFIX + "collecting coverage...");
101-
final float coverage = ServiceRegistry.getCoverageRepository().get(workspace);
103+
final float coverage = ServiceRegistry.getCoverageRepository(settingsRepository.isDisableSimpleCov()).get(workspace);
102104
buildLog.println(BUILD_LOG_PREFIX + "build coverage: " + coverage);
103105

104106
final Message message = new Message(coverage, masterCoverage);
105107
buildLog.println(BUILD_LOG_PREFIX + message.forConsole());
106108

107109
final String buildUrl = Utils.getBuildUrl(build, listener);
108110

109-
String jenkinsUrl = ServiceRegistry.getSettingsRepository().getJenkinsUrl();
111+
String jenkinsUrl = settingsRepository.getJenkinsUrl();
110112
if (jenkinsUrl == null) jenkinsUrl = Utils.getJenkinsUrlFromBuildUrl(buildUrl);
111113

112-
final SettingsRepository settingsRepository = ServiceRegistry.getSettingsRepository();
113114

114115
try {
115116
final String comment = message.forComment(

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/Configuration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static final class ConfigurationDescriptor extends Descriptor<Configurati
9494

9595
private final Map<String, Float> coverageByRepo = new ConcurrentHashMap<String, Float>();
9696

97+
private boolean disableSimpleCov;
9798
private String gitHubApiUrl;
9899
private String personalAccessToken;
99100
private String jenkinsUrl;
@@ -156,6 +157,11 @@ public boolean isUseSonarForMasterCoverage() {
156157
return useSonarForMasterCoverage;
157158
}
158159

160+
@Override
161+
public boolean isDisableSimpleCov() {
162+
return disableSimpleCov;
163+
}
164+
159165
@Override
160166
public String getSonarUrl() {
161167
return sonarUrl;
@@ -188,6 +194,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
188194
jenkinsUrl = StringUtils.trimToNull(formData.getString("jenkinsUrl"));
189195
privateJenkinsPublicGitHub = BooleanUtils.toBoolean(formData.getString("privateJenkinsPublicGitHub"));
190196
useSonarForMasterCoverage = BooleanUtils.toBoolean(formData.getString("useSonarForMasterCoverage"));
197+
disableSimpleCov = BooleanUtils.toBoolean(formData.getString("disableSimpleCov"));
191198
sonarUrl = StringUtils.trimToNull(formData.getString("sonarUrl"));
192199
sonarToken = StringUtils.trimToNull(formData.getString("sonarToken"));
193200
sonarLogin = StringUtils.trimToNull(formData.getString("sonarLogin"));

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/GetCoverageCallable.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
@SuppressWarnings("WeakerAccess")
3333
final class GetCoverageCallable extends MasterToSlaveFileCallable<Float> implements CoverageRepository {
3434

35+
private final boolean disableSimpleCov;
36+
37+
GetCoverageCallable(final boolean disableSimpleCov) {
38+
this.disableSimpleCov = disableSimpleCov;
39+
}
40+
3541
private static List<Float> getFloats(File ws, String path, CoverageReportParser parser) {
3642
FileSet fs = Util.createFileSet(ws, path);
3743
DirectoryScanner ds = fs.getDirectoryScanner();
@@ -44,7 +50,7 @@ private static List<Float> getFloats(File ws, String path, CoverageReportParser
4450
@Override
4551
public float get(final FilePath workspace) throws IOException, InterruptedException {
4652
if (workspace == null) throw new IllegalArgumentException("Workspace should not be null!");
47-
return workspace.act(new GetCoverageCallable());
53+
return workspace.act(new GetCoverageCallable(disableSimpleCov));
4854
}
4955

5056
@Override
@@ -55,7 +61,7 @@ public Float invoke(final File ws, final VirtualChannel channel) throws IOExcept
5561
cov.addAll(getFloats(ws, "**/jacoco.xml", new JacocoParser()));
5662
cov.addAll(getFloats(ws, "**/jacocoTestReport.xml", new JacocoParser())); //default for gradle
5763
cov.addAll(getFloats(ws, "**/clover.xml", new CloverParser()));
58-
cov.addAll(getFloats(ws, "**/coverage.json", new SimpleCovParser()));
64+
if (!disableSimpleCov) cov.addAll(getFloats(ws, "**/coverage.json", new SimpleCovParser()));
5965

6066
float s = 0;
6167
for (float v : cov) s += v;

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/MasterCoverageAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public void perform(final Run build, final FilePath workspace, final Launcher la
7070
final PrintStream buildLog = listener.getLogger();
7171
final String gitUrl = PrIdAndUrlUtils.getGitUrl(scmVars, build, listener);
7272

73-
final float masterCoverage = ServiceRegistry.getCoverageRepository().get(workspace);
73+
final boolean disableSimpleCov = ServiceRegistry.getSettingsRepository().isDisableSimpleCov();
74+
final float masterCoverage = ServiceRegistry.getCoverageRepository(disableSimpleCov).get(workspace);
7475
buildLog.println("Master coverage " + Percent.toWholeString(masterCoverage));
7576
Configuration.setMasterCoverage(gitUrl, masterCoverage);
7677
}

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/ServiceRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public static void setMasterCoverageRepository(MasterCoverageRepository masterCo
5151
ServiceRegistry.masterCoverageRepository = masterCoverageRepository;
5252
}
5353

54-
public static CoverageRepository getCoverageRepository() {
55-
return coverageRepository != null ? coverageRepository : new GetCoverageCallable();
54+
public static CoverageRepository getCoverageRepository(final boolean disableSimpleCov) {
55+
return coverageRepository != null ? coverageRepository : new GetCoverageCallable(disableSimpleCov);
5656
}
5757

5858
public static void setCoverageRepository(CoverageRepository coverageRepository) {

src/main/java/com/github/terma/jenkins/githubprcoveragestatus/SettingsRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface SettingsRepository {
1616

1717
boolean isUseSonarForMasterCoverage();
1818

19+
boolean isDisableSimpleCov();
20+
1921
String getSonarUrl();
2022

2123
String getSonarToken();

src/main/resources/com/github/terma/jenkins/githubprcoveragestatus/Configuration/global.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ f.section(title: descriptor.displayName) {
4848
f.password()
4949
}
5050

51+
f.entry(field: "disableSimpleCov", title: _("Disable SimpleCov coverage parser")) {
52+
f.checkbox()
53+
}
54+
5155
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
SimpleCov coverage generate has pretty wide search criteria for coverage file <code>**/coverage.json</code>
3+
Often it can fails because some of files from JS/Node JS projects have similar name but definitely not a
4+
SimpleCov format so parser will fail entire build.
5+
</div>

0 commit comments

Comments
 (0)