Skip to content

Commit

Permalink
fix: jbang doesn't store additional deps in JAR Class-Path anymore
Browse files Browse the repository at this point in the history
Fixes #707
  • Loading branch information
quintesse committed Feb 5, 2021
1 parent b276d7f commit 4b4a182
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/main/java/dev/jbang/source/RunContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -234,23 +233,27 @@ public List<String> collectAllDependenciesFor(Source src) {
if (getProperties() != null) {
p.putAll(getProperties());
}
return getAllDependencies(src, p);
}

private List<String> getAllDependencies(Source src, Properties props) {
return Stream .concat(getAdditionalDependencies().stream(), src.getAllDependencies(props).stream())
.collect(Collectors.toList());
return src.getAllDependencies(p);
}

/**
* Return resolved classpath lazily. resolution will only happen once, any
* 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);
Expand All @@ -261,14 +264,14 @@ public String resolveClassPath(Source src, boolean offline) {
}

public List<String> 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;
}

/**
Expand Down

0 comments on commit 4b4a182

Please sign in to comment.