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());
}
}
});
}
}
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;
}
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);
}
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));
}
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());
}
}
Aggregations