From 5ce460118f7910243b39ec7e0161236d4d5a567c Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 30 Nov 2020 15:57:55 +1100 Subject: [PATCH] Some fixes to allow JBang to work - 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 --- core/launcher/pom.xml | 6 +++++ .../io/quarkus/launcher/JBangIntegration.java | 14 +++++++++- .../resolver/BootstrapAppModelResolver.java | 26 +++++++++++++++++-- .../src/main/resources/quarkus-version.txt | 1 + 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 independent-projects/bootstrap/maven-resolver/src/main/resources/quarkus-version.txt diff --git a/core/launcher/pom.xml b/core/launcher/pom.xml index 2d7267d3846421..1c518816d2a6b8 100644 --- a/core/launcher/pom.xml +++ b/core/launcher/pom.xml @@ -22,6 +22,12 @@ + + + src/main/resources + true + + org.apache.maven.plugins diff --git a/core/launcher/src/main/java/io/quarkus/launcher/JBangIntegration.java b/core/launcher/src/main/java/io/quarkus/launcher/JBangIntegration.java index e740b106183188..78ed124de063c8 100644 --- a/core/launcher/src/main/java/io/quarkus/launcher/JBangIntegration.java +++ b/core/launcher/src/main/java/io/quarkus/launcher/JBangIntegration.java @@ -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; @@ -15,7 +16,7 @@ public class JBangIntegration { public static final String CONFIG = "//Q:CONFIG"; public static Map postBuild(Path appClasses, Path pomFile, List> repositories, - List> dependencies, + List> originalDeps, List comments, boolean nativeImage) { for (String comment : comments) { //we allow config to be provided via //Q:CONFIG name=value @@ -29,6 +30,17 @@ public static Map 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> dependencies = new ArrayList<>(); + for (Map.Entry i : originalDeps) { + if (!i.getKey().startsWith("org.ow2.asm:asm:")) { + dependencies.add(i); + } + } + ClassLoader old = Thread.currentThread().getContextClassLoader(); try { RuntimeLaunchClassLoader loader = new RuntimeLaunchClassLoader( diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java index 3ceee3026d94b9..82442b0c6de3de 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java @@ -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; @@ -43,7 +45,6 @@ import org.eclipse.aether.version.Version; /** - * * @author Alexey Loubyansky */ public class BootstrapAppModelResolver implements AppModelResolver { @@ -142,7 +143,8 @@ public AppModel resolveModel(AppArtifact appArtifact) throws AppModelResolverExc @Override public AppModel resolveModel(AppArtifact appArtifact, List directDeps) throws AppModelResolverException { - return resolveManagedModel(appArtifact, directDeps, null, Collections.emptySet()); + return resolveManagedModel(appArtifact, directDeps, + null, Collections.emptySet()); } @Override @@ -155,6 +157,12 @@ public AppModel resolveManagedModel(AppArtifact appArtifact, List private AppModel doResolveModel(AppArtifact appArtifact, List directMvnDeps, AppArtifact managingProject, Set 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"); } @@ -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 managedDeps) throws AppModelResolverException { final Set descriptorKeys = new HashSet<>(4); diff --git a/independent-projects/bootstrap/maven-resolver/src/main/resources/quarkus-version.txt b/independent-projects/bootstrap/maven-resolver/src/main/resources/quarkus-version.txt new file mode 100644 index 00000000000000..f2ab45c3b0ef08 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/main/resources/quarkus-version.txt @@ -0,0 +1 @@ +${project.version} \ No newline at end of file