Search in sources :

Example 1 with WorkspaceModule

use of io.quarkus.bootstrap.workspace.WorkspaceModule in project quarkus by quarkusio.

the class InfoCommandHandler method resolveProjectState.

protected static ProjectState resolveProjectState(ApplicationModel appModel, ExtensionCatalog currentCatalog) {
    final ProjectState.Builder projectBuilder = ProjectState.builder();
    final Collection<ArtifactCoords> importedPlatformBoms = appModel.getPlatforms().getImportedPlatformBoms();
    if (importedPlatformBoms.isEmpty()) {
        return projectBuilder.build();
    }
    final Map<String, ExtensionProvider.Builder> extProviderBuilders = new LinkedHashMap<>(importedPlatformBoms.size());
    importedPlatformBoms.forEach(bom -> {
        projectBuilder.addPlatformBom(bom);
        extProviderBuilders.put(ExtensionProvider.key(bom, true), ExtensionProvider.builder().setArtifact(bom).setPlatform(true));
    });
    final Map<WorkspaceModuleId, ModuleState.Builder> projectModuleBuilders = new HashMap<>();
    final Map<ArtifactKey, List<ModuleState.Builder>> directModuleDeps = new HashMap<>();
    final WorkspaceModule appModule = appModel.getAppArtifact().getWorkspaceModule();
    if (appModule != null) {
        final ModuleState.Builder module = ModuleState.builder().setWorkspaceModule(appModule).setMainModule(true);
        projectModuleBuilders.put(appModule.getId(), module);
        appModule.getDirectDependencies().forEach(d -> directModuleDeps.computeIfAbsent(d.getKey(), dk -> new ArrayList<>()).add(module));
        for (Dependency constraint : appModule.getDirectDependencyConstraints()) {
            if (extProviderBuilders.containsKey(constraint.toCompactCoords())) {
                module.addPlatformBom(constraint);
            }
        }
    }
    for (ResolvedDependency dep : appModel.getDependencies()) {
        if (dep.getWorkspaceModule() != null) {
            projectModuleBuilders.computeIfAbsent(dep.getWorkspaceModule().getId(), k -> {
                final ModuleState.Builder module = ModuleState.builder().setWorkspaceModule(dep.getWorkspaceModule());
                dep.getWorkspaceModule().getDirectDependencies().forEach(d -> directModuleDeps.computeIfAbsent(d.getKey(), dk -> new ArrayList<>()).add(module));
                return module;
            });
        }
    }
    final Map<ArtifactKey, TopExtensionDependency.Builder> directExtDeps = new HashMap<>();
    for (ResolvedDependency dep : appModel.getDependencies()) {
        if (dep.isFlagSet(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT)) {
            directExtDeps.put(dep.getKey(), TopExtensionDependency.builder().setResolvedDependency(dep).setTransitive(!directModuleDeps.containsKey(dep.getKey())));
        } else if (dep.isRuntimeExtensionArtifact() && directModuleDeps.containsKey(dep.getKey())) {
            directExtDeps.put(dep.getKey(), TopExtensionDependency.builder().setResolvedDependency(dep));
        }
    }
    if (directExtDeps.isEmpty()) {
        return projectBuilder.build();
    }
    currentCatalog.getExtensions().forEach(e -> {
        final ArtifactKey key = e.getArtifact().getKey();
        final TopExtensionDependency.Builder dep = directExtDeps.get(key);
        if (dep != null) {
            dep.setCatalogMetadata(e);
        }
    });
    for (TopExtensionDependency.Builder extBuilder : directExtDeps.values()) {
        final List<ModuleState.Builder> modules = directModuleDeps.getOrDefault(extBuilder.getKey(), Collections.emptyList());
        final TopExtensionDependency dep = extBuilder.setTransitive(modules.isEmpty()).build();
        projectBuilder.addExtensionDependency(dep);
        for (ModuleState.Builder module : modules) {
            module.addExtensionDependency(dep);
        }
        final ExtensionProvider.Builder provider = extProviderBuilders.computeIfAbsent(dep.getProviderKey(), k -> ExtensionProvider.builder().setOrigin(dep.getOrigin()));
        provider.addExtension(dep);
    }
    for (ExtensionProvider.Builder builder : extProviderBuilders.values()) {
        projectBuilder.addExtensionProvider(builder.build());
    }
    for (ModuleState.Builder builder : projectModuleBuilders.values()) {
        projectBuilder.addModule(builder.build());
    }
    return projectBuilder.build();
}
Also used : ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ExtensionProvider(io.quarkus.devtools.project.state.ExtensionProvider) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) WorkspaceModuleId(io.quarkus.bootstrap.workspace.WorkspaceModuleId) Dependency(io.quarkus.maven.dependency.Dependency) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ModuleState(io.quarkus.devtools.project.state.ModuleState) ProjectState(io.quarkus.devtools.project.state.ProjectState) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) TopExtensionDependency(io.quarkus.devtools.project.state.TopExtensionDependency)

Example 2 with WorkspaceModule

use of io.quarkus.bootstrap.workspace.WorkspaceModule in project quarkus by quarkusio.

the class QuarkusModelBuilderTest method shouldLoadMultiModuleDevModel.

@Test
public void shouldLoadMultiModuleDevModel() throws URISyntaxException, IOException {
    File projectDir = getResourcesProject("builder/multi-module-project");
    final ApplicationModel quarkusModel = QuarkusGradleModelFactory.create(new File(projectDir, "application"), "DEVELOPMENT");
    assertNotNull(quarkusModel);
    assertProjectModule(quarkusModel.getApplicationModule(), new File(projectDir, quarkusModel.getApplicationModule().getId().getArtifactId()), true);
    final Collection<WorkspaceModule> projectModules = quarkusModel.getWorkspaceModules();
    assertEquals(projectModules.size(), 1);
    for (WorkspaceModule p : projectModules) {
        assertProjectModule(p, new File(projectDir, p.getId().getArtifactId()), false);
    }
    final ResolvedDependency appArtifact = quarkusModel.getAppArtifact();
    assertThat(appArtifact).isNotNull();
    assertThat(appArtifact.getWorkspaceModule()).isNotNull();
    final ArtifactSources testSources = appArtifact.getWorkspaceModule().getTestSources();
    assertThat(testSources).isNotNull();
    assertThat(testSources.getSourceDirs().size()).isEqualTo(1);
    final SourceDir testSrcDir = testSources.getSourceDirs().iterator().next();
    assertThat(testSrcDir.getDir()).isEqualTo(projectDir.toPath().resolve("application").resolve("src").resolve("test").resolve("java"));
    assertThat(testSources.getResourceDirs().size()).isEqualTo(1);
    final SourceDir testResourcesDir = testSources.getResourceDirs().iterator().next();
    assertThat(testResourcesDir.getDir()).isEqualTo(projectDir.toPath().resolve("application").resolve("src").resolve("test").resolve("resources"));
}
Also used : SourceDir(io.quarkus.bootstrap.workspace.SourceDir) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with WorkspaceModule

use of io.quarkus.bootstrap.workspace.WorkspaceModule in project quarkus by quarkusio.

the class QuarkusModelBuilderTest method shouldLoadMultiModuleTestModel.

@Test
public void shouldLoadMultiModuleTestModel() throws URISyntaxException, IOException {
    File projectDir = getResourcesProject("builder/multi-module-project");
    final ApplicationModel quarkusModel = QuarkusGradleModelFactory.create(new File(projectDir, "application"), "TEST");
    assertNotNull(quarkusModel);
    assertProjectModule(quarkusModel.getApplicationModule(), new File(projectDir, quarkusModel.getApplicationModule().getId().getArtifactId()), true);
    final Collection<WorkspaceModule> projectModules = quarkusModel.getWorkspaceModules();
    assertEquals(projectModules.size(), 1);
    for (WorkspaceModule p : projectModules) {
        assertProjectModule(p, new File(projectDir, p.getId().getArtifactId()), false);
    }
    final ResolvedDependency appArtifact = quarkusModel.getAppArtifact();
    assertThat(appArtifact).isNotNull();
    assertThat(appArtifact.getWorkspaceModule()).isNotNull();
    final ArtifactSources testSources = appArtifact.getWorkspaceModule().getTestSources();
    assertThat(testSources).isNotNull();
    assertThat(testSources.getSourceDirs().size()).isEqualTo(1);
    final SourceDir testSrcDir = testSources.getSourceDirs().iterator().next();
    assertThat(testSrcDir.getDir()).isEqualTo(projectDir.toPath().resolve("application").resolve("src").resolve("test").resolve("java"));
    assertThat(testSources.getResourceDirs().size()).isEqualTo(1);
    final SourceDir testResourcesDir = testSources.getResourceDirs().iterator().next();
    assertThat(testResourcesDir.getDir()).isEqualTo(projectDir.toPath().resolve("application").resolve("src").resolve("test").resolve("resources"));
}
Also used : SourceDir(io.quarkus.bootstrap.workspace.SourceDir) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with WorkspaceModule

use of io.quarkus.bootstrap.workspace.WorkspaceModule in project quarkus by quarkusio.

the class QuarkusMavenWorkspaceBuilder method toProjectModule.

static WorkspaceModule toProjectModule(MavenProject project) {
    final Build build = project.getBuild();
    final WorkspaceModule.Mutable moduleBuilder = WorkspaceModule.builder().setModuleId(getId(project)).setModuleDir(project.getBasedir().toPath()).setBuildDir(Path.of(build.getDirectory()));
    final Path classesDir = Path.of(build.getOutputDirectory());
    final List<SourceDir> sources = new ArrayList<>(project.getCompileSourceRoots().size());
    project.getCompileSourceRoots().forEach(s -> sources.add(new DefaultSourceDir(Path.of(s), classesDir)));
    final List<SourceDir> resources = new ArrayList<>(build.getResources().size());
    for (Resource r : build.getResources()) {
        resources.add(new DefaultSourceDir(Path.of(r.getDirectory()), r.getTargetPath() == null ? classesDir : Path.of(r.getTargetPath())));
    }
    moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.MAIN, sources, resources));
    final Path testClassesDir = Path.of(build.getTestOutputDirectory());
    final List<SourceDir> testSources = new ArrayList<>(project.getCompileSourceRoots().size());
    project.getTestCompileSourceRoots().forEach(s -> testSources.add(new DefaultSourceDir(Path.of(s), testClassesDir)));
    final List<SourceDir> testResources = new ArrayList<>(build.getTestResources().size());
    for (Resource r : build.getTestResources()) {
        testResources.add(new DefaultSourceDir(Path.of(r.getDirectory()), r.getTargetPath() == null ? testClassesDir : Path.of(r.getTargetPath())));
    }
    moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.TEST, testSources, testResources));
    moduleBuilder.setBuildFile(project.getFile().toPath());
    return moduleBuilder.build();
}
Also used : Path(java.nio.file.Path) DefaultArtifactSources(io.quarkus.bootstrap.workspace.DefaultArtifactSources) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir) SourceDir(io.quarkus.bootstrap.workspace.SourceDir) Build(org.apache.maven.model.Build) ArrayList(java.util.ArrayList) Resource(org.apache.maven.model.Resource) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir)

Example 5 with WorkspaceModule

use of io.quarkus.bootstrap.workspace.WorkspaceModule in project quarkus-platform by quarkusio.

the class QuarkusMavenWorkspaceBuilder method toProjectModule.

static WorkspaceModule toProjectModule(MavenProject project) {
    final Build build = project.getBuild();
    final WorkspaceModule.Mutable moduleBuilder = WorkspaceModule.builder().setModuleId(getId(project)).setModuleDir(project.getBasedir().toPath()).setBuildDir(Path.of(build.getDirectory()));
    final Path classesDir = Path.of(build.getOutputDirectory());
    final List<SourceDir> sources = new ArrayList<>(project.getCompileSourceRoots().size());
    project.getCompileSourceRoots().forEach(s -> sources.add(new DefaultSourceDir(Path.of(s), classesDir)));
    final List<SourceDir> resources = new ArrayList<>(build.getResources().size());
    for (Resource r : build.getResources()) {
        resources.add(new DefaultSourceDir(Path.of(r.getDirectory()), r.getTargetPath() == null ? classesDir : Path.of(r.getTargetPath())));
    }
    moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.MAIN, sources, resources));
    final Path testClassesDir = Path.of(build.getTestOutputDirectory());
    final List<SourceDir> testSources = new ArrayList<>(project.getCompileSourceRoots().size());
    project.getTestCompileSourceRoots().forEach(s -> testSources.add(new DefaultSourceDir(Path.of(s), testClassesDir)));
    final List<SourceDir> testResources = new ArrayList<>(build.getTestResources().size());
    for (Resource r : build.getTestResources()) {
        testResources.add(new DefaultSourceDir(Path.of(r.getDirectory()), r.getTargetPath() == null ? testClassesDir : Path.of(r.getTargetPath())));
    }
    moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.TEST, testSources, testResources));
    moduleBuilder.setBuildFile(project.getFile().toPath());
    return moduleBuilder.build();
}
Also used : Path(java.nio.file.Path) DefaultArtifactSources(io.quarkus.bootstrap.workspace.DefaultArtifactSources) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir) SourceDir(io.quarkus.bootstrap.workspace.SourceDir) Build(org.apache.maven.model.Build) ArrayList(java.util.ArrayList) Resource(org.apache.maven.model.Resource) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir)

Aggregations

WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)13 SourceDir (io.quarkus.bootstrap.workspace.SourceDir)6 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)5 Path (java.nio.file.Path)5 ArtifactSources (io.quarkus.bootstrap.workspace.ArtifactSources)4 ArrayList (java.util.ArrayList)4 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)3 DefaultArtifactSources (io.quarkus.bootstrap.workspace.DefaultArtifactSources)3 DefaultSourceDir (io.quarkus.bootstrap.workspace.DefaultSourceDir)3 File (java.io.File)3 Build (org.apache.maven.model.Build)3 BootstrapDependencyProcessingException (io.quarkus.bootstrap.BootstrapDependencyProcessingException)2 PathCollection (io.quarkus.paths.PathCollection)2 PathTree (io.quarkus.paths.PathTree)2 IOException (java.io.IOException)2 Resource (org.apache.maven.model.Resource)2 Artifact (org.eclipse.aether.artifact.Artifact)2 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 Test (org.junit.jupiter.api.Test)2 AdditionalDependency (io.quarkus.bootstrap.app.AdditionalDependency)1