Search in sources :

Example 31 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class XCTestConventionPlugin method configureTestSuiteWithTestedComponentWhenAvailable.

private void configureTestSuiteWithTestedComponentWhenAvailable(final Project project, final DefaultSwiftXCTestSuite testSuite, final DefaultSwiftXCTestBinary testExecutable) {
    SwiftComponent target = testSuite.getTestedComponent().getOrNull();
    if (!(target instanceof ProductionSwiftComponent)) {
        return;
    }
    final ProductionSwiftComponent testedComponent = (ProductionSwiftComponent) target;
    final TaskContainer tasks = project.getTasks();
    testedComponent.getBinaries().whenElementFinalized(testedBinary -> {
        if (testedBinary != testedComponent.getDevelopmentBinary().get()) {
            return;
        }
        // Setup the dependency on the main binary
        // This should all be replaced by a single dependency that points at some "testable" variants of the main binary
        // Inherit implementation dependencies
        testExecutable.getImplementationDependencies().extendsFrom(((DefaultSwiftBinary) testedBinary).getImplementationDependencies());
        // Configure test binary to compile against binary under test
        Dependency compileDependency = project.getDependencies().create(project.files(testedBinary.getModuleFile()));
        testExecutable.getImportPathConfiguration().getDependencies().add(compileDependency);
        // Configure test binary to link against tested component compiled objects
        ConfigurableFileCollection testableObjects = project.files();
        if (testedComponent instanceof SwiftApplication) {
            TaskProvider<UnexportMainSymbol> unexportMainSymbol = tasks.register("relocateMainForTest", UnexportMainSymbol.class, task -> {
                String dirName = ((DefaultSwiftBinary) testedBinary).getNames().getDirName();
                task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("obj/for-test/" + dirName));
                task.getObjects().from(testedBinary.getObjects());
            });
            testableObjects.from(unexportMainSymbol.map(task -> task.getRelocatedObjects()));
        } else {
            testableObjects.from(testedBinary.getObjects());
        }
        Dependency linkDependency = project.getDependencies().create(testableObjects);
        testExecutable.getLinkConfiguration().getDependencies().add(linkDependency);
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) Arrays(java.util.Arrays) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) NativeToolChainRegistryInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainRegistryInternal) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) DefaultSwiftXCTestExecutable(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestExecutable) GUtil(org.gradle.util.internal.GUtil) Provider(org.gradle.api.provider.Provider) ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) DefaultSwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestSuite) TaskProvider(org.gradle.api.tasks.TaskProvider) XCTest(org.gradle.nativeplatform.test.xctest.tasks.XCTest) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) SwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.SwiftXCTestBundle) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) SwiftBasePlugin(org.gradle.language.swift.plugins.SwiftBasePlugin) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) MacOSSdkPlatformPathLocator(org.gradle.nativeplatform.toolchain.internal.xcode.MacOSSdkPlatformPathLocator) TaskContainer(org.gradle.api.tasks.TaskContainer) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) SwiftPlatform(org.gradle.language.swift.SwiftPlatform) SwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.SwiftXCTestBinary) DefaultSwiftXCTestBinary(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBinary) NativeTestingBasePlugin(org.gradle.nativeplatform.test.plugins.NativeTestingBasePlugin) Dimensions.useHostAsDefaultTargetMachine(org.gradle.language.nativeplatform.internal.Dimensions.useHostAsDefaultTargetMachine) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) Inject(javax.inject.Inject) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Lists(com.google.common.collect.Lists) Sync(org.gradle.api.tasks.Sync) LinkMachOBundle(org.gradle.nativeplatform.tasks.LinkMachOBundle) DefaultSwiftPlatform(org.gradle.language.swift.internal.DefaultSwiftPlatform) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) SwiftApplication(org.gradle.language.swift.SwiftApplication) SwiftComponent(org.gradle.language.swift.SwiftComponent) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) SwiftCompile(org.gradle.language.swift.tasks.SwiftCompile) File(java.io.File) SetProperty(org.gradle.api.provider.SetProperty) ProviderFactory(org.gradle.api.provider.ProviderFactory) DefaultSwiftBinary(org.gradle.language.swift.internal.DefaultSwiftBinary) ObjectFactory(org.gradle.api.model.ObjectFactory) DefaultSwiftXCTestBundle(org.gradle.nativeplatform.test.xctest.internal.DefaultSwiftXCTestBundle) RegularFile(org.gradle.api.file.RegularFile) InstallXCTestBundle(org.gradle.nativeplatform.test.xctest.tasks.InstallXCTestBundle) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) SwiftXCTestSuite(org.gradle.nativeplatform.test.xctest.SwiftXCTestSuite) TaskContainer(org.gradle.api.tasks.TaskContainer) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) Dependency(org.gradle.api.artifacts.Dependency) ProductionSwiftComponent(org.gradle.language.swift.ProductionSwiftComponent) SwiftComponent(org.gradle.language.swift.SwiftComponent) SwiftApplication(org.gradle.language.swift.SwiftApplication)

Example 32 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class CppUnitTestPlugin method configureTestSuiteWithTestedComponentWhenAvailable.

private void configureTestSuiteWithTestedComponentWhenAvailable(Project project, DefaultCppTestSuite testSuite, DefaultCppTestExecutable testExecutable) {
    CppComponent target = testSuite.getTestedComponent().getOrNull();
    if (!(target instanceof ProductionCppComponent)) {
        return;
    }
    final ProductionCppComponent testedComponent = (ProductionCppComponent) target;
    final TaskContainer tasks = project.getTasks();
    testedComponent.getBinaries().whenElementFinalized(testedBinary -> {
        if (!isTestedBinary(testExecutable, testedComponent, testedBinary)) {
            return;
        }
        // TODO - move this to a base plugin
        // Setup the dependency on the main binary
        // This should all be replaced by a single dependency that points at some "testable" variants of the main binary
        // Inherit implementation dependencies
        testExecutable.getImplementationDependencies().extendsFrom(((DefaultCppBinary) testedBinary).getImplementationDependencies());
        // Configure test binary to link against tested component compiled objects
        ConfigurableFileCollection testableObjects = project.files();
        if (target instanceof CppApplication) {
            // TODO - this should be an outgoing variant of the component under test
            TaskProvider<UnexportMainSymbol> unexportMainSymbol = tasks.register(testExecutable.getNames().getTaskName("relocateMainFor"), UnexportMainSymbol.class, task -> {
                String dirName = ((DefaultCppBinary) testedBinary).getNames().getDirName();
                task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir("obj/for-test/" + dirName));
                task.getObjects().from(testedBinary.getObjects());
            });
            testableObjects.from(unexportMainSymbol.map(task -> task.getRelocatedObjects()));
        } else {
            testableObjects.from(testedBinary.getObjects());
        }
        Dependency linkDependency = project.getDependencies().create(testableObjects);
        testExecutable.getLinkConfiguration().getDependencies().add(linkDependency);
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) NativeTestingBasePlugin(org.gradle.nativeplatform.test.plugins.NativeTestingBasePlugin) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) DefaultCppTestSuite(org.gradle.nativeplatform.test.cpp.internal.DefaultCppTestSuite) Callable(java.util.concurrent.Callable) Dimensions.tryToBuildOnHost(org.gradle.language.nativeplatform.internal.Dimensions.tryToBuildOnHost) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) CppPlatform(org.gradle.language.cpp.CppPlatform) Inject(javax.inject.Inject) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) DefaultNativePlatform(org.gradle.nativeplatform.platform.internal.DefaultNativePlatform) TaskProvider(org.gradle.api.tasks.TaskProvider) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) CppComponent(org.gradle.language.cpp.CppComponent) CppApplication(org.gradle.language.cpp.CppApplication) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) NativeComponentFactory(org.gradle.language.internal.NativeComponentFactory) ConfigurableComponentWithLinkUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithLinkUsage) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) DefaultCppTestExecutable(org.gradle.nativeplatform.test.cpp.internal.DefaultCppTestExecutable) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) Dimensions(org.gradle.language.nativeplatform.internal.Dimensions) InstallExecutable(org.gradle.nativeplatform.tasks.InstallExecutable) ToolChainSelector(org.gradle.language.nativeplatform.internal.toolchains.ToolChainSelector) CppTestSuite(org.gradle.nativeplatform.test.cpp.CppTestSuite) CppTestExecutable(org.gradle.nativeplatform.test.cpp.CppTestExecutable) SetProperty(org.gradle.api.provider.SetProperty) ProviderFactory(org.gradle.api.provider.ProviderFactory) Stream(java.util.stream.Stream) ObjectFactory(org.gradle.api.model.ObjectFactory) TaskContainer(org.gradle.api.tasks.TaskContainer) CppBinary(org.gradle.language.cpp.CppBinary) CppBasePlugin(org.gradle.language.cpp.plugins.CppBasePlugin) Dependency(org.gradle.api.artifacts.Dependency) Plugin(org.gradle.api.Plugin) RunTestExecutable(org.gradle.nativeplatform.test.tasks.RunTestExecutable) DefaultCppPlatform(org.gradle.language.cpp.internal.DefaultCppPlatform) TaskContainer(org.gradle.api.tasks.TaskContainer) CppComponent(org.gradle.language.cpp.CppComponent) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) CppApplication(org.gradle.language.cpp.CppApplication) UnexportMainSymbol(org.gradle.language.nativeplatform.tasks.UnexportMainSymbol) Dependency(org.gradle.api.artifacts.Dependency) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent)

Example 33 with Dependency

use of org.gradle.api.artifacts.Dependency in project curiostack by curioswitch.

the class GenerateProtoTask method downloadTools.

private Map<String, File> downloadTools(List<String> artifacts) {
    RepositoryHandler repositories = getProject().getRepositories();
    List<ArtifactRepository> currentRepositories = ImmutableList.copyOf(repositories);
    // Make sure Maven Central is present as a repository since it's the usual place to
    // get protoc, even for non-Java projects. We restore to the previous state after the task.
    repositories.mavenCentral();
    List<Dependency> dependencies = artifacts.stream().map(artifact -> {
        checkArgument(!artifact.isEmpty(), "artifact must not be empty");
        List<String> coordinateParts = COORDINATE_SPLITTER.splitToList(artifact);
        List<String> artifactParts = ARTIFACT_SPLITTER.splitToList(coordinateParts.get(0));
        ImmutableMap.Builder<String, String> depParts = ImmutableMap.builderWithExpectedSize(5);
        // manipulation.
        if (artifactParts.size() > 0) {
            depParts.put("group", artifactParts.get(0));
        }
        if (artifactParts.size() > 1) {
            depParts.put("name", artifactParts.get(1));
        }
        if (artifactParts.size() > 2) {
            depParts.put("version", artifactParts.get(2));
        }
        if (artifactParts.size() > 3) {
            depParts.put("classifier", artifactParts.get(3));
        } else {
            depParts.put("classifier", getProject().getExtensions().getByType(OsDetector.class).getClassifier());
        }
        if (coordinateParts.size() > 1) {
            depParts.put("ext", coordinateParts.get(1));
        } else {
            depParts.put("ext", "exe");
        }
        return getProject().getDependencies().create(depParts.build());
    }).collect(toImmutableList());
    Configuration configuration = getProject().getConfigurations().getByName("protobufTools");
    configuration.getDependencies().addAll(dependencies);
    // Resolve once to download all tools in parallel.
    configuration.resolve();
    // This will not re-download.
    ResolvedConfiguration resolved = configuration.getResolvedConfiguration();
    Map<String, File> downloaded = Streams.zip(artifacts.stream(), dependencies.stream(), (artifact, dep) -> {
        Set<File> files = resolved.getFiles(d -> {
            // Dependency.contentEquals doesn't match for some reason...
            return Objects.equals(dep.getGroup(), d.getGroup()) && dep.getName().equals(d.getName()) && Objects.equals(dep.getVersion(), d.getVersion());
        });
        checkState(files.size() == 1);
        File file = Iterables.getOnlyElement(files);
        if (!file.canExecute()) {
            if (!file.setExecutable(true)) {
                throw new IllegalStateException("Could not set proto tool to executable: " + file.getAbsolutePath());
            }
        }
        return new SimpleImmutableEntry<>(artifact, file);
    }).collect(toImmutableMap(Entry::getKey, Entry::getValue));
    repositories.clear();
    repositories.addAll(currentRepositories);
    return downloaded;
}
Also used : Executable(org.curioswitch.gradle.protobuf.ProtobufExtension.Executable) ArtifactRepository(org.gradle.api.artifacts.repositories.ArtifactRepository) ListProperty(org.gradle.api.provider.ListProperty) InputFiles(org.gradle.api.tasks.InputFiles) TaskAction(org.gradle.api.tasks.TaskAction) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) DefaultTask(org.gradle.api.DefaultTask) Splitter(com.google.common.base.Splitter) ImmutableMap(com.google.common.collect.ImmutableMap) DescriptorSetOptions(org.curioswitch.gradle.protobuf.ProtobufExtension.DescriptorSetOptions) Project(org.gradle.api.Project) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) ExternalExecUtil(org.curioswitch.gradle.helpers.exec.ExternalExecUtil) Set(java.util.Set) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) OutputDirectories(org.gradle.api.tasks.OutputDirectories) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) List(java.util.List) OutputFile(org.gradle.api.tasks.OutputFile) WorkerExecutor(org.gradle.workers.WorkerExecutor) Entry(java.util.Map.Entry) ExecSpec(org.gradle.process.ExecSpec) ProtobufExtension(org.curioswitch.gradle.protobuf.ProtobufExtension) Iterables(com.google.common.collect.Iterables) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) ImmutableList(com.google.common.collect.ImmutableList) DirectoryProperty(org.gradle.api.file.DirectoryProperty) PathSensitivity(org.gradle.api.tasks.PathSensitivity) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) OsDetector(com.google.gradle.osdetector.OsDetector) Action(org.gradle.api.Action) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) File(java.io.File) LanguageSettings(org.curioswitch.gradle.protobuf.ProtobufExtension.LanguageSettings) ObjectFactory(org.gradle.api.model.ObjectFactory) SourceSetUtils(org.curioswitch.gradle.protobuf.utils.SourceSetUtils) Property(org.gradle.api.provider.Property) CacheableTask(org.gradle.api.tasks.CacheableTask) PathSensitive(org.gradle.api.tasks.PathSensitive) Dependency(org.gradle.api.artifacts.Dependency) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) Set(java.util.Set) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) ArtifactRepository(org.gradle.api.artifacts.repositories.ArtifactRepository) Dependency(org.gradle.api.artifacts.Dependency) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) OsDetector(com.google.gradle.osdetector.OsDetector) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler) OutputFile(org.gradle.api.tasks.OutputFile) File(java.io.File)

Example 34 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class DefaultDependenciesToModuleDescriptorConverter method addDependencies.

private void addDependencies(BuildableLocalComponentMetadata metaData, ConfigurationInternal configuration) {
    AttributeContainerInternal attributes = configuration.getAttributes();
    for (Dependency dependency : configuration.getDependencies()) {
        if (dependency instanceof ModuleDependency) {
            ModuleDependency moduleDependency = (ModuleDependency) dependency;
            metaData.addDependency(dependencyDescriptorFactory.createDependencyDescriptor(configuration.getName(), attributes, moduleDependency));
        } else if (dependency instanceof FileCollectionDependency) {
            final FileCollectionDependency fileDependency = (FileCollectionDependency) dependency;
            metaData.addFiles(configuration.getName(), new DefaultLocalFileDependencyMetadata(fileDependency));
        } else {
            throw new IllegalArgumentException("Cannot convert dependency " + dependency + " to local component dependency metadata.");
        }
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) Dependency(org.gradle.api.artifacts.Dependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) FileCollectionDependency(org.gradle.api.artifacts.FileCollectionDependency) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 35 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class PluginResolutionServiceResolver method resolvePluginDependencies.

private ClassPath resolvePluginDependencies(final PluginUseMetaData metadata) {
    DependencyResolutionServices resolution = dependencyResolutionServicesFactory.create();
    RepositoryHandler repositories = resolution.getResolveRepositoryHandler();
    final String repoUrl = metadata.implementation.get("repo");
    repositories.maven(new Action<MavenArtifactRepository>() {

        public void execute(MavenArtifactRepository mavenArtifactRepository) {
            mavenArtifactRepository.setUrl(repoUrl);
        }
    });
    Dependency dependency = resolution.getDependencyHandler().create(metadata.implementation.get("gav"));
    ConfigurationContainerInternal configurations = (ConfigurationContainerInternal) resolution.getConfigurationContainer();
    ConfigurationInternal configuration = configurations.detachedConfiguration(dependency);
    try {
        Set<File> files = configuration.getResolvedConfiguration().getFiles(Specs.satisfyAll());
        return new DefaultClassPath(files);
    } catch (ResolveException e) {
        throw new DependencyResolutionException("Failed to resolve all plugin dependencies from " + repoUrl, e.getCause());
    }
}
Also used : ConfigurationContainerInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationContainerInternal) Dependency(org.gradle.api.artifacts.Dependency) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) ResolveException(org.gradle.api.artifacts.ResolveException) DependencyResolutionServices(org.gradle.api.internal.artifacts.DependencyResolutionServices) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler) File(java.io.File) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Aggregations

Dependency (org.gradle.api.artifacts.Dependency)58 Configuration (org.gradle.api.artifacts.Configuration)20 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)16 File (java.io.File)13 Project (org.gradle.api.Project)13 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)12 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)8 MinimalExternalModuleDependency (org.gradle.api.artifacts.MinimalExternalModuleDependency)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)6 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 DependencySet (org.gradle.api.artifacts.DependencySet)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 TaskDependency (org.gradle.api.tasks.TaskDependency)5 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)4 Map (java.util.Map)4 Provider (org.gradle.api.provider.Provider)4