Search in sources :

Example 11 with ArtifactDependency

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);
}
Also used : ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) Dependency(io.quarkus.maven.dependency.Dependency) GACTV(io.quarkus.maven.dependency.GACTV) HashSet(java.util.HashSet)

Example 12 with ArtifactDependency

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);
}
Also used : ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) Dependency(io.quarkus.maven.dependency.Dependency) GACTV(io.quarkus.maven.dependency.GACTV) HashSet(java.util.HashSet)

Example 13 with ArtifactDependency

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);
        }
    }
}
Also used : PathCollection(io.quarkus.paths.PathCollection) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) ApplicationDeploymentClasspathBuilder(io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder) ApplicationModelBuilder(io.quarkus.bootstrap.model.ApplicationModelBuilder) ParameterizedToolingModelBuilder(org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder) PathList(io.quarkus.paths.PathList) GACT(io.quarkus.maven.dependency.GACT) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder) Project(org.gradle.api.Project) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) DefaultWorkspaceModule(io.quarkus.bootstrap.workspace.DefaultWorkspaceModule) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) IncludedBuild(org.gradle.api.initialization.IncludedBuild)

Example 14 with ArtifactDependency

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);
    }
}
Also used : ResolvedArtifactDependency(io.quarkus.maven.dependency.ResolvedArtifactDependency) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ZipEntry(java.util.zip.ZipEntry) Closeable(java.io.Closeable) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) LocalProject(io.quarkus.bootstrap.resolver.maven.workspace.LocalProject) URL(java.net.URL) Path(java.nio.file.Path) BootstrapMavenContext(io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext) ResolvedArtifactDependency(io.quarkus.maven.dependency.ResolvedArtifactDependency) IOException(java.io.IOException) ResolvedArtifactDependency(io.quarkus.maven.dependency.ResolvedArtifactDependency) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) Dependency(io.quarkus.maven.dependency.Dependency) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) DataInputStream(java.io.DataInputStream) GACTV(io.quarkus.maven.dependency.GACTV) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 15 with ArtifactDependency

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);
    }
}
Also used : Path(java.nio.file.Path) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Files(java.nio.file.Files) ResolvedArtifactDependency(io.quarkus.maven.dependency.ResolvedArtifactDependency) BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver) IOException(java.io.IOException) HashMap(java.util.HashMap) BootstrapMavenContext(io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) List(java.util.List) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) Map(java.util.Map) Dependency(io.quarkus.maven.dependency.Dependency) Path(java.nio.file.Path) GACTV(io.quarkus.maven.dependency.GACTV) InputStream(java.io.InputStream) BootstrapMavenContext(io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext) ResolvedArtifactDependency(io.quarkus.maven.dependency.ResolvedArtifactDependency) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) HashMap(java.util.HashMap) ResolvedArtifactDependency(io.quarkus.maven.dependency.ResolvedArtifactDependency) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ResolvedArtifactDependency(io.quarkus.maven.dependency.ResolvedArtifactDependency) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) Dependency(io.quarkus.maven.dependency.Dependency) GACTV(io.quarkus.maven.dependency.GACTV) BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) IOException(java.io.IOException) BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) CuratedApplication(io.quarkus.bootstrap.app.CuratedApplication) QuarkusBootstrap(io.quarkus.bootstrap.app.QuarkusBootstrap) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver)

Aggregations

ArtifactDependency (io.quarkus.maven.dependency.ArtifactDependency)15 Dependency (io.quarkus.maven.dependency.Dependency)13 GACTV (io.quarkus.maven.dependency.GACTV)12 HashSet (java.util.HashSet)11 TsDependency (io.quarkus.bootstrap.resolver.TsDependency)6 Collectors (java.util.stream.Collectors)6 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)5 TsArtifact (io.quarkus.bootstrap.resolver.TsArtifact)5 TsQuarkusExt (io.quarkus.bootstrap.resolver.TsQuarkusExt)4 DependencyFlags (io.quarkus.maven.dependency.DependencyFlags)4 Set (java.util.Set)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 CuratedApplication (io.quarkus.bootstrap.app.CuratedApplication)3 QuarkusBootstrap (io.quarkus.bootstrap.app.QuarkusBootstrap)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 BootstrapMavenContext (io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext)2 MavenArtifactResolver (io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver)2 BootstrapFromOriginalJarTestBase (io.quarkus.deployment.runnerjar.BootstrapFromOriginalJarTestBase)2 ArtifactCoords (io.quarkus.maven.dependency.ArtifactCoords)2