[codegen ignore] Add tests, fix two minor issues

Tests are create to act on actual files to gauarantee functionality of
.swagger-codegen-ignore processing. Found two minor issues, one with
directory processing of files below the directory and another with
filename.* patterns reversing as *filename. for the pattern.

Added documentation to the README about .swagger-codegen-ignore file
support and syntax.
This commit is contained in:
Jim Schubert
2016-05-28 22:25:45 -04:00
parent bd1aab0cf0
commit d172de260d
4 changed files with 164 additions and 12 deletions

View File

@@ -1,20 +1,27 @@
package io.swagger.codegen.ignore.rules;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
import java.nio.file.*;
import java.util.List;
public class DirectoryRule extends FileRule {
private PathMatcher matcher = null;
private PathMatcher directoryMatcher = null;
private PathMatcher contentsMatcher = null;
DirectoryRule(List<Part> syntax, String definition) {
super(syntax, definition);
matcher = FileSystems.getDefault().getPathMatcher("glob:**/"+this.getPattern());
String pattern = this.getPattern();
StringBuilder sb = new StringBuilder();
sb.append("glob:");
sb.append(pattern);
if(!pattern.endsWith("/")) sb.append("/");
directoryMatcher = FileSystems.getDefault().getPathMatcher(sb.toString());
sb.append("**");
contentsMatcher = FileSystems.getDefault().getPathMatcher(sb.toString());
}
@Override
public Boolean matches(String relativePath) {
return matcher.matches(FileSystems.getDefault().getPath(relativePath));
return contentsMatcher.matches(FileSystems.getDefault().getPath(relativePath)) || directoryMatcher.matches(FileSystems.getDefault().getPath(relativePath));
}
}

View File

@@ -78,6 +78,13 @@ public class IgnoreLineParser {
i++;
continue;
} else {
if (sb.length() > 0) {
// A MATCH_ANY may commonly follow a filename or some other character. Dump that to results before the MATCH_ANY.
parts.add(new Part(Token.TEXT, sb.toString()));
sb.delete(0, sb.length());
}
parts.add(new Part(Token.MATCH_ANY));
continue;
}