use of io.quarkus.bootstrap.workspace.DefaultSourceDir in project quarkus by quarkusio.
the class LocalProject method collectTestResources.
private Collection<SourceDir> collectTestResources(PathFilter filter) {
final List<Resource> resources = rawModel.getBuild() == null ? Collections.emptyList() : rawModel.getBuild().getTestResources();
final Path testClassesDir = getTestClassesDir();
if (resources.isEmpty()) {
return Collections.singletonList(new DefaultSourceDir(new DirectoryPathTree(resolveRelativeToBaseDir(null, "src/test/resources")), new DirectoryPathTree(testClassesDir, filter), Collections.emptyMap()));
}
final List<SourceDir> sourceDirs = new ArrayList<>(resources.size());
for (Resource r : resources) {
sourceDirs.add(new DefaultSourceDir(new DirectoryPathTree(resolveRelativeToBaseDir(r.getDirectory(), "src/test/resources")), new DirectoryPathTree((r.getTargetPath() == null ? testClassesDir : testClassesDir.resolve(stripProjectBasedirPrefix(r.getTargetPath(), PROJECT_OUTPUT_DIR))), filter), Collections.emptyMap()));
}
return sourceDirs;
}
use of io.quarkus.bootstrap.workspace.DefaultSourceDir in project quarkus by quarkusio.
the class LocalProject method collectMainResources.
private Collection<SourceDir> collectMainResources(PathFilter filter) {
final List<Resource> resources = rawModel.getBuild() == null ? Collections.emptyList() : rawModel.getBuild().getResources();
final Path classesDir = getClassesDir();
if (resources.isEmpty()) {
return Collections.singletonList(new DefaultSourceDir(new DirectoryPathTree(resolveRelativeToBaseDir(null, "src/main/resources")), new DirectoryPathTree(classesDir, filter), Collections.emptyMap()));
}
final List<SourceDir> sourceDirs = new ArrayList<>(resources.size());
for (Resource r : resources) {
sourceDirs.add(new DefaultSourceDir(new DirectoryPathTree(resolveRelativeToBaseDir(r.getDirectory(), "src/main/resources")), new DirectoryPathTree((r.getTargetPath() == null ? classesDir : classesDir.resolve(stripProjectBasedirPrefix(r.getTargetPath(), PROJECT_OUTPUT_DIR))), filter), Collections.emptyMap()));
}
return sourceDirs;
}
use of io.quarkus.bootstrap.workspace.DefaultSourceDir 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.DefaultSourceDir 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.DefaultSourceDir 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