Search in sources :

Example 1 with DependencySet

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

the class JacocoPlugin method configureTaskClasspathDefaults.

/**
     * Configures the classpath for Jacoco tasks using the 'jacocoAnt' configuration. Uses the version information declared in 'toolVersion' of the Jacoco extension if no dependencies are explicitly
     * declared.
     *
     * @param extension the JacocoPluginExtension
     */
private void configureTaskClasspathDefaults(final JacocoPluginExtension extension) {
    final Configuration config = this.project.getConfigurations().getAt(ANT_CONFIGURATION_NAME);
    project.getTasks().withType(JacocoBase.class, new Action<JacocoBase>() {

        @Override
        public void execute(JacocoBase task) {
            ((IConventionAware) task).getConventionMapping().map("jacocoClasspath", Callables.returning(config));
        }
    });
    config.defaultDependencies(new Action<DependencySet>() {

        @Override
        public void execute(DependencySet dependencies) {
            dependencies.add(project.getDependencies().create("org.jacoco:org.jacoco.ant:" + extension.getToolVersion()));
        }
    });
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) DependencySet(org.gradle.api.artifacts.DependencySet) JacocoBase(org.gradle.testing.jacoco.tasks.JacocoBase) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 2 with DependencySet

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

the class CoffeeScriptBasePlugin method addJsConfiguration.

private Configuration addJsConfiguration(ConfigurationContainer configurations, final DependencyHandler dependencies, final CoffeeScriptExtension extension) {
    Configuration configuration = configurations.create(CoffeeScriptExtension.JS_CONFIGURATION_NAME);
    configuration.defaultDependencies(new Action<DependencySet>() {

        @Override
        public void execute(DependencySet configDependencies) {
            String notation = CoffeeScriptExtension.DEFAULT_JS_DEPENDENCY_GROUP + ":" + CoffeeScriptExtension.DEFAULT_JS_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 3 with DependencySet

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

the class UnresolvableConfigurationResult method getChildren.

@Override
public Set<? extends RenderableDependency> getChildren() {
    final DependencySet dependencies = configuration.getDependencies();
    if (dependencies.isEmpty()) {
        return Collections.emptySet();
    }
    Set<RenderableDependency> children = Sets.newLinkedHashSet();
    for (final Dependency dependency : dependencies) {
        children.add(new RenderableDependency() {

            @Override
            public Object getId() {
                return dependency;
            }

            @Override
            public String getName() {
                String label;
                if (dependency instanceof ProjectDependency) {
                    label = "project " + dependency.getName();
                } else {
                    label = Joiner.on(":").join(Iterables.filter(Arrays.asList(dependency.getGroup(), dependency.getName(), dependency.getVersion()), Predicates.<String>notNull()));
                }
                return label;
            }

            @Override
            public String getDescription() {
                return null;
            }

            @Override
            public ResolutionState getResolutionState() {
                return ResolutionState.UNRESOLVED;
            }

            @Override
            public Set<? extends RenderableDependency> getChildren() {
                return Collections.emptySet();
            }
        });
    }
    return children;
}
Also used : Set(java.util.Set) DependencySet(org.gradle.api.artifacts.DependencySet) DependencySet(org.gradle.api.artifacts.DependencySet) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Dependency(org.gradle.api.artifacts.Dependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 4 with DependencySet

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

the class TomEEEmbeddedPlugin method apply.

@Override
public void apply(final Project project) {
    final List<String> extensions = asList(TomEEEmbeddedExtension.NAME, TomEEEmbeddedExtension.ALIAS);
    for (final String name : extensions) {
        project.getExtensions().create(name, TomEEEmbeddedExtension.class);
    }
    project.afterEvaluate(new Action<Project>() {

        @Override
        public void execute(final Project actionProject) {
            for (final String name : extensions) {
                final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(actionProject.getExtensions().findByName(name));
                if (extension == null) {
                    return;
                }
                if (extension.isSkipDefaultRepository() != null && !extension.isSkipDefaultRepository()) {
                    actionProject.getRepositories().mavenCentral();
                    return;
                }
            }
            actionProject.getRepositories().mavenCentral();
        }
    });
    String configName = TomEEEmbeddedExtension.ALIAS;
    try {
        project.getConfigurations().getByName(configName);
    } catch (final UnknownConfigurationException uce) {
        configName = TomEEEmbeddedExtension.NAME;
    }
    final Configuration configuration = project.getConfigurations().maybeCreate(configName);
    configuration.getIncoming().beforeResolve(new Action<ResolvableDependencies>() {

        @Override
        public void execute(final ResolvableDependencies resolvableDependencies) {
            String tomeeVersion = null;
            for (final String name : extensions) {
                final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(project.getExtensions().findByName(name));
                if (extension == null) {
                    return;
                }
                tomeeVersion = extension.getTomeeVersion();
                if (tomeeVersion != null) {
                    break;
                }
            }
            if (tomeeVersion == null) {
                try {
                    try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/maven/org.apache.tomee.gradle/tomee-embedded/pom.properties")) {
                        final Properties p = new Properties();
                        p.load(is);
                        tomeeVersion = p.getProperty("version");
                    }
                } catch (final IOException e) {
                    // we should never be there
                    tomeeVersion = "7.0.2";
                }
            }
            final DependencyHandler dependencyHandler = project.getDependencies();
            final DependencySet dependencies = configuration.getDependencies();
            dependencies.add(dependencyHandler.create("org.apache.tomee:tomee-embedded:" + tomeeVersion));
        }
    });
    project.task(new HashMap<String, Object>() {

        {
            put("type", TomEEEmbeddedTask.class);
            put("group", "Embedded Application Server");
            put("description", "Start an embedded Apache TomEE server deploying application classpath");
        }
    }, TomEEEmbeddedExtension.NAME);
}
Also used : UnknownConfigurationException(org.gradle.api.artifacts.UnknownConfigurationException) Configuration(org.gradle.api.artifacts.Configuration) InputStream(java.io.InputStream) DependencySet(org.gradle.api.artifacts.DependencySet) IOException(java.io.IOException) Properties(java.util.Properties) ResolvableDependencies(org.gradle.api.artifacts.ResolvableDependencies) Project(org.gradle.api.Project) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler)

Example 5 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)8 Configuration (org.gradle.api.artifacts.Configuration)7 Dependency (org.gradle.api.artifacts.Dependency)4 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)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 DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)1 IConventionAware (org.gradle.api.internal.IConventionAware)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