Skip to content

Commit

Permalink
Some fixes to allow JBang to work
Browse files Browse the repository at this point in the history
- Remove ASM dep from provided dep list (JBang will resolve an old
  version)
- Default to using the quarkus bom if no managing project is supplied
  • Loading branch information
stuartwdouglas committed Nov 30, 2020
1 parent 47e80c5 commit 5ce4601
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
6 changes: 6 additions & 0 deletions core/launcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
Expand All @@ -15,7 +16,7 @@ public class JBangIntegration {
public static final String CONFIG = "//Q:CONFIG";

public static Map<String, Object> postBuild(Path appClasses, Path pomFile, List<Map.Entry<String, String>> repositories,
List<Map.Entry<String, Path>> dependencies,
List<Map.Entry<String, Path>> originalDeps,
List<String> comments, boolean nativeImage) {
for (String comment : comments) {
//we allow config to be provided via //Q:CONFIG name=value
Expand All @@ -29,6 +30,17 @@ public static Map<String, Object> postBuild(Path appClasses, Path pomFile, List<
}
}

//huge hack
//jbang does not consider the pom when resolving dependencies
//so can get the wrong version of asm
//we remove it from the deps list so we can use the correct one
List<Map.Entry<String, Path>> dependencies = new ArrayList<>();
for (Map.Entry<String, Path> i : originalDeps) {
if (!i.getKey().startsWith("org.ow2.asm:asm:")) {
dependencies.add(i);
}
}

ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
RuntimeLaunchClassLoader loader = new RuntimeLaunchClassLoader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import io.quarkus.bootstrap.resolver.maven.DeploymentInjectingDependencyVisitor;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.resolver.maven.SimpleDependencyGraphTransformationContext;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -43,7 +45,6 @@
import org.eclipse.aether.version.Version;

/**
*
* @author Alexey Loubyansky
*/
public class BootstrapAppModelResolver implements AppModelResolver {
Expand Down Expand Up @@ -142,7 +143,8 @@ public AppModel resolveModel(AppArtifact appArtifact) throws AppModelResolverExc

@Override
public AppModel resolveModel(AppArtifact appArtifact, List<AppDependency> directDeps) throws AppModelResolverException {
return resolveManagedModel(appArtifact, directDeps, null, Collections.emptySet());
return resolveManagedModel(appArtifact, directDeps,
null, Collections.emptySet());
}

@Override
Expand All @@ -155,6 +157,12 @@ public AppModel resolveManagedModel(AppArtifact appArtifact, List<AppDependency>
private AppModel doResolveModel(AppArtifact appArtifact, List<Dependency> directMvnDeps, AppArtifact managingProject,
Set<AppArtifactKey> localProjects)
throws AppModelResolverException {
if (managingProject == null) {
//this is a bit of a hack, but it lets Quarkus work correctly if there is no managing project
//if the bom has not been used then different dependency version could be resolved
//even though this is not perfect, it is better than the alternative
managingProject = new AppArtifact("io.quarkus", "quarkus-bom", "", "pom", getQuarkusVersion());
}
if (appArtifact == null) {
throw new IllegalArgumentException("Application artifact is null");
}
Expand Down Expand Up @@ -291,6 +299,20 @@ public boolean visitLeave(DependencyNode node) {
.build();
}

private String getQuarkusVersion() {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("quarkus-version.txt")) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[10];
int r;
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
return new String(out.toByteArray(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private void collectPlatformProperties(AppModel.Builder appBuilder, List<Dependency> managedDeps)
throws AppModelResolverException {
final Set<AppArtifactKey> descriptorKeys = new HashSet<>(4);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${project.version}

0 comments on commit 5ce4601

Please sign in to comment.