From 4b4a1821a6aaff5faca28c3f4182cf600f1eb3dc Mon Sep 17 00:00:00 2001 From: Tako Schotanus Date: Fri, 5 Feb 2021 03:03:17 +0100 Subject: [PATCH] fix: jbang doesn't store additional deps in JAR Class-Path anymore Fixes #707 --- .../java/dev/jbang/source/RunContext.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/dev/jbang/source/RunContext.java b/src/main/java/dev/jbang/source/RunContext.java index 476344367..607f121d9 100644 --- a/src/main/java/dev/jbang/source/RunContext.java +++ b/src/main/java/dev/jbang/source/RunContext.java @@ -6,8 +6,6 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.stream.Collectors; -import java.util.stream.Stream; import dev.jbang.Settings; import dev.jbang.catalog.Alias; @@ -43,7 +41,8 @@ public class RunContext { private Alias alias; - private ModularClassPath classpath; + private ModularClassPath mcp; + private ModularClassPath additionalMcp; public static RunContext empty() { return new RunContext(); @@ -234,12 +233,7 @@ public List collectAllDependenciesFor(Source src) { if (getProperties() != null) { p.putAll(getProperties()); } - return getAllDependencies(src, p); - } - - private List getAllDependencies(Source src, Properties props) { - return Stream .concat(getAdditionalDependencies().stream(), src.getAllDependencies(props).stream()) - .collect(Collectors.toList()); + return src.getAllDependencies(p); } /** @@ -247,10 +241,19 @@ private List getAllDependencies(Source src, Properties props) { * consecutive calls return the same classpath. **/ public String resolveClassPath(Source src, boolean offline) { - if (classpath == null) { - classpath = src.resolveClassPath(collectAllDependenciesFor(src), offline); + if (additionalMcp == null) { + additionalMcp = src.resolveClassPath(getAdditionalDependencies(), offline); + } + if (mcp == null) { + mcp = src.resolveClassPath(collectAllDependenciesFor(src), offline); + } + StringBuilder cp = new StringBuilder(additionalMcp.getClassPath()); + if (!mcp.getArtifacts().isEmpty()) { + if (cp.length() > 0) { + cp.append(Settings.CP_SEPARATOR); + } + cp.append(mcp.getClassPath()); } - StringBuilder cp = new StringBuilder(classpath.getClassPath()); for (String addcp : getAdditionalClasspaths()) { if (cp.length() > 0) { cp.append(Settings.CP_SEPARATOR); @@ -261,14 +264,14 @@ public String resolveClassPath(Source src, boolean offline) { } public List getAutoDetectedModuleArguments(Source src, String requestedVersion, boolean offline) { - if (classpath == null) { + if (mcp == null) { resolveClassPath(src, offline); } - return classpath.getAutoDectectedModuleArguments(requestedVersion); + return mcp.getAutoDectectedModuleArguments(requestedVersion); } public ModularClassPath getClassPath() { - return classpath; + return mcp; } /**