Search in sources :

Example 1 with ArtifactRepository

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;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) ArtifactRepository(org.gradle.api.artifacts.repositories.ArtifactRepository) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler)

Example 2 with ArtifactRepository

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;
}
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)

Aggregations

ArrayList (java.util.ArrayList)2 RepositoryHandler (org.gradle.api.artifacts.dsl.RepositoryHandler)2 ArtifactRepository (org.gradle.api.artifacts.repositories.ArtifactRepository)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Splitter (com.google.common.base.Splitter)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Streams (com.google.common.collect.Streams)1 OsDetector (com.google.gradle.osdetector.OsDetector)1 File (java.io.File)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1