Search in sources :

Example 6 with ConfigurationInternal

use of org.gradle.api.internal.artifacts.configurations.ConfigurationInternal in project gradle by gradle.

the class IvyBackedArtifactPublisher method publish.

public void publish(final Iterable<? extends PublicationAwareRepository> repositories, final Module module, final Configuration configuration, final File descriptor) throws PublishException {
    Set<ConfigurationInternal> allConfigurations = Cast.uncheckedCast(configuration.getAll());
    Set<ConfigurationInternal> configurationsToPublish = Cast.uncheckedCast(configuration.getHierarchy());
    if (descriptor != null) {
        // Convert once, in order to write the Ivy descriptor with _all_ configurations
        IvyModulePublishMetadata publishMetaData = toPublishMetaData(module, allConfigurations);
        validatePublishMetaData(publishMetaData);
        ivyModuleDescriptorWriter.write(publishMetaData, descriptor);
    }
    // Convert a second time with only the published configurations: this ensures that the correct artifacts are included
    BuildableIvyModulePublishMetadata publishMetaData = toPublishMetaData(module, configurationsToPublish);
    if (descriptor != null) {
        IvyArtifactName artifact = new DefaultIvyArtifactName("ivy", "ivy", "xml");
        publishMetaData.addArtifact(artifact, descriptor);
    }
    List<ModuleVersionPublisher> publishResolvers = new ArrayList<ModuleVersionPublisher>();
    for (PublicationAwareRepository repository : repositories) {
        ModuleVersionPublisher publisher = repository.createPublisher();
        publishResolvers.add(publisher);
    }
    dependencyPublisher.publish(publishResolvers, publishMetaData);
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ArrayList(java.util.ArrayList) BuildableIvyModulePublishMetadata(org.gradle.internal.component.external.model.BuildableIvyModulePublishMetadata) PublicationAwareRepository(org.gradle.api.internal.artifacts.repositories.PublicationAwareRepository) IvyModulePublishMetadata(org.gradle.internal.component.external.model.IvyModulePublishMetadata) BuildableIvyModulePublishMetadata(org.gradle.internal.component.external.model.BuildableIvyModulePublishMetadata) DefaultIvyModulePublishMetadata(org.gradle.internal.component.external.model.DefaultIvyModulePublishMetadata) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) ModuleVersionPublisher(org.gradle.api.internal.artifacts.ModuleVersionPublisher)

Example 7 with ConfigurationInternal

use of org.gradle.api.internal.artifacts.configurations.ConfigurationInternal in project gradle by gradle.

the class PluginResolutionServiceResolver method resolvePluginDependencies.

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());
    }
}
Also used : ConfigurationContainerInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationContainerInternal) Dependency(org.gradle.api.artifacts.Dependency) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) ResolveException(org.gradle.api.artifacts.ResolveException) DependencyResolutionServices(org.gradle.api.internal.artifacts.DependencyResolutionServices) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler) File(java.io.File) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Example 8 with ConfigurationInternal

use of org.gradle.api.internal.artifacts.configurations.ConfigurationInternal in project gradle by gradle.

the class ScalaBasePlugin method configureConfigurations.

private void configureConfigurations(final Project project, final Usage incrementalAnalysisUsage, ScalaPluginExtension scalaPluginExtension) {
    DependencyHandler dependencyHandler = project.getDependencies();
    ConfigurationInternal plugins = (ConfigurationInternal) project.getConfigurations().create(SCALA_COMPILER_PLUGINS_CONFIGURATION_NAME);
    plugins.setTransitive(false);
    plugins.setCanBeConsumed(false);
    jvmEcosystemUtilities.configureAsRuntimeClasspath(plugins);
    Configuration zinc = project.getConfigurations().create(ZINC_CONFIGURATION_NAME);
    zinc.setVisible(false);
    zinc.setDescription("The Zinc incremental compiler to be used for this Scala project.");
    ((DeprecatableConfiguration) zinc).deprecateForConsumption(deprecation -> deprecation.willBecomeAnErrorInGradle8().withUpgradeGuideSection(7, "plugin_configuration_consumption"));
    zinc.getResolutionStrategy().eachDependency(rule -> {
        if (rule.getRequested().getGroup().equals("com.typesafe.zinc") && rule.getRequested().getName().equals("zinc")) {
            rule.useTarget("org.scala-sbt:zinc_" + DEFAULT_SCALA_ZINC_VERSION + ":" + DEFAULT_ZINC_VERSION);
            rule.because("Typesafe Zinc is no longer maintained.");
        }
    });
    zinc.defaultDependencies(dependencies -> {
        dependencies.add(dependencyHandler.create("org.scala-sbt:zinc_" + DEFAULT_SCALA_ZINC_VERSION + ":" + scalaPluginExtension.getZincVersion().get()));
        // Add safeguard and clear error if the user changed the scala version when using default zinc
        zinc.getIncoming().afterResolve(resolvableDependencies -> {
            resolvableDependencies.getResolutionResult().allComponents(component -> {
                if (component.getModuleVersion() != null && component.getModuleVersion().getName().equals("scala-library")) {
                    if (!component.getModuleVersion().getVersion().startsWith(DEFAULT_SCALA_ZINC_VERSION)) {
                        throw new InvalidUserCodeException("The version of 'scala-library' was changed while using the default Zinc version. " + "Version " + component.getModuleVersion().getVersion() + " is not compatible with org.scala-sbt:zinc_" + DEFAULT_SCALA_ZINC_VERSION + ":" + DEFAULT_ZINC_VERSION);
                    }
                }
            });
        });
    });
    zinc.getDependencyConstraints().add(dependencyHandler.getConstraints().create(Log4jBannedVersion.LOG4J2_CORE_COORDINATES, constraint -> constraint.version(version -> {
        version.require(Log4jBannedVersion.LOG4J2_CORE_REQUIRED_VERSION);
        version.reject(Log4jBannedVersion.LOG4J2_CORE_VULNERABLE_VERSION_RANGE);
    })));
    final Configuration incrementalAnalysisElements = project.getConfigurations().create("incrementalScalaAnalysisElements");
    incrementalAnalysisElements.setVisible(false);
    incrementalAnalysisElements.setDescription("Incremental compilation analysis files");
    incrementalAnalysisElements.setCanBeResolved(false);
    incrementalAnalysisElements.setCanBeConsumed(true);
    incrementalAnalysisElements.getAttributes().attribute(USAGE_ATTRIBUTE, incrementalAnalysisUsage);
    AttributeMatchingStrategy<Usage> matchingStrategy = dependencyHandler.getAttributesSchema().attribute(USAGE_ATTRIBUTE);
    matchingStrategy.getDisambiguationRules().add(UsageDisambiguationRules.class, actionConfiguration -> {
        actionConfiguration.params(incrementalAnalysisUsage);
        actionConfiguration.params(objectFactory.named(Usage.class, Usage.JAVA_API));
        actionConfiguration.params(objectFactory.named(Usage.class, Usage.JAVA_RUNTIME));
    });
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) BiFunction(java.util.function.BiFunction) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) MultipleCandidatesDetails(org.gradle.api.attributes.MultipleCandidatesDetails) TaskProvider(org.gradle.api.tasks.TaskProvider) Log4jBannedVersion(org.gradle.internal.logging.util.Log4jBannedVersion) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) ExtensionAware(org.gradle.api.plugins.ExtensionAware) Transformer(org.gradle.api.Transformer) ScalaRuntime(org.gradle.api.tasks.ScalaRuntime) CompileOptions(org.gradle.api.tasks.compile.CompileOptions) DefaultScalaPluginExtension(org.gradle.api.internal.tasks.scala.DefaultScalaPluginExtension) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.gradle.api.Project) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) ArtifactView(org.gradle.api.artifacts.ArtifactView) JvmEcosystemUtilities(org.gradle.api.plugins.jvm.internal.JvmEcosystemUtilities) AttributeDisambiguationRule(org.gradle.api.attributes.AttributeDisambiguationRule) Spec(org.gradle.api.specs.Spec) AttributeMatchingStrategy(org.gradle.api.attributes.AttributeMatchingStrategy) SerializableLambdas.spec(org.gradle.api.internal.lambdas.SerializableLambdas.spec) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) Callable(java.util.concurrent.Callable) FileCollection(org.gradle.api.file.FileCollection) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) ScalaDoc(org.gradle.api.tasks.scala.ScalaDoc) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) ScalaSourceDirectorySet(org.gradle.api.tasks.ScalaSourceDirectorySet) ScalaCompile(org.gradle.api.tasks.scala.ScalaCompile) Usage(org.gradle.api.attributes.Usage) InvokerHelper(org.codehaus.groovy.runtime.InvokerHelper) Action(org.gradle.api.Action) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Jar(org.gradle.jvm.tasks.Jar) JvmPluginsHelper(org.gradle.api.plugins.internal.JvmPluginsHelper) JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) File(java.io.File) USAGE_ATTRIBUTE(org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE) ObjectFactory(org.gradle.api.model.ObjectFactory) Convention(org.gradle.api.plugins.Convention) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Plugin(org.gradle.api.Plugin) IncrementalCompileOptions(org.gradle.api.tasks.scala.IncrementalCompileOptions) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Usage(org.gradle.api.attributes.Usage) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) Configuration(org.gradle.api.artifacts.Configuration) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)

Example 9 with ConfigurationInternal

use of org.gradle.api.internal.artifacts.configurations.ConfigurationInternal in project gradle by gradle.

the class Upload method upload.

@TaskAction
protected void upload() {
    getLogger().info("Publishing configuration: {}", configuration);
    DeprecationLogger.deprecateTaskType(Upload.class, getPath()).willBeRemovedInGradle8().withUpgradeGuideSection(7, "upload_task_deprecation").nagUser();
    Module module = ((ConfigurationInternal) configuration).getModule();
    ArtifactPublisher artifactPublisher = getPublicationServices().createArtifactPublisher();
    File descriptorDestination = isUploadDescriptor() ? getDescriptorDestination() : null;
    List<PublicationAwareRepository> publishRepositories = collect(getRepositories(), Transformers.cast(PublicationAwareRepository.class));
    try {
        artifactPublisher.publish(publishRepositories, module, configuration, descriptorDestination);
    } catch (Exception e) {
        throw new PublishException(String.format("Could not publish configuration '%s'", configuration.getName()), e);
    }
}
Also used : ArtifactPublisher(org.gradle.api.internal.artifacts.ArtifactPublisher) PublicationAwareRepository(org.gradle.api.internal.artifacts.repositories.PublicationAwareRepository) PublishException(org.gradle.api.artifacts.PublishException) Module(org.gradle.api.internal.artifacts.Module) File(java.io.File) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) PublishException(org.gradle.api.artifacts.PublishException)

Example 10 with ConfigurationInternal

use of org.gradle.api.internal.artifacts.configurations.ConfigurationInternal in project gradle by gradle.

the class DefaultProjectLocalComponentProvider method getLocalComponentMetadata.

private LocalComponentMetadata getLocalComponentMetadata(ProjectState projectState, ProjectInternal project) {
    Module module = project.getDependencyMetaDataProvider().getModule();
    ModuleVersionIdentifier moduleVersionIdentifier = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getName(), module.getVersion());
    ProjectComponentIdentifier componentIdentifier = projectState.getComponentIdentifier();
    DefaultLocalComponentMetadata metaData = new DefaultLocalComponentMetadata(moduleVersionIdentifier, componentIdentifier, module.getStatus(), (AttributesSchemaInternal) project.getDependencies().getAttributesSchema());
    for (ConfigurationInternal configuration : project.getConfigurations().withType(ConfigurationInternal.class)) {
        metadataBuilder.addConfiguration(metaData, configuration);
    }
    return metaData;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultLocalComponentMetadata(org.gradle.internal.component.local.model.DefaultLocalComponentMetadata) Module(org.gradle.api.internal.artifacts.Module) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)

Aggregations

ConfigurationInternal (org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)13 File (java.io.File)3 PublicationAwareRepository (org.gradle.api.internal.artifacts.repositories.PublicationAwareRepository)3 Configuration (org.gradle.api.artifacts.Configuration)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 Module (org.gradle.api.internal.artifacts.Module)2 ModuleVersionPublisher (org.gradle.api.internal.artifacts.ModuleVersionPublisher)2 OutgoingVariant (org.gradle.api.internal.artifacts.configurations.OutgoingVariant)2 DefaultIvyArtifactName (org.gradle.internal.component.model.DefaultIvyArtifactName)2 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 BiFunction (java.util.function.BiFunction)1 Inject (javax.inject.Inject)1 InvokerHelper (org.codehaus.groovy.runtime.InvokerHelper)1 Action (org.gradle.api.Action)1