Search in sources :

Example 1 with DependencyHandler

use of org.gradle.api.artifacts.dsl.DependencyHandler in project gradle-eta by typelead.

the class DefaultEtaConfiguration method doResolve.

public void doResolve(final Project project, final DependencyHandler handler, final ImmutableDAG<String, PackageInfo> dependencyGraph, Set<String> resolvedDependencies) {
    final Logger logger = project.getLogger();
    final String configurationName = parentConfiguration.getName();
    Set<String> resolvedDeps = new HashSet<String>();
    for (Configuration configuration : parentConfiguration.getExtendsFrom()) {
        DefaultEtaConfiguration etaConfiguration = ExtensionHelper.getExtension(configuration, DefaultEtaConfiguration.class);
        etaConfiguration.doResolve(project, handler, dependencyGraph, resolvedDeps);
    }
    List<String> keys = new ArrayList<String>();
    for (EtaDependency dep : dependencies) {
        if (dep instanceof HasPackageName) {
            keys.add(((HasPackageName) dep).getPackageName());
        }
    }
    if (!resolved.get() && resolved.compareAndSet(false, true)) {
        logger.info("Resolving Eta Configuration '" + parentConfiguration.getIncoming().getPath() + "'");
        List<PackageInfo> packageInfos = dependencyGraph.differenceClosure(keys, resolvedDeps);
        if (packageInfos.size() > 0) {
            mavenRepository.installPackages(packageInfos, dependencyGraph);
            resolvedMavenDependencies = packageInfos.stream().filter(packageInfo -> keys.contains(packageInfo.getName())).map(mavenRepository::getMavenDependency).collect(Collectors.toList());
            for (String mavenDep : resolvedMavenDependencies) {
                handler.add(configurationName, mavenDep);
                logger.info("Injecting maven dependency '" + mavenDep + "'");
            }
        } else {
            resolvedMavenDependencies = Collections.emptyList();
        }
    }
    resolvedDependencies.addAll(resolvedDeps);
    resolvedDependencies.addAll(keys);
}
Also used : DomainObjectCollection(org.gradle.api.DomainObjectCollection) ExtensionHelper(com.typelead.gradle.utils.ExtensionHelper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FileCollection(org.gradle.api.file.FileCollection) Logger(org.gradle.api.logging.Logger) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Configuration(org.gradle.api.artifacts.Configuration) Provider(org.gradle.api.provider.Provider) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) ConfigurationUtils(com.typelead.gradle.eta.internal.ConfigurationUtils) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Map(java.util.Map) EtaBasePlugin(com.typelead.gradle.eta.plugins.EtaBasePlugin) LinkedHashSet(java.util.LinkedHashSet) ImmutableDAG(com.typelead.gradle.utils.ImmutableDAG) Project(org.gradle.api.Project) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) HasPackageName(com.typelead.gradle.eta.api.HasPackageName) PackageInfo(com.typelead.gradle.utils.PackageInfo) GradleException(org.gradle.api.GradleException) EtlasMavenRepository(com.typelead.gradle.eta.internal.EtlasMavenRepository) Collections(java.util.Collections) Dependency(org.gradle.api.artifacts.Dependency) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Configuration(org.gradle.api.artifacts.Configuration) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) PackageInfo(com.typelead.gradle.utils.PackageInfo) ArrayList(java.util.ArrayList) Logger(org.gradle.api.logging.Logger) HasPackageName(com.typelead.gradle.eta.api.HasPackageName) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with DependencyHandler

use of org.gradle.api.artifacts.dsl.DependencyHandler in project component-runtime by Talend.

the class TaCoKitPlugin method apply.

@Override
public void apply(final Project project) {
    // setup the global config
    project.getExtensions().add("talendComponentKit", TaCoKitExtension.class);
    // ensure we can find our dependencies
    project.afterEvaluate(actionProject -> actionProject.getRepositories().mavenCentral());
    // create the configuration for our task execution
    final Configuration configuration = project.getConfigurations().maybeCreate("talendComponentKit");
    configuration.getIncoming().beforeResolve(resolvableDependencies -> {
        TaCoKitExtension extension = TaCoKitExtension.class.cast(project.getExtensions().findByName("talendComponentKit"));
        if (extension == null) {
            extension = new TaCoKitExtension();
        }
        final DependencyHandler dependencyHandler = project.getDependencies();
        final DependencySet dependencies = configuration.getDependencies();
        dependencies.add(dependencyHandler.create("org.talend.sdk.component:component-api:" + extension.getApiVersion()));
        dependencies.add(dependencyHandler.create("org.talend.sdk.component:component-tools:" + extension.getSdkVersion()));
        dependencies.add(dependencyHandler.create("org.talend.sdk.component:component-runtime-design-extension:" + extension.getSdkVersion()));
    });
    // create the web configuration for our web task
    final Configuration webConfiguration = project.getConfigurations().maybeCreate("talendComponentKitWeb");
    webConfiguration.getIncoming().beforeResolve(resolvableDependencies -> {
        TaCoKitExtension extension = TaCoKitExtension.class.cast(project.getExtensions().findByName("talendComponentKitWeb"));
        if (extension == null) {
            extension = new TaCoKitExtension();
        }
        final DependencyHandler dependencyHandler = project.getDependencies();
        final DependencySet dependencies = configuration.getDependencies();
        dependencies.add(dependencyHandler.create("org.talend.sdk.component:component-tools-webapp:" + extension.getSdkVersion()));
    });
    // tasks
    final String group = "Talend Component Kit";
    // TALEND-INF/dependencies.txt
    project.task(new HashMap<String, Object>() {

        {
            put("type", DependenciesTask.class);
            put("group", group);
            put("description", "Creates the Talend Component Kit dependencies file used by the runtime to build the component classloader");
        }
    }, "talendComponentKitDependencies");
    project.afterEvaluate(p -> p.getTasksByName("compileJava", false).stream().findFirst().ifPresent(compileJava -> compileJava.setFinalizedBy(singleton("talendComponentKitDependencies"))));
    // validation
    project.task(new HashMap<String, Object>() {

        {
            put("type", ValidateTask.class);
            put("group", group);
            put("description", "Validates that the module components are respecting the component standards.");
        }
    }, "talendComponentKitValidation");
    project.afterEvaluate(p -> p.getTasksByName("classes", false).stream().findFirst().ifPresent(compileJava -> compileJava.setFinalizedBy(singleton("talendComponentKitValidation"))));
    // documentation
    project.task(new HashMap<String, Object>() {

        {
            put("type", DocumentationTask.class);
            put("group", group);
            put("description", "Generates an asciidoc file with the documentation of the components.");
        }
    }, "talendComponentKitDocumentation");
    project.afterEvaluate(p -> p.getTasksByName("classes", false).stream().findFirst().ifPresent(compileJava -> compileJava.setFinalizedBy(singleton("talendComponentKitDocumentation"))));
    // web
    project.task(new HashMap<String, Object>() {

        {
            put("type", WebTask.class);
            put("group", group);
            put("description", "Starts a web server allowing you to browse your components (requires the component to be installed before).");
        }
    }, "talendComponentKitWebServer");
    // car
    project.task(new HashMap<String, Object>() {

        {
            put("type", CarTask.class);
            put("group", group);
            put("description", "Creates a Component ARchive (.car) based on current project.");
        }
    }, "talendComponentKitComponentArchive");
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) Collections.singleton(java.util.Collections.singleton) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Project(org.gradle.api.Project) HashMap(java.util.HashMap) DependencySet(org.gradle.api.artifacts.DependencySet) Plugin(org.gradle.api.Plugin) Configuration(org.gradle.api.artifacts.Configuration) DependencySet(org.gradle.api.artifacts.DependencySet) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler)

Example 3 with DependencyHandler

use of org.gradle.api.artifacts.dsl.DependencyHandler in project atlas by alibaba.

the class AtlasConfigurationHelper method registAtlasStreams.

// public void configDexPatchTasksAfterEvaluate() {
// if (PluginTypeUtils.isAppProject(project)) {
// AppExtension appExtension = DefaultGroovyMethods.asType(DefaultGroovyMethods.getAt(
// project.getExtensions(),
// "android"), AppExtension.class);
// new DexPatchTaskManager(AtlasBuildContext.androidBuilderMap.get(project),
// appExtension,
// project,
// atlasExtension).run();
// }
// 
// }
public void registAtlasStreams() {
    DependencyHandler dependencyHandler = project.getDependencies();
    final String explodedAwbType = AtlasAndroidArtifacts.TYPE_EXPLODED_AWB;
    final String explodedApType = AtlasAndroidArtifacts.TYPE_EXPLODED_AP;
    final String explodedSolibType = AtlasAndroidArtifacts.TYPE_EXPLODED_SOLIB;
    dependencyHandler.registerTransform(reg -> {
        reg.getFrom().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_AWB);
        reg.getTo().attribute(ARTIFACT_FORMAT, explodedAwbType);
        reg.artifactTransform(ExtractAwbTransform.class);
    });
    for (AndroidArtifacts.ArtifactType transformTarget : AarTransform.getTransformTargets()) {
        dependencyHandler.registerTransform(reg -> {
            reg.getFrom().attribute(ARTIFACT_FORMAT, explodedAwbType);
            reg.getTo().attribute(ARTIFACT_FORMAT, transformTarget.getType());
            reg.artifactTransform(AarTransform.class, config -> config.params(transformTarget));
        });
    }
    dependencyHandler.registerTransform(reg -> {
        reg.getFrom().attribute(ARTIFACT_FORMAT, explodedAwbType);
        reg.getTo().attribute(ARTIFACT_FORMAT, AndroidArtifacts.ArtifactType.SYMBOL_LIST_WITH_PACKAGE_NAME.getType());
        reg.artifactTransform(LibrarySymbolTableTransform.class);
    });
    dependencyHandler.registerTransform(reg -> {
        reg.getFrom().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_AP);
        reg.getTo().attribute(ARTIFACT_FORMAT, explodedApType);
        reg.artifactTransform(ExtractApTransform.class);
    });
    dependencyHandler.registerTransform(reg -> {
        reg.getFrom().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_SOLIB);
        reg.getTo().attribute(ARTIFACT_FORMAT, explodedSolibType);
        reg.artifactTransform(ExtractSolibTransform.class);
    });
    dependencyHandler.registerTransform(reg -> {
        reg.getFrom().attribute(ARTIFACT_FORMAT, explodedSolibType);
        reg.getTo().attribute(ARTIFACT_FORMAT, AndroidArtifacts.ArtifactType.JNI.getType());
        reg.artifactTransform(LoadSolibTransform.class);
    });
    dependencyHandler.registerTransform(reg -> {
        reg.getFrom().attribute(ARTIFACT_FORMAT, explodedAwbType);
        reg.getTo().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_LIBS);
        reg.artifactTransform(LoadSolibFromLibsTransform.class);
    });
    dependencyHandler.registerTransform(reg -> {
        reg.getFrom().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.AtlasArtifactType.EXPLODED_AAR.getType());
        reg.getTo().attribute(ARTIFACT_FORMAT, AtlasAndroidArtifacts.TYPE_LIBS);
        reg.artifactTransform(LoadSolibFromLibsTransform.class);
    });
}
Also used : DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) AtlasAndroidArtifacts(com.android.build.gradle.internal.publishing.AtlasAndroidArtifacts) AndroidArtifacts(com.android.build.gradle.internal.publishing.AndroidArtifacts)

Example 4 with DependencyHandler

use of org.gradle.api.artifacts.dsl.DependencyHandler 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 DependencyHandler

use of org.gradle.api.artifacts.dsl.DependencyHandler in project gradle by gradle.

the class PomProjectInitDescriptor method configureClasspath.

@Override
public void configureClasspath(ProjectInternal.DetachedResolver detachedResolver, ObjectFactory objects) {
    DependencyHandler dependencies = detachedResolver.getDependencies();
    Configuration config = detachedResolver.getConfigurations().detachedConfiguration(dependencies.create("org.apache.maven:maven-core:" + MAVEN_VERSION), dependencies.create("org.apache.maven:maven-plugin-api:" + MAVEN_VERSION), dependencies.create("org.apache.maven:maven-compat:" + MAVEN_VERSION), dependencies.create("org.apache.maven.wagon:wagon-http:" + MAVEN_WAGON_VERSION), dependencies.create("org.apache.maven.wagon:wagon-provider-api:" + MAVEN_WAGON_VERSION), dependencies.create("org.eclipse.aether:aether-connector-basic:" + AETHER_VERSION), dependencies.create("org.eclipse.aether:aether-transport-wagon:" + AETHER_VERSION));
    config.getAttributes().attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.class, Usage.JAVA_RUNTIME));
    detachedResolver.getRepositories().mavenCentral();
    mavenClasspath = config;
}
Also used : DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Usage(org.gradle.api.attributes.Usage) Configuration(org.gradle.api.artifacts.Configuration)

Aggregations

DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)18 Configuration (org.gradle.api.artifacts.Configuration)12 Project (org.gradle.api.Project)7 File (java.io.File)6 EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)3 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)3 DependencySet (org.gradle.api.artifacts.DependencySet)3 Usage (org.gradle.api.attributes.Usage)3 FileCollection (org.gradle.api.file.FileCollection)3 AndroidArtifacts (com.android.build.gradle.internal.publishing.AndroidArtifacts)2 AtlasAndroidArtifacts (com.android.build.gradle.internal.publishing.AtlasAndroidArtifacts)2 EtlasCommand (com.typelead.gradle.utils.EtlasCommand)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 Callable (java.util.concurrent.Callable)2 Action (org.gradle.api.Action)2 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 AttributeContainer (org.gradle.api.attributes.AttributeContainer)2