Search in sources :

Example 1 with RepositoryHandler

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

the class DefaultPluginRequestApplicator method applyPlugins.

public void applyPlugins(final PluginRequests requests, final ScriptHandlerInternal scriptHandler, @Nullable final PluginManagerInternal target, ClassLoaderScope classLoaderScope) {
    if (requests.isEmpty()) {
        defineScriptHandlerClassScope(scriptHandler, classLoaderScope, Collections.<PluginImplementation<?>>emptyList());
        return;
    }
    if (target == null) {
        throw new IllegalStateException("Plugin target is 'null' and there are plugin requests");
    }
    final PluginResolver effectivePluginResolver = wrapInNotInClasspathCheck(classLoaderScope);
    List<Result> results = collect(requests, new Transformer<Result, PluginRequestInternal>() {

        public Result transform(PluginRequestInternal request) {
            PluginRequestInternal configuredRequest = pluginResolutionStrategy.applyTo(request);
            return resolveToFoundResult(effectivePluginResolver, configuredRequest);
        }
    });
    // Could be different to ids in the requests as they may be unqualified
    final Map<Result, PluginId> legacyActualPluginIds = Maps.newLinkedHashMap();
    final Map<Result, PluginImplementation<?>> pluginImpls = Maps.newLinkedHashMap();
    final Map<Result, PluginImplementation<?>> pluginImplsFromOtherLoaders = Maps.newLinkedHashMap();
    if (!results.isEmpty()) {
        final RepositoryHandler repositories = scriptHandler.getRepositories();
        for (PluginRepository pluginRepository : pluginRepositoryRegistry.getPluginRepositories()) {
            if (pluginRepository instanceof BackedByArtifactRepositories) {
                ((BackedByArtifactRepositories) pluginRepository).createArtifactRepositories(repositories);
            }
        }
        final List<MavenArtifactRepository> mavenRepos = repositories.withType(MavenArtifactRepository.class);
        final Set<String> repoUrls = Sets.newLinkedHashSet();
        for (final Result result : results) {
            applyPlugin(result.request, result.found.getPluginId(), new Runnable() {

                @Override
                public void run() {
                    result.found.execute(new PluginResolveContext() {

                        public void addLegacy(PluginId pluginId, final String m2RepoUrl, Object dependencyNotation) {
                            repoUrls.add(m2RepoUrl);
                            addLegacy(pluginId, dependencyNotation);
                        }

                        @Override
                        public void addLegacy(PluginId pluginId, Object dependencyNotation) {
                            legacyActualPluginIds.put(result, pluginId);
                            scriptHandler.addScriptClassPathDependency(dependencyNotation);
                        }

                        @Override
                        public void add(PluginImplementation<?> plugin) {
                            pluginImpls.put(result, plugin);
                        }

                        @Override
                        public void addFromDifferentLoader(PluginImplementation<?> plugin) {
                            pluginImplsFromOtherLoaders.put(result, plugin);
                        }
                    });
                }
            });
        }
        for (final String m2RepoUrl : repoUrls) {
            boolean repoExists = any(mavenRepos, new Spec<MavenArtifactRepository>() {

                public boolean isSatisfiedBy(MavenArtifactRepository element) {
                    return element.getUrl().toString().equals(m2RepoUrl);
                }
            });
            if (!repoExists) {
                repositories.maven(new Action<MavenArtifactRepository>() {

                    public void execute(MavenArtifactRepository mavenArtifactRepository) {
                        mavenArtifactRepository.setUrl(m2RepoUrl);
                    }
                });
            }
        }
    }
    defineScriptHandlerClassScope(scriptHandler, classLoaderScope, pluginImplsFromOtherLoaders.values());
    // It won't for arbitrary scripts though.
    for (final Map.Entry<Result, PluginId> entry : legacyActualPluginIds.entrySet()) {
        final PluginRequestInternal request = entry.getKey().request;
        final PluginId id = entry.getValue();
        applyPlugin(request, id, new Runnable() {

            public void run() {
                if (request.isApply()) {
                    target.apply(id.toString());
                }
            }
        });
    }
    for (final Map.Entry<Result, PluginImplementation<?>> entry : Iterables.concat(pluginImpls.entrySet(), pluginImplsFromOtherLoaders.entrySet())) {
        final Result result = entry.getKey();
        applyPlugin(result.request, result.found.getPluginId(), new Runnable() {

            public void run() {
                if (result.request.isApply()) {
                    target.apply(entry.getValue());
                }
            }
        });
    }
}
Also used : PluginResolveContext(org.gradle.plugin.use.resolve.internal.PluginResolveContext) PluginRepository(org.gradle.plugin.repository.PluginRepository) PluginId(org.gradle.plugin.use.PluginId) PluginResolutionResult(org.gradle.plugin.use.resolve.internal.PluginResolutionResult) BackedByArtifactRepositories(org.gradle.plugin.repository.internal.BackedByArtifactRepositories) PluginImplementation(org.gradle.api.internal.plugins.PluginImplementation) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) PluginResolver(org.gradle.plugin.use.resolve.internal.PluginResolver) NotNonCorePluginOnClasspathCheckPluginResolver(org.gradle.plugin.use.resolve.internal.NotNonCorePluginOnClasspathCheckPluginResolver) PluginRequestInternal(org.gradle.plugin.management.internal.PluginRequestInternal) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler) Map(java.util.Map)

Example 2 with RepositoryHandler

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

the class Upload method repositories.

/**
     * Configures the set of repositories to upload to.
     * @since 3.5
     */
public RepositoryHandler repositories(Action<? super RepositoryHandler> configureAction) {
    RepositoryHandler repositories = getRepositories();
    configureAction.execute(repositories);
    return repositories;
}
Also used : RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler)

Example 3 with RepositoryHandler

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

the class PublishingPlugin method apply.

public void apply(final Project project) {
    RepositoryHandler repositories = publicationServices.createRepositoryHandler();
    PublicationContainer publications = instantiator.newInstance(DefaultPublicationContainer.class, instantiator);
    // TODO Registering an extension should register it with the model registry as well
    project.getExtensions().create(PublishingExtension.class, PublishingExtension.NAME, DefaultPublishingExtension.class, repositories, publications);
    Task publishLifecycleTask = project.getTasks().create(PUBLISH_LIFECYCLE_TASK_NAME);
    publishLifecycleTask.setDescription("Publishes all publications produced by this project.");
    publishLifecycleTask.setGroup(PUBLISH_TASK_GROUP);
}
Also used : Task(org.gradle.api.Task) PublicationContainer(org.gradle.api.publish.PublicationContainer) DefaultPublicationContainer(org.gradle.api.publish.internal.DefaultPublicationContainer) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler)

Example 4 with RepositoryHandler

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

the class JvmTestSuiteBasePlugin method configureRuntimeClasspath.

@Finalize
public void configureRuntimeClasspath(@Each JvmTestSuiteBinarySpecInternal testBinary, ServiceRegistry serviceRegistry, ModelSchemaStore modelSchemaStore) {
    ArtifactDependencyResolver dependencyResolver = serviceRegistry.get(ArtifactDependencyResolver.class);
    RepositoryHandler repositories = serviceRegistry.get(RepositoryHandler.class);
    List<ResolutionAwareRepository> resolutionAwareRepositories = CollectionUtils.collect(repositories, Transformers.cast(ResolutionAwareRepository.class));
    ModelSchema<? extends JvmTestSuiteBinarySpec> schema = Cast.uncheckedCast(modelSchemaStore.getSchema(((BinarySpecInternal) testBinary).getPublicType()));
    AttributesSchema attributesSchema = serviceRegistry.get(AttributesSchema.class);
    ImmutableModuleIdentifierFactory moduleIdentifierFactory = serviceRegistry.get(ImmutableModuleIdentifierFactory.class);
    ModuleExclusions moduleExclusions = serviceRegistry.get(ModuleExclusions.class);
    BuildOperationProcessor buildOperationProcessor = serviceRegistry.get(BuildOperationProcessor.class);
    testBinary.setRuntimeClasspath(configureRuntimeClasspath(testBinary, dependencyResolver, resolutionAwareRepositories, schema, attributesSchema, moduleIdentifierFactory, moduleExclusions, buildOperationProcessor));
}
Also used : ArtifactDependencyResolver(org.gradle.api.internal.artifacts.ArtifactDependencyResolver) ImmutableModuleIdentifierFactory(org.gradle.api.internal.artifacts.ImmutableModuleIdentifierFactory) ModuleExclusions(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.ModuleExclusions) BinarySpecInternal(org.gradle.platform.base.internal.BinarySpecInternal) JvmBinarySpecInternal(org.gradle.jvm.internal.JvmBinarySpecInternal) JvmTestSuiteBinarySpecInternal(org.gradle.jvm.test.internal.JvmTestSuiteBinarySpecInternal) ResolutionAwareRepository(org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository) BuildOperationProcessor(org.gradle.internal.operations.BuildOperationProcessor) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler) AttributesSchema(org.gradle.api.attributes.AttributesSchema)

Example 5 with RepositoryHandler

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

the class PluginResolutionServiceResolver method resolvePluginDependencies.

private ClassPath resolvePluginDependencies(final PluginUseMetaData metadata) {
    DependencyResolutionServices resolution = dependencyResolutionServicesFactory.create();
    RepositoryHandler repositories = resolution.getResolveRepositoryHandler();
    final String repoUrl = metadata.implementation.get("repo");
    repositories.maven(new Action<MavenArtifactRepository>() {

        public void execute(MavenArtifactRepository mavenArtifactRepository) {
            mavenArtifactRepository.setUrl(repoUrl);
        }
    });
    Dependency dependency = resolution.getDependencyHandler().create(metadata.implementation.get("gav"));
    ConfigurationContainerInternal configurations = (ConfigurationContainerInternal) resolution.getConfigurationContainer();
    ConfigurationInternal configuration = configurations.detachedConfiguration(dependency);
    try {
        Set<File> files = configuration.getResolvedConfiguration().getFiles(Specs.satisfyAll());
        return new DefaultClassPath(files);
    } catch (ResolveException e) {
        throw new DependencyResolutionException("Failed to resolve all plugin dependencies from " + repoUrl, e.getCause());
    }
}
Also used : ConfigurationContainerInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationContainerInternal) Dependency(org.gradle.api.artifacts.Dependency) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) ResolveException(org.gradle.api.artifacts.ResolveException) DependencyResolutionServices(org.gradle.api.internal.artifacts.DependencyResolutionServices) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler) File(java.io.File) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Aggregations

RepositoryHandler (org.gradle.api.artifacts.dsl.RepositoryHandler)5 MavenArtifactRepository (org.gradle.api.artifacts.repositories.MavenArtifactRepository)2 File (java.io.File)1 Map (java.util.Map)1 Task (org.gradle.api.Task)1 Dependency (org.gradle.api.artifacts.Dependency)1 ResolveException (org.gradle.api.artifacts.ResolveException)1 AttributesSchema (org.gradle.api.attributes.AttributesSchema)1 ArtifactDependencyResolver (org.gradle.api.internal.artifacts.ArtifactDependencyResolver)1 DependencyResolutionServices (org.gradle.api.internal.artifacts.DependencyResolutionServices)1 ImmutableModuleIdentifierFactory (org.gradle.api.internal.artifacts.ImmutableModuleIdentifierFactory)1 ConfigurationContainerInternal (org.gradle.api.internal.artifacts.configurations.ConfigurationContainerInternal)1 ConfigurationInternal (org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)1 ModuleExclusions (org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.ModuleExclusions)1 ResolutionAwareRepository (org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository)1 PluginImplementation (org.gradle.api.internal.plugins.PluginImplementation)1 PublicationContainer (org.gradle.api.publish.PublicationContainer)1 DefaultPublicationContainer (org.gradle.api.publish.internal.DefaultPublicationContainer)1 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)1 BuildOperationProcessor (org.gradle.internal.operations.BuildOperationProcessor)1