Search in sources :

Example 1 with DefaultSourceDir

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;
}
Also used : Path(java.nio.file.Path) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir) SourceDir(io.quarkus.bootstrap.workspace.SourceDir) DirectoryPathTree(io.quarkus.paths.DirectoryPathTree) Resource(org.apache.maven.model.Resource) ArrayList(java.util.ArrayList) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir)

Example 2 with DefaultSourceDir

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;
}
Also used : Path(java.nio.file.Path) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir) SourceDir(io.quarkus.bootstrap.workspace.SourceDir) DirectoryPathTree(io.quarkus.paths.DirectoryPathTree) Resource(org.apache.maven.model.Resource) ArrayList(java.util.ArrayList) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir)

Example 3 with DefaultSourceDir

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));
}
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) ArrayList(java.util.ArrayList) FileTree(org.gradle.api.file.FileTree) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir)

Example 4 with DefaultSourceDir

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

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

DefaultSourceDir (io.quarkus.bootstrap.workspace.DefaultSourceDir)7 SourceDir (io.quarkus.bootstrap.workspace.SourceDir)6 DefaultArtifactSources (io.quarkus.bootstrap.workspace.DefaultArtifactSources)5 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Resource (org.apache.maven.model.Resource)4 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)3 DirectoryPathTree (io.quarkus.paths.DirectoryPathTree)3 Build (org.apache.maven.model.Build)3 GAV (io.quarkus.maven.dependency.GAV)1 PathFilter (io.quarkus.paths.PathFilter)1 File (java.io.File)1 Model (org.apache.maven.model.Model)1 Plugin (org.apache.maven.model.Plugin)1 PluginExecution (org.apache.maven.model.PluginExecution)1 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)1 FileCollection (org.gradle.api.file.FileCollection)1 FileTree (org.gradle.api.file.FileTree)1