use of org.gradle.plugin.use.resolve.internal.PluginResolver 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());
}
}
});
}
}
Aggregations