use of io.quarkus.maven.dependency.ArtifactDependency in project quarkus by quarkusio.
the class CascadingConditionalDependenciesTest method assertDeploymentDeps.
@Override
protected void assertDeploymentDeps(Set<Dependency> deploymentDeps) throws Exception {
final Set<Dependency> expected = new HashSet<>();
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-c-deployment", TsArtifact.DEFAULT_VERSION), "compile", DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-a-deployment", TsArtifact.DEFAULT_VERSION), "compile", DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-b-deployment", TsArtifact.DEFAULT_VERSION), "runtime", DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-d-deployment", TsArtifact.DEFAULT_VERSION), "runtime", DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-e-deployment", TsArtifact.DEFAULT_VERSION), "compile", DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-f-deployment", TsArtifact.DEFAULT_VERSION), "runtime", DependencyFlags.DEPLOYMENT_CP));
assertEquals(expected, deploymentDeps);
}
use of io.quarkus.maven.dependency.ArtifactDependency in project quarkus by quarkusio.
the class ConditionalDependencyWithTwoConditionsTest method assertDeploymentDeps.
@Override
protected void assertDeploymentDeps(Set<Dependency> deploymentDeps) throws Exception {
final Set<Dependency> expected = new HashSet<>();
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-c-deployment", TsArtifact.DEFAULT_VERSION), "compile", DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-a-deployment", TsArtifact.DEFAULT_VERSION), "compile", DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-b-deployment", TsArtifact.DEFAULT_VERSION), "runtime", DependencyFlags.DEPLOYMENT_CP));
expected.add(new ArtifactDependency(new GACTV(TsArtifact.DEFAULT_GROUP_ID, "ext-d-deployment", TsArtifact.DEFAULT_VERSION), "compile", DependencyFlags.DEPLOYMENT_CP));
assertEquals(expected, deploymentDeps);
}
use of io.quarkus.maven.dependency.ArtifactDependency in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method collectDependencies.
private void collectDependencies(org.gradle.api.artifacts.ResolvedDependency resolvedDep, LaunchMode mode, Project project, Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies, Set<File> artifactFiles, Set<ArtifactKey> processedModules, ApplicationModelBuilder modelBuilder, WorkspaceModule.Mutable parentModule, byte flags) {
WorkspaceModule.Mutable projectModule = null;
for (ResolvedArtifact a : resolvedDep.getModuleArtifacts()) {
final ArtifactKey artifactKey = toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier());
if (!isDependency(a) || appDependencies.containsKey(artifactKey)) {
continue;
}
final ArtifactCoords depCoords = toArtifactCoords(a);
final ResolvedDependencyBuilder depBuilder = ResolvedDependencyBuilder.newInstance().setCoords(depCoords).setRuntimeCp();
if (isFlagOn(flags, COLLECT_DIRECT_DEPS)) {
depBuilder.setDirect(true);
flags = clearFlag(flags, COLLECT_DIRECT_DEPS);
}
if (parentModule != null) {
parentModule.addDependency(new ArtifactDependency(depCoords));
}
PathCollection paths = null;
if ((LaunchMode.DEVELOPMENT.equals(mode) || LaunchMode.TEST.equals(mode)) && a.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) {
final Project projectDep = project.getRootProject().findProject(((ProjectComponentIdentifier) a.getId().getComponentIdentifier()).getProjectPath());
final JavaPluginConvention javaExtension = projectDep == null ? null : projectDep.getConvention().findPlugin(JavaPluginConvention.class);
final String classifier = a.getClassifier();
if (classifier == null || classifier.isEmpty()) {
final IncludedBuild includedBuild = ToolingUtils.includedBuild(project.getRootProject(), a.getName());
if (includedBuild != null) {
final PathList.Builder pathBuilder = PathList.builder();
addSubstitutedProject(pathBuilder, includedBuild.getProjectDir());
paths = pathBuilder.build();
} else if (javaExtension != null) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, SourceSet.MAIN_SOURCE_SET_NAME, false);
paths = pathBuilder.build();
}
} else if (javaExtension != null) {
if ("test".equals(classifier)) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, SourceSet.TEST_SOURCE_SET_NAME, true);
paths = pathBuilder.build();
} else if ("test-fixtures".equals(classifier)) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, "testFixtures", true);
paths = pathBuilder.build();
}
}
}
depBuilder.setResolvedPaths(paths == null ? PathList.of(a.getFile().toPath()) : paths).setWorkspaceModule(projectModule);
if (processQuarkusDependency(depBuilder, modelBuilder)) {
if (isFlagOn(flags, COLLECT_TOP_EXTENSION_RUNTIME_NODES)) {
depBuilder.setFlags(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
flags = clearFlag(flags, COLLECT_TOP_EXTENSION_RUNTIME_NODES);
}
flags = clearFlag(flags, COLLECT_RELOADABLE_MODULES);
}
if (!isFlagOn(flags, COLLECT_RELOADABLE_MODULES)) {
depBuilder.clearFlag(DependencyFlags.RELOADABLE);
}
appDependencies.put(depBuilder.getKey(), depBuilder);
if (artifactFiles != null) {
artifactFiles.add(a.getFile());
}
}
processedModules.add(new GACT(resolvedDep.getModuleGroup(), resolvedDep.getModuleName()));
for (org.gradle.api.artifacts.ResolvedDependency child : resolvedDep.getChildren()) {
if (!processedModules.contains(new GACT(child.getModuleGroup(), child.getModuleName()))) {
collectDependencies(child, mode, project, appDependencies, artifactFiles, processedModules, modelBuilder, projectModule, flags);
}
}
}
use of io.quarkus.maven.dependency.ArtifactDependency 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.ArtifactDependency 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