org.gradle.api.Plugin Java Examples

The following examples show how to use org.gradle.api.Plugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Boolean load(@SuppressWarnings("NullableProblems") IdLookupCacheKey key) throws Exception {
    Class<?> pluginClass = key.pluginClass;

    // Plugin registry will have the mapping cached in memory for most plugins, try first
    try {
        Class<? extends Plugin<?>> typeForId = pluginRegistry.getTypeForId(key.id);
        if (typeForId.equals(pluginClass)) {
            return true;
        }
    } catch (UnknownPluginException ignore) {
        // ignore
    }

    PluginDescriptorLocator locator = new ClassloaderBackedPluginDescriptorLocator(pluginClass.getClassLoader());
    PluginDescriptor pluginDescriptor = locator.findPluginDescriptor(key.id);
    return pluginDescriptor != null && pluginDescriptor.getImplementationClassName().equals(pluginClass.getName());
}
 
Example #2
Source Project: Pushjet-Android   Author: Pushjet   File: CorePluginResolver.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void resolve(PluginRequest pluginRequest, PluginResolutionResult result) {
    PluginId id = pluginRequest.getId();

    if (!id.isQualified() || id.inNamespace(CorePluginRegistry.CORE_PLUGIN_NAMESPACE)) {
        try {
            Class<? extends Plugin> typeForId = pluginRegistry.getTypeForId(id.getName());
            if (pluginRequest.getVersion() != null) {
                throw new InvalidPluginRequestException(pluginRequest,
                        "Plugin '" + id + "' is a core Gradle plugin, which cannot be specified with a version number. "
                                + "Such plugins are versioned as part of Gradle. Please remove the version number from the declaration."
                );
            }
            result.found(getDescription(), new SimplePluginResolution(id, typeForId));
        } catch (UnknownPluginException e) {
            result.notFound(getDescription(), String.format("not a core plugin, please see %s for available core plugins", documentationRegistry.getDocumentationFor("standard_plugins")));
        }
    } else {
        result.notFound(getDescription(), String.format("plugin is not in '%s' namespace", CorePluginRegistry.CORE_PLUGIN_NAMESPACE));
    }
}
 
Example #3
Source Project: pushfish-android   Author: PushFish   File: ClassPathPluginResolution.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Class<? extends Plugin> resolve() {
    ClassPath classPath = classPathFactory.create();
    ClassLoaderScope loaderScope = parent.createChild();
    loaderScope.local(classPath);
    loaderScope.lock();
    PluginRegistry pluginRegistry = new DefaultPluginRegistry(loaderScope.getLocalClassLoader(), instantiator);
    return pluginRegistry.getTypeForId(pluginId.toString());
}
 
Example #4
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <P extends Plugin> P findPlugin(Class<P> type) {
    for (Plugin plugin : this) {
        if (plugin.getClass().equals(type)) {
            return type.cast(plugin);
        }
    }
    return null;
}
 
Example #5
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdPluginTest.java    License: Apache License 2.0 5 votes vote down vote up
static Stream<Class<? extends Plugin>> CpdPlugin_shouldAddCpdCheckTaskAsDependencyOfCheckLifecycleTaskIfPluginIsApplied() {
    return Stream.of(
            LifecycleBasePlugin.class,
            BasePlugin.class,
            LanguageBasePlugin.class,
            JavaBasePlugin.class,

            JavaPlugin.class,
            GroovyPlugin.class,
            CppPlugin.class
        );
}
 
Example #6
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Plugin findPlugin(String id) {
    try {
        return findPlugin(getTypeForId(id));
    } catch (UnknownPluginException e) {
        return null;
    }
}
 
Example #7
Source Project: Pushjet-Android   Author: Pushjet   File: ClassPathPluginResolution.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Class<? extends Plugin> resolve() {
    ClassPath classPath = classPathFactory.create();
    ClassLoaderScope loaderScope = parent.createChild();
    loaderScope.local(classPath);
    loaderScope.lock();
    PluginRegistry pluginRegistry = new DefaultPluginRegistry(loaderScope.getLocalClassLoader(), instantiator);
    return pluginRegistry.getTypeForId(pluginId.toString());
}
 
Example #8
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <P extends Plugin<?>> P addPluginInternal(Class<P> type) {
    if (findPlugin(type) == null) {
        Plugin plugin = providePlugin(type);
        for (PluginApplicationAction onApplyAction : pluginApplicationActions) {
            onApplyAction.execute(new PluginApplication(plugin, pluginAware));
        }
        add(plugin);
    }
    return type.cast(findPlugin(type));
}
 
Example #9
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <P extends Plugin> P getPlugin(Class<P> type) throws UnknownPluginException {
    Plugin plugin = findPlugin(type);
    if (plugin == null) {
        throw new UnknownPluginException("Plugin with type " + type + " has not been used.");
    }
    return type.cast(plugin);
}
 
Example #10
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void withId(final String pluginId, Action<? super Plugin> action) {
    matching(new Spec<Plugin>() {
        public boolean isSatisfiedBy(Plugin element) {
            try {
                return idLookupCache.get(new IdLookupCacheKey(element.getClass(), pluginId));
            } catch (ExecutionException e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        }
    }).all(action);
}
 
Example #11
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginRegistry.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends Plugin<?>> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}
 
Example #12
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultPluginRegistry.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends Plugin<?>> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}
 
Example #13
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <P extends Plugin> P getPlugin(Class<P> type) throws UnknownPluginException {
    Plugin plugin = findPlugin(type);
    if (plugin == null) {
        throw new UnknownPluginException("Plugin with type " + type + " has not been used.");
    }
    return type.cast(plugin);
}
 
Example #14
Source Project: pushfish-android   Author: PushFish   File: PluginRegistryPluginResolver.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public PluginResolution resolve(PluginRequest pluginRequest) {
    try {
        Class<? extends Plugin> typeForId = pluginRegistry.getTypeForId(pluginRequest.getId());
        if (pluginRequest.getVersion() != null) {
            throw new InvalidPluginRequestException(
                    "Plugin '" + pluginRequest.getId() + "' is a core Gradle plugin, which cannot be specified with a version number. "
                    + "Such plugins are versioned as part of Gradle. Please remove the version number from the declaration.");
        }
        return new SimplePluginResolution(typeForId);
    } catch (UnknownPluginException e) {
        return null;
    }
}
 
Example #15
Source Project: pushfish-android   Author: PushFish   File: ClassPathPluginResolution.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Class<? extends Plugin> resolve(ClassLoaderScope classLoaderScope) {
    ClassPath classPath = classPathFactory.create();
    ClassLoader classLoader = classLoaderScope.addLocal(classPath);
    PluginRegistry pluginRegistry = new DefaultPluginRegistry(classLoader, instantiator);
    Class<? extends Plugin> typeForId = pluginRegistry.getTypeForId(pluginId);
    return typeForId;
}
 
Example #16
public ObjectConfigurationAction plugin(final Class<? extends Plugin> pluginClass) {
    actions.add(new Runnable() {
        public void run() {
            applyPlugin(pluginClass);
        }
    });
    return this;
}
 
Example #17
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends Plugin> T addPluginInternal(Class<T> type) {
    if (findPlugin(type) == null) {
        Plugin plugin = providePlugin(type);
        add(plugin);
    }
    return type.cast(findPlugin(type));
}
 
Example #18
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Plugin findPlugin(String id) {
    try {
        return findPlugin(getTypeForId(id));
    } catch (UnknownPluginException e) {
        return null;
    }
}
 
Example #19
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends Plugin> T findPlugin(Class<T> type) {
    for (Plugin plugin : this) {
        if (plugin.getClass().equals(type)) {
            return type.cast(plugin);
        }
    }
    return null;
}
 
Example #20
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends Plugin> T addPluginInternal(Class<T> type) {
    if (findPlugin(type) == null) {
        Plugin plugin = providePlugin(type);
        add(plugin);
    }
    return type.cast(findPlugin(type));
}
 
Example #21
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Plugin getPlugin(String id) {
    Plugin plugin = findPlugin(id);
    if (plugin == null) {
        throw new UnknownPluginException("Plugin with id " + id + " has not been used.");
    }
    return plugin;
}
 
Example #22
Source Project: gradle-cpd-plugin   Author: aaschmid   File: CpdPluginTest.java    License: Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource
void CpdPlugin_shouldAddCpdCheckTaskAsDependencyOfCheckLifecycleTaskIfPluginIsApplied(Class<? extends Plugin> pluginClass, Project project, TaskProvider<Cpd> cpdCheck) {
    // When:
    project.getPlugins().apply(pluginClass);

    // Then:
    Task check = project.getTasks().getByName("check");
    @SuppressWarnings("unchecked") Set<Task> dependencies = (Set<Task>) check.getTaskDependencies().getDependencies(check);

    assertThat(check.getDependsOn()).contains(cpdCheck);
    assertThat(dependencies).contains(cpdCheck.get());
}
 
Example #23
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends Plugin> T getPlugin(Class<T> type) throws UnknownPluginException {
    Plugin plugin = findPlugin(type);
    if (plugin == null) {
        throw new UnknownPluginException("Plugin with type " + type + " has not been used.");
    }
    return type.cast(plugin);
}
 
Example #24
Source Project: pushfish-android   Author: PushFish   File: DefaultPluginRegistry.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends Plugin> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}
 
Example #25
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultPluginRegistry.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends Plugin> T loadPlugin(Class<T> pluginClass) {
    if (!Plugin.class.isAssignableFrom(pluginClass)) {
        throw new InvalidUserDataException(String.format(
                "Cannot create plugin of type '%s' as it does not implement the Plugin interface.",
                pluginClass.getSimpleName()));
    }
    try {
        return instantiator.newInstance(pluginClass);
    } catch (ObjectInstantiationException e) {
        throw new PluginInstantiationException(String.format("Could not create plugin of type '%s'.",
                pluginClass.getSimpleName()), e.getCause());
    }
}
 
Example #26
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T extends Plugin> T findPlugin(Class<T> type) {
    for (Plugin plugin : this) {
        if (plugin.getClass().equals(type)) {
            return type.cast(plugin);
        }
    }
    return null;
}
 
Example #27
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultPluginContainer.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Plugin findPlugin(String id) {
    try {
        return findPlugin(getTypeForId(id));
    } catch (UnknownPluginException e) {
        return null;
    }
}
 
Example #28
public ObjectConfigurationAction plugin(final Class<? extends Plugin> pluginClass) {
    actions.add(new Runnable() {
        public void run() {
            applyPlugin(pluginClass);
        }
    });
    return this;
}
 
Example #29
Source Project: Pushjet-Android   Author: Pushjet   File: PluginModelRuleExtractor.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void execute(PluginApplication pluginApplication) {
    Class<? extends Plugin> pluginClass = pluginApplication.getPlugin().getClass();
    Set<Class<?>> sources = inspector.getDeclaredSources(pluginClass);
    if (!sources.isEmpty()) {
        PluginAware target = pluginApplication.getTarget();
        if (!(target instanceof ModelRegistryScope)) {
            throw new UnsupportedOperationException(String.format("Cannot apply model rules of plugin '%s' as the target '%s' is not model rule aware", pluginClass.getName(), target));
        }

        ModelRegistry modelRegistry = ((ModelRegistryScope) target).getModelRegistry();
        for (Class<?> source : sources) {
            inspector.inspect(source, modelRegistry, new PluginRuleSourceDependencies(target));
        }
    }
}
 
Example #30
Source Project: gradle-plugins   Author: freefair   File: MavenPublishWarPlugin.java    License: MIT License 4 votes vote down vote up
@Override
protected Class<? extends Plugin> getPluginClass() {
    return WarPlugin.class;
}