Skip to content
Permalink
Browse files

JENKINS-32847: add warning for sub directory filter

  • Loading branch information...
mheinzerling committed Mar 14, 2017
1 parent d771e0b commit d061b94be2718747e60d32b1f55722c209bac221
@@ -459,6 +459,11 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
logger.print(" " + Util.join(matchedExecFiles," "));
FilePath[] matchedClassDirs = resolveDirPaths(filePath, taskListener, classPattern);
logger.print("\n[JaCoCo plugin] Saving matched class directories for class-pattern: " + classPattern + ": ");
final String warning = "\n[JaCoCo plugin] WARNING: You are using directory patterns with trailing /, /* or /** . This will most likely" +
" multiply the copied files in your build directory. Check the list below and ignore this warning if you know what you are doing.";
if (hasSubDirectories(classPattern)) {
logger.print(warning);
}
for (FilePath dir : matchedClassDirs) {
int copied = reportDir.saveClassesFrom(dir, "**/*.class");
logger.print("\n[JaCoCo plugin] - " + dir + " " + copied + " files");
@@ -468,6 +473,7 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
if(!this.skipCopyOfSrcFiles) {
FilePath[] matchedSrcDirs = resolveDirPaths(filePath, taskListener, sourcePattern);
logger.print("\n[JaCoCo plugin] Saving matched source directories for source-pattern: " + sourcePattern + ": ");
if (hasSubDirectories(sourcePattern)) logger.print(warning);
for (FilePath dir : matchedSrcDirs) {
int copied = reportDir.saveSourcesFrom(dir, "**/*.java");
logger.print("\n[JaCoCo plugin] - " + dir + " " + copied + " files");
@@ -515,6 +521,18 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath filePath, @Nonnull
}
}

private boolean hasSubDirectories(String pattern) {
for (String dir : pattern.split(DIR_SEP)) {
if (dir.endsWith("\\") || dir.endsWith("/") ||
dir.endsWith("\\*") || dir.endsWith("/*") ||
dir.endsWith("\\**") || dir.endsWith("/**")
) {
return true;
}
}
return false;
}

private JacocoHealthReportThresholds createJacocoHealthReportThresholds(EnvVars env) {
try {
return healthReports = new JacocoHealthReportThresholds(
@@ -414,4 +414,29 @@ public void testCopyClassAndSource() throws IOException, InterruptedException {
assertFalse(new File(run.getRootDir(), "jacoco/sources/test.png").exists());
verify(taskListener, run);
}

@Test
public void testCopyClass_Wrong() throws IOException, InterruptedException {

final Run run = new RunBuilder().taskListener(taskListener).build();
FilePath workspace = new WorkspaceBuilder().name("workspace", ".tst")
.file("classes/Test.class")
.file("classes/Test.jar")
.file("classes/sub/Test2.class")
.build();

JacocoPublisher publisher = new JacocoPublisher();
publisher.setClassPattern("**/classes/");
publisher.perform(run, workspace, launcher, taskListener);

assertTrue(new File(run.getRootDir(), "jacoco/classes/Test.class").exists());
assertFalse(new File(run.getRootDir(), "jacoco/classes/Test.jar").exists());
assertTrue(new File(run.getRootDir(), "jacoco/classes/sub/Test2.class").exists());
assertTrue(new File(run.getRootDir(), "jacoco/classes/Test2.class").exists()); // will be copied accidentally

assertTrue(logContent.toString().contains("WARNING: You are using directory patterns with trailing /, /* or /**"));
assertTrue(logContent.toString().contains("tst\\classes 2 files"));
assertTrue(logContent.toString().contains("tst\\classes\\sub 1 files"));
verify(taskListener, run);
}
}

0 comments on commit d061b94

Please sign in to comment.
You can’t perform that action at this time.