Skip to content

Commit 692af00

Browse files
committed
Simplify data-structures in BuildErrorReporters
1 parent 1049786 commit 692af00

File tree

2 files changed

+64
-206
lines changed

2 files changed

+64
-206
lines changed

Diff for: ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BuildErrorReporter.java

+22-46
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
package org.eclipse.pde.internal.core.builders;
2020

2121
import java.io.File;
22-
import java.io.FilenameFilter;
2322
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
2425
import java.util.ArrayList;
2526
import java.util.Arrays;
2627
import java.util.HashMap;
2728
import java.util.List;
2829
import java.util.Map;
2930
import java.util.Objects;
3031
import java.util.Set;
31-
import java.util.regex.Matcher;
32-
import java.util.regex.Pattern;
32+
import java.util.function.Predicate;
3333

3434
import javax.xml.parsers.DocumentBuilder;
3535
import javax.xml.parsers.ParserConfigurationException;
@@ -151,22 +151,6 @@ public void addAttributes(Map<String, String> attributes) {
151151
}
152152
}
153153

154-
static class WildcardFilenameFilter implements FilenameFilter {
155-
156-
private final Pattern pattern;
157-
158-
public WildcardFilenameFilter(String file) {
159-
pattern = PatternConstructor.createPattern(file, false);
160-
}
161-
162-
@Override
163-
public boolean accept(File dir, String name) {
164-
Matcher matcher = pattern.matcher(name);
165-
return matcher.matches();
166-
}
167-
168-
}
169-
170154
protected List<BuildProblem> fProblemList = new ArrayList<>();
171155
protected int fBuildSeverity;
172156
protected int fClasspathSeverity;
@@ -736,12 +720,15 @@ private void validateBinIncludes(IBuildEntry binIncludes, String key) {
736720
// check for wildcards
737721
IPath project = fFile.getProject().getLocation();
738722
if (project != null && token != null) {
739-
File projectFile = project.toFile();
740-
File[] files = projectFile.listFiles(new WildcardFilenameFilter(token));
741-
for (File file : files) {
742-
if (file.toString().endsWith(key)) {
743-
return true;
723+
Predicate<String> isMatch = toMatcher(token);
724+
try (var files = Files.newDirectoryStream(project.toPath(),
725+
path -> isMatch.test(path.getFileName().toString()));) {
726+
for (Path file : files) {
727+
if (file.toString().endsWith(key)) {
728+
return true;
729+
}
744730
}
731+
} catch (IOException e) { // ignore
745732
}
746733
}
747734
return false;
@@ -820,29 +807,14 @@ private void validateMissingSourceInBinIncludes(IBuildEntry binIncludes, List<St
820807
continue;
821808
}
822809
}
823-
key = key.substring(PROPERTY_SOURCE_PREFIX.length());
824-
boolean found = false;
825-
String[] binIncludesTokens = binIncludes.getTokens();
826-
for (String token : binIncludesTokens) {
827-
Pattern pattern = PatternConstructor.createPattern(token, false);
828-
if (pattern.matcher(key).matches()) {
829-
found = true;
830-
}
831-
}
810+
String libName = key.substring(PROPERTY_SOURCE_PREFIX.length());
811+
List<Predicate<String>> matchers = Arrays.stream(binIncludes.getTokens()).map(BuildErrorReporter::toMatcher)
812+
.toList();
813+
boolean found = matchers.stream().anyMatch(m -> m.test(libName));
832814
// account for trailing slash on class file folders
833-
if (!found) {
834-
IPath path = IPath.fromOSString(key);
835-
if (path.getFileExtension() == null) {
836-
if (!key.endsWith("/")) { //$NON-NLS-1$
837-
key = key + "/"; //$NON-NLS-1$
838-
for (String token : binIncludesTokens) {
839-
Pattern pattern = PatternConstructor.createPattern(token, false);
840-
if (pattern.matcher(key).matches()) {
841-
found = true;
842-
}
843-
}
844-
}
845-
}
815+
if (!found && IPath.fromOSString(libName).getFileExtension() == null && !libName.endsWith("/")) { //$NON-NLS-1$
816+
String folderName = libName + "/"; //$NON-NLS-1$
817+
found = matchers.stream().anyMatch(m -> m.test(folderName));
846818
}
847819
if (!found) {
848820
String msg = NLS.bind(PDECoreMessages.BuildErrorReporter_binIncludesMissing, key);
@@ -1333,6 +1305,10 @@ private VirtualMarker report(String message, int line, int problemID, String bui
13331305
return marker;
13341306
}
13351307

1308+
private static Predicate<String> toMatcher(String token) {
1309+
return PatternConstructor.createPattern(token, false).asMatchPredicate();
1310+
}
1311+
13361312
public boolean isCustomBuild() {
13371313
WorkspaceBuildModel wbm = new WorkspaceBuildModel(fFile);
13381314
IBuild build = wbm.getBuild();

0 commit comments

Comments
 (0)