use of org.gradle.api.plugins.ExtensionContainer in project gradle by gradle.
the class DefaultDependenciesAccessors method createExtensions.
@Override
public void createExtensions(ProjectInternal project) {
ExtensionContainer container = project.getExtensions();
ProviderFactory providerFactory = project.getProviders();
try {
if (!models.isEmpty()) {
ImmutableMap.Builder<String, VersionCatalog> catalogs = ImmutableMap.builderWithExpectedSize(models.size());
for (DefaultVersionCatalog model : models) {
if (model.isNotEmpty()) {
Class<? extends ExternalModuleDependencyFactory> factory;
synchronized (this) {
factory = factories.computeIfAbsent(model.getName(), n -> loadFactory(classLoaderScope, ACCESSORS_PACKAGE + "." + ACCESSORS_CLASSNAME_PREFIX + StringUtils.capitalize(n)));
}
if (factory != null) {
container.create(model.getName(), factory, model);
catalogs.put(model.getName(), new VersionCatalogView(model, providerFactory));
}
}
}
container.create(VersionCatalogsExtension.class, "versionCatalogs", DefaultVersionCatalogsExtension.class, catalogs.build());
}
} finally {
if (featurePreviews.isFeatureEnabled(FeaturePreviews.Feature.TYPESAFE_PROJECT_ACCESSORS)) {
ServiceRegistry services = project.getServices();
DependencyResolutionManagementInternal drm = services.get(DependencyResolutionManagementInternal.class);
ProjectFinder projectFinder = services.get(ProjectFinder.class);
createProjectsExtension(container, drm, projectFinder);
}
}
}
use of org.gradle.api.plugins.ExtensionContainer in project gradle by gradle.
the class CoffeeScriptBasePlugin method apply.
public void apply(Project project) {
project.getPluginManager().apply(RhinoPlugin.class);
JavaScriptExtension jsExtension = project.getExtensions().getByType(JavaScriptExtension.class);
ExtensionContainer extensionContainer = ((ExtensionAware) jsExtension).getExtensions();
final CoffeeScriptExtension csExtension = extensionContainer.create(CoffeeScriptExtension.NAME, CoffeeScriptExtension.class);
final Configuration jsConfiguration = addJsConfiguration(project.getConfigurations(), project.getDependencies(), csExtension);
ConventionMapping conventionMapping = ((IConventionAware) csExtension).getConventionMapping();
conventionMapping.map("js", new Callable<Configuration>() {
@Override
public Configuration call() {
return jsConfiguration;
}
});
conventionMapping.map("version", new Callable<String>() {
@Override
public String call() {
return CoffeeScriptExtension.DEFAULT_JS_DEPENDENCY_VERSION;
}
});
final RhinoExtension rhinoExtension = extensionContainer.getByType(RhinoExtension.class);
project.getTasks().withType(CoffeeScriptCompile.class, new Action<CoffeeScriptCompile>() {
@Override
public void execute(CoffeeScriptCompile task) {
task.getConventionMapping().map("rhinoClasspath", new Callable<FileCollection>() {
public FileCollection call() {
return rhinoExtension.getClasspath();
}
});
task.getConventionMapping().map("coffeeScriptJs", new Callable<FileCollection>() {
public FileCollection call() {
return csExtension.getJs();
}
});
}
});
}
use of org.gradle.api.plugins.ExtensionContainer in project wildfly-gradle-tools by wildfly.
the class GradleArtifactFileResolver method extractPublishingExtension.
/**
* @param project
* @return the list of PublishingExtension(s), if some are defined: this will depend on the project (could be empty).
*/
private static PublishingExtension extractPublishingExtension(final Project project) {
final ExtensionContainer extensions = project.getExtensions();
final Object publishing = extensions.findByName("publishing");
if (publishing == null) {
return null;
}
if (!PublishingExtension.class.isAssignableFrom(publishing.getClass())) {
throw new RuntimeException("The registered 'publishing' extension is not of the expected type PublishingExtension");
}
return (PublishingExtension) publishing;
}
use of org.gradle.api.plugins.ExtensionContainer in project ossindex-gradle-plugin by OSSIndex.
the class ProxyTests method mockProject.
/**
* Assemble the gradle project with appropriate task.
*/
private Project mockProject() {
Project project = mock(Project.class);
ExtensionContainer extension = mock(ExtensionContainer.class);
when(project.getExtensions()).thenReturn(extension);
Task audit = mock(Task.class);
when(audit.getProject()).thenReturn(project);
when(project.task("audit")).thenReturn(audit);
return project;
}
use of org.gradle.api.plugins.ExtensionContainer in project spring-boot by spring-projects.
the class ResolveMainClassName method registerForTask.
static TaskProvider<ResolveMainClassName> registerForTask(String taskName, Project project, Callable<FileCollection> classpath) {
TaskProvider<ResolveMainClassName> resolveMainClassNameProvider = project.getTasks().register(taskName + "MainClassName", ResolveMainClassName.class, (resolveMainClassName) -> {
ExtensionContainer extensions = project.getExtensions();
resolveMainClassName.setDescription("Resolves the name of the application's main class for the " + taskName + " task.");
resolveMainClassName.setGroup(BasePlugin.BUILD_GROUP);
resolveMainClassName.setClasspath(classpath);
resolveMainClassName.getConfiguredMainClassName().convention(project.provider(() -> {
String javaApplicationMainClass = getJavaApplicationMainClass(extensions);
if (javaApplicationMainClass != null) {
return javaApplicationMainClass;
}
SpringBootExtension springBootExtension = project.getExtensions().findByType(SpringBootExtension.class);
return springBootExtension.getMainClass().getOrNull();
}));
resolveMainClassName.getOutputFile().set(project.getLayout().getBuildDirectory().file(taskName + "MainClassName"));
});
return resolveMainClassNameProvider;
}
Aggregations