org.gradle.api.artifacts.repositories.ArtifactRepository Java Examples

The following examples show how to use org.gradle.api.artifacts.repositories.ArtifactRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProjectDependencyArtifactIdExtractorHack.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String extract() {
    Collection<Upload> tasks = project.getTasks().withType(Upload.class);
    Collection<ArtifactRepository> repositories = getRepositories(tasks);
    if (!onlyContainsMavenResolvers(repositories)) { return project.getName(); }

    Collection<MavenDeployer> deployers = getMavenDeployers(repositories);
    Set<String> artifactIds = getArtifactIds(deployers);
    if (artifactIds.size() == 1) {
        String artifactId = artifactIds.iterator().next();
        if (artifactId != null && !artifactId.equals(MavenProject.EMPTY_PROJECT_ARTIFACT_ID)) {
            return artifactId;
        }
    }
    String baseName = getArchivesBaseName();
    return baseName != null ? baseName : project.getName();
}
 
Example #2
Source File: DefaultArtifactRepositoryContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DependencyResolver addAfter(Object userDescription, final String beforeResolverName, Closure configureClosure) {
    if (!GUtil.isTrue(beforeResolverName)) {
        throw new InvalidUserDataException("You must specify beforeResolverName");
    }
    DeprecationLogger.nagUserOfDiscontinuedMethod("ArtifactRepositoryContainer.addAfter()");
    final ArtifactRepository before = getByName(beforeResolverName);

    return addCustomDependencyResolver(userDescription, configureClosure, new Action<ArtifactRepository>() {
        public void execute(ArtifactRepository repository) {
            int insertPos = indexOf(before) + 1;
            if (insertPos == size()) {
                DefaultArtifactRepositoryContainer.super.add(repository);
            } else {
                DefaultArtifactRepositoryContainer.this.add(insertPos, repository);
            }
        }
    });
}
 
Example #3
Source File: ProjectDependencyArtifactIdExtractorHack.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String extract() {
    Collection<Upload> tasks = project.getTasks().withType(Upload.class);
    Collection<ArtifactRepository> repositories = getRepositories(tasks);
    if (!onlyContainsMavenResolvers(repositories)) { return project.getName(); }

    Collection<MavenDeployer> deployers = getMavenDeployers(repositories);
    Set<String> artifactIds = getArtifactIds(deployers);
    if (artifactIds.size() == 1) {
        String artifactId = artifactIds.iterator().next();
        if (artifactId != null && !artifactId.equals(MavenProject.EMPTY_PROJECT_ARTIFACT_ID)) {
            return artifactId;
        }
    }
    String baseName = getArchivesBaseName();
    return baseName != null ? baseName : project.getName();
}
 
Example #4
Source File: ProjectDependencyArtifactIdExtractorHack.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public String extract() {
    Collection<Upload> tasks = project.getTasks().withType(Upload.class);
    Collection<ArtifactRepository> repositories = getRepositories(tasks);
    if (!onlyContainsMavenResolvers(repositories)) { return project.getName(); }

    Collection<MavenDeployer> deployers = getMavenDeployers(repositories);
    Set<String> artifactIds = getArtifactIds(deployers);
    if (artifactIds.size() == 1) {
        String artifactId = artifactIds.iterator().next();
        if (artifactId != null && !artifactId.equals(MavenProject.EMPTY_PROJECT_ARTIFACT_ID)) {
            return artifactId;
        }
    }
    String baseName = getArchivesBaseName();
    return baseName != null ? baseName : project.getName();
}
 
Example #5
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DependencyResolver addAfter(Object userDescription, final String beforeResolverName, Closure configureClosure) {
    if (!GUtil.isTrue(beforeResolverName)) {
        throw new InvalidUserDataException("You must specify beforeResolverName");
    }
    DeprecationLogger.nagUserOfDiscontinuedMethod("ArtifactRepositoryContainer.addAfter()");
    final ArtifactRepository before = getByName(beforeResolverName);

    return addCustomDependencyResolver(userDescription, configureClosure, new Action<ArtifactRepository>() {
        public void execute(ArtifactRepository repository) {
            int insertPos = indexOf(before) + 1;
            if (insertPos == size()) {
                DefaultArtifactRepositoryContainer.super.add(repository);
            } else {
                DefaultArtifactRepositoryContainer.this.add(insertPos, repository);
            }
        }
    });
}
 
Example #6
Source File: DefaultArtifactRepositoryContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends ArtifactRepository> T addWithUniqueName(T repository, String defaultName, Action<? super T> insertion) {
    String repositoryName = repository.getName();
    if (!GUtil.isTrue(repositoryName)) {
        repository.setName(uniquifyName(defaultName));
    } else {
        repository.setName(uniquifyName(repositoryName));
    }

    assertCanAdd(repository.getName());
    insertion.execute(repository);
    return repository;
}
 
Example #7
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultArtifactRepositoryContainer(Instantiator instantiator) {
    super(ArtifactRepository.class, instantiator, new RepositoryNamer());
    whenObjectAdded(new Action<ArtifactRepository>() {
        public void execute(ArtifactRepository artifactRepository) {
            if (artifactRepository instanceof ArtifactRepositoryInternal) {
                ArtifactRepositoryInternal repository = (ArtifactRepositoryInternal) artifactRepository;
                repository.onAddToContainer(DefaultArtifactRepositoryContainer.this);
            }
        }
    });
}
 
Example #8
Source File: ProjectDependencyArtifactIdExtractorHack.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean onlyContainsMavenResolvers(Collection<ArtifactRepository> repositories) {
    for (ArtifactRepository repository : repositories) {
        if (!(repository instanceof MavenResolver)) {
            return false;
        }
    }
    return true;
}
 
Example #9
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends ArtifactRepository> T addWithUniqueName(T repository, String defaultName, Action<? super T> insertion) {
    String repositoryName = repository.getName();
    if (!GUtil.isTrue(repositoryName)) {
        repository.setName(uniquifyName(defaultName));
    } else {
        repository.setName(uniquifyName(repositoryName));
    }

    assertCanAdd(repository.getName());
    insertion.execute(repository);
    return repository;
}
 
Example #10
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DependencyResolver addBefore(Object userDescription, final String afterResolverName, Closure configureClosure) {
    if (!GUtil.isTrue(afterResolverName)) {
        throw new InvalidUserDataException("You must specify afterResolverName");
    }
    DeprecationLogger.nagUserOfDiscontinuedMethod("ArtifactRepositoryContainer.addBefore()");
    final ArtifactRepository after = getByName(afterResolverName);
    return addCustomDependencyResolver(userDescription, configureClosure, new Action<ArtifactRepository>() {
        public void execute(ArtifactRepository repository) {
            DefaultArtifactRepositoryContainer.super.add(indexOf(after), repository);
        }
    });
}
 
Example #11
Source File: ProjectDependencyArtifactIdExtractorHack.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean onlyContainsMavenResolvers(Collection<ArtifactRepository> repositories) {
    for (ArtifactRepository repository : repositories) {
        if (!(repository instanceof MavenResolver)) {
            return false;
        }
    }
    return true;
}
 
Example #12
Source File: NativeComponentModelPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DefaultRepositories(final Instantiator instantiator, final FileResolver fileResolver, final Action<PrebuiltLibrary> binaryFactory) {
    super(ArtifactRepository.class, instantiator, new ArtifactRepositoryNamer());
    registerFactory(PrebuiltLibraries.class, new NamedDomainObjectFactory<PrebuiltLibraries>() {
        public PrebuiltLibraries create(String name) {
            return instantiator.newInstance(DefaultPrebuiltLibraries.class, name, instantiator, fileResolver, binaryFactory);
        }
    });
}
 
Example #13
Source File: RepositoriesFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DefaultRepositories(final Instantiator instantiator, final FileResolver fileResolver, final Action<PrebuiltLibrary> binaryFactory) {
    super(ArtifactRepository.class, instantiator, new ArtifactRepositoryNamer());
    registerFactory(PrebuiltLibraries.class, new NamedDomainObjectFactory<PrebuiltLibraries>() {
        public PrebuiltLibraries create(String name) {
            return instantiator.newInstance(DefaultPrebuiltLibraries.class, name, instantiator, fileResolver, binaryFactory);
        }
    });
}
 
Example #14
Source File: ProjectDependencyArtifactIdExtractorHack.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Collection<MavenDeployer> getMavenDeployers(Collection<ArtifactRepository> repositories) {
    Collection<MavenDeployer> result = Lists.newArrayList();
    for (ArtifactRepository repository : repositories) {
        if (repository instanceof MavenDeployer) {
            result.add((MavenDeployer) repository);
        }
    }
    return result;
}
 
Example #15
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<DependencyResolver> getResolvers() {
    DeprecationLogger.nagUserOfDiscontinuedMethod("ArtifactRepositoryContainer.getResolvers()");
    List<DependencyResolver> returnedResolvers = new ArrayList<DependencyResolver>();
    for (ArtifactRepository repository : this) {
        returnedResolvers.add(baseRepositoryFactory.toResolver(repository));
    }
    return returnedResolvers;
}
 
Example #16
Source File: DefaultArtifactRepositoryContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DependencyResolver addCustomDependencyResolver(Object userDescription, Closure configureClosure, Action<ArtifactRepository> orderAction) {
    ArtifactRepository repository = baseRepositoryFactory.createRepository(userDescription);
    DependencyResolver resolver = baseRepositoryFactory.toResolver(repository);
    ConfigureUtil.configure(configureClosure, resolver);
    ArtifactRepository resolverRepository = baseRepositoryFactory.createResolverBackedRepository(resolver);
    addWithUniqueName(resolverRepository, "repository", orderAction);
    return resolver;
}
 
Example #17
Source File: DefaultArtifactRepositoryContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DependencyResolver addBefore(Object userDescription, final String afterResolverName, Closure configureClosure) {
    if (!GUtil.isTrue(afterResolverName)) {
        throw new InvalidUserDataException("You must specify afterResolverName");
    }
    DeprecationLogger.nagUserOfDiscontinuedMethod("ArtifactRepositoryContainer.addBefore()");
    final ArtifactRepository after = getByName(afterResolverName);
    return addCustomDependencyResolver(userDescription, configureClosure, new Action<ArtifactRepository>() {
        public void execute(ArtifactRepository repository) {
            DefaultArtifactRepositoryContainer.super.add(indexOf(after), repository);
        }
    });
}
 
Example #18
Source File: DefaultArtifactRepositoryContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends ArtifactRepository> T addWithUniqueName(T repository, String defaultName, Action<? super T> insertion) {
    String repositoryName = repository.getName();
    if (!GUtil.isTrue(repositoryName)) {
        repository.setName(uniquifyName(defaultName));
    } else {
        repository.setName(uniquifyName(repositoryName));
    }

    assertCanAdd(repository.getName());
    insertion.execute(repository);
    cast(ArtifactRepositoryInternal.class, repository).onAddToContainer(this);
    return repository;
}
 
Example #19
Source File: RepositoriesFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DefaultRepositories(final Instantiator instantiator, final FileResolver fileResolver, final Action<PrebuiltLibrary> binaryFactory) {
    super(ArtifactRepository.class, instantiator, new ArtifactRepositoryNamer());
    registerFactory(PrebuiltLibraries.class, new NamedDomainObjectFactory<PrebuiltLibraries>() {
        public PrebuiltLibraries create(String name) {
            return instantiator.newInstance(DefaultPrebuiltLibraries.class, name, instantiator, fileResolver, binaryFactory);
        }
    });
}
 
Example #20
Source File: ProjectDependencyArtifactIdExtractorHack.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Collection<ArtifactRepository> getRepositories(Collection<Upload> tasks) {
    Collection<ArtifactRepository> result = Lists.newArrayList();
    for (Upload task : tasks) {
        result.addAll(task.getRepositories());
    }
    return result;
}
 
Example #21
Source File: ProjectDependencyArtifactIdExtractorHack.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean onlyContainsMavenResolvers(Collection<ArtifactRepository> repositories) {
    for (ArtifactRepository repository : repositories) {
        if (!(repository instanceof MavenResolver)) {
            return false;
        }
    }
    return true;
}
 
Example #22
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private <T extends ArtifactRepository> T addWithUniqueName(T repository, String defaultName, Action<? super T> insertion) {
    String repositoryName = repository.getName();
    if (!GUtil.isTrue(repositoryName)) {
        repository.setName(uniquifyName(defaultName));
    } else {
        repository.setName(uniquifyName(repositoryName));
    }

    assertCanAdd(repository.getName());
    insertion.execute(repository);
    cast(ArtifactRepositoryInternal.class, repository).onAddToContainer(this);
    return repository;
}
 
Example #23
Source File: GenerateProtoTask.java    From curiostack with MIT License 4 votes vote down vote up
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);

                // Do a loose matching to allow for the possibility of dependency management
                // 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;
}
 
Example #24
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addFirst(ArtifactRepository repository) {
    add(0, repository);
}
 
Example #25
Source File: NativeComponentModelPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public String determineName(ArtifactRepository object) {
    return object.getName();
}
 
Example #26
Source File: PublishOperation.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected PublishOperation(Publication publication, ArtifactRepository repository) {
    this.publication = publication;
    this.repository = repository;
}
 
Example #27
Source File: NativeComponentModelPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public String determineName(ArtifactRepository object) {
    return object.getName();
}
 
Example #28
Source File: JavaScriptRepositoriesExtension.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactRepository gradle() {
    return gradle(Actions.doNothing());
}
 
Example #29
Source File: DefaultArtifactRepositoryContainer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void addLast(ArtifactRepository repository) {
    add(repository);
}
 
Example #30
Source File: AbstractArtifactRepository.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onAddToContainer(NamedDomainObjectCollection<ArtifactRepository> container) {
    isPartOfContainer = true;
}