Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take into account ignoreChangesInFiles + fix associated tests #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>no.sparebank1</groupId>
<artifactId>turbo-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0.0</version>
<version>1.0.1</version>

<name>turbo-maven-plugin Maven Mojo</name>
<description>
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/no/sparebank1/turbo/SourceFileFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ public List<String> getSourceFiles(final String projectRoot, final String ignore
List<String> filesInSrc = findFilesInDirRecursively(projectRoot + "/src");
sourceFiles.addAll(filesInSrc);
//Remove files that are configured not to be included:
List<String> prunedSourcefiles = pruneSourefiles(sourceFiles, ignoreChangesInFiles);
List<String> prunedSourcefiles = pruneSourcefiles(sourceFiles, ignoreChangesInFiles);

return prunedSourcefiles;
}

List<String> pruneSourefiles(final List<String> sourcefiles, final String ignoreChangesInFiles) {
List<String> pruneSourcefiles(List<String> sourcefiles, String ignoreChangesInFiles) {
List<String> ignoredFiles = ignoreChangesInFiles != null ? Arrays.asList(ignoreChangesInFiles.split(",")) : new ArrayList<>();
List<String> prunedSourcefiles = new ArrayList<>(sourcefiles);
sourcefiles.forEach(sourcefile -> {
if (sourcefile.contains("swagger.json") ||
sourcefile.contains(".iml") ||
sourcefile.contains("editorconfig") ||
sourcefile.contains("docker-image-id")) {
prunedSourcefiles.remove(sourcefile);
}
});
sourcefiles.forEach(sourcefile -> prunedSourcefiles.removeIf(sourceFile -> containsAnyIgnoredFile(sourceFile, ignoredFiles)));
return prunedSourcefiles;
}

boolean containsAnyIgnoredFile(String sourceFile, List< String > ignoredFiles) {
return ignoredFiles.stream()
.anyMatch(ignoredFile -> ignoredFile != null &&
!ignoredFile.trim().isEmpty() &&
sourceFile.contains(ignoredFile));
}

List<String> findFilesInDir(final String dir) {
File dirFile = new File(dir);
List<File> list = Arrays.asList(dirFile.listFiles());
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/test/bar/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sometext
1 change: 1 addition & 0 deletions src/test/foo/src/bar1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar1
1 change: 1 addition & 0 deletions src/test/foo/src/bar2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar2
6 changes: 3 additions & 3 deletions src/test/java/no/sparebank1/turbo/ArtifactAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private List<String> getListOfSources() {
String path = new File(".").getAbsolutePath();
ArrayList<String> listOfSources = new ArrayList<>();
listOfSources.add(path + "/src/test/foo/pom.xml");
listOfSources.add(path + "/src/test/foo/bar/bar1.txt");
listOfSources.add(path + "/src/test/foo/bar/bar2.txt");
listOfSources.add(path + "/src/test/foo/src/bar1.txt");
listOfSources.add(path + "/src/test/foo/src/bar2.txt");
return listOfSources;
}

Expand Down Expand Up @@ -141,4 +141,4 @@ private File addArtifact(final String m2Repository, final String groupId, final
return file;
}

}
}
17 changes: 14 additions & 3 deletions src/test/java/no/sparebank1/turbo/SourceFileFinderTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.sparebank1.turbo;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
Expand All @@ -9,9 +10,19 @@

class SourceFileFinderTest {
@Test
public void shall_find_all_files_in_subdirectories() {
void shall_find_all_files_in_subdirectories() {
String path1 = new File(".").getAbsolutePath() + "/src/test/foo";
String path2 = new File(".").getAbsolutePath() + "/src/test/bar";
assertEquals( 3, new SourceFileFinder().getSourceFiles(path1, "").size() );
assertEquals( 1, new SourceFileFinder().getSourceFiles(path2, "").size() );
}

@Test
public void shall_find_with_ignore_files() {
String path = new File(".").getAbsolutePath() + "/src/test/foo";
List<String> sourcefiles = new SourceFileFinder().getSourceFiles(path, "");
assertTrue(true);
assertEquals( 1, new SourceFileFinder().getSourceFiles(path, "bar1,bar2").size() );
assertEquals( 1, new SourceFileFinder().getSourceFiles(path, "bar").size() );
assertEquals( 3, new SourceFileFinder().getSourceFiles(path, null).size() );
}

}