use of org.gradle.api.artifacts.Configuration in project gradle by gradle.
the class DependencyInsightReportTask method report.
@TaskAction
public void report() {
final Configuration configuration = getConfiguration();
if (configuration == null) {
throw new InvalidUserDataException("Dependency insight report cannot be generated because the input configuration was not specified. " + "\nIt can be specified from the command line, e.g: '" + getPath() + " --configuration someConf --dependency someDep'");
}
if (dependencySpec == null) {
throw new InvalidUserDataException("Dependency insight report cannot be generated because the dependency to show was not specified." + "\nIt can be specified from the command line, e.g: '" + getPath() + " --dependency someDep'");
}
StyledTextOutput output = getTextOutputFactory().create(getClass());
final GraphRenderer renderer = new GraphRenderer(output);
ResolutionResult result = configuration.getIncoming().getResolutionResult();
final Set<DependencyResult> selectedDependencies = new LinkedHashSet<DependencyResult>();
result.allDependencies(new Action<DependencyResult>() {
@Override
public void execute(DependencyResult dependencyResult) {
if (dependencySpec.isSatisfiedBy(dependencyResult)) {
selectedDependencies.add(dependencyResult);
}
}
});
if (selectedDependencies.isEmpty()) {
output.println("No dependencies matching given input were found in " + String.valueOf(configuration));
return;
}
Collection<RenderableDependency> sortedDeps = new DependencyInsightReporter().prepare(selectedDependencies, getVersionSelectorScheme(), getVersionComparator());
NodeRenderer nodeRenderer = new NodeRenderer() {
public void renderNode(StyledTextOutput target, RenderableDependency node, boolean alreadyRendered) {
boolean leaf = node.getChildren().isEmpty();
target.text(leaf ? configuration.getName() : node.getName());
if (alreadyRendered && !leaf) {
target.withStyle(Info).text(" (*)");
}
}
};
LegendRenderer legendRenderer = new LegendRenderer(output);
DependencyGraphRenderer dependencyGraphRenderer = new DependencyGraphRenderer(renderer, nodeRenderer, legendRenderer);
int i = 1;
for (final RenderableDependency dependency : sortedDeps) {
renderer.visit(new RenderDependencyAction(dependency, configuration), true);
dependencyGraphRenderer.render(dependency);
boolean last = i++ == sortedDeps.size();
if (!last) {
output.println();
}
}
legendRenderer.printLegend();
output.println();
output.text("A web-based, searchable dependency report is available by adding the ");
output.withStyle(UserInput).format("--%s", StartParameterBuildOptions.BuildScanOption.LONG_OPTION);
output.println(" option.");
}
use of org.gradle.api.artifacts.Configuration in project gradle by gradle.
the class JacocoPlugin method configureAgentDependencies.
/**
* Configures the agent dependencies using the 'jacocoAnt' configuration. Uses the version declared in 'toolVersion' of the Jacoco extension if no dependencies are explicitly declared.
*
* @param extension the extension that has the tool version to use
*/
private void configureAgentDependencies(JacocoAgentJar jacocoAgentJar, final JacocoPluginExtension extension) {
final Configuration config = project.getConfigurations().getAt(AGENT_CONFIGURATION_NAME);
jacocoAgentJar.setAgentConf(config);
config.defaultDependencies(new Action<DependencySet>() {
@Override
public void execute(DependencySet dependencies) {
dependencies.add(project.getDependencies().create("org.jacoco:org.jacoco.agent:" + extension.getToolVersion()));
}
});
}
use of org.gradle.api.artifacts.Configuration in project gradle by gradle.
the class AntlrPlugin method apply.
public void apply(final Project project) {
project.getPluginManager().apply(JavaPlugin.class);
// set up a configuration named 'antlr' for the user to specify the antlr libs to use in case
// they want a specific version etc.
final Configuration antlrConfiguration = project.getConfigurations().create(ANTLR_CONFIGURATION_NAME).setVisible(false).setDescription("The Antlr libraries to be used for this project.");
antlrConfiguration.defaultDependencies(new Action<DependencySet>() {
@Override
public void execute(DependencySet dependencies) {
dependencies.add(project.getDependencies().create("antlr:antlr:2.7.7@jar"));
}
});
project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);
// Wire the antlr configuration into all antlr tasks
project.getTasks().withType(AntlrTask.class, new Action<AntlrTask>() {
public void execute(AntlrTask antlrTask) {
antlrTask.getConventionMapping().map("antlrClasspath", new Callable<Object>() {
public Object call() throws Exception {
return project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME);
}
});
}
});
project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
public void execute(SourceSet sourceSet) {
// for each source set we will:
// 1) Add a new 'antlr' virtual directory mapping
final AntlrSourceVirtualDirectoryImpl antlrDirectoryDelegate = new AntlrSourceVirtualDirectoryImpl(((DefaultSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory);
new DslObject(sourceSet).getConvention().getPlugins().put(AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
final String srcDir = "src/" + sourceSet.getName() + "/antlr";
antlrDirectoryDelegate.getAntlr().srcDir(srcDir);
sourceSet.getAllSource().source(antlrDirectoryDelegate.getAntlr());
// 2) create an AntlrTask for this sourceSet following the gradle
// naming conventions via call to sourceSet.getTaskName()
final String taskName = sourceSet.getTaskName("generate", "GrammarSource");
AntlrTask antlrTask = project.getTasks().create(taskName, AntlrTask.class);
antlrTask.setDescription("Processes the " + sourceSet.getName() + " Antlr grammars.");
// 3) set up convention mapping for default sources (allows user to not have to specify)
antlrTask.setSource(antlrDirectoryDelegate.getAntlr());
// 4) Set up the Antlr output directory (adding to javac inputs!)
final String outputDirectoryName = project.getBuildDir() + "/generated-src/antlr/" + sourceSet.getName();
final File outputDirectory = new File(outputDirectoryName);
antlrTask.setOutputDirectory(outputDirectory);
sourceSet.getJava().srcDir(outputDirectory);
// 6) register fact that antlr should be run before compiling
project.getTasks().getByName(sourceSet.getCompileJavaTaskName()).dependsOn(taskName);
}
});
}
use of org.gradle.api.artifacts.Configuration in project gradle by gradle.
the class DownloadingScalaToolChain method select.
@Override
public ToolProvider select(ScalaPlatform targetPlatform) {
try {
Configuration scalaClasspath = resolveDependency("org.scala-lang:scala-compiler:" + targetPlatform.getScalaVersion());
Configuration zincClasspath = resolveDependency("com.typesafe.zinc:zinc:" + DefaultScalaToolProvider.DEFAULT_ZINC_VERSION);
Set<File> resolvedScalaClasspath = scalaClasspath.resolve();
Set<File> resolvedZincClasspath = zincClasspath.resolve();
return new DefaultScalaToolProvider(gradleUserHomeDir, daemonWorkingDir, workerDaemonFactory, fileResolver, resolvedScalaClasspath, resolvedZincClasspath);
} catch (ResolveException resolveException) {
return new NotFoundScalaToolProvider(resolveException);
}
}
use of org.gradle.api.artifacts.Configuration in project gradle by gradle.
the class DefaultAutoAppliedPluginHandler method isAlreadyRequestedInBuildScriptBlock.
private static boolean isAlreadyRequestedInBuildScriptBlock(PluginRequestInternal autoAppliedPlugin, ScriptHandler scriptHandler) {
ModuleVersionSelector module = autoAppliedPlugin.getModule();
if (module == null) {
return false;
}
Configuration classpathConfiguration = scriptHandler.getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION);
for (Dependency dependency : classpathConfiguration.getDependencies()) {
if (module.getGroup().equals(dependency.getGroup()) && module.getName().equals(dependency.getName())) {
return true;
}
}
return false;
}
Aggregations