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()); } }
@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()); } }); } } }); }
ConfigurationResolver createDependencyResolver(ArtifactDependencyResolver artifactDependencyResolver, RepositoryHandler repositories, GlobalDependencyResolutionRules metadataHandler, ComponentIdentifierFactory componentIdentifierFactory, CacheLockingManager cacheLockingManager, ResolutionResultsStoreFactory resolutionResultsStoreFactory, StartParameter startParameter, AttributesSchema attributesSchema) { return new ErrorHandlingConfigurationResolver( new ShortCircuitEmptyConfigurationResolver( new DefaultConfigurationResolver( artifactDependencyResolver, repositories, metadataHandler, cacheLockingManager, resolutionResultsStoreFactory, startParameter.isBuildProjectDependencies(), attributesSchema), componentIdentifierFactory) ); }
/** * @see me.seeber.gradle.plugin.AbstractProjectConfigPlugin#initialize() */ @Override protected void initialize() { checkGradleVersion(); getProject().getPlugins().apply(TaskTreePlugin.class); ProjectContext context = new ProjectContext(getProject()); getProject().getExtensions().add("projectContext", context); RepositoryHandler repositories = getProject().getRepositories(); repositories.add(repositories.mavenLocal()); repositories.add(repositories.mavenCentral()); repositories.add(repositories.maven(r -> r.setUrl("https://plugins.gradle.org/m2"))); repositories.add(repositories.jcenter()); getProject().getConfigurations().all(c -> { c.resolutionStrategy(s -> { s.preferProjectModules(); s.cacheChangingModulesFor(0, "seconds"); }); }); }
/** * Creates a Provisioner for the given repositories. * * The first time a project is created, there are ~7 seconds of configuration * which will go away for all subsequent runs. * * Every call to resolve will take about 1 second, even when all artifacts are resolved. */ private static Supplier<Provisioner> createLazyWithRepositories(Consumer<RepositoryHandler> repoConfig) { // Running this takes ~3 seconds the first time it is called. Probably because of classloading. return Suppliers.memoize(() -> { Project project = ProjectBuilder.builder().build(); repoConfig.accept(project.getRepositories()); return mavenCoords -> { Dependency[] deps = mavenCoords.stream() .map(project.getDependencies()::create) .toArray(Dependency[]::new); Configuration config = project.getConfigurations().detachedConfiguration(deps); config.setDescription(mavenCoords.toString()); try { return config.resolve(); } catch (ResolveException e) { /* Provide Maven coordinates in exception message instead of static string 'detachedConfiguration' */ throw new ResolveException(config.getDescription(), e); } }; }); }
private void configureUploadTasks(final DefaultDeployerFactory deployerFactory) { project.getTasks().withType(Upload.class, new Action<Upload>() { public void execute(Upload upload) { RepositoryHandler repositories = upload.getRepositories(); DefaultRepositoryHandler handler = (DefaultRepositoryHandler) repositories; DefaultMavenRepositoryHandlerConvention repositoryConvention = new DefaultMavenRepositoryHandlerConvention(handler, deployerFactory); new DslObject(repositories).getConvention().getPlugins().put("maven", repositoryConvention); } }); }
public void apply(final Project project) { RepositoryHandler repositories = publicationServices.createRepositoryHandler(); PublicationContainer publications = instantiator.newInstance(DefaultPublicationContainer.class, instantiator); // TODO Registering an extension should register it with the model registry as well project.getExtensions().create(PublishingExtension.NAME, DefaultPublishingExtension.class, repositories, publications); Task publishLifecycleTask = project.getTasks().create(PUBLISH_LIFECYCLE_TASK_NAME); publishLifecycleTask.setDescription("Publishes all publications produced by this project."); publishLifecycleTask.setGroup(PUBLISH_TASK_GROUP); }
@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"); } }); }
public DefaultConfigurationResolver(ArtifactDependencyResolver resolver, RepositoryHandler repositories, GlobalDependencyResolutionRules metadataHandler, CacheLockingManager cacheLockingManager, ResolutionResultsStoreFactory storeFactory, boolean buildProjectDependencies, AttributesSchema attributesSchema) { this.resolver = resolver; this.repositories = repositories; this.metadataHandler = metadataHandler; this.cacheLockingManager = cacheLockingManager; this.storeFactory = storeFactory; this.buildProjectDependencies = buildProjectDependencies; this.attributesSchema = attributesSchema; }
public DefaultArtifactResolutionQuery(ConfigurationContainerInternal configurationContainer, RepositoryHandler repositoryHandler, ResolveIvyFactory ivyFactory, GlobalDependencyResolutionRules metadataHandler, CacheLockingManager lockingManager, ComponentTypeRegistry componentTypeRegistry) { this.configurationContainer = configurationContainer; this.repositoryHandler = repositoryHandler; this.ivyFactory = ivyFactory; this.metadataHandler = metadataHandler; this.lockingManager = lockingManager; this.componentTypeRegistry = componentTypeRegistry; }
public DefaultArtifactResolutionQueryFactory(ConfigurationContainerInternal configurationContainer, RepositoryHandler repositoryHandler, ResolveIvyFactory ivyFactory, GlobalDependencyResolutionRules metadataHandler, CacheLockingManager cacheLockingManager, ComponentTypeRegistry componentTypeRegistry) { this.configurationContainer = configurationContainer; this.repositoryHandler = repositoryHandler; this.ivyFactory = ivyFactory; this.metadataHandler = metadataHandler; this.cacheLockingManager = cacheLockingManager; this.componentTypeRegistry = componentTypeRegistry; }
private static SourceSetDependencyResolvingClasspath classpathFor(BinarySpec binary, JavaSourceSet javaSourceSet, ServiceRegistry serviceRegistry, ModelSchemaStore schemaStore) { Iterable<DependencySpec> dependencies = compileDependencies(binary, javaSourceSet); ArtifactDependencyResolver dependencyResolver = serviceRegistry.get(ArtifactDependencyResolver.class); RepositoryHandler repositories = serviceRegistry.get(RepositoryHandler.class); List<ResolutionAwareRepository> resolutionAwareRepositories = collect(repositories, Transformers.cast(ResolutionAwareRepository.class)); ModelSchema<? extends BinarySpec> schema = schemaStore.getSchema(((BinarySpecInternal) binary).getPublicType()); VariantsMetaData variantsMetaData = DefaultVariantsMetaData.extractFrom(binary, schema); AttributesSchema attributesSchema = serviceRegistry.get(AttributesSchema.class); return new SourceSetDependencyResolvingClasspath((BinarySpecInternal) binary, javaSourceSet, dependencies, dependencyResolver, variantsMetaData, resolutionAwareRepositories, attributesSchema); }
@Finalize public void configureRuntimeClasspath(@Each JvmTestSuiteBinarySpecInternal testBinary, ServiceRegistry serviceRegistry, ModelSchemaStore modelSchemaStore) { ArtifactDependencyResolver dependencyResolver = serviceRegistry.get(ArtifactDependencyResolver.class); RepositoryHandler repositories = serviceRegistry.get(RepositoryHandler.class); List<ResolutionAwareRepository> resolutionAwareRepositories = CollectionUtils.collect(repositories, Transformers.cast(ResolutionAwareRepository.class)); ModelSchema<? extends JvmTestSuiteBinarySpec> schema = Cast.uncheckedCast(modelSchemaStore.getSchema(((BinarySpecInternal) testBinary).getPublicType())); AttributesSchema attributesSchema = serviceRegistry.get(AttributesSchema.class); testBinary.setRuntimeClasspath(configureRuntimeClasspath(testBinary, dependencyResolver, resolutionAwareRepositories, schema, attributesSchema)); }
@Mutate @SuppressWarnings("UnusedDeclaration") public void createTasks(ModelMap<Task> tasks, PublishingExtension publishingExtension, @Path("buildDir") final File buildDir) { PublicationContainer publications = publishingExtension.getPublications(); RepositoryHandler repositories = publishingExtension.getRepositories(); for (final IvyPublicationInternal publication : publications.withType(IvyPublicationInternal.class)) { final String publicationName = publication.getName(); final String descriptorTaskName = "generateDescriptorFileFor" + capitalize(publicationName) + "Publication"; tasks.create(descriptorTaskName, GenerateIvyDescriptor.class, new Action<GenerateIvyDescriptor>() { public void execute(final GenerateIvyDescriptor descriptorTask) { descriptorTask.setDescription("Generates the Ivy Module Descriptor XML file for publication '" + publicationName + "'."); descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); descriptorTask.setDescriptor(publication.getDescriptor()); descriptorTask.setDestination(new File(buildDir, "publications/" + publicationName + "/ivy.xml")); } }); publication.setDescriptorFile(tasks.get(descriptorTaskName).getOutputs().getFiles()); for (final IvyArtifactRepository repository : repositories.withType(IvyArtifactRepository.class)) { final String repositoryName = repository.getName(); final String publishTaskName = "publish" + capitalize(publicationName) + "PublicationTo" + capitalize(repositoryName) + "Repository"; tasks.create(publishTaskName, PublishToIvyRepository.class, new Action<PublishToIvyRepository>() { public void execute(PublishToIvyRepository publishTask) { publishTask.setPublication(publication); publishTask.setRepository(repository); publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); publishTask.setDescription("Publishes Ivy publication '" + publicationName + "' to Ivy repository '" + repositoryName + "'."); } }); tasks.get(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).dependsOn(publishTaskName); } } }
@Override public RepositoryHandler getRepositories() { if (repositoryHandler == null) { repositoryHandler = dependencyResolutionServices.getResolveRepositoryHandler(); } return repositoryHandler; }
/** * Returns the repositories to upload to. */ @Internal public RepositoryHandler getRepositories() { if (repositories == null) { repositories = getPublicationServices().createRepositoryHandler(); } return repositories; }
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; }
public ScriptHandler create(ScriptSource scriptSource, ClassLoaderScope classLoaderScope, DomainObjectContext context) { DependencyResolutionServices services = dependencyManagementServices.create(fileResolver, dependencyMetaDataProvider, projectFinder, context); RepositoryHandler repositoryHandler = services.getResolveRepositoryHandler(); ConfigurationContainer configurationContainer = services.getConfigurationContainer(); DependencyHandler dependencyHandler = services.getDependencyHandler(); return new DefaultScriptHandler(scriptSource, repositoryHandler, dependencyHandler, configurationContainer, new ScriptHandlerClassLoaderFactory(scriptSource, classLoaderScope)); }
public DefaultScriptHandler( ScriptSource scriptSource, RepositoryHandler repositoryHandler, DependencyHandler dependencyHandler, ConfigurationContainer configContainer, Factory<ClassLoader> classLoaderFactory ) { this.repositoryHandler = repositoryHandler; this.dependencyHandler = dependencyHandler; this.scriptSource = scriptSource; this.configContainer = configContainer; this.classLoaderFactory = classLoaderFactory; classpathConfiguration = configContainer.create(CLASSPATH_CONFIGURATION); }
public AbstractScriptHandler(RepositoryHandler repositoryHandler, DependencyHandler dependencyHandler, ScriptSource scriptSource, ConfigurationContainer configContainer) { this.repositoryHandler = repositoryHandler; this.dependencyHandler = dependencyHandler; this.scriptSource = scriptSource; this.configContainer = configContainer; classpathConfiguration = configContainer.create(CLASSPATH_CONFIGURATION); }
/** * Returns the repositories to upload to. */ public RepositoryHandler getRepositories() { if (repositories == null) { repositories = getPublicationServices().createRepositoryHandler(); } return repositories; }
public DefaultArtifactResolutionQuery(ConfigurationContainerInternal configurationContainer, RepositoryHandler repositoryHandler, ResolveIvyFactory ivyFactory, ModuleMetadataProcessor metadataProcessor, CacheLockingManager lockingManager) { this.configurationContainer = configurationContainer; this.repositoryHandler = repositoryHandler; this.ivyFactory = ivyFactory; this.metadataProcessor = metadataProcessor; this.lockingManager = lockingManager; }
public DefaultArtifactResolutionQueryFactory(ConfigurationContainerInternal configurationContainer, RepositoryHandler repositoryHandler, ResolveIvyFactory ivyFactory, ModuleMetadataProcessor metadataProcessor, CacheLockingManager cacheLockingManager) { this.configurationContainer = configurationContainer; this.repositoryHandler = repositoryHandler; this.ivyFactory = ivyFactory; this.metadataProcessor = metadataProcessor; this.cacheLockingManager = cacheLockingManager; }
public void createTasks(TaskContainer tasks, PublishingExtension publishingExtension) { PublicationContainer publications = publishingExtension.getPublications(); RepositoryHandler repositories = publishingExtension.getRepositories(); for (final IvyPublicationInternal publication : publications.withType(IvyPublicationInternal.class)) { final String publicationName = publication.getName(); final String descriptorTaskName = String.format("generateDescriptorFileFor%sPublication", capitalize(publicationName)); GenerateIvyDescriptor descriptorTask = tasks.create(descriptorTaskName, GenerateIvyDescriptor.class); descriptorTask.setDescription(String.format("Generates the Ivy Module Descriptor XML file for publication '%s'.", publication.getName())); descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); descriptorTask.setDescriptor(publication.getDescriptor()); ConventionMapping descriptorTaskConventionMapping = new DslObject(descriptorTask).getConventionMapping(); descriptorTaskConventionMapping.map("destination", new Callable<Object>() { public Object call() throws Exception { return new File(project.getBuildDir(), "publications/" + publication.getName() + "/ivy.xml"); } }); publication.setDescriptorFile(descriptorTask.getOutputs().getFiles()); for (IvyArtifactRepository repository : repositories.withType(IvyArtifactRepository.class)) { final String repositoryName = repository.getName(); final String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName)); PublishToIvyRepository publishTask = tasks.create(publishTaskName, PublishToIvyRepository.class); publishTask.setPublication(publication); publishTask.setRepository(repository); publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP); publishTask.setDescription(String.format("Publishes Ivy publication '%s' to Ivy repository '%s'.", publicationName, repositoryName)); tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).dependsOn(publishTask); } } }
public ModuleMappingPluginResolver(String name, DependencyResolutionServices dependencyResolutionServices, Instantiator instantiator, Mapper mapper, Action<? super RepositoryHandler> repositoriesConfigurer) { this.name = name; this.dependencyResolutionServices = dependencyResolutionServices; this.instantiator = instantiator; this.mapper = mapper; this.repositoriesConfigurer = repositoriesConfigurer; }
public DefaultPublishingExtension(RepositoryHandler repositories, PublicationContainer publications) { this.repositories = repositories; this.publications = publications; }
public RepositoryHandler getRepositories() { return repositories; }
public void repositories(Action<? super RepositoryHandler> configure) { configure.execute(repositories); }
public JavaScriptRepositoriesExtension(RepositoryHandler repositories) { this.repositories = repositories; }
@Override public ArtifactRepository createArtifactRepository(RepositoryHandler repositoryHandler) { ArtifactRepository repo = internalCreateArtifactRepository(repositoryHandler); hasYieldedArtifactRepository.set(true); return repo; }