Skip to content

Commit

Permalink
Correctly check a file for exclusion.
Browse files Browse the repository at this point in the history
The filename is relative to the project root (e.g
`tm/auto/test.*`\\.tmx`), and all the file separators are converted to
forward slashes to be consistent across all platforms.
  • Loading branch information
briacp committed Jan 24, 2020
1 parent d15a7e2 commit 05a749e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/main/java/net/briac/omegat/plugin/omt/DirectoryFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@
import java.util.logging.Level;
import java.util.regex.Pattern;

import org.apache.commons.io.FilenameUtils;

public class DirectoryFilter implements DirectoryStream.Filter<Path> {

private List<Pattern> excludePatterns = new ArrayList<>();
private final List<Pattern> excludePatterns = new ArrayList<>();
private final Path projectRoot;

public DirectoryFilter(List<String> excludePatterns) {
public DirectoryFilter(Path projectRoot, List<String> excludePatterns) {
this.projectRoot = projectRoot;
for (String e : excludePatterns) {
this.excludePatterns.add(Pattern.compile(e));
}
}

@Override
public boolean accept(Path entry) throws IOException {
//Log.log(String.format("filter\tentry:[%s]", entry));
String matchEntry = FilenameUtils.normalizeNoEndSeparator(projectRoot.relativize(entry).toString(), true);
//org.omegat.util.Log.log(String.format("filter\tentry:[%s]", matchEntry));
for (Pattern excludePattern : excludePatterns) {
if (excludePattern.matcher(entry.toString()).find()) {
if (excludePattern.matcher(matchEntry).find()) {
ManageOMTPackage.LOGGER.log(Level.FINE, String.format("Excluded\t%s", entry));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public static void createOmt(final File omtZip, final ProjectProperties props) t

List<String> listExcludes = Arrays.asList(pluginProps.getProperty(PROPERTY_EXCLUDE, DEFAULT_EXCLUDE).split(";"));

DirectoryStream.Filter<Path> filter = new DirectoryFilter(listExcludes);
DirectoryStream.Filter<Path> filter = new DirectoryFilter(path, listExcludes);

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(omtZip));
Log.log(String.format("Zipping project [%s] to file [%s]", path, omtZip.getAbsolutePath()));
Expand Down

0 comments on commit 05a749e

Please sign in to comment.