-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure exclusions win over inclusions for scanning
using maven shared utils and adding a flag to have a fast scan
- Loading branch information
1 parent
91b730a
commit 65877c4
Showing
5 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,29 @@ | |
package com.mycila.maven.plugin.license.util; | ||
|
||
import com.mycila.maven.plugin.license.Default; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Mathieu Carbou ([email protected]) | ||
*/ | ||
public final class SelectionTest { | ||
@Rule | ||
public final TemporaryFolder temp = new TemporaryFolder(); | ||
|
||
@Test | ||
public void test_default_select_all() { | ||
Selection selection = new Selection(new File("."), new String[0], new String[0], false); | ||
|
@@ -52,4 +63,46 @@ public void test_limit_inclusion_and_check_default_excludes() { | |
assertEquals(selection.getSelectedFiles().length, 0); | ||
assertTrue(Arrays.asList(selection.getExcluded()).containsAll(Arrays.asList(Default.EXCLUDES))); | ||
} | ||
|
||
@Test | ||
public void test_exclusions_violated_by_default() throws IOException { | ||
createAFakeProject(); | ||
|
||
Selection selection = new Selection(temp.getRoot(), new String[]{"**/*.txt"}, new String[] {"**/target/**"}, false); | ||
|
||
assertIncludedFilesInFakeProject(selection); | ||
assertEquals(3, selection.getFilesExcluded().length); | ||
} | ||
|
||
@Test | ||
public void test_exclusions_respect_with_fastScan() throws IOException { | ||
createAFakeProject(); | ||
|
||
Selection selection = new Selection(temp.getRoot(), new String[]{"**/*.txt"}, new String[] {"**/target/**"}, false); | ||
selection.setFastScan(true); | ||
|
||
assertIncludedFilesInFakeProject(selection); | ||
assertEquals(0, selection.getFilesExcluded().length); | ||
} | ||
|
||
private void assertIncludedFilesInFakeProject(Selection selection) { | ||
List<String> selected = new ArrayList<String>(asList(selection.getSelectedFiles())); | ||
Collections.sort(selected); | ||
assertEquals(asList("included.txt", "module/src/main/java/not-ignored.txt", "module/sub/subsub/src/main/java/not-ignored.txt"), selected); | ||
} | ||
|
||
private void createAFakeProject() throws IOException { | ||
touch(temp.newFile("included.txt")); | ||
touch(new File(temp.newFolder("target"), "ignored.txt")); | ||
touch(new File(temp.getRoot(), "module/src/main/java/not-ignored.txt")); | ||
touch(new File(temp.getRoot(), "module/target/ignored.txt")); | ||
touch(new File(temp.getRoot(), "module/sub/subsub/src/main/java/not-ignored.txt")); | ||
touch(new File(temp.getRoot(), "module/sub/subsub/target/foo/not-ignored.txt")); | ||
} | ||
|
||
private void touch(final File newFile) throws IOException { | ||
newFile.getParentFile().mkdirs(); | ||
final FileWriter w = new FileWriter(newFile); | ||
w.close(); | ||
} | ||
} |