This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_5_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_5_0_X by this push:
new 76c5b9a562 GROOVY-11795: Let groovysh startup time not depend on
contents of CWD
76c5b9a562 is described below
commit 76c5b9a562532f4a6975d1fc09632c5cfa73c7d0
Author: Paul King <[email protected]>
AuthorDate: Wed Nov 5 14:09:09 2025 +1000
GROOVY-11795: Let groovysh startup time not depend on contents of CWD
---
.../apache/groovy/groovysh/jline/GroovyEngine.java | 54 +++++++++++-----------
1 file changed, 28 insertions(+), 26 deletions(-)
diff --git
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
index aecfa63e9d..3cb2d52fca 100644
---
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
+++
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
@@ -1029,38 +1029,40 @@ public class GroovyEngine implements ScriptEngine {
}
private static Set<String> sourcesForPackage(String domain) {
- String separator = FileSystems.getDefault().getSeparator();
- if (separator.equals("\\")) {
- separator += separator;
- }
- boolean onlyPackage = domain != null && domain.endsWith("*");
- if (onlyPackage) {
- domain = domain.substring(0, domain.lastIndexOf("."));
- }
- String pkg = domain;
- String dom;
- if (domain == null) {
- dom = separator + "(|.*)";
- } else if (domain.isEmpty()) {
- dom = ".*" + separator;
- } else {
- dom = separator + domain.replace(".", separator) + "(|.*)";
- }
- dom = "regex:\\." + dom + "[A-Z]+[a-zA-Z]*\\.groovy";
- PathMatcher matcher = FileSystems.getDefault().getPathMatcher(dom);
Set<String> out = new HashSet<>();
- try (Stream<Path> pathStream = Files.walk(Paths.get("."))) {
- Stream<String> classes = pathStream
+ if (!domain.startsWith("java.") && !domain.startsWith("groovy.")) {
+ String separator = FileSystems.getDefault().getSeparator();
+ if (separator.equals("\\")) {
+ separator += separator;
+ }
+ boolean onlyPackage = domain != null && domain.endsWith("*");
+ if (onlyPackage) {
+ domain = domain.substring(0, domain.lastIndexOf("."));
+ }
+ String pkg = domain;
+ String dom;
+ if (domain == null) {
+ dom = separator + "(|.*)";
+ } else if (domain.isEmpty()) {
+ dom = ".*" + separator;
+ } else {
+ dom = separator + domain.replace(".", separator) + "(|.*)";
+ }
+ dom = "regex:\\." + dom + "[A-Z]+[a-zA-Z]*\\.groovy";
+ PathMatcher matcher =
FileSystems.getDefault().getPathMatcher(dom);
+ try (Stream<Path> pathStream = Files.walk(Paths.get("."))) {
+ Stream<String> classes = pathStream
.filter(matcher::matches)
.filter(p ->
p.getFileName().toString().matches("[A-Z]+[a-zA-Z]*\\.groovy"))
.map(Path::toString)
.map(source -> source.substring(2,
source.lastIndexOf("."))
-
.replace(FileSystems.getDefault().getSeparator(), "."));
- if (onlyPackage) {
- classes = classes.filter(cl ->
Character.isUpperCase(cl.charAt(pkg.length() + 1)));
+ .replace(FileSystems.getDefault().getSeparator(),
"."));
+ if (onlyPackage) {
+ classes = classes.filter(cl ->
Character.isUpperCase(cl.charAt(pkg.length() + 1)));
+ }
+ classes.forEach(out::add);
+ } catch (Exception ignore) {
}
- classes.forEach(out::add);
- } catch (Exception ignore) {
}
return out;
}