Skip to content

Commit

Permalink
adding logs to investigate travis issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Jun 9, 2020
1 parent 66ee377 commit 0aaa91e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ private Map<String, String> mergeProperties(final LicenseSet licenseSet, final D

private String[] listSelectedFiles(final LicenseSet licenseSet) {
final boolean useDefaultExcludes = (licenseSet.useDefaultExcludes != null ? licenseSet.useDefaultExcludes : defaultUseDefaultExcludes);
final Selection selection = new Selection(firstNonNull(licenseSet.basedir, defaultBasedir), licenseSet.includes, buildExcludes(licenseSet), useDefaultExcludes);
final Selection selection = new Selection(
firstNonNull(licenseSet.basedir, defaultBasedir), licenseSet.includes, buildExcludes(licenseSet), useDefaultExcludes,
getLog());
debug("From: %s", firstNonNull(licenseSet.basedir, defaultBasedir));
debug("Including: %s", deepToString(selection.getIncluded()));
debug("Excluding: %s", deepToString(selection.getExcluded()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.mycila.maven.plugin.license.util;

import com.mycila.maven.plugin.license.Default;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.shared.utils.io.DirectoryScanner;
import org.apache.maven.shared.utils.io.MatchPatterns;
import org.apache.maven.shared.utils.io.ScanConductor;
Expand All @@ -35,11 +36,14 @@ public final class Selection {
private final File basedir;
private final String[] included;
private final String[] excluded;
private final Log log;

private DirectoryScanner scanner;

public Selection(File basedir, String[] included, String[] excluded, boolean useDefaultExcludes) {
public Selection(File basedir, String[] included, String[] excluded, boolean useDefaultExcludes,
final Log log) {
this.basedir = basedir;
this.log = log;
String[] overrides = buildOverrideInclusions(useDefaultExcludes, included);
this.included = buildInclusions(included, overrides);
this.excluded = buildExclusions(useDefaultExcludes, excluded, overrides);
Expand Down Expand Up @@ -69,14 +73,24 @@ public String[] getExcluded() {

private void scanIfneeded() {
if (scanner == null) {
final boolean debugEnabled = log.isDebugEnabled();
if (debugEnabled) {
log.debug("Starting to visit '" + basedir + "'");
}
final MatchPatterns excludePatterns = MatchPatterns.from(excluded);
scanner = new DirectoryScanner();
scanner.setScanConductor(new ScanConductor() {
@Override
public ScanAction visitDirectory(final String name, final File directory) {
if (excludePatterns.matches(name, true)) {
if (debugEnabled) {
log.debug("Skipping '" + name + "' since it is excluded");
}
return ScanAction.ABORT_DIRECTORY;
}
if (debugEnabled) {
log.debug("Visiting '" + name + "' since it is not excluded");
}
return ScanAction.CONTINUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.mycila.maven.plugin.license.util;

import com.mycila.maven.plugin.license.Default;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.logging.SystemStreamLog;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand All @@ -39,25 +41,27 @@ public final class SelectionTest {
@Rule
public final TemporaryFolder temp = new TemporaryFolder();

private final Log log = new SystemStreamLog();

@Test
public void test_default_select_all() {
Selection selection = new Selection(new File("."), new String[0], new String[0], false);
Selection selection = new Selection(new File("."), new String[0], new String[0], false, log);
assertEquals(selection.getExcluded().length, 0);
assertEquals(selection.getIncluded().length, 1);
assertTrue(selection.getSelectedFiles().length > 0);
}

@Test
public void test_limit_inclusion() {
Selection selection = new Selection(new File("."), new String[]{"toto"}, new String[]{"tata"}, false);
Selection selection = new Selection(new File("."), new String[]{"toto"}, new String[]{"tata"}, false, log);
assertEquals(selection.getExcluded().length, 1);
assertEquals(selection.getIncluded().length, 1);
assertEquals(selection.getSelectedFiles().length, 0);
}

@Test
public void test_limit_inclusion_and_check_default_excludes() {
Selection selection = new Selection(new File("."), new String[]{"toto"}, new String[0], true);
Selection selection = new Selection(new File("."), new String[]{"toto"}, new String[0], true, log);
assertEquals(selection.getExcluded().length, Default.EXCLUDES.length); // default exludes from Scanner and Selection + toto
assertEquals(selection.getIncluded().length, 1);
assertEquals(selection.getSelectedFiles().length, 0);
Expand All @@ -69,8 +73,16 @@ public void test_exclusions_respect_with_fastScan() throws IOException {
createAFakeProject();

Selection selection = new Selection(temp.getRoot(),
new String[]{"**" + File.separator + "*.txt"},
new String[] {"**" + File.separator + "target" + File.separator + "**"}, false);
new String[] { "**" + File.separator + "*.txt" },
new String[] {"target" + File.separator + "**", "module/**/target" + File.separator + "**"}, false,
new SystemStreamLog()
{
@Override
public boolean isDebugEnabled()
{
return true;
}
});

assertIncludedFilesInFakeProject(selection);
assertEquals(0, selection.getFilesExcluded().length);
Expand Down

0 comments on commit 0aaa91e

Please sign in to comment.