Search in sources :

Example 1 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class DefaultPluginManager method addPluginInternal.

// if the plugin has already been added
@Nullable
private Runnable addPluginInternal(final PluginImplementation<?> plugin) {
    final Class<?> pluginClass = plugin.asClass();
    if (plugins.containsKey(pluginClass)) {
        return null;
    }
    plugins.put(pluginClass, plugin);
    return new Runnable() {

        @Override
        public void run() {
            // Take a copy because adding to an idMappings value may result in new mappings being added (i.e. ConcurrentModificationException)
            Iterable<PluginId> pluginIds = Lists.newArrayList(idMappings.keySet());
            for (PluginId id : pluginIds) {
                if (plugin.isAlsoKnownAs(id)) {
                    idMappings.get(id).add(new PluginWithId(id, pluginClass));
                }
            }
        }
    };
}
Also used : PluginId(org.gradle.plugin.use.PluginId) DefaultPluginId(org.gradle.plugin.use.internal.DefaultPluginId) Nullable(javax.annotation.Nullable)

Example 2 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class TypeValidationProblemRenderer method introductionFor.

private static String introductionFor(TypeValidationProblemLocation location) {
    StringBuilder builder = new StringBuilder();
    Class<?> rootType = location.getType().filter(TypeValidationProblemRenderer::shouldRenderType).orElse(null);
    PluginId pluginId = location.getPlugin().orElse(null);
    if (rootType != null) {
        if (pluginId != null) {
            builder.append("In plugin '").append(pluginId).append("' type '");
        } else {
            builder.append("Type '");
        }
        builder.append(ModelType.of(rootType).getName());
        builder.append("' ");
    }
    String property = location.getPropertyName().orElse(null);
    if (property != null) {
        if (rootType == null) {
            if (pluginId != null) {
                builder.append("In plugin '").append(pluginId).append("' property '");
            } else {
                builder.append("Property '");
            }
        } else {
            builder.append("property '");
        }
        location.getParentPropertyName().ifPresent(parentProperty -> {
            builder.append(parentProperty);
            builder.append('.');
        });
        builder.append(property);
        builder.append("' ");
    }
    return builder.toString();
}
Also used : PluginId(org.gradle.plugin.use.PluginId)

Example 3 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class ExternalPluginValidationPlugin method configurePluginValidation.

private void configurePluginValidation(Project project, TaskProvider<Task> lifecycleTask, PluginRegistry registry, Map<String, List<File>> jarsByPlugin, Plugin<?> plugin) {
    Class<?> pluginClass = plugin.getClass();
    if (isExternal(pluginClass)) {
        Optional<PluginId> pluginForClass = registry.findPluginForClass(pluginClass);
        String pluginId;
        pluginId = pluginForClass.map(PluginId::getId).orElseGet(() -> computePluginName(plugin));
        File pluginJar = findPluginJar(pluginClass);
        if (pluginJar != null) {
            jarsByPlugin.computeIfAbsent(pluginId, firstSeenPlugin -> registerValidationTaskForNewPlugin(firstSeenPlugin, project, lifecycleTask)).add(pluginJar);
        } else {
            LOGGER.warn("Validation won't be performed for plugin '{}' because we couldn't locate its jar file", pluginId);
        }
    }
}
Also used : PluginId(org.gradle.plugin.use.PluginId) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) Logger(org.gradle.api.logging.Logger) Inject(javax.inject.Inject) Task(org.gradle.api.Task) Lists(com.google.common.collect.Lists) FileTree(org.gradle.api.file.FileTree) TaskProvider(org.gradle.api.tasks.TaskProvider) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Map(java.util.Map) FileOperations(org.gradle.api.internal.file.FileOperations) Incubating(org.gradle.api.Incubating) Nullable(javax.annotation.Nullable) ValidatePlugins(org.gradle.plugin.devel.tasks.ValidatePlugins) PluginRegistry(org.gradle.api.internal.plugins.PluginRegistry) Project(org.gradle.api.Project) VALIDATE_PLUGIN_TASK_DESCRIPTION(org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin.VALIDATE_PLUGIN_TASK_DESCRIPTION) PLUGIN_DEVELOPMENT_GROUP(org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin.PLUGIN_DEVELOPMENT_GROUP) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) File(java.io.File) ScriptHandlerInternal(org.gradle.api.internal.initialization.ScriptHandlerInternal) List(java.util.List) Logging(org.gradle.api.logging.Logging) CacheableTask(org.gradle.api.tasks.CacheableTask) Optional(java.util.Optional) Plugin(org.gradle.api.Plugin) PluginId(org.gradle.plugin.use.PluginId) File(java.io.File)

Example 4 with PluginId

use of org.gradle.plugin.use.PluginId 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)

Example 5 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class CorePluginResolver method resolve.

@Override
public void resolve(PluginRequestInternal pluginRequest, PluginResolutionResult result) {
    PluginId id = pluginRequest.getId();
    if (!isCorePluginRequest(id)) {
        result.notFound(getDescription(), format("plugin is not in '%s' namespace", CORE_PLUGIN_NAMESPACE));
        return;
    }
    PluginImplementation<?> plugin = pluginRegistry.lookup(id);
    if (plugin == null) {
        result.notFound(getDescription(), format("not a core plugin, please see %s for available core plugins", documentationRegistry.getDocumentationFor("standard_plugins")));
        return;
    }
    validate(pluginRequest);
    result.found(getDescription(), new SimplePluginResolution(plugin));
}
Also used : PluginId(org.gradle.plugin.use.PluginId)

Aggregations

PluginId (org.gradle.plugin.use.PluginId)14 DefaultPluginId (org.gradle.plugin.use.internal.DefaultPluginId)5 Nullable (javax.annotation.Nullable)3 InvalidPluginRequestException (org.gradle.plugin.management.internal.InvalidPluginRequestException)3 Collection (java.util.Collection)2 Map (java.util.Map)2 Optional (java.util.Optional)2 PluginRequestInternal (org.gradle.plugin.management.internal.PluginRequestInternal)2 PluginResolveContext (org.gradle.plugin.use.resolve.internal.PluginResolveContext)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1