use of io.quarkus.bootstrap.workspace.DefaultArtifactSources in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method initProjectModule.
private static void initProjectModule(Project project, WorkspaceModule.Mutable module, SourceSet sourceSet, String sourceName, String classifier) {
if (sourceSet == null) {
return;
}
final FileCollection allClassesDirs = sourceSet.getOutput().getClassesDirs();
// some plugins do not add source directories to source sets and they may be missing from sourceSet.getAllJava()
// see https://github.com/quarkusio/quarkus/issues/20755
final List<SourceDir> sourceDirs = new ArrayList<>(1);
final List<SourceDir> resourceDirs = new ArrayList<>(1);
project.getTasks().withType(AbstractCompile.class, t -> {
if (!t.getEnabled()) {
return;
}
final FileTree source = t.getSource();
if (source.isEmpty()) {
return;
}
final File destDir = t.getDestinationDirectory().getAsFile().get();
if (!allClassesDirs.contains(destDir)) {
return;
}
final List<File> srcDirs = new ArrayList<>(1);
source.visit(a -> {
// we are looking for the root dirs containing sources
if (a.getRelativePath().getSegments().length == 1) {
final File srcDir = a.getFile().getParentFile();
if (srcDirs.add(srcDir)) {
DefaultSourceDir sources = new DefaultSourceDir(srcDir.toPath(), destDir.toPath(), Collections.singletonMap("compiler", t.getName()));
sourceDirs.add(sources);
}
}
});
});
final File resourcesOutputDir = sourceSet.getOutput().getResourcesDir();
project.getTasks().withType(ProcessResources.class, t -> {
if (!t.getEnabled()) {
return;
}
final FileCollection source = t.getSource();
if (source.isEmpty()) {
return;
}
if (!t.getDestinationDir().equals(resourcesOutputDir)) {
return;
}
final Path destDir = t.getDestinationDir().toPath();
final List<File> srcDirs = new ArrayList<>(1);
source.getAsFileTree().visit(a -> {
// we are looking for the root dirs containing sources
if (a.getRelativePath().getSegments().length == 1) {
final File srcDir = a.getFile().getParentFile();
if (srcDirs.add(srcDir)) {
resourceDirs.add(new DefaultSourceDir(srcDir.toPath(), destDir));
}
}
});
});
// there could be a task generating resources
if (resourcesOutputDir.exists() && resourceDirs.isEmpty()) {
sourceSet.getResources().getSrcDirs().forEach(srcDir -> resourceDirs.add(new DefaultSourceDir(srcDir.toPath(), resourcesOutputDir.toPath())));
}
module.addArtifactSources(new DefaultArtifactSources(classifier, sourceDirs, resourceDirs));
}
use of io.quarkus.bootstrap.workspace.DefaultArtifactSources 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.DefaultArtifactSources 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();
}
use of io.quarkus.bootstrap.workspace.DefaultArtifactSources in project quarkus by quarkusio.
the class LocalProject method toWorkspaceModule.
public WorkspaceModule toWorkspaceModule() {
if (module != null) {
return module;
}
final WorkspaceModule.Mutable moduleBuilder = WorkspaceModule.builder().setModuleId(new GAV(key.getGroupId(), key.getArtifactId(), getVersion())).setModuleDir(dir).setBuildDir(getOutputDir());
final Build build = (modelBuildingResult == null ? getRawModel() : modelBuildingResult.getEffectiveModel()).getBuild();
boolean addDefaultSourceSet = true;
if (build != null && !build.getPlugins().isEmpty()) {
for (Plugin plugin : build.getPlugins()) {
if (!plugin.getArtifactId().equals("maven-jar-plugin")) {
continue;
}
if (plugin.getExecutions().isEmpty()) {
final DefaultArtifactSources src = processJarPluginExecutionConfig(plugin.getConfiguration(), false);
if (src != null) {
addDefaultSourceSet = false;
moduleBuilder.addArtifactSources(src);
}
} else {
for (PluginExecution e : plugin.getExecutions()) {
DefaultArtifactSources src = null;
if (e.getGoals().contains(ArtifactCoords.TYPE_JAR)) {
src = processJarPluginExecutionConfig(e.getConfiguration(), false);
addDefaultSourceSet &= !e.getId().equals("default-jar");
} else if (e.getGoals().contains("test-jar")) {
src = processJarPluginExecutionConfig(e.getConfiguration(), true);
}
if (src != null) {
moduleBuilder.addArtifactSources(src);
}
}
}
break;
}
}
if (addDefaultSourceSet) {
moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.MAIN, Collections.singletonList(new DefaultSourceDir(getSourcesSourcesDir(), getClassesDir())), collectMainResources(null)));
}
if (!moduleBuilder.hasTestSources()) {
moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.TEST, Collections.singletonList(new DefaultSourceDir(getTestSourcesSourcesDir(), getTestClassesDir())), collectTestResources(null)));
}
moduleBuilder.setBuildFile(getRawModel().getPomFile().toPath());
moduleBuilder.setDependencyConstraints(getRawModel().getDependencyManagement() == null ? Collections.emptyList() : toArtifactDependencies(getRawModel().getDependencyManagement().getDependencies()));
final Model model = modelBuildingResult == null ? rawModel : modelBuildingResult.getEffectiveModel();
moduleBuilder.setDependencies(toArtifactDependencies(model.getDependencies()));
return this.module = moduleBuilder.build();
}
use of io.quarkus.bootstrap.workspace.DefaultArtifactSources in project quarkus by quarkusio.
the class LocalProject method processJarPluginExecutionConfig.
private DefaultArtifactSources processJarPluginExecutionConfig(Object config, boolean test) {
if (config == null || !(config instanceof Xpp3Dom)) {
return null;
}
Xpp3Dom dom = (Xpp3Dom) config;
final List<String> includes = collectChildValues(dom.getChild("includes"));
final List<String> excludes = collectChildValues(dom.getChild("excludes"));
final PathFilter filter = includes == null && excludes == null ? null : new PathFilter(includes, excludes);
final String classifier = getClassifier(dom, test);
final Collection<SourceDir> sources = Collections.singletonList(new DefaultSourceDir(new DirectoryPathTree(test ? getTestSourcesSourcesDir() : getSourcesSourcesDir()), new DirectoryPathTree(test ? getTestClassesDir() : getClassesDir(), filter), Collections.emptyMap()));
final Collection<SourceDir> resources = test ? collectTestResources(filter) : collectMainResources(filter);
return new DefaultArtifactSources(classifier, sources, resources);
}
Aggregations