Search in sources :

Example 1 with DefaultArtifactSources

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));
}
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 2 with DefaultArtifactSources

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

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

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();
}
Also used : DefaultArtifactSources(io.quarkus.bootstrap.workspace.DefaultArtifactSources) PluginExecution(org.apache.maven.model.PluginExecution) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) GAV(io.quarkus.maven.dependency.GAV) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir) Plugin(org.apache.maven.model.Plugin)

Example 5 with DefaultArtifactSources

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);
}
Also used : DefaultArtifactSources(io.quarkus.bootstrap.workspace.DefaultArtifactSources) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) PathFilter(io.quarkus.paths.PathFilter) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir) SourceDir(io.quarkus.bootstrap.workspace.SourceDir) DirectoryPathTree(io.quarkus.paths.DirectoryPathTree) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir)

Aggregations

DefaultArtifactSources (io.quarkus.bootstrap.workspace.DefaultArtifactSources)5 DefaultSourceDir (io.quarkus.bootstrap.workspace.DefaultSourceDir)5 SourceDir (io.quarkus.bootstrap.workspace.SourceDir)4 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Build (org.apache.maven.model.Build)3 Resource (org.apache.maven.model.Resource)2 GAV (io.quarkus.maven.dependency.GAV)1 DirectoryPathTree (io.quarkus.paths.DirectoryPathTree)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