Search in sources :

Example 76 with Configuration

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.");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) Configuration(org.gradle.api.artifacts.Configuration) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) DependencyGraphRenderer(org.gradle.api.tasks.diagnostics.internal.graph.DependencyGraphRenderer) NodeRenderer(org.gradle.api.tasks.diagnostics.internal.graph.NodeRenderer) DependencyInsightReporter(org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter) LegendRenderer(org.gradle.api.tasks.diagnostics.internal.graph.LegendRenderer) GraphRenderer(org.gradle.internal.graph.GraphRenderer) DependencyGraphRenderer(org.gradle.api.tasks.diagnostics.internal.graph.DependencyGraphRenderer) InvalidUserDataException(org.gradle.api.InvalidUserDataException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 77 with Configuration

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()));
        }
    });
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) DependencySet(org.gradle.api.artifacts.DependencySet)

Example 78 with Configuration

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);
        }
    });
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) DslObject(org.gradle.api.internal.plugins.DslObject) DependencySet(org.gradle.api.artifacts.DependencySet) Callable(java.util.concurrent.Callable) DefaultSourceSet(org.gradle.api.internal.tasks.DefaultSourceSet) SourceSet(org.gradle.api.tasks.SourceSet) AntlrSourceVirtualDirectoryImpl(org.gradle.api.plugins.antlr.internal.AntlrSourceVirtualDirectoryImpl) DefaultSourceSet(org.gradle.api.internal.tasks.DefaultSourceSet) File(java.io.File)

Example 79 with Configuration

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);
    }
}
Also used : ResolveException(org.gradle.api.artifacts.ResolveException) Configuration(org.gradle.api.artifacts.Configuration) File(java.io.File)

Example 80 with Configuration

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;
}
Also used : ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) Configuration(org.gradle.api.artifacts.Configuration) Dependency(org.gradle.api.artifacts.Dependency)

Aggregations

Configuration (org.gradle.api.artifacts.Configuration)85 Project (org.gradle.api.Project)11 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)11 File (java.io.File)10 Dependency (org.gradle.api.artifacts.Dependency)10 Callable (java.util.concurrent.Callable)9 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)9 ResolvedProjectConfiguration (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration)9 DependencySet (org.gradle.api.artifacts.DependencySet)8 DefaultLenientConfiguration (org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration)7 LinkedHashSet (java.util.LinkedHashSet)6 Usage (org.gradle.api.attributes.Usage)6 Action (org.gradle.api.Action)5 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)4 IConventionAware (org.gradle.api.internal.IConventionAware)4 ArchivePublishArtifact (org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact)4 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)4 Set (java.util.Set)3 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)3