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 99f1859
Show file tree
Hide file tree
Showing 6 changed files with 47 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
6 changes: 6 additions & 0 deletions independent-projects/bootstrap/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 @@ -7,6 +7,10 @@
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import java.io.ByteArrayOutputStream;
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 @@ -49,6 +53,7 @@ public static Map<String, Object> postBuild(Path appClasses, Path pomFile, List<
.setMavenArtifactResolver(quarkusResolver)
.setProjectRoot(pomFile.getParent())
.setTargetDirectory(target)
.setManagingProject(new AppArtifact("io.quarkus", "quarkus-bom", "", "pom", getQuarkusVersion()))
.setForcedDependencies(dependencies.stream().map(s -> {
String[] parts = s.getKey().split(":");
AppArtifact artifact;
Expand Down Expand Up @@ -81,4 +86,18 @@ public static Map<String, Object> postBuild(Path appClasses, Path pomFile, List<
throw new RuntimeException(e);
}
}

private static String getQuarkusVersion() {
try (InputStream in = JBangBuilderImpl.class.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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${project.version}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.eclipse.aether.version.Version;

/**
*
* @author Alexey Loubyansky
*/
public class BootstrapAppModelResolver implements AppModelResolver {
Expand Down Expand Up @@ -142,7 +141,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 Down

0 comments on commit 99f1859

Please sign in to comment.