private void configureExtensionRule() { final ConventionMapping extensionMapping = conventionMappingOf(extension); extensionMapping.map("sourceSets", Callables.returning(new ArrayList())); extensionMapping.map("reportsDir", new Callable<File>() { @Override public File call() { return project.getExtensions().getByType(ReportingExtension.class).file(getReportName()); } }); withBasePlugin(new Action<Plugin>() { @Override public void execute(Plugin plugin) { extensionMapping.map("sourceSets", new Callable<SourceSetContainer>() { @Override public SourceSetContainer call() { return getJavaPluginConvention().getSourceSets(); } }); } }); }
public void apply(final Project project) { project.getPlugins().apply(GitHubPlugin.class); project.getPlugins().apply(BintrayReleasePlugin.class); project.getPlugins().apply(TravisPlugin.class); project.allprojects(new Action<Project>() { public void execute(final Project subproject) { subproject.getPlugins().withId("java", new Action<Plugin>() { @Override public void execute(Plugin plugin) { subproject.getPlugins().apply(JavaBintrayPlugin.class); } }); } }); }
@Override public void apply(final Project project) { project.getPlugins().apply(GitHubContributorsPlugin.class); project.allprojects(new Action<Project>() { public void execute(final Project subproject) { subproject.getPlugins().withType(JavaPublishPlugin.class, new Action<Plugin>() { @Override public void execute(Plugin plugin) { final Task fetcher = project.getTasks().getByName(GitHubContributorsPlugin.FETCH_CONTRIBUTORS); //Because maven-publish plugin uses new configuration model, we cannot get the task directly //So we use 'matching' technique subproject.getTasks().matching(withName(POM_TASK)).all(new Action<Task>() { public void execute(Task t) { t.dependsOn(fetcher); } }); } }); } }); }
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)); } }
@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()); }
private void configureSourceSetRule() { withBasePlugin(new Action<Plugin>() { @Override public void execute(Plugin plugin) { configureForSourceSets(getJavaPluginConvention().getSourceSets()); } }); }
private void configureCheckTask() { withBasePlugin(new Action<Plugin>() { @Override public void execute(Plugin plugin) { configureCheckTaskDependents(); } }); }
private Action<Plugin<Project>> createActionApplyingEclipseWtpPlugin() { return new Action<Plugin<Project>>() { @Override public void execute(Plugin<Project> plugin) { project.getPluginManager().apply(EclipseWtpPlugin.class); } }; }
public ObjectConfigurationAction plugin(final Class<? extends Plugin> pluginClass) { actions.add(new Runnable() { public void run() { applyPlugin(pluginClass); } }); return this; }
public DefaultPluginContainer(PluginRegistry pluginRegistry, final PluginManagerInternal pluginManager) { super(Plugin.class); this.pluginRegistry = pluginRegistry; this.pluginManager = pluginManager; // Need this to make withId() work when someone does project.plugins.add(new SomePlugin()); whenObjectAdded(new Action<Plugin>() { public void execute(Plugin plugin) { pluginManager.addImperativePlugin(plugin.getClass()); } }); }
public Plugin apply(String id) { PluginImplementation plugin = pluginRegistry.lookup(PluginId.unvalidated(id)); if (plugin == null) { throw new UnknownPluginException("Plugin with id '" + id + "' not found."); } if (!Plugin.class.isAssignableFrom(plugin.asClass())) { throw new IllegalArgumentException("Plugin implementation '" + plugin.asClass().getName() + "' does not implement the Plugin interface. This plugin cannot be applied directly via the PluginContainer."); } else { return pluginManager.addImperativePlugin(plugin); } }
public <P extends Plugin> P findPlugin(Class<P> type) { for (Plugin plugin : this) { if (plugin.getClass().equals(type)) { return type.cast(plugin); } } return null; }
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; }
public <P extends Plugin> P getPlugin(Class<P> type) throws UnknownPluginException { P plugin = findPlugin(type); if (plugin == null) { throw new UnknownPluginException("Plugin with type " + type + " has not been used."); } return type.cast(plugin); }
public void withId(final String pluginId, final Action<? super Plugin> action) { Action<DefaultPluginManager.PluginWithId> wrappedAction = new Action<DefaultPluginManager.PluginWithId>() { public void execute(final DefaultPluginManager.PluginWithId pluginWithId) { matching(new Spec<Plugin>() { public boolean isSatisfiedBy(Plugin element) { return pluginWithId.clazz.equals(element.getClass()); } }).all(action); } }; pluginManager.pluginsForId(pluginId).all(wrappedAction); }
@Override public <S extends Plugin> PluginCollection<S> withType(Class<S> type) { // runtime check because method is used from Groovy where type bounds are not respected if (!Plugin.class.isAssignableFrom(type)) { throw new IllegalArgumentException(String.format("'%s' does not implement the Plugin interface.", type.getName())); } return super.withType(type); }
private Plugin<?> producePluginInstance(Class<?> pluginClass) { // This insanity is needed for the case where someone calls pluginContainer.add(new SomePlugin()) // That is, the plugin container has the instance that we want, but we don't think (we can't know) it has been applied Object instance = findInstance(pluginClass, pluginContainer); if (instance == null) { instance = instantiatePlugin(pluginClass); } return Cast.uncheckedCast(instance); }
public <T> PotentialPlugin<T> inspect(Class<T> type) { boolean implementsInterface = Plugin.class.isAssignableFrom(type); boolean hasRules = this.modelRuleSourceDetector.hasRules(type); if (implementsInterface) { @SuppressWarnings("unchecked") Class<? extends Plugin<?>> cast = (Class<? extends Plugin<?>>) type; return Cast.uncheckedCast(toImperative(cast, hasRules)); } else if (hasRules) { return new PotentialPureRuleSourceClassPlugin<T>(type); } else { return new PotentialUnknownTypePlugin<T>(type); } }
private <T extends Plugin<?>> PotentialPlugin<T> toImperative(Class<T> type, boolean hasRules) { if (hasRules) { return new PotentialHybridImperativeAndRulesPlugin<T>(type); } else { return new PotentialImperativeClassPlugin<T>(type); } }
private void addPluginDescription(Project project, final ProjectDescriptor projectDescriptor) { project.getPlugins().all(new Action<Plugin>() { @Override public void execute(Plugin plugin) { projectDescriptor.addPluginClass(plugin.getClass()); } }); }
@Override public void apply(final Project project) { project.getPlugins().apply(ReleasePlugin.class); final ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration(); final Task performRelease = project.getTasks().getByName(ReleasePlugin.PERFORM_RELEASE_TASK); final Task gitPush = project.getTasks().getByName(GitPlugin.GIT_PUSH_TASK); project.allprojects(new Action<Project>() { @Override public void execute(final Project subproject) { subproject.getPlugins().withId("com.gradle.plugin-publish", new Action<Plugin>() { @Override public void execute(Plugin plugin) { subproject.getPlugins().apply(PluginDiscoveryPlugin.class); subproject.getPlugins().apply(PluginValidationPlugin.class); subproject.getPlugins().apply(GradlePortalPublishPlugin.class); Task publishPlugins = subproject.getTasks().getByName(GradlePortalPublishPlugin.PUBLISH_PLUGINS_TASK); performRelease.dependsOn(publishPlugins); //perform release will actually publish the plugins publishPlugins.mustRunAfter(gitPush); //git push is easier to revert than perform release //We first build plugins to be published, then do git push, we're using 'buildArchives' for that //We know that "buildArchives" task exists because 'com.gradle.plugin-publish' applies Java plugin Task archivesTask = subproject.getTasks().getByName("buildArchives"); publishPlugins.dependsOn(archivesTask); gitPush.mustRunAfter(archivesTask); UpdateReleaseNotesTask updateNotes = (UpdateReleaseNotesTask) project.getTasks().getByName(ReleaseNotesPlugin.UPDATE_NOTES_TASK); updateNotes.setPublicationRepository(conf.getReleaseNotes().getPublicationRepository()); } }); } }); }
/** Returns the instance of the given plugin, by returning the existing or applying brand new, as appropriate. */ public static <T extends Plugin<?>> T getPlugin(Project project, Class<T> pluginClazz) { // make sure the eclipse plugin has been applied if (project.getPlugins().hasPlugin(pluginClazz)) { return project.getPlugins().getPlugin(pluginClazz); } else { return project.getPlugins().apply(pluginClazz); } }
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()); }
private void applyPlugin(Class<? extends Plugin> pluginClass) { for (Object target : targets) { if (target instanceof PluginAware) { try { ((PluginAware) target).getPlugins().apply(pluginClass); } catch (Exception e) { throw new PluginApplicationException("class '" + pluginClass.getName() + "'", e); } } else { throw new UnsupportedOperationException(String.format("Cannot apply plugin of class '%s' to '%s' (class: %s) as it does not implement PluginAware", pluginClass.getName(), target.toString(), target.getClass().getName())); } } }
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)); } } }
public Plugin findPlugin(String id) { try { return findPlugin(getTypeForId(id)); } catch (UnknownPluginException e) { return null; } }
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)); }
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); }
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); }
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()); } }
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; } }
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; }
private void applyPlugin(Class<? extends Plugin> pluginClass) { for (Object target : targets) { if (target instanceof PluginAware) { PluginAware pluginAware = (PluginAware) target; pluginAware.getPlugins().apply(pluginClass); } else { throw new UnsupportedOperationException(String.format("Cannot apply plugin of class '%s' to '%s' (class: %s) as it does not implement PluginAware", pluginClass.getName(), target.toString(), target.getClass().getName())); } } }
public <T extends Plugin> T findPlugin(Class<T> type) { for (Plugin plugin : this) { if (plugin.getClass().equals(type)) { return type.cast(plugin); } } return null; }
private <T extends Plugin> T addPluginInternal(Class<T> type) { if (findPlugin(type) == null) { Plugin plugin = providePlugin(type); add(plugin); } return type.cast(findPlugin(type)); }