Skip to content

Commit 05a749e

Browse files
committed
Correctly check a file for exclusion.
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.
1 parent d15a7e2 commit 05a749e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/main/java/net/briac/omegat/plugin/omt/DirectoryFilter.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,26 @@
88
import java.util.logging.Level;
99
import java.util.regex.Pattern;
1010

11+
import org.apache.commons.io.FilenameUtils;
12+
1113
public class DirectoryFilter implements DirectoryStream.Filter<Path> {
1214

13-
private List<Pattern> excludePatterns = new ArrayList<>();
15+
private final List<Pattern> excludePatterns = new ArrayList<>();
16+
private final Path projectRoot;
1417

15-
public DirectoryFilter(List<String> excludePatterns) {
18+
public DirectoryFilter(Path projectRoot, List<String> excludePatterns) {
19+
this.projectRoot = projectRoot;
1620
for (String e : excludePatterns) {
1721
this.excludePatterns.add(Pattern.compile(e));
1822
}
1923
}
2024

2125
@Override
2226
public boolean accept(Path entry) throws IOException {
23-
//Log.log(String.format("filter\tentry:[%s]", entry));
27+
String matchEntry = FilenameUtils.normalizeNoEndSeparator(projectRoot.relativize(entry).toString(), true);
28+
//org.omegat.util.Log.log(String.format("filter\tentry:[%s]", matchEntry));
2429
for (Pattern excludePattern : excludePatterns) {
25-
if (excludePattern.matcher(entry.toString()).find()) {
30+
if (excludePattern.matcher(matchEntry).find()) {
2631
ManageOMTPackage.LOGGER.log(Level.FINE, String.format("Excluded\t%s", entry));
2732
return false;
2833
}

src/main/java/net/briac/omegat/plugin/omt/ManageOMTPackage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public static void createOmt(final File omtZip, final ProjectProperties props) t
555555

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

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

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

0 commit comments

Comments
 (0)