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 File: CorePluginResolver.java    From Pushjet-Android with 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 #2
Source File: DefaultPluginContainer.java    From Pushjet-Android with 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 #3
Source File: DefaultPluginContainer.java    From Pushjet-Android with 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 #4
Source File: CpdPluginTest.java    From gradle-cpd-plugin with 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 #5
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #6
Source File: CpdPluginTest.java    From gradle-cpd-plugin with 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 #7
Source File: ClassPathPluginResolution.java    From Pushjet-Android with 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 File: DefaultPluginRegistry.java    From pushfish-android with 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 #9
Source File: DefaultPluginRegistry.java    From Pushjet-Android with 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 #10
Source File: DefaultPluginContainer.java    From Pushjet-Android with 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 #11
Source File: DefaultPluginContainer.java    From Pushjet-Android with 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 #12
Source File: DefaultPluginContainer.java    From Pushjet-Android with 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 #13
Source File: DefaultObjectConfigurationAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ObjectConfigurationAction plugin(final Class<? extends Plugin> pluginClass) {
    actions.add(new Runnable() {
        public void run() {
            applyPlugin(pluginClass);
        }
    });
    return this;
}
 
Example #14
Source File: PluginModelRuleExtractor.java    From Pushjet-Android with 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 #15
Source File: ClassPathPluginResolution.java    From pushfish-android with 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 #16
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #17
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #18
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #19
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #20
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #21
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #22
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #23
Source File: DefaultPluginRegistry.java    From pushfish-android with 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 #24
Source File: DefaultPluginContainer.java    From Pushjet-Android with 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 #25
Source File: DefaultObjectConfigurationAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ObjectConfigurationAction plugin(final Class<? extends Plugin> pluginClass) {
    actions.add(new Runnable() {
        public void run() {
            applyPlugin(pluginClass);
        }
    });
    return this;
}
 
Example #26
Source File: ClassPathPluginResolution.java    From pushfish-android with 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 #27
Source File: PluginRegistryPluginResolver.java    From pushfish-android with 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 #28
Source File: DefaultPluginRegistry.java    From Pushjet-Android with 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 #29
Source File: DefaultPluginContainer.java    From pushfish-android with 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 #30
Source File: SimplePluginResolution.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class<? extends Plugin> resolve(ClassLoaderScope classLoaderScope) {
    return pluginClass;
}