Search in sources :

Example 1 with RegularFile

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

the class XCTestConventionPlugin method configureTestSuiteBuildingTasks.

private void configureTestSuiteBuildingTasks(ProjectInternal project, final DefaultSwiftXCTestBinary binary) {
    if (binary instanceof SwiftXCTestBundle) {
        TaskContainer tasks = project.getTasks();
        final Names names = binary.getNames();
        SwiftCompile compile = binary.getCompileTask().get();
        // TODO - creating a bundle should be done by some general purpose plugin
        // TODO - make this lazy
        DefaultNativePlatform currentPlatform = new DefaultNativePlatform("current");
        final ModelRegistry modelRegistry = project.getModelRegistry();
        NativeToolChain toolChain = modelRegistry.realize("toolChains", NativeToolChainRegistryInternal.class).getForPlatform(currentPlatform);
        // Platform specific arguments
        compile.getCompilerArgs().addAll(project.provider(new Callable<List<String>>() {

            @Override
            public List<String> call() {
                File frameworkDir = new File(sdkPlatformPathLocator.find(), "Developer/Library/Frameworks");
                return Arrays.asList("-parse-as-library", "-F" + frameworkDir.getAbsolutePath());
            }
        }));
        // Add a link task
        final LinkMachOBundle link = tasks.create(names.getTaskName("link"), LinkMachOBundle.class);
        link.getLinkerArgs().set(project.provider(new Callable<List<String>>() {

            @Override
            public List<String> call() {
                File frameworkDir = new File(sdkPlatformPathLocator.find(), "Developer/Library/Frameworks");
                return Lists.newArrayList("-F" + frameworkDir.getAbsolutePath(), "-framework", "XCTest", "-Xlinker", "-rpath", "-Xlinker", "@executable_path/../Frameworks", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/../Frameworks");
            }
        }));
        InstallXCTestBundle install = tasks.create(names.getTaskName("install"), InstallXCTestBundle.class);
        install.getBundleBinaryFile().set(link.getLinkedFile());
        install.getInstallDirectory().set(project.getLayout().getBuildDirectory().dir("install/" + names.getDirName()));
        binary.getInstallDirectory().set(install.getInstallDirectory());
        link.source(binary.getObjects());
        link.lib(binary.getLinkLibraries());
        final PlatformToolProvider toolProvider = ((NativeToolChainInternal) toolChain).select(currentPlatform);
        Provider<RegularFile> exeLocation = project.getLayout().getBuildDirectory().file(project.getProviders().provider(new Callable<String>() {

            @Override
            public String call() {
                return toolProvider.getExecutableName("exe/" + names.getDirName() + binary.getBaseName().get());
            }
        }));
        link.getLinkedFile().set(exeLocation);
        link.getTargetPlatform().set(currentPlatform);
        link.getToolChain().set(toolChain);
        link.getDebuggable().set(binary.isDebuggable());
        binary.getExecutableFile().set(link.getLinkedFile());
        DefaultSwiftXCTestBundle bundle = (DefaultSwiftXCTestBundle) binary;
        bundle.getLinkTask().set(link);
        bundle.getRunScriptFile().set(install.getRunScriptFile());
    } else {
        DefaultSwiftXCTestExecutable executable = (DefaultSwiftXCTestExecutable) binary;
        executable.getRunScriptFile().set(executable.getInstallTask().get().getRunScriptFile());
    }
}
Also used : DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) RegularFile(org.gradle.api.file.RegularFile) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) Callable(java.util.concurrent.Callable) Names(org.gradle.language.nativeplatform.internal.Names) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) TaskContainer(org.gradle.api.tasks.TaskContainer) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Example 2 with RegularFile

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

the class PmdPlugin method configureReportsConventionMapping.

private void configureReportsConventionMapping(Pmd task, final String baseName) {
    ProjectLayout layout = project.getLayout();
    ProviderFactory providers = project.getProviders();
    Provider<RegularFile> reportsDir = layout.file(providers.provider(() -> extension.getReportsDir()));
    task.getReports().all(action(report -> {
        report.getRequired().convention(true);
        report.getOutputLocation().convention(layout.getProjectDirectory().file(providers.provider(() -> {
            String reportFileName = baseName + "." + report.getName();
            return new File(reportsDir.get().getAsFile(), reportFileName).getAbsolutePath();
        })));
    }));
}
Also used : SerializableLambdas.action(org.gradle.api.internal.lambdas.SerializableLambdas.action) JavaVersion(org.gradle.api.JavaVersion) FileCollection(org.gradle.api.file.FileCollection) ConventionMapping(org.gradle.api.internal.ConventionMapping) File(java.io.File) SourceSet(org.gradle.api.tasks.SourceSet) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) ProviderFactory(org.gradle.api.provider.ProviderFactory) Provider(org.gradle.api.provider.Provider) ProjectLayout(org.gradle.api.file.ProjectLayout) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) RegularFile(org.gradle.api.file.RegularFile) VersionNumber(org.gradle.util.internal.VersionNumber) AbstractCodeQualityPlugin(org.gradle.api.plugins.quality.internal.AbstractCodeQualityPlugin) Collections(java.util.Collections) JvmPluginServices(org.gradle.api.plugins.jvm.internal.JvmPluginServices) RegularFile(org.gradle.api.file.RegularFile) ProjectLayout(org.gradle.api.file.ProjectLayout) ProviderFactory(org.gradle.api.provider.ProviderFactory) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Example 3 with RegularFile

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

the class CheckstylePlugin method configureReportsConventionMapping.

private void configureReportsConventionMapping(Checkstyle task, final String baseName) {
    ProjectLayout layout = project.getLayout();
    ProviderFactory providers = project.getProviders();
    Provider<RegularFile> reportsDir = layout.file(providers.provider(() -> extension.getReportsDir()));
    task.getReports().all(action(report -> {
        report.getRequired().convention(true);
        report.getOutputLocation().convention(layout.getProjectDirectory().file(providers.provider(() -> {
            String reportFileName = baseName + "." + report.getName();
            return new File(reportsDir.get().getAsFile(), reportFileName).getAbsolutePath();
        })));
    }));
}
Also used : Callables(com.google.common.util.concurrent.Callables) TextResource(org.gradle.api.resources.TextResource) Callable(java.util.concurrent.Callable) SerializableLambdas.action(org.gradle.api.internal.lambdas.SerializableLambdas.action) ConventionMapping(org.gradle.api.internal.ConventionMapping) File(java.io.File) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) ProviderFactory(org.gradle.api.provider.ProviderFactory) Provider(org.gradle.api.provider.Provider) ProjectLayout(org.gradle.api.file.ProjectLayout) RegularFile(org.gradle.api.file.RegularFile) Map(java.util.Map) AbstractCodeQualityPlugin(org.gradle.api.plugins.quality.internal.AbstractCodeQualityPlugin) Directory(org.gradle.api.file.Directory) RegularFile(org.gradle.api.file.RegularFile) ProjectLayout(org.gradle.api.file.ProjectLayout) ProviderFactory(org.gradle.api.provider.ProviderFactory) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Example 4 with RegularFile

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

the class CodeNarcPlugin method configureReportsConventionMapping.

private void configureReportsConventionMapping(CodeNarc task, final String baseName) {
    ProjectLayout layout = project.getLayout();
    ProviderFactory providers = project.getProviders();
    Provider<String> reportFormat = providers.provider(() -> extension.getReportFormat());
    Provider<RegularFile> reportsDir = layout.file(providers.provider(() -> extension.getReportsDir()));
    task.getReports().all(action(report -> {
        report.getRequired().convention(providers.provider(() -> report.getName().equals(reportFormat.get())));
        report.getOutputLocation().convention(layout.getProjectDirectory().file(providers.provider(() -> {
            String fileSuffix = report.getName().equals("text") ? "txt" : report.getName();
            return new File(reportsDir.get().getAsFile(), baseName + "." + fileSuffix).getAbsolutePath();
        })));
    }));
}
Also used : SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) SerializableLambdas.action(org.gradle.api.internal.lambdas.SerializableLambdas.action) ConventionMapping(org.gradle.api.internal.ConventionMapping) File(java.io.File) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) ProviderFactory(org.gradle.api.provider.ProviderFactory) Provider(org.gradle.api.provider.Provider) ProjectLayout(org.gradle.api.file.ProjectLayout) GroovyBasePlugin(org.gradle.api.plugins.GroovyBasePlugin) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) RegularFile(org.gradle.api.file.RegularFile) AbstractCodeQualityPlugin(org.gradle.api.plugins.quality.internal.AbstractCodeQualityPlugin) Plugin(org.gradle.api.Plugin) RegularFile(org.gradle.api.file.RegularFile) ProjectLayout(org.gradle.api.file.ProjectLayout) ProviderFactory(org.gradle.api.provider.ProviderFactory) File(java.io.File) RegularFile(org.gradle.api.file.RegularFile)

Example 5 with RegularFile

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

the class NativeBasePlugin method addTasksForComponentWithExecutable.

private void addTasksForComponentWithExecutable(final TaskContainer tasks, final DirectoryProperty buildDirectory, SoftwareComponentContainer components) {
    components.withType(ConfigurableComponentWithExecutable.class, executable -> {
        final Names names = executable.getNames();
        final NativeToolChain toolChain = executable.getToolChain();
        final NativePlatform targetPlatform = executable.getNativePlatform();
        final PlatformToolProvider toolProvider = executable.getPlatformToolProvider();
        // Add a link task
        TaskProvider<LinkExecutable> link = tasks.register(names.getTaskName("link"), LinkExecutable.class, task -> {
            task.source(executable.getObjects());
            task.lib(executable.getLinkLibraries());
            task.getLinkedFile().set(buildDirectory.file(executable.getBaseName().map(baseName -> toolProvider.getExecutableName("exe/" + names.getDirName() + baseName))));
            task.getTargetPlatform().set(targetPlatform);
            task.getToolChain().set(toolChain);
            task.getDebuggable().set(executable.isDebuggable());
        });
        executable.getLinkTask().set(link);
        executable.getDebuggerExecutableFile().set(link.flatMap(linkExecutable -> linkExecutable.getLinkedFile()));
        if (executable.isDebuggable() && executable.isOptimized() && toolProvider.requiresDebugBinaryStripping()) {
            Provider<RegularFile> symbolLocation = buildDirectory.file(executable.getBaseName().map(baseName -> toolProvider.getExecutableSymbolFileName("exe/" + names.getDirName() + "stripped/" + baseName)));
            Provider<RegularFile> strippedLocation = buildDirectory.file(executable.getBaseName().map(baseName -> toolProvider.getExecutableName("exe/" + names.getDirName() + "stripped/" + baseName)));
            TaskProvider<StripSymbols> stripSymbols = stripSymbols(link, names, tasks, toolChain, targetPlatform, strippedLocation);
            executable.getExecutableFile().set(stripSymbols.flatMap(task -> task.getOutputFile()));
            TaskProvider<ExtractSymbols> extractSymbols = extractSymbols(link, names, tasks, toolChain, targetPlatform, symbolLocation);
            executable.getOutputs().from(extractSymbols.flatMap(task -> task.getSymbolFile()));
            executable.getExecutableFileProducer().set(stripSymbols);
        } else {
            executable.getExecutableFile().set(link.flatMap(task -> task.getLinkedFile()));
            executable.getExecutableFileProducer().set(link);
        }
        // Add an install task
        // TODO - should probably not add this for all executables?
        // TODO - add stripped symbols to the installation
        final TaskProvider<InstallExecutable> install = tasks.register(names.getTaskName("install"), InstallExecutable.class, task -> {
            task.getTargetPlatform().set(targetPlatform);
            task.getToolChain().set(toolChain);
            task.getInstallDirectory().set(buildDirectory.dir("install/" + names.getDirName()));
            task.getExecutableFile().set(executable.getExecutableFile());
            task.lib(executable.getRuntimeLibraries());
        });
        executable.getInstallTask().set(install);
        executable.getInstallDirectory().set(install.flatMap(task -> task.getInstallDirectory()));
        executable.getOutputs().from(executable.getInstallDirectory());
        executable.getDebuggerExecutableFile().set(install.flatMap(task -> task.getInstalledExecutable()));
    });
}
Also used : ConfigurableComponentWithRuntimeUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithRuntimeUsage) ConfigurableComponentWithSharedLibrary(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithSharedLibrary) ComponentWithVariants(org.gradle.api.component.ComponentWithVariants) LinkSharedLibrary(org.gradle.nativeplatform.tasks.LinkSharedLibrary) ComponentWithBinaries(org.gradle.language.ComponentWithBinaries) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) PublishingExtension(org.gradle.api.publish.PublishingExtension) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) MultipleCandidatesDetails(org.gradle.api.attributes.MultipleCandidatesDetails) TaskProvider(org.gradle.api.tasks.TaskProvider) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) Linkage(org.gradle.nativeplatform.Linkage) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) UnzipTransform(org.gradle.api.internal.artifacts.transform.UnzipTransform) Incubating(org.gradle.api.Incubating) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Set(java.util.Set) MutableMavenProjectIdentity(org.gradle.api.publish.maven.internal.publisher.MutableMavenProjectIdentity) DIRECTORY_TYPE(org.gradle.api.artifacts.type.ArtifactTypeDefinition.DIRECTORY_TYPE) AttributeDisambiguationRule(org.gradle.api.attributes.AttributeDisambiguationRule) TaskContainer(org.gradle.api.tasks.TaskContainer) AbstractLinkTask(org.gradle.nativeplatform.tasks.AbstractLinkTask) ArtifactTypeDefinition(org.gradle.api.artifacts.type.ArtifactTypeDefinition) Names(org.gradle.language.nativeplatform.internal.Names) SoftwareComponent(org.gradle.api.component.SoftwareComponent) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) CreateStaticLibrary(org.gradle.nativeplatform.tasks.CreateStaticLibrary) ZIP_TYPE(org.gradle.api.artifacts.type.ArtifactTypeDefinition.ZIP_TYPE) ConfigurableComponentWithStaticLibrary(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithStaticLibrary) StripSymbols(org.gradle.nativeplatform.tasks.StripSymbols) PublishableComponent(org.gradle.api.component.PublishableComponent) Callable(java.util.concurrent.Callable) MavenPublication(org.gradle.api.publish.maven.MavenPublication) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) FileCollection(org.gradle.api.file.FileCollection) ProductionComponent(org.gradle.language.ProductionComponent) ExtractSymbols(org.gradle.nativeplatform.tasks.ExtractSymbols) LinkExecutable(org.gradle.nativeplatform.tasks.LinkExecutable) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) AttributeContainer(org.gradle.api.attributes.AttributeContainer) DefaultTargetMachineFactory(org.gradle.nativeplatform.internal.DefaultTargetMachineFactory) Attribute(org.gradle.api.attributes.Attribute) DirectoryProperty(org.gradle.api.file.DirectoryProperty) DomainObjectSet(org.gradle.api.DomainObjectSet) Usage(org.gradle.api.attributes.Usage) ConfigurableComponentWithLinkUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithLinkUsage) ConfigurableComponentWithExecutable(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithExecutable) PublicationAwareComponent(org.gradle.language.nativeplatform.internal.PublicationAwareComponent) InstallExecutable(org.gradle.nativeplatform.tasks.InstallExecutable) ComponentWithTargetMachines(org.gradle.language.ComponentWithTargetMachines) Cast(org.gradle.internal.Cast) LINKAGE_ATTRIBUTE(org.gradle.language.cpp.CppBinary.LINKAGE_ATTRIBUTE) ObjectFactory(org.gradle.api.model.ObjectFactory) RegularFile(org.gradle.api.file.RegularFile) ComponentWithOutputs(org.gradle.language.ComponentWithOutputs) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) RegularFile(org.gradle.api.file.RegularFile) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Names(org.gradle.language.nativeplatform.internal.Names) LinkExecutable(org.gradle.nativeplatform.tasks.LinkExecutable) StripSymbols(org.gradle.nativeplatform.tasks.StripSymbols) ExtractSymbols(org.gradle.nativeplatform.tasks.ExtractSymbols) InstallExecutable(org.gradle.nativeplatform.tasks.InstallExecutable) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform)

Aggregations

RegularFile (org.gradle.api.file.RegularFile)14 File (java.io.File)9 Configuration (org.gradle.api.artifacts.Configuration)7 Provider (org.gradle.api.provider.Provider)7 Callable (java.util.concurrent.Callable)5 Inject (javax.inject.Inject)5 Plugin (org.gradle.api.Plugin)5 TaskContainer (org.gradle.api.tasks.TaskContainer)5 Names (org.gradle.language.nativeplatform.internal.Names)5 NativeToolChain (org.gradle.nativeplatform.toolchain.NativeToolChain)5 PlatformToolProvider (org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider)5 Collections (java.util.Collections)4 Project (org.gradle.api.Project)4 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)4 FileCollection (org.gradle.api.file.FileCollection)4 ObjectFactory (org.gradle.api.model.ObjectFactory)4 ProviderFactory (org.gradle.api.provider.ProviderFactory)4 SourceSet (org.gradle.api.tasks.SourceSet)4 TaskProvider (org.gradle.api.tasks.TaskProvider)4 LifecycleBasePlugin (org.gradle.language.base.plugins.LifecycleBasePlugin)4