use of io.quarkus.maven.dependency.ResolvedArtifactDependency in project quarkus by quarkusio.
the class AppModelGradleResolver method resolveArtifact.
private ResolvedDependency resolveArtifact(ArtifactCoords appArtifact) throws AppModelResolverException {
if (ResolvedDependency.class.isAssignableFrom(appArtifact.getClass())) {
final ResolvedDependency resolved = (ResolvedDependency) appArtifact;
if (resolved.isResolved()) {
return resolved;
}
}
final DefaultDependencyArtifact dep = new DefaultDependencyArtifact();
dep.setExtension(appArtifact.getType());
dep.setType(appArtifact.getType());
dep.setName(appArtifact.getArtifactId());
if (appArtifact.getClassifier() != null) {
dep.setClassifier(appArtifact.getClassifier());
}
final DefaultExternalModuleDependency gradleDep = new DefaultExternalModuleDependency(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getVersion(), null);
gradleDep.addArtifact(dep);
final Configuration detachedConfig = project.getConfigurations().detachedConfiguration(gradleDep);
final ResolvedConfiguration rc = detachedConfig.getResolvedConfiguration();
Set<ResolvedArtifact> resolvedArtifacts;
try {
resolvedArtifacts = rc.getResolvedArtifacts();
} catch (ResolveException e) {
throw new AppModelResolverException("Failed to resolve " + appArtifact, e);
}
for (ResolvedArtifact a : resolvedArtifacts) {
if (appArtifact.getArtifactId().equals(a.getName()) && appArtifact.getType().equals(a.getType()) && (a.getClassifier() == null ? appArtifact.getClassifier() == null : a.getClassifier().equals(appArtifact.getClassifier())) && appArtifact.getGroupId().equals(a.getModuleVersion().getId().getGroup())) {
final String version = appArtifact.getVersion().equals(a.getModuleVersion().getId().getVersion()) ? appArtifact.getVersion() : a.getModuleVersion().getId().getVersion();
return new ResolvedArtifactDependency(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getClassifier(), appArtifact.getType(), version, a.getFile().toPath());
}
}
throw new AppModelResolverException("Failed to resolve " + appArtifact);
}
use of io.quarkus.maven.dependency.ResolvedArtifactDependency in project quarkus by quarkusio.
the class JBangDevModeLauncherImpl method main.
public static Closeable main(String... args) {
// avoid unknown config key warnings
System.clearProperty("quarkus.dev");
System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
URL url = JBangDevModeLauncherImpl.class.getClassLoader().getResource("jbang-dev.dat");
String jarFilePath = url.getPath().substring(5, url.getPath().indexOf("!"));
try (DataInputStream contextStream = new DataInputStream(JBangDevModeLauncherImpl.class.getClassLoader().getResourceAsStream("jbang-dev.dat"))) {
String pomContents = contextStream.readUTF();
Path sourceFile = Paths.get(contextStream.readUTF());
int depCount = contextStream.readInt();
Map<String, Path> deps = new HashMap<>();
for (int i = 0; i < depCount; ++i) {
String name = contextStream.readUTF();
Path path = Paths.get(contextStream.readUTF());
deps.put(name, path);
}
Path projectRoot = Files.createTempDirectory("quarkus-jbang");
try (OutputStream out = Files.newOutputStream(projectRoot.resolve("pom.xml"))) {
out.write(pomContents.getBytes(StandardCharsets.UTF_8));
}
Path targetClasses = projectRoot.resolve("target/classes");
Files.createDirectories(targetClasses);
try (ZipFile fz = new ZipFile(new File(jarFilePath))) {
Enumeration<? extends ZipEntry> entries = fz.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
Path path = targetClasses.resolve(entry.getName()).normalize();
if (!path.startsWith(targetClasses)) {
throw new IOException("Bad ZIP entry: " + path);
}
if (entry.isDirectory()) {
Files.createDirectories(path);
} else {
Files.createDirectories(path.getParent());
Files.copy(fz.getInputStream(entry), path);
Files.setLastModifiedTime(path, entry.getLastModifiedTime());
}
}
}
Path srcDir = projectRoot.resolve("src/main/java");
Files.createDirectories(srcDir);
Files.createSymbolicLink(srcDir.resolve(sourceFile.getFileName().toString()), sourceFile);
final LocalProject currentProject = LocalProject.loadWorkspace(projectRoot);
final ResolvedDependency appArtifact = ResolvedDependencyBuilder.newInstance().setCoords(currentProject.getAppArtifact(ArtifactCoords.TYPE_JAR)).setResolvedPath(targetClasses).setWorkspaceModule(currentProject.toWorkspaceModule()).build();
// todo : proper support for everything
final QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder().setBaseClassLoader(JBangDevModeLauncherImpl.class.getClassLoader()).setIsolateDeployment(true).setMode(QuarkusBootstrap.Mode.DEV).setTargetDirectory(targetClasses).setAppArtifact(appArtifact).setManagingProject(new GACTV("io.quarkus", "quarkus-bom", "", "pom", getQuarkusVersion())).setForcedDependencies(deps.entrySet().stream().map(s -> {
String[] parts = s.getKey().split(":");
Dependency artifact;
if (parts.length == 3) {
artifact = new ArtifactDependency(parts[0], parts[1], null, ArtifactCoords.TYPE_JAR, parts[2]);
} else if (parts.length == 4) {
artifact = new ArtifactDependency(parts[0], parts[1], null, parts[2], parts[3]);
} else if (parts.length == 5) {
artifact = new ArtifactDependency(parts[0], parts[1], parts[3], parts[2], parts[4]);
} else {
throw new RuntimeException("Invalid artifact " + s);
}
// artifact.setPath(s.getValue());
return artifact;
}).collect(Collectors.toList())).setApplicationRoot(targetClasses).setProjectRoot(projectRoot);
Map<String, Object> context = new HashMap<>();
context.put("app-project", currentProject);
context.put("args", args);
context.put("app-classes", targetClasses);
final BootstrapMavenContext mvnCtx = new BootstrapMavenContext(BootstrapMavenContext.config().setCurrentProject(currentProject));
final MavenArtifactResolver mvnResolver = new MavenArtifactResolver(mvnCtx);
builder.setMavenArtifactResolver(mvnResolver);
((ResolvedArtifactDependency) currentProject.getAppArtifact(ArtifactCoords.TYPE_JAR)).setResolvedPaths(PathList.of(targetClasses));
final CuratedApplication curatedApp = builder.build().bootstrap();
final Object appInstance = curatedApp.runInAugmentClassLoader("io.quarkus.deployment.dev.IDEDevModeMain", context);
return new JBangDevModeLauncherImpl(curatedApp, appInstance == null ? null : appInstance instanceof Closeable ? (Closeable) appInstance : null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.quarkus.maven.dependency.ResolvedArtifactDependency in project quarkus by quarkusio.
the class JBangBuilderImpl method postBuild.
public static Map<String, Object> postBuild(Path appClasses, Path pomFile, List<Map.Entry<String, String>> repositories, List<Map.Entry<String, Path>> dependencies, boolean nativeImage) {
final MavenArtifactResolver quarkusResolver;
try {
final BootstrapMavenContext mvnCtx = new BootstrapMavenContext(BootstrapMavenContext.config().setCurrentProject(pomFile.getParent().toString()));
final List<RemoteRepository> remoteRepos = new ArrayList<>(mvnCtx.getRemoteRepositories());
repositories.forEach(repo -> {
remoteRepos.add(new RemoteRepository.Builder(repo.getKey(), "default", repo.getValue()).build());
});
quarkusResolver = MavenArtifactResolver.builder().setRepositorySystem(mvnCtx.getRepositorySystem()).setRepositorySystemSession(mvnCtx.getRepositorySystemSession()).setRemoteRepositoryManager(mvnCtx.getRemoteRepositoryManager()).setRemoteRepositories(remoteRepos).build();
} catch (BootstrapMavenException e) {
throw new IllegalStateException("Failed to initialize Quarkus bootstrap Maven resolver", e);
}
try {
Path target = Files.createTempDirectory("quarkus-jbang");
final ResolvedArtifactDependency appArtifact = new ResolvedArtifactDependency("dev.jbang.user", "quarkus", null, "jar", "999-SNAPSHOT", appClasses);
final QuarkusBootstrap.Builder builder = QuarkusBootstrap.builder().setBaseClassLoader(JBangBuilderImpl.class.getClassLoader()).setMavenArtifactResolver(quarkusResolver).setProjectRoot(pomFile.getParent()).setTargetDirectory(target).setManagingProject(new GACTV("io.quarkus", "quarkus-bom", "", "pom", getQuarkusVersion())).setForcedDependencies(dependencies.stream().map(s -> {
String[] parts = s.getKey().split(":");
Dependency artifact;
if (parts.length == 3) {
artifact = new ArtifactDependency(parts[0], parts[1], null, ArtifactCoords.TYPE_JAR, parts[2]);
} else if (parts.length == 4) {
artifact = new ArtifactDependency(parts[0], parts[1], null, parts[2], parts[3]);
} else if (parts.length == 5) {
artifact = new ArtifactDependency(parts[0], parts[1], parts[3], parts[2], parts[4]);
} else {
throw new RuntimeException("Invalid artifact " + s.getKey());
}
// artifact.setPath(s.getValue());
return artifact;
}).collect(Collectors.toList())).setAppArtifact(appArtifact).setIsolateDeployment(true).setMode(QuarkusBootstrap.Mode.PROD);
CuratedApplication app = builder.build().bootstrap();
if (nativeImage) {
System.setProperty("quarkus.package.type", "native");
}
Map<String, Object> output = new HashMap<>();
app.runInAugmentClassLoader("io.quarkus.deployment.jbang.JBangAugmentorImpl", output);
return output;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations