Skip to content

Commit

Permalink
fixing excludetests flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rodhilton committed Jul 12, 2018
1 parent 06bed14 commit ceb037d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 70 deletions.
64 changes: 57 additions & 7 deletions src/main/java/org/jasome/executive/CommandLineExecutive.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jasome.executive;

import com.google.common.collect.ImmutableSet;
import org.apache.commons.cli.*;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
Expand All @@ -15,6 +16,7 @@
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import java.util.regex.Pattern;

public class CommandLineExecutive {
Expand Down Expand Up @@ -59,12 +61,7 @@ public static void main(String[] args) throws IOException, ParseException {
File scanDir = new File(fileParam);
FileScanner scanner = new FileScanner(scanDir);

IOFileFilter doesNotHaveTestSuffix = new NotFileFilter(new RegexFileFilter(Pattern.compile("(Test|Spec)\\.java$")));
IOFileFilter isNotInTestSubDirectory = FileFilterUtils.asFileFilter(pathname -> {
return !pathname.getPath().contains("/src/test/java");
});

IOFileFilter fileFilter = line.hasOption("excludetests") ? FileFilterUtils.and(doesNotHaveTestSuffix, isNotInTestSubDirectory) : FileFilterUtils.trueFileFilter();
IOFileFilter fileFilter = line.hasOption("excludetests") ? new ExcludeTestsFilter() : FileFilterUtils.trueFileFilter();

scanner.setFilter(fileFilter);

Expand Down Expand Up @@ -95,7 +92,7 @@ public static void main(String[] args) throws IOException, ParseException {
result = new StreamResult(tempOutputFile);
transformer.transform(source, result);
tempOutputFile.renameTo(finalOutputFile);
System.out.println("Operation completed in "+((endTime - startTime)/1000)+" seconds, output written to "+finalOutputFile);
System.out.println("Operation completed in " + ((endTime - startTime) / 1000) + " seconds, output written to " + finalOutputFile);
} else {
result = new StreamResult(System.out);
transformer.transform(source, result);
Expand All @@ -109,4 +106,57 @@ public static void main(String[] args) throws IOException, ParseException {

}
}

private static class ExcludeTestsFilter implements IOFileFilter {
private static Set<String> testSuffixes = ImmutableSet.of(
"Test",
"Spec",
"Tests",
"Specs",
"Suite",
"TestCase"
);

private static Set<String> testDirectories = ImmutableSet.of(
"test",
"tests",
"examples",
"example"
);


private IOFileFilter underlyingFilter;

public ExcludeTestsFilter() {
IOFileFilter doesNotHaveTestSuffix = new NotFileFilter(FileFilterUtils.asFileFilter(pathname -> {
for(String testSuffix: testSuffixes) {
if(pathname.getName().endsWith(testSuffix+".java")) {
return true;
}
}
return false;
}));

IOFileFilter isNotInTestSubDirectory = new NotFileFilter(FileFilterUtils.asFileFilter(pathname -> {
for(String testDirectory: testDirectories) {
if(pathname.getPath().contains(File.separator+testDirectory+File.separator)) {
return true;
}
}
return false;
}));

this.underlyingFilter = FileFilterUtils.and(doesNotHaveTestSuffix, isNotInTestSubDirectory);
}

@Override
public boolean accept(File file) {
return underlyingFilter.accept(file);
}

@Override
public boolean accept(File dir, String name) {
return underlyingFilter.accept(dir, name);
}
}
}
9 changes: 6 additions & 3 deletions src/main/java/org/jasome/input/FileScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

public class FileScanner extends Scanner {
private File scanDir;
private IOFileFilter filter = FileFilterUtils.and(new SuffixFileFilter(".java"), CanReadFileFilter.CAN_READ);
;
private IOFileFilter filter = FileFilterUtils.and(
new SuffixFileFilter(".java"),
CanReadFileFilter.CAN_READ,
HiddenFileFilter.VISIBLE
);

public FileScanner(File scanDir) {
this.scanDir = scanDir;
Expand All @@ -26,7 +29,7 @@ public FileScanner(File scanDir) {
public Project scan() {

Collection<File> inputFiles = gatherFilesFrom(scanDir, filter);

Collection<Pair<String, Map<String, String>>> sourceCodeWithAttributes = inputFiles
.stream()
.<Optional<Pair<String, Map<String, String>>>>map(file -> {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jasome/input/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ private JavaSymbolSolver configureParserAndResolver(Collection<Pair<String, Map<

} catch(ParseProblemException e) {
String file = attributes.get("sourceFile");
System.err.format("Unable to parse code from file %s, ignoring", file);
System.err.print(e.getProblems());
System.err.format("Unable to parse code from file %s, ignoring\n", file);
System.err.println(e.getProblems());
}
}

Expand Down Expand Up @@ -158,8 +158,8 @@ private Map<String, List<Pair<ClassOrInterfaceDeclaration, Map<String, String>>>
}
} catch(ParseProblemException e) {
String file = attributes.get("sourceFile");
System.err.format("Unable to parse code from file %s, ignoring", file);
System.err.print(e.getProblems());
System.err.format("Unable to parse code from file %s, ignoring\n", file);
System.err.println(e.getProblems());
}
}

Expand Down
56 changes: 0 additions & 56 deletions src/main/java/org/jasome/util/DistinctNode.java

This file was deleted.

0 comments on commit ceb037d

Please sign in to comment.