michaelsembwever commented on code in PR #9545:
URL: https://github.com/apache/netbeans/pull/9545#discussion_r3745104225
##########
java/java.freeform/src/org/netbeans/modules/java/freeform/Classpaths.java:
##########
@@ -430,26 +451,90 @@ private List<URL> createClasspath(
final String[] path = PropertyUtils.tokenizePath(cpEval);
final List<URL> res = new ArrayList<>();
for (String pathElement : path) {
- res.addAll(translate.apply(createClasspathEntry(pathElement)));
+ for (URL entry : createClasspathEntries(pathElement, watchedDirs))
{
+ res.addAll(translate.apply(entry));
+ }
}
return res;
}
-
+
+ /**
+ * Turn a single (already property-evaluated) classpath token into zero or
+ * more classpath root URLs. Ordinary tokens map to exactly one URL; a
token
+ * whose last path component is a filename glob is expanded to the matching
+ * archives in the directory it names.
+ */
+ private List<URL> createClasspathEntries(String text, Set<File>
watchedDirs) {
+ final int slash = Math.max(text.lastIndexOf('/'),
text.lastIndexOf(File.separatorChar));
+ final String lastComponent = slash >= 0 ? text.substring(slash + 1) :
text;
+ if (lastComponent.indexOf('*') < 0 && lastComponent.indexOf('?') < 0) {
+ return Collections.singletonList(createClasspathEntry(text));
+ }
+ final String prefix = slash >= 0 ? text.substring(0, slash) : ""; //
NOI18N
+ final File dir = helper.resolveFile(prefix.isEmpty() ? "." : prefix);
// NOI18N
+ if (watchedDirs != null) {
+ // Watch the directory even if it does not exist yet: a build may
+ // create it (and the matching JARs) after the project is opened.
+ watchedDirs.add(dir);
+ }
+ final File[] kids = dir.listFiles();
+ if (kids == null) {
+ return Collections.emptyList();
+ }
+ // Sort for a stable classpath order independent of directory listing
order.
+ Arrays.sort(kids);
+ final Pattern pattern = wildcardToRegex(lastComponent);
+ final List<URL> res = new ArrayList<>();
+ for (File kid : kids) {
+ if (!kid.isFile() || !pattern.matcher(kid.getName()).matches()) {
+ continue;
+ }
+ final URL entry = FileUtil.urlForArchiveOrDir(kid);
+ // Only archives yield a URL ending in '/'; skip anything that is
not
+ // a valid classpath root (matches the java launcher's JARs-only
rule).
+ if (entry != null && entry.toExternalForm().endsWith("/")) { //
NOI18N
Review Comment:
addressed in
https://github.com/apache/netbeans/pull/9545/changes/c9969aa2f1bef8469db4567b1bd05bac8fb8836e
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists