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);
});
}
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);
});
}
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;
}
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.");
}
}
}
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());
}
}
Aggregations