Search in sources :

Example 1 with ExtensionContainer

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);
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) DirectorySensitivity(org.gradle.internal.fingerprint.DirectorySensitivity) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) Hashing(org.gradle.internal.hash.Hashing) SettingsInternal(org.gradle.api.internal.SettingsInternal) FileValueSupplier(org.gradle.internal.execution.fingerprint.InputFingerprinter.FileValueSupplier) ExecutionResult(org.gradle.internal.execution.ExecutionResult) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) IncubationLogger(org.gradle.util.internal.IncubationLogger) VersionCatalogBuilder(org.gradle.api.initialization.dsl.VersionCatalogBuilder) DependencyResolutionManagementInternal(org.gradle.internal.management.DependencyResolutionManagementInternal) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Map(java.util.Map) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) InputVisitor(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputVisitor) Set(java.util.Set) InputPropertyType(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputPropertyType) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) Hasher(org.gradle.internal.hash.Hasher) Settings(org.gradle.api.initialization.Settings) Collectors(java.util.stream.Collectors) List(java.util.List) ProjectRegistry(org.gradle.api.internal.project.ProjectRegistry) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) DefaultProjectDependencyFactory(org.gradle.api.internal.artifacts.DefaultProjectDependencyFactory) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) Optional(java.util.Optional) ClassPath(org.gradle.internal.classpath.ClassPath) Pattern(java.util.regex.Pattern) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) Inject(javax.inject.Inject) ExecutionEngine(org.gradle.internal.execution.ExecutionEngine) Lists(com.google.common.collect.Lists) FeaturePreviews(org.gradle.api.internal.FeaturePreviews) TreeType(org.gradle.internal.file.TreeType) ProjectDescriptor(org.gradle.api.initialization.ProjectDescriptor) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) WorkspaceProvider(org.gradle.internal.execution.workspace.WorkspaceProvider) DependenciesAccessors(org.gradle.initialization.DependenciesAccessors) VersionCatalogsExtension(org.gradle.api.artifacts.VersionCatalogsExtension) Nullable(javax.annotation.Nullable) UnitOfWork(org.gradle.internal.execution.UnitOfWork) ClassPathRegistry(org.gradle.api.internal.ClassPathRegistry) ClasspathNormalizer(org.gradle.api.tasks.ClasspathNormalizer) Iterator(java.util.Iterator) ProjectFinder(org.gradle.api.internal.artifacts.dsl.dependencies.ProjectFinder) StringWriter(java.io.StringWriter) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) LineEndingSensitivity(org.gradle.internal.fingerprint.LineEndingSensitivity) VersionCatalogBuilderInternal(org.gradle.internal.management.VersionCatalogBuilderInternal) Cast(org.gradle.internal.Cast) Maps(com.google.common.collect.Maps) File(java.io.File) ProviderFactory(org.gradle.api.provider.ProviderFactory) VersionCatalog(org.gradle.api.artifacts.VersionCatalog) Property(org.gradle.api.provider.Property) InvalidUserDataException(org.gradle.api.InvalidUserDataException) Collections(java.util.Collections) ProjectFinder(org.gradle.api.internal.artifacts.dsl.dependencies.ProjectFinder) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) ImmutableMap(com.google.common.collect.ImmutableMap) VersionCatalog(org.gradle.api.artifacts.VersionCatalog) ProviderFactory(org.gradle.api.provider.ProviderFactory) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) DependencyResolutionManagementInternal(org.gradle.internal.management.DependencyResolutionManagementInternal)

Example 2 with ExtensionContainer

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();
                }
            });
        }
    });
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) RhinoExtension(org.gradle.plugins.javascript.rhino.RhinoExtension) JavaScriptExtension(org.gradle.plugins.javascript.base.JavaScriptExtension) ConventionMapping(org.gradle.api.internal.ConventionMapping) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) Callable(java.util.concurrent.Callable) ExtensionAware(org.gradle.api.plugins.ExtensionAware) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 3 with ExtensionContainer

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;
}
Also used : ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) PublishingExtension(org.gradle.api.publish.PublishingExtension)

Example 4 with ExtensionContainer

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;
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer)

Example 5 with ExtensionContainer

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;
}
Also used : SpringBootExtension(org.springframework.boot.gradle.dsl.SpringBootExtension) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer)

Aggregations

ExtensionContainer (org.gradle.api.plugins.ExtensionContainer)5 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 StringUtils (org.apache.commons.lang.StringUtils)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1