|
19 | 19 | package org.eclipse.pde.internal.core.builders;
|
20 | 20 |
|
21 | 21 | import java.io.File;
|
22 |
| -import java.io.FilenameFilter; |
23 | 22 | import java.io.IOException;
|
| 23 | +import java.nio.file.Files; |
| 24 | +import java.nio.file.Path; |
24 | 25 | import java.util.ArrayList;
|
25 | 26 | import java.util.Arrays;
|
26 | 27 | import java.util.HashMap;
|
27 | 28 | import java.util.List;
|
28 | 29 | import java.util.Map;
|
29 | 30 | import java.util.Objects;
|
30 | 31 | import java.util.Set;
|
31 |
| -import java.util.regex.Matcher; |
32 |
| -import java.util.regex.Pattern; |
| 32 | +import java.util.function.Predicate; |
33 | 33 |
|
34 | 34 | import javax.xml.parsers.DocumentBuilder;
|
35 | 35 | import javax.xml.parsers.ParserConfigurationException;
|
@@ -151,22 +151,6 @@ public void addAttributes(Map<String, String> attributes) {
|
151 | 151 | }
|
152 | 152 | }
|
153 | 153 |
|
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 |
| - |
170 | 154 | protected List<BuildProblem> fProblemList = new ArrayList<>();
|
171 | 155 | protected int fBuildSeverity;
|
172 | 156 | protected int fClasspathSeverity;
|
@@ -736,12 +720,15 @@ private void validateBinIncludes(IBuildEntry binIncludes, String key) {
|
736 | 720 | // check for wildcards
|
737 | 721 | IPath project = fFile.getProject().getLocation();
|
738 | 722 | 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 | + } |
744 | 730 | }
|
| 731 | + } catch (IOException e) { // ignore |
745 | 732 | }
|
746 | 733 | }
|
747 | 734 | return false;
|
@@ -820,29 +807,14 @@ private void validateMissingSourceInBinIncludes(IBuildEntry binIncludes, List<St
|
820 | 807 | continue;
|
821 | 808 | }
|
822 | 809 | }
|
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)); |
832 | 814 | // 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)); |
846 | 818 | }
|
847 | 819 | if (!found) {
|
848 | 820 | String msg = NLS.bind(PDECoreMessages.BuildErrorReporter_binIncludesMissing, key);
|
@@ -1333,6 +1305,10 @@ private VirtualMarker report(String message, int line, int problemID, String bui
|
1333 | 1305 | return marker;
|
1334 | 1306 | }
|
1335 | 1307 |
|
| 1308 | + private static Predicate<String> toMatcher(String token) { |
| 1309 | + return PatternConstructor.createPattern(token, false).asMatchPredicate(); |
| 1310 | + } |
| 1311 | + |
1336 | 1312 | public boolean isCustomBuild() {
|
1337 | 1313 | WorkspaceBuildModel wbm = new WorkspaceBuildModel(fFile);
|
1338 | 1314 | IBuild build = wbm.getBuild();
|
|
0 commit comments