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();
}
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"));
}
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"));
}
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();
}
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();
}
Aggregations