Search in sources :

Example 1 with DirectoryProperty

use of org.gradle.api.file.DirectoryProperty in project gradle by gradle.

the class BuildDependenciesOnlyFileCollectionResolveContext method add.

@Override
public FileCollectionResolveContext add(Object element) {
    // TODO - need to sync with DefaultFileCollectionResolveContext
    if (element instanceof Buildable) {
        taskContext.add(element);
    } else if (element instanceof Task) {
        taskContext.add(element);
    } else if (element instanceof TaskOutputs) {
        TaskOutputs outputs = (TaskOutputs) element;
        taskContext.add(outputs.getFiles());
    } else if (element instanceof RegularFileProperty || element instanceof DirectoryProperty) {
        taskContext.add(element);
    } else if (element instanceof Closure) {
        Closure closure = (Closure) element;
        Object closureResult = closure.call();
        if (closureResult != null) {
            add(closureResult);
        }
    } else if (element instanceof Callable) {
        Callable callable = (Callable) element;
        Object callableResult = uncheckedCall(callable);
        if (callableResult != null) {
            add(callableResult);
        }
    } else if (element instanceof Iterable && !(element instanceof Path)) {
        // Ignore Path
        Iterable<?> iterable = (Iterable) element;
        for (Object value : iterable) {
            add(value);
        }
    } else if (element instanceof Object[]) {
        Object[] array = (Object[]) element;
        for (Object value : array) {
            add(value);
        }
    }
    // Everything else assume has no dependencies
    return this;
}
Also used : Path(java.nio.file.Path) Task(org.gradle.api.Task) DirectoryProperty(org.gradle.api.file.DirectoryProperty) Closure(groovy.lang.Closure) RegularFileProperty(org.gradle.api.file.RegularFileProperty) TaskOutputs(org.gradle.api.tasks.TaskOutputs) Buildable(org.gradle.api.Buildable) Callable(java.util.concurrent.Callable)

Example 2 with DirectoryProperty

use of org.gradle.api.file.DirectoryProperty in project gradle by gradle.

the class NativeBasePlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    project.getPluginManager().apply(LifecycleBasePlugin.class);
    final TaskContainer tasks = project.getTasks();
    final ProviderFactory providers = project.getProviders();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    final SoftwareComponentContainer components = project.getComponents();
    addLifecycleTasks(tasks, components);
    // Add tasks to build various kinds of components
    addTasksForComponentWithExecutable(tasks, providers, buildDirectory, components);
    addTasksForComponentWithSharedLibrary(tasks, providers, buildDirectory, components);
    addTasksForComponentWithStaticLibrary(tasks, providers, buildDirectory, components);
    // Add outgoing configurations and publications
    final ConfigurationContainer configurations = project.getConfigurations();
    project.getDependencies().getAttributesSchema().attribute(LINKAGE_ATTRIBUTE).getDisambiguationRules().add(LinkageSelectionRule.class);
    addOutgoingConfigurationForLinkUsage(components, configurations);
    addOutgoingConfigurationForRuntimeUsage(components, configurations);
    addPublicationsFromVariants(project, components);
}
Also used : TaskContainer(org.gradle.api.tasks.TaskContainer) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) ProviderFactory(org.gradle.api.provider.ProviderFactory) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer)

Example 3 with DirectoryProperty

use of org.gradle.api.file.DirectoryProperty in project gradle by gradle.

the class ReportingExtension method setBaseDir.

/**
 * Sets the base directory to use for all reports
 * <p>
 * The value will be converted to a {@code File} on demand via {@link Project#file(Object)}.
 *
 * @param baseDir The base directory to use for all reports
 */
public void setBaseDir(final Object baseDir) {
    this.baseDirectory.set(project.provider(new Callable<Directory>() {

        @Override
        public Directory call() throws Exception {
            DirectoryProperty result = project.getLayout().directoryProperty();
            result.set(project.file(baseDir));
            return result.get();
        }
    }));
}
Also used : DirectoryProperty(org.gradle.api.file.DirectoryProperty) Callable(java.util.concurrent.Callable)

Example 4 with DirectoryProperty

use of org.gradle.api.file.DirectoryProperty in project gradle by gradle.

the class CppBasePlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(StandardToolChainsPlugin.class);
    final TaskContainerInternal tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    // Enable the use of Gradle metadata. This is a temporary opt-in switch until available by default
    project.getGradle().getServices().get(FeaturePreviews.class).enableFeature(GRADLE_METADATA);
    // Create the tasks for each C++ binary that is registered
    project.getComponents().withType(DefaultCppBinary.class, new Action<DefaultCppBinary>() {

        @Override
        public void execute(final DefaultCppBinary binary) {
            final Names names = binary.getNames();
            String language = "cpp";
            final NativePlatform currentPlatform = binary.getTargetPlatform();
            // TODO - make this lazy
            final NativeToolChainInternal toolChain = binary.getToolChain();
            Callable<List<File>> systemIncludes = new Callable<List<File>>() {

                @Override
                public List<File> call() {
                    PlatformToolProvider platformToolProvider = binary.getPlatformToolProvider();
                    return platformToolProvider.getSystemLibraries(ToolType.CPP_COMPILER).getIncludeDirs();
                }
            };
            CppCompile compile = tasks.create(names.getCompileTaskName(language), CppCompile.class);
            compile.includes(binary.getCompileIncludePath());
            compile.includes(systemIncludes);
            compile.source(binary.getCppSource());
            if (binary.isDebuggable()) {
                compile.setDebuggable(true);
            }
            if (binary.isOptimized()) {
                compile.setOptimized(true);
            }
            compile.getTargetPlatform().set(currentPlatform);
            compile.getToolChain().set(toolChain);
            compile.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            binary.getObjectsDir().set(compile.getObjectFileDir());
            binary.getCompileTask().set(compile);
        }
    });
    project.getComponents().withType(CppSharedLibrary.class, new Action<CppSharedLibrary>() {

        @Override
        public void execute(CppSharedLibrary library) {
            library.getCompileTask().get().setPositionIndependentCode(true);
        }
    });
    project.getComponents().withType(ProductionCppComponent.class, new Action<ProductionCppComponent>() {

        @Override
        public void execute(final ProductionCppComponent component) {
            project.afterEvaluate(new Action<Project>() {

                @Override
                public void execute(Project project) {
                    DefaultCppComponent componentInternal = (DefaultCppComponent) component;
                    publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getBaseName().get()), false));
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) Callable(java.util.concurrent.Callable) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) List(java.util.List) CppSharedLibrary(org.gradle.language.cpp.CppSharedLibrary) FeaturePreviews(org.gradle.api.internal.FeaturePreviews) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) Project(org.gradle.api.Project) DefaultCppComponent(org.gradle.language.cpp.internal.DefaultCppComponent) DirectoryProperty(org.gradle.api.file.DirectoryProperty) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) CppCompile(org.gradle.language.cpp.tasks.CppCompile) DefaultProjectPublication(org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication) File(java.io.File)

Example 5 with DirectoryProperty

use of org.gradle.api.file.DirectoryProperty in project gradle by gradle.

the class SwiftBasePlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(SwiftCompilerPlugin.class);
    final TaskContainerInternal tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    final ProviderFactory providers = project.getProviders();
    project.getDependencies().getAttributesSchema().attribute(Usage.USAGE_ATTRIBUTE).getCompatibilityRules().add(SwiftCppUsageCompatibilityRule.class);
    project.getComponents().withType(DefaultSwiftBinary.class, new Action<DefaultSwiftBinary>() {

        @Override
        public void execute(final DefaultSwiftBinary binary) {
            final Names names = binary.getNames();
            SwiftCompile compile = tasks.create(names.getCompileTaskName("swift"), SwiftCompile.class);
            compile.getModules().from(binary.getCompileModules());
            compile.getSource().from(binary.getSwiftSource());
            compile.getDebuggable().set(binary.isDebuggable());
            compile.getOptimized().set(binary.isOptimized());
            if (binary.isTestable()) {
                compile.getCompilerArgs().add("-enable-testing");
            }
            if (binary.getTargetPlatform().getOperatingSystem().isMacOsX()) {
                compile.getCompilerArgs().add("-sdk");
                compile.getCompilerArgs().add(locator.find().getAbsolutePath());
            }
            compile.getModuleName().set(binary.getModule());
            compile.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            compile.getModuleFile().set(buildDirectory.file(providers.provider(new Callable<String>() {

                @Override
                public String call() {
                    return "modules/" + names.getDirName() + binary.getModule().get() + ".swiftmodule";
                }
            })));
            compile.getSourceCompatibility().set(binary.getSourceCompatibility());
            binary.getModuleFile().set(compile.getModuleFile());
            compile.getTargetPlatform().set(binary.getTargetPlatform());
            // TODO - make this lazy
            compile.getToolChain().set(binary.getToolChain());
            binary.getCompileTask().set(compile);
            binary.getObjectsDir().set(compile.getObjectFileDir());
        }
    });
    project.getComponents().withType(SwiftSharedLibrary.class, new Action<SwiftSharedLibrary>() {

        @Override
        public void execute(SwiftSharedLibrary library) {
            // Specific compiler arguments
            library.getCompileTask().get().getCompilerArgs().add("-parse-as-library");
        }
    });
    project.getComponents().withType(SwiftStaticLibrary.class, new Action<SwiftStaticLibrary>() {

        @Override
        public void execute(SwiftStaticLibrary library) {
            // Specific compiler arguments
            library.getCompileTask().get().getCompilerArgs().add("-parse-as-library");
        }
    });
    project.getComponents().withType(DefaultSwiftComponent.class, new Action<DefaultSwiftComponent>() {

        @Override
        public void execute(final DefaultSwiftComponent component) {
            project.afterEvaluate(new Action<Project>() {

                @Override
                public void execute(Project project) {
                    component.getSourceCompatibility().lockNow();
                }
            });
            component.getBinaries().whenElementKnown(DefaultSwiftBinary.class, new Action<DefaultSwiftBinary>() {

                @Override
                public void execute(final DefaultSwiftBinary binary) {
                    Provider<SwiftVersion> swiftLanguageVersionProvider = project.provider(new Callable<SwiftVersion>() {

                        @Override
                        public SwiftVersion call() throws Exception {
                            SwiftVersion swiftSourceCompatibility = component.getSourceCompatibility().getOrNull();
                            if (swiftSourceCompatibility == null) {
                                return toSwiftVersion(binary.getPlatformToolProvider().getCompilerMetadata(ToolType.SWIFT_COMPILER).getVersion());
                            }
                            return swiftSourceCompatibility;
                        }
                    });
                    binary.getSourceCompatibility().set(swiftLanguageVersionProvider);
                }
            });
        }
    });
    project.getComponents().withType(ProductionSwiftComponent.class, new Action<ProductionSwiftComponent>() {

        @Override
        public void execute(final ProductionSwiftComponent component) {
            project.afterEvaluate(new Action<Project>() {

                @Override
                public void execute(Project project) {
                    DefaultSwiftComponent componentInternal = (DefaultSwiftComponent) component;
                    publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getModule().get()), false));
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) SwiftStaticLibrary(org.gradle.language.swift.SwiftStaticLibrary) Callable(java.util.concurrent.Callable) Names(org.gradle.language.nativeplatform.internal.Names) ProviderFactory(org.gradle.api.provider.ProviderFactory) SwiftVersion(org.gradle.language.swift.SwiftVersion) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal) Project(org.gradle.api.Project) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) SwiftSharedLibrary(org.gradle.language.swift.SwiftSharedLibrary) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) DefaultSwiftComponent(org.gradle.language.swift.internal.DefaultSwiftComponent) DefaultProjectPublication(org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication)

Aggregations

DirectoryProperty (org.gradle.api.file.DirectoryProperty)5 Callable (java.util.concurrent.Callable)4 Action (org.gradle.api.Action)2 Project (org.gradle.api.Project)2 DefaultProjectPublication (org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication)2 TaskContainerInternal (org.gradle.api.internal.tasks.TaskContainerInternal)2 ProviderFactory (org.gradle.api.provider.ProviderFactory)2 Names (org.gradle.language.nativeplatform.internal.Names)2 SwiftPmTarget (org.gradle.swiftpm.internal.SwiftPmTarget)2 Closure (groovy.lang.Closure)1 File (java.io.File)1 Path (java.nio.file.Path)1 List (java.util.List)1 Buildable (org.gradle.api.Buildable)1 Task (org.gradle.api.Task)1 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)1 SoftwareComponentContainer (org.gradle.api.component.SoftwareComponentContainer)1 RegularFileProperty (org.gradle.api.file.RegularFileProperty)1 FeaturePreviews (org.gradle.api.internal.FeaturePreviews)1 TaskContainer (org.gradle.api.tasks.TaskContainer)1