Search in sources :

Example 1 with ArtifactView

use of org.gradle.api.artifacts.ArtifactView in project gradle by gradle.

the class JacocoReportAggregationPlugin method apply.

@Override
public void apply(Project project) {
    project.getPluginManager().apply("org.gradle.reporting-base");
    project.getPluginManager().apply("jvm-ecosystem");
    project.getPluginManager().apply("jacoco");
    Configuration jacocoAggregation = project.getConfigurations().create(JACOCO_AGGREGATION_CONFIGURATION_NAME);
    jacocoAggregation.setDescription("Collects project dependencies for purposes of JaCoCo coverage report aggregation");
    jacocoAggregation.setVisible(false);
    jacocoAggregation.setCanBeConsumed(false);
    jacocoAggregation.setCanBeResolved(false);
    ObjectFactory objects = project.getObjects();
    Configuration sourceDirectoriesConf = project.getConfigurations().create("allCodeCoverageReportSourceDirectories");
    sourceDirectoriesConf.setDescription("Supplies the source directories used to produce all aggregated JaCoCo coverage data reports");
    sourceDirectoriesConf.extendsFrom(jacocoAggregation);
    sourceDirectoriesConf.setVisible(false);
    sourceDirectoriesConf.setCanBeConsumed(false);
    sourceDirectoriesConf.setCanBeResolved(true);
    sourceDirectoriesConf.attributes(attributes -> {
        attributes.attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.class, Bundling.EXTERNAL));
        attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
        attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.MAIN_SOURCES));
    });
    ArtifactView sourceDirectories = sourceDirectoriesConf.getIncoming().artifactView(view -> {
        view.componentFilter(id -> id instanceof ProjectComponentIdentifier);
        view.lenient(true);
    });
    Configuration classDirectoriesConf = project.getConfigurations().create("allCodeCoverageReportClassDirectories");
    classDirectoriesConf.extendsFrom(jacocoAggregation);
    classDirectoriesConf.setDescription("Supplies the class directories used to produce all aggregated JaCoCo coverage data reports");
    classDirectoriesConf.setVisible(false);
    classDirectoriesConf.setCanBeConsumed(false);
    classDirectoriesConf.setCanBeResolved(true);
    ArtifactView classDirectories = classDirectoriesConf.getIncoming().artifactView(view -> {
        view.componentFilter(id -> id instanceof ProjectComponentIdentifier);
    });
    ReportingExtension reporting = project.getExtensions().getByType(ReportingExtension.class);
    reporting.getReports().registerBinding(JacocoCoverageReport.class, DefaultJacocoCoverageReport.class);
    // iterate and configure each user-specified report, creating a <reportName>ExecutionData configuration for each
    reporting.getReports().withType(JacocoCoverageReport.class).all(report -> {
        // A resolvable configuration to collect JaCoCo coverage data; typically named "testCodeCoverageReportExecutionData"
        Configuration executionDataConf = project.getConfigurations().create(report.getName() + "ExecutionData");
        executionDataConf.extendsFrom(jacocoAggregation);
        executionDataConf.setDescription(String.format("Supplies JaCoCo coverage data to the %s.  External library dependencies may appear as resolution failures, but this is expected behavior.", report.getName()));
        executionDataConf.setVisible(false);
        executionDataConf.setCanBeConsumed(false);
        executionDataConf.setCanBeResolved(true);
        executionDataConf.attributes(attributes -> {
            attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
            attributes.attributeProvider(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, report.getTestType().map(tt -> objects.named(TestSuiteType.class, tt)));
            attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.JACOCO_RESULTS));
        });
        report.getReportTask().configure(task -> {
            Callable<FileCollection> executionData = () -> executionDataConf.getIncoming().artifactView(view -> {
                view.componentFilter(id -> id instanceof ProjectComponentIdentifier);
                view.lenient(true);
            }).getFiles();
            configureReportTaskInputs(task, classDirectories, sourceDirectories, executionData);
        });
    });
    // convention for synthesizing reports based on existing test suites in "this" project
    project.getPlugins().withId("jvm-test-suite", plugin -> {
        // Depend on this project for aggregation
        project.getDependencies().add(JACOCO_AGGREGATION_CONFIGURATION_NAME, project);
        TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
        ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
        testSuites.withType(JvmTestSuite.class).all(testSuite -> {
            reporting.getReports().create(testSuite.getName() + "CodeCoverageReport", JacocoCoverageReport.class, report -> {
                report.getTestType().convention(testSuite.getTestType());
            });
        });
    });
}
Also used : TestSuiteType(org.gradle.api.attributes.TestSuiteType) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Project(org.gradle.api.Project) Category(org.gradle.api.attributes.Category) TestingExtension(org.gradle.testing.base.TestingExtension) Callable(java.util.concurrent.Callable) FileCollection(org.gradle.api.file.FileCollection) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite) Bundling(org.gradle.api.attributes.Bundling) ArtifactView(org.gradle.api.artifacts.ArtifactView) Configuration(org.gradle.api.artifacts.Configuration) TestSuite(org.gradle.testing.base.TestSuite) DefaultJacocoCoverageReport(org.gradle.internal.jacoco.DefaultJacocoCoverageReport) VerificationType(org.gradle.api.attributes.VerificationType) ObjectFactory(org.gradle.api.model.ObjectFactory) ExtensiblePolymorphicDomainObjectContainer(org.gradle.api.ExtensiblePolymorphicDomainObjectContainer) Incubating(org.gradle.api.Incubating) JacocoReport(org.gradle.testing.jacoco.tasks.JacocoReport) Plugin(org.gradle.api.Plugin) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Category(org.gradle.api.attributes.Category) Configuration(org.gradle.api.artifacts.Configuration) DefaultJacocoCoverageReport(org.gradle.internal.jacoco.DefaultJacocoCoverageReport) TestingExtension(org.gradle.testing.base.TestingExtension) VerificationType(org.gradle.api.attributes.VerificationType) FileCollection(org.gradle.api.file.FileCollection) ArtifactView(org.gradle.api.artifacts.ArtifactView) Bundling(org.gradle.api.attributes.Bundling) ObjectFactory(org.gradle.api.model.ObjectFactory) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite) TestSuite(org.gradle.testing.base.TestSuite) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite)

Example 2 with ArtifactView

use of org.gradle.api.artifacts.ArtifactView in project gradle by gradle.

the class DefaultIdeDependencyResolver method getIdeRepoFileDependencies.

public List<IdeExtendedRepoFileDependency> getIdeRepoFileDependencies(Configuration configuration) {
    Set<ResolvedArtifactResult> artifacts = configuration.getIncoming().artifactView(new Action<ArtifactView.ViewConfiguration>() {

        @Override
        public void execute(ArtifactView.ViewConfiguration viewConfiguration) {
            viewConfiguration.lenient(true);
            viewConfiguration.componentFilter(IS_A_MODULE_ID);
        }
    }).getArtifacts().getArtifacts();
    List<IdeExtendedRepoFileDependency> externalDependencies = new ArrayList<IdeExtendedRepoFileDependency>(artifacts.size());
    for (ResolvedArtifactResult artifact : artifacts) {
        ModuleComponentIdentifier moduleId = (ModuleComponentIdentifier) artifact.getId().getComponentIdentifier();
        IdeExtendedRepoFileDependency ideRepoFileDependency = new IdeExtendedRepoFileDependency();
        ideRepoFileDependency.setId(DefaultModuleVersionIdentifier.newId(moduleId.getModuleIdentifier(), moduleId.getVersion()));
        externalDependencies.add(ideRepoFileDependency);
    }
    return externalDependencies;
}
Also used : IdeExtendedRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeExtendedRepoFileDependency) ArrayList(java.util.ArrayList) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) ArtifactView(org.gradle.api.artifacts.ArtifactView)

Example 3 with ArtifactView

use of org.gradle.api.artifacts.ArtifactView in project gradle by gradle.

the class ScalaBasePlugin method configureScalaCompile.

@SuppressWarnings("deprecation")
private void configureScalaCompile(final Project project, final SourceSet sourceSet, final Configuration incrementalAnalysis, final Usage incrementalAnalysisUsage, final ScalaRuntime scalaRuntime) {
    final ScalaSourceDirectorySet scalaSourceSet = sourceSet.getExtensions().getByType(ScalaSourceDirectorySet.class);
    final TaskProvider<ScalaCompile> scalaCompileTask = project.getTasks().register(sourceSet.getCompileTaskName("scala"), ScalaCompile.class, scalaCompile -> {
        JvmPluginsHelper.configureForSourceSet(sourceSet, scalaSourceSet, scalaCompile, scalaCompile.getOptions(), project);
        scalaCompile.setDescription("Compiles the " + scalaSourceSet + ".");
        scalaCompile.setSource(scalaSourceSet);
        scalaCompile.getJavaLauncher().convention(getToolchainTool(project, JavaToolchainService::launcherFor));
        scalaCompile.getAnalysisMappingFile().set(project.getLayout().getBuildDirectory().file("tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".mapping"));
        // cannot compute at task execution time because we need association with source set
        IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
        incrementalOptions.getAnalysisFile().set(project.getLayout().getBuildDirectory().file("tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis"));
        incrementalOptions.getClassfileBackupDir().set(project.getLayout().getBuildDirectory().file("tmp/scala/classfileBackup/" + scalaCompile.getName() + ".bak"));
        final Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
        if (jarTask != null) {
            incrementalOptions.getPublishedCode().set(jarTask.getArchiveFile());
        }
        scalaCompile.getAnalysisFiles().from(incrementalAnalysis.getIncoming().artifactView(new Action<ArtifactView.ViewConfiguration>() {

            @Override
            public void execute(ArtifactView.ViewConfiguration viewConfiguration) {
                viewConfiguration.lenient(true);
                viewConfiguration.componentFilter(new IsProjectComponent());
            }
        }).getFiles());
        // See https://github.com/gradle/gradle/issues/14434.  We do this so that the incrementalScalaAnalysisForXXX configuration
        // is resolved during task graph calculation.  It is not an input, but if we leave it to be resolved during task execution,
        // it can potentially block trying to resolve project dependencies.
        scalaCompile.dependsOn(scalaCompile.getAnalysisFiles());
    });
    JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, scalaSourceSet, project, scalaCompileTask, scalaCompileTask.map(new Transformer<CompileOptions, ScalaCompile>() {

        @Override
        public CompileOptions transform(ScalaCompile scalaCompile) {
            return scalaCompile.getOptions();
        }
    }));
    project.getTasks().named(sourceSet.getClassesTaskName(), new Action<Task>() {

        @Override
        public void execute(Task task) {
            task.dependsOn(scalaCompileTask);
        }
    });
}
Also used : IncrementalCompileOptions(org.gradle.api.tasks.scala.IncrementalCompileOptions) Task(org.gradle.api.Task) ScalaCompile(org.gradle.api.tasks.scala.ScalaCompile) Transformer(org.gradle.api.Transformer) ArtifactView(org.gradle.api.artifacts.ArtifactView) ScalaSourceDirectorySet(org.gradle.api.tasks.ScalaSourceDirectorySet) Jar(org.gradle.jvm.tasks.Jar)

Aggregations

ArtifactView (org.gradle.api.artifacts.ArtifactView)3 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExtensiblePolymorphicDomainObjectContainer (org.gradle.api.ExtensiblePolymorphicDomainObjectContainer)1 Incubating (org.gradle.api.Incubating)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 Transformer (org.gradle.api.Transformer)1 Configuration (org.gradle.api.artifacts.Configuration)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 ResolvedArtifactResult (org.gradle.api.artifacts.result.ResolvedArtifactResult)1 Bundling (org.gradle.api.attributes.Bundling)1 Category (org.gradle.api.attributes.Category)1 TestSuiteType (org.gradle.api.attributes.TestSuiteType)1 VerificationType (org.gradle.api.attributes.VerificationType)1 FileCollection (org.gradle.api.file.FileCollection)1 ObjectFactory (org.gradle.api.model.ObjectFactory)1 JvmTestSuite (org.gradle.api.plugins.jvm.JvmTestSuite)1