diff --git a/src/org/rascalmpl/uri/file/MavenRepositoryURIResolver.java b/src/org/rascalmpl/uri/file/MavenRepositoryURIResolver.java index 2c762b32bc..583d49b10c 100644 --- a/src/org/rascalmpl/uri/file/MavenRepositoryURIResolver.java +++ b/src/org/rascalmpl/uri/file/MavenRepositoryURIResolver.java @@ -79,6 +79,8 @@ * idea; but there is currently no way to register read-only logical schemes. */ public class MavenRepositoryURIResolver extends AliasedFileResolver { + private static String localRepoLocationCache; + private final Pattern authorityRegEx = Pattern.compile("^([a-zA-Z0-9-_.]+?)[!]([a-zA-Z0-9-_.]+)([!][a-zA-Z0-9\\-_.]+)$"); // groupId ! artifactId ! optionAlComplexVersionString @@ -113,7 +115,7 @@ private static String inferMavenRepositoryLocation() { // note that since it does not exist this will make all downstream resolutions fail // to "file does not exist" } - + return m2HomeFolder; } @@ -132,9 +134,14 @@ private static String computeMavenCommandName() { /** * This (slow) code runs only if the ~/.m2 folder does not exist and nobody -D'ed its location either. * That is not necessarily how mvn prioritizes its configuration steps, but it is the way we can - * get a quick enough answer most of the time. + * get a quick enough answer most of the time. It caches its result to make sure repeated calls + * to here are faster than the first. */ private static String getLocalRepositoryLocationFromMavenCommand() { + if (localRepoLocationCache != null) { + return localRepoLocationCache; + } + try { ProcessBuilder processBuilder = new ProcessBuilder(computeMavenCommandName(), "-q", @@ -150,7 +157,7 @@ private static String getLocalRepositoryLocationFromMavenCommand() { } try (var reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { - return reader.lines().collect(Collectors.joining()).trim(); + return (localRepoLocationCache = reader.lines().collect(Collectors.joining()).trim()); } } catch (IOException | InterruptedException e) { @@ -159,7 +166,6 @@ private static String getLocalRepositoryLocationFromMavenCommand() { } } - @Override public ISourceLocation resolve(ISourceLocation input) throws IOException { String authority = input.getAuthority();