Search in sources :

Example 1 with PluginImplementation

use of org.gradle.api.internal.plugins.PluginImplementation in project gradle by gradle.

the class DefaultPluginRequestApplicator method applyPlugins.

@Override
public void applyPlugins(final PluginRequests requests, final ScriptHandlerInternal scriptHandler, @Nullable final PluginManagerInternal target, final ClassLoaderScope classLoaderScope) {
    if (target == null || requests.isEmpty()) {
        defineScriptHandlerClassScope(scriptHandler, classLoaderScope, Collections.emptyList());
        return;
    }
    // This should move to settings finalization
    pluginRepositoriesProvider.prepareForPluginResolution();
    final PluginResolver effectivePluginResolver = wrapInAlreadyInClasspathResolver(classLoaderScope);
    if (!requests.isEmpty()) {
        addPluginArtifactRepositories(scriptHandler.getRepositories());
    }
    List<Result> results = resolvePluginRequests(requests, effectivePluginResolver);
    final List<Consumer<PluginManagerInternal>> pluginApplyActions = newLinkedList();
    final Map<Result, PluginImplementation<?>> pluginImplsFromOtherLoaders = newLinkedHashMap();
    if (!results.isEmpty()) {
        for (final Result result : results) {
            applyPlugin(result.request, result.found.getPluginId(), new Runnable() {

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

                        @Override
                        public void addLegacy(PluginId pluginId, Object dependencyNotation) {
                            pluginApplyActions.add(target -> applyLegacyPlugin(target, result, pluginId));
                            scriptHandler.addScriptClassPathDependency(dependencyNotation);
                        }

                        @Override
                        public void add(PluginImplementation<?> plugin) {
                            pluginApplyActions.add(target -> applyPlugin(target, result, plugin));
                        }

                        @Override
                        public void addFromDifferentLoader(PluginImplementation<?> plugin) {
                            pluginApplyActions.add(target -> applyPlugin(target, result, plugin));
                            pluginImplsFromOtherLoaders.put(result, plugin);
                        }
                    });
                    String pluginVersion = result.found.getPluginVersion();
                    if (pluginVersion != null) {
                        pluginVersionTracker.setPluginVersionAt(classLoaderScope, result.found.getPluginId().getId(), pluginVersion);
                    }
                }
            });
        }
    }
    defineScriptHandlerClassScope(scriptHandler, classLoaderScope, pluginImplsFromOtherLoaders.values());
    pluginApplyActions.forEach(pluginApplyAction -> pluginApplyAction.accept(target));
}
Also used : PluginResolveContext(org.gradle.plugin.use.resolve.internal.PluginResolveContext) PluginResolver(org.gradle.plugin.use.resolve.internal.PluginResolver) AlreadyOnClasspathPluginResolver(org.gradle.plugin.use.resolve.internal.AlreadyOnClasspathPluginResolver) PluginId(org.gradle.plugin.use.PluginId) PluginResolutionResult(org.gradle.plugin.use.resolve.internal.PluginResolutionResult) Consumer(java.util.function.Consumer) PluginImplementation(org.gradle.api.internal.plugins.PluginImplementation)

Aggregations

Consumer (java.util.function.Consumer)1 PluginImplementation (org.gradle.api.internal.plugins.PluginImplementation)1 PluginId (org.gradle.plugin.use.PluginId)1 AlreadyOnClasspathPluginResolver (org.gradle.plugin.use.resolve.internal.AlreadyOnClasspathPluginResolver)1 PluginResolutionResult (org.gradle.plugin.use.resolve.internal.PluginResolutionResult)1 PluginResolveContext (org.gradle.plugin.use.resolve.internal.PluginResolveContext)1 PluginResolver (org.gradle.plugin.use.resolve.internal.PluginResolver)1