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(); }
@Override protected ArtifactRepository internalCreateArtifactRepository(RepositoryHandler repositoryHandler) { return repositoryHandler.maven(new Action<MavenArtifactRepository>() { @Override public void execute(MavenArtifactRepository mavenArtifactRepository) { mavenArtifactRepository.setName(getArtifactRepositoryName()); mavenArtifactRepository.setUrl(getUrl()); Credentials credentials = authenticationSupport().getConfiguredCredentials(); if (credentials != null) { ((AuthenticationSupportedInternal)mavenArtifactRepository).setConfiguredCredentials(credentials); mavenArtifactRepository.authentication(new Action<AuthenticationContainer>() { @Override public void execute(AuthenticationContainer authenticationContainer) { authenticationContainer.addAll(authenticationSupport().getConfiguredAuthentication()); } }); } } }); }
@Override protected ArtifactRepository internalCreateArtifactRepository(RepositoryHandler repositoryHandler) { return repositoryHandler.ivy(new Action<IvyArtifactRepository>() { @Override public void execute(IvyArtifactRepository ivyArtifactRepository) { ivyArtifactRepository.setName(getArtifactRepositoryName()); ivyArtifactRepository.setUrl(getUrl()); Credentials credentials = authenticationSupport().getConfiguredCredentials(); if (credentials != null) { ((AuthenticationSupportedInternal)ivyArtifactRepository).setConfiguredCredentials(credentials); ivyArtifactRepository.authentication(new Action<AuthenticationContainer>() { @Override public void execute(AuthenticationContainer authenticationContainer) { authenticationContainer.addAll(authenticationSupport().getConfiguredAuthentication()); } }); } } }); }
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); } } }); }
private Collection<ArtifactRepository> getRepositories(Collection<Upload> tasks) { Collection<ArtifactRepository> result = Lists.newArrayList(); for (Upload task : tasks) { result.addAll(task.getRepositories()); } return result; }
private boolean onlyContainsMavenResolvers(Collection<ArtifactRepository> repositories) { for (ArtifactRepository repository : repositories) { if (!(repository instanceof MavenResolver)) { return false; } } return true; }
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; }
@Override public ArtifactRepository createArtifactRepository(RepositoryHandler repositoryHandler) { return repositoryHandler.maven(new Action<MavenArtifactRepository>() { @Override public void execute(MavenArtifactRepository mavenArtifactRepository) { mavenArtifactRepository.setUrl("https://plugins.gradle.org/m2"); } }); }
private DefaultRepositories(final Instantiator instantiator, final SourceDirectorySetFactory sourceDirectorySetFactory, 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, sourceDirectorySetFactory, binaryFactory); } }); }
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); } } }); }
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; }
public static List<DefaultMavenArtifactRepository> getMavenRepositories(Project project) { List<DefaultMavenArtifactRepository> repos = new ArrayList<>(); PublishingExtension publishingExtension = getPublishingExtension(project); if (publishingExtension != null) { RepositoryHandler repositoryHandler = publishingExtension.getRepositories(); for (ArtifactRepository repo : repositoryHandler) { repos.add((DefaultMavenArtifactRepository)repo); } } return repos; }
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); } }); }
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); } }); }
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; }
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; }
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; }
@Override public void execute(DependencyResolveDetails dependencyResolveDetails) { String group = dependencyResolveDetails.getTarget().getGroup(); String name = dependencyResolveDetails.getTarget().getName(); if (aetherPlugin.getVersionMap().containsKey(group) && aetherPlugin.getVersionMap().get(group).containsKey(name)) { if (dependencyResolveDetails.getRequested().getVersion().equals(dependencyResolveDetails.getTarget().getVersion())) { dependencyResolveDetails.useVersion(aetherPlugin.getVersionMap().get(group).get(name)); } } else { RepositorySystem system = setupRepositorySystem(); RepositorySystemSession session = setupSession(project, system); List<RemoteRepository> remoteRepositories = new ArrayList<>(); for (ArtifactRepository artifactRepository : project.getRepositories()) { if (artifactRepository instanceof MavenArtifactRepository) { MavenArtifactRepository mavenArtifactRepository = (MavenArtifactRepository) artifactRepository; remoteRepositories.add(new RemoteRepository.Builder(mavenArtifactRepository.getName(), "default", mavenArtifactRepository.getUrl().toString()).build()); } } Artifact artifact = new DefaultArtifact(dependencyResolveDetails.getTarget().getGroup() + ":" + dependencyResolveDetails.getTarget().getName() + ":" + dependencyResolveDetails.getTarget().getVersion()); CollectRequest collectRequest = new CollectRequest(); String scope; if (configuration.getName().contains("test")) { scope = JavaScopes.TEST; } else if (configuration.getName().contains("runtime")) { scope = JavaScopes.RUNTIME; } else if (configuration.getName().equals("providedCompile") || configuration.getName().equals("compileOnly")) { scope = JavaScopes.PROVIDED; } else scope = JavaScopes.COMPILE; collectRequest.setRoot(new Dependency(artifact, scope)); collectRequest.setRepositories(remoteRepositories); try { CollectResult collectResult = system.collectDependencies(session, collectRequest); processDependencyNode(collectResult.getRoot()); } catch (DependencyCollectionException e) { e.printStackTrace(); } } }
public ArtifactRepository gradle() { return gradle(Actions.doNothing()); }
@Override public ArtifactRepository createArtifactRepository(RepositoryHandler repositoryHandler) { ArtifactRepository repo = internalCreateArtifactRepository(repositoryHandler); hasYieldedArtifactRepository.set(true); return repo; }
public void onAddToContainer(NamedDomainObjectCollection<ArtifactRepository> container) { isPartOfContainer = true; }
@Override public String determineName(ArtifactRepository object) { return object.getName(); }
public void execute(ArtifactRepository repository) { DefaultArtifactRepositoryContainer.super.add(repository); }
public String determineName(ArtifactRepository r) { return r.getName(); }
public void addFirst(ArtifactRepository repository) { add(0, repository); }
public void addLast(ArtifactRepository repository) { add(repository); }
public <T extends ArtifactRepository> T addRepository(T repository, String defaultName) { return addRepository(repository, defaultName, Actions.doNothing()); }
public <T extends ArtifactRepository> T addRepository(T repository, String defaultName, Action<? super T> configureAction) { configureAction.execute(repository); return addWithUniqueName(repository, defaultName, addLastAction); }
/** * Performs the wiring for the given Gradle {@link Project}. * * @param project */ public static void init(final Project project) { final Path srcdepsYamlPath = project.getRootDir().toPath().resolve("srcdeps.yaml"); Gradle gradle = project.getGradle(); if (!(gradle instanceof GradleInternal)) { throw new RuntimeException(String.format("Expected %s, but found %s", GradleInternal.class.getName(), gradle.getClass().getName())); } ServiceRegistry services = ((GradleInternal) gradle).getServices(); if (!(services instanceof DefaultServiceRegistry)) { throw new RuntimeException(String.format("Expected %s, but found %s", DefaultServiceRegistry.class.getName(), services.getClass().getName())); } ArtifactRepository repo = project.getRepositories() .findByName(org.gradle.api.artifacts.ArtifactRepositoryContainer.DEFAULT_MAVEN_LOCAL_REPO_NAME); if (!(repo instanceof MavenArtifactRepository)) { throw new RuntimeException( String.format("Expected %s, but found %s", MavenArtifactRepository.class.getName(), repo)); } final MavenLocalRepository localRepository = new MavenLocalRepository(Paths.get(((MavenArtifactRepository) repo).getUrl())); final Path scrdepsDir = localRepository.getRootDirectory().getParent().resolve("srcdeps"); final PathLocker<SrcVersion> pathLocker = new PathLocker<>(); final BuildDirectoriesManager buildDirectoriesManager = new BuildDirectoriesManager(scrdepsDir, pathLocker); ClassLoader classloader = Wiring.class.getClassLoader(); final Module spaceModule = new SpaceModule(new URLClassSpace(classloader)); Module wrappedWiremodule = new Module() { @Override public void configure(Binder binder) { spaceModule.configure(binder); binder.bind(Path.class).annotatedWith(Names.named(ConfigurationService.SRCDEPS_YAML_PATH)) .toInstance(srcdepsYamlPath); binder.bind(MavenLocalRepository.class).toInstance(localRepository); binder.bind(new TypeLiteral<PathLocker<SrcVersion>>() { }).toInstance(pathLocker); binder.bind(BuildDirectoriesManager.class).toInstance(buildDirectoriesManager); } }; final Module wireModule = new WireModule(wrappedWiremodule); injector = Guice.createInjector(wireModule); }