Search in sources :

Example 6 with DependencySet

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

the class JsHintPlugin method addConfiguration.

public Configuration addConfiguration(ConfigurationContainer configurations, final DependencyHandler dependencies, final JsHintExtension extension) {
    Configuration configuration = configurations.create(JsHintExtension.CONFIGURATION_NAME);
    configuration.defaultDependencies(new Action<DependencySet>() {

        @Override
        public void execute(DependencySet configDependencies) {
            String notation = JsHintExtension.DEFAULT_DEPENDENCY_GROUP + ":" + JsHintExtension.DEFAULT_DEPENDENCY_MODULE + ":" + extension.getVersion() + "@js";
            Dependency dependency = dependencies.create(notation);
            configDependencies.add(dependency);
        }
    });
    return configuration;
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) DependencySet(org.gradle.api.artifacts.DependencySet) Dependency(org.gradle.api.artifacts.Dependency)

Example 7 with DependencySet

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

the class EnvJsPlugin method addConfiguration.

public Configuration addConfiguration(ConfigurationContainer configurations, final DependencyHandler dependencies, final EnvJsExtension extension) {
    Configuration configuration = configurations.create(EnvJsExtension.CONFIGURATION_NAME);
    configuration.defaultDependencies(new Action<DependencySet>() {

        @Override
        public void execute(DependencySet configDependencies) {
            String notation = EnvJsExtension.DEFAULT_DEPENDENCY_GROUP + ":" + EnvJsExtension.DEFAULT_DEPENDENCY_MODULE + ":" + extension.getVersion() + "@js";
            Dependency dependency = dependencies.create(notation);
            configDependencies.add(dependency);
        }
    });
    return configuration;
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) DependencySet(org.gradle.api.artifacts.DependencySet) Dependency(org.gradle.api.artifacts.Dependency)

Example 8 with DependencySet

use of org.gradle.api.artifacts.DependencySet 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 9 with DependencySet

use of org.gradle.api.artifacts.DependencySet 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)

Aggregations

DependencySet (org.gradle.api.artifacts.DependencySet)9 Configuration (org.gradle.api.artifacts.Configuration)8 Dependency (org.gradle.api.artifacts.Dependency)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)2 File (java.io.File)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Project (org.gradle.api.Project)1 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)1 ResolvableDependencies (org.gradle.api.artifacts.ResolvableDependencies)1 UnknownConfigurationException (org.gradle.api.artifacts.UnknownConfigurationException)1 ResolvedVariantResult (org.gradle.api.artifacts.result.ResolvedVariantResult)1 DslObject (org.gradle.api.internal.plugins.DslObject)1 DefaultSourceSet (org.gradle.api.internal.tasks.DefaultSourceSet)1 AntlrSourceVirtualDirectoryImpl (org.gradle.api.plugins.antlr.internal.AntlrSourceVirtualDirectoryImpl)1 SourceSet (org.gradle.api.tasks.SourceSet)1 JacocoBase (org.gradle.testing.jacoco.tasks.JacocoBase)1