use of org.gradle.api.artifacts.repositories.ArtifactRepository in project gradle by gradle.
the class PluginDependencyResolutionServices method getPluginRepositoriesProvider.
public PluginRepositoriesProvider getPluginRepositoriesProvider() {
return new PluginRepositoriesProvider() {
@Override
public List<ArtifactRepository> getPluginRepositories() {
RepositoryHandler repositories = getResolveRepositoryHandler();
List<ArtifactRepository> list = new ArrayList<ArtifactRepository>(repositories.size());
for (ArtifactRepository repository : repositories) {
list.add(new PluginArtifactRepository(repository));
}
return list;
}
};
}
use of org.gradle.api.artifacts.repositories.ArtifactRepository 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;
}
Aggregations