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