From 34b37637bd469621bb3eadfdf5fb856a806722df Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Mon, 2 Oct 2017 12:01:09 +0300 Subject: [PATCH] Port to Gradle 4.2 --- libs/gradle-core-api/pom.xml | 32 ++++++ libs/gradle-logging/pom.xml | 32 ++++++ libs/gradle-model-core/pom.xml | 32 ++++++ libs/pom.xml | 3 + xmvn-connector-gradle/pom.xml | 15 +++ .../xmvn/connector/gradle/GradleResolver.java | 119 ++++++++++++++------- .../xmvn/connector/gradle/XMvnGradlePlugin.java | 16 +-- .../xmvn/connector/gradle/XMvnInstallTask.java | 22 +++- xmvn-parent/pom.xml | 17 ++- 9 files changed, 235 insertions(+), 53 deletions(-) create mode 100644 libs/gradle-core-api/pom.xml create mode 100644 libs/gradle-logging/pom.xml create mode 100644 libs/gradle-model-core/pom.xml diff --git a/libs/gradle-core-api/pom.xml b/libs/gradle-core-api/pom.xml new file mode 100644 index 00000000..7b3d68d5 --- /dev/null +++ b/libs/gradle-core-api/pom.xml @@ -0,0 +1,32 @@ + + + + 4.0.0 + + org.fedoraproject.xmvn + libs + 3.0.0 + .. + + org.gradle + gradle-core-api + ${gradleVersion} + Gradle core API module + diff --git a/libs/gradle-logging/pom.xml b/libs/gradle-logging/pom.xml new file mode 100644 index 00000000..d2dec7c1 --- /dev/null +++ b/libs/gradle-logging/pom.xml @@ -0,0 +1,32 @@ + + + + 4.0.0 + + org.fedoraproject.xmvn + libs + 3.0.0 + .. + + org.gradle + gradle-logging + ${gradleVersion} + Gradle logging module + diff --git a/libs/gradle-model-core/pom.xml b/libs/gradle-model-core/pom.xml new file mode 100644 index 00000000..f841b960 --- /dev/null +++ b/libs/gradle-model-core/pom.xml @@ -0,0 +1,32 @@ + + + + 4.0.0 + + org.fedoraproject.xmvn + libs + 3.0.0 + .. + + org.gradle + gradle-model-core + ${gradleVersion} + Gradle model-core module + diff --git a/libs/pom.xml b/libs/pom.xml index 2b31c5d0..fc29e359 100644 --- a/libs/pom.xml +++ b/libs/pom.xml @@ -37,8 +37,11 @@ gradle-base-services gradle-base-services-groovy gradle-core + gradle-core-api + gradle-model-core gradle-dependency-management gradle-resources + gradle-logging diff --git a/xmvn-connector-gradle/pom.xml b/xmvn-connector-gradle/pom.xml index b433e5dd..f18a285e 100644 --- a/xmvn-connector-gradle/pom.xml +++ b/xmvn-connector-gradle/pom.xml @@ -54,11 +54,21 @@ org.gradle + gradle-core-api + provided + + + org.gradle gradle-core provided org.gradle + gradle-model-core + provided + + + org.gradle gradle-dependency-management provided @@ -68,6 +78,11 @@ provided + org.gradle + gradle-logging + provided + + org.apache.ivy ivy provided diff --git a/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/GradleResolver.java b/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/GradleResolver.java index a81c5bc0..6305aa86 100644 --- a/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/GradleResolver.java +++ b/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/GradleResolver.java @@ -18,41 +18,47 @@ package org.fedoraproject.xmvn.connector.gradle; import java.nio.file.Path; import java.util.Collections; import java.util.LinkedHashSet; +import java.util.Map; import java.util.Set; +import org.gradle.api.artifacts.ComponentMetadataSupplier; import org.gradle.api.artifacts.ModuleVersionIdentifier; +import org.gradle.api.artifacts.component.ComponentArtifactIdentifier; import org.gradle.api.artifacts.component.ModuleComponentIdentifier; +import org.gradle.api.internal.artifacts.ImmutableModuleIdentifierFactory; import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ConfiguredModuleComponentRepository; import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ModuleComponentRepositoryAccess; import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.DescriptorParseContext; -import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.GradlePomModuleDescriptorParser; import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.MetaDataParser; -import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionComparator; -import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.DefaultVersionSelectorScheme; +import org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvableArtifact; import org.gradle.api.internal.artifacts.repositories.AbstractArtifactRepository; import org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository; +import org.gradle.api.internal.artifacts.repositories.resolver.MetadataFetchingCost; import org.gradle.api.internal.component.ArtifactType; -import org.gradle.internal.component.external.model.DefaultMavenModuleResolveMetaData; -import org.gradle.internal.component.external.model.DefaultModuleComponentArtifactMetaData; -import org.gradle.internal.component.external.model.ModuleComponentResolveMetaData; -import org.gradle.internal.component.external.model.MutableModuleComponentResolveMetaData; -import org.gradle.internal.component.model.ComponentArtifactMetaData; +import org.gradle.internal.component.external.model.DefaultModuleComponentArtifactMetadata; +import org.gradle.internal.component.external.model.DefaultMutableMavenModuleResolveMetadata; +import org.gradle.internal.component.external.model.FixedComponentArtifacts; +import org.gradle.internal.component.external.model.ModuleComponentArtifactMetadata; +import org.gradle.internal.component.external.model.ModuleComponentResolveMetadata; +import org.gradle.internal.component.external.model.MutableMavenModuleResolveMetadata; +import org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata; +import org.gradle.internal.component.model.ComponentArtifactMetadata; import org.gradle.internal.component.model.ComponentOverrideMetadata; -import org.gradle.internal.component.model.ComponentResolveMetaData; -import org.gradle.internal.component.model.ComponentUsage; +import org.gradle.internal.component.model.ComponentResolveMetadata; import org.gradle.internal.component.model.DefaultIvyArtifactName; -import org.gradle.internal.component.model.DependencyMetaData; +import org.gradle.internal.component.model.DependencyMetadata; import org.gradle.internal.component.model.IvyArtifactName; import org.gradle.internal.component.model.ModuleSource; import org.gradle.internal.resolve.ArtifactResolveException; import org.gradle.internal.resolve.ModuleVersionResolveException; import org.gradle.internal.resolve.result.BuildableArtifactResolveResult; import org.gradle.internal.resolve.result.BuildableArtifactSetResolveResult; +import org.gradle.internal.resolve.result.BuildableComponentArtifactsResolveResult; import org.gradle.internal.resolve.result.BuildableModuleComponentMetaDataResolveResult; import org.gradle.internal.resolve.result.BuildableModuleVersionListingResolveResult; -import org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource; -import org.gradle.internal.resource.local.DefaultLocallyAvailableResource; +import org.gradle.internal.resource.local.FileResourceRepository; import org.gradle.internal.resource.local.LocallyAvailableExternalResource; +import org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,6 +78,21 @@ public class GradleResolver implements ResolutionAwareRepository, ConfiguredModuleComponentRepository, ModuleComponentRepositoryAccess, DescriptorParseContext { + public GradleResolver( MetaDataParser pomParser, + ImmutableModuleIdentifierFactory moduleIdentifierFactory, + FileResourceRepository fileRepository ) + { + this.pomParser = pomParser; + this.moduleIdentifierFactory = moduleIdentifierFactory; + this.fileRepository = fileRepository; + } + + private MetaDataParser pomParser; + + private ImmutableModuleIdentifierFactory moduleIdentifierFactory; + + private FileResourceRepository fileRepository; + private final Logger logger = LoggerFactory.getLogger( GradleResolver.class ); static class LazyLocatorProvider @@ -135,17 +156,17 @@ public class GradleResolver } @Override - public void listModuleVersions( DependencyMetaData arg0, BuildableModuleVersionListingResolveResult arg1 ) + public void listModuleVersions( DependencyMetadata arg0, BuildableModuleVersionListingResolveResult arg1 ) { logger.debug( "listModuleVersions() called, but it is NOT IMPLEMENTED" ); } @Override - public void resolveArtifact( ComponentArtifactMetaData artifact, ModuleSource module, + public void resolveArtifact( ComponentArtifactMetadata artifact, ModuleSource module, BuildableArtifactResolveResult result ) { ModuleVersionIdentifier moduleId = - ( (DefaultModuleComponentArtifactMetaData) artifact ).toArtifactIdentifier().getModuleVersionIdentifier(); + ( (DefaultModuleComponentArtifactMetadata) artifact ).toArtifactIdentifier().getModuleVersionIdentifier(); String groupId = moduleId.getGroup(); String artifactId = artifact.getName().getName(); String extension = artifact.getName().getExtension(); @@ -180,11 +201,9 @@ public class GradleResolver { logger.debug( "Found Maven POM: {}", pomPath ); - MetaDataParser parser = - new GradlePomModuleDescriptorParser( new DefaultVersionSelectorScheme( new DefaultVersionComparator() ) ); - MutableModuleComponentResolveMetaData metaData = parser.parseMetaData( this, pomPath.toFile() ); + MutableModuleComponentResolveMetadata metaData = pomParser.parseMetaData( this, pomPath.toFile() ); - result.resolved( metaData ); + result.resolved( metaData.asImmutable() ); return; } else @@ -204,9 +223,11 @@ public class GradleResolver if ( path != null ) { logger.debug( "Artifact {} found, returning minimal model", artifact3 ); - MutableModuleComponentResolveMetaData metaData = - new DefaultMavenModuleResolveMetaData( id, request.getArtifacts() ); - result.resolved( metaData ); + ModuleVersionIdentifier mvi = + moduleIdentifierFactory.moduleWithVersion( id.getGroup(), id.getModule(), id.getVersion() ); + MutableModuleComponentResolveMetadata metaData = + new DefaultMutableMavenModuleResolveMetadata( mvi, id, request.getArtifacts() ); + result.resolved( metaData.asImmutable() ); return; } } @@ -224,24 +245,15 @@ public class GradleResolver if ( artifactSet.isEmpty() ) { - artifactSet.add( new DefaultIvyArtifactName( id.getModule(), "jar", "jar", - Collections.emptyMap() ) ); + artifactSet.add( new DefaultIvyArtifactName( id.getModule(), "jar", "jar", null ) ); } return artifactSet; } @Override - public void resolveModuleArtifacts( ComponentResolveMetaData component, ComponentUsage usage, - BuildableArtifactSetResolveResult result ) - { - result.resolved( Collections.singleton( ( (ModuleComponentResolveMetaData) component ).artifact( "jar", "jar", - null ) ) ); - } - - @Override - public void resolveModuleArtifacts( ComponentResolveMetaData component, ArtifactType type, - BuildableArtifactSetResolveResult result ) + public void resolveArtifactsWithType( ComponentResolveMetadata component, ArtifactType type, + BuildableArtifactSetResolveResult result ) { if ( type != ArtifactType.MAVEN_POM ) { @@ -250,15 +262,22 @@ public class GradleResolver return; } - ModuleComponentResolveMetaData metaData = (ModuleComponentResolveMetaData) component; - ModuleComponentIdentifier id = metaData.getComponentId(); + ModuleComponentIdentifier id = (ModuleComponentIdentifier) component.getComponentId(); DefaultIvyArtifactName name = new DefaultIvyArtifactName( id.getModule(), "pom", "pom" ); - DefaultModuleComponentArtifactMetaData resolvedMetaData = - new DefaultModuleComponentArtifactMetaData( id, name ); + DefaultModuleComponentArtifactMetadata resolvedMetaData = + new DefaultModuleComponentArtifactMetadata( id, name ); result.resolved( Collections.singleton( resolvedMetaData ) ); } @Override + public void resolveArtifacts( ComponentResolveMetadata component, BuildableComponentArtifactsResolveResult result ) + { + ModuleComponentArtifactMetadata artifact = + ( (ModuleComponentResolveMetadata) component ).artifact( "jar", "jar", null ); + result.resolved( new FixedComponentArtifacts( Collections.singleton( artifact ) ) ); + } + + @Override public LocallyAvailableExternalResource getMetaDataArtifact( ModuleComponentIdentifier id, ArtifactType type ) { Path pomPath = resolve( new DefaultArtifact( id.getGroup(), id.getModule(), "pom", id.getVersion() ) ); @@ -266,7 +285,25 @@ public class GradleResolver if ( pomPath == null ) return null; - return new DefaultLocallyAvailableExternalResource( pomPath.toUri(), - new DefaultLocallyAvailableResource( pomPath.toFile() ) ); + DefaultExternalResourceMetaData metadata = new DefaultExternalResourceMetaData( pomPath.toUri(), 0, 0 ); + return fileRepository.resource( pomPath.toFile(), pomPath.toUri(), metadata ); + } + + @Override + public ComponentMetadataSupplier createMetadataSupplier() + { + return null; + } + + @Override + public Map getArtifactCache() + { + return Collections.emptyMap(); + } + + @Override + public MetadataFetchingCost estimateMetadataFetchingCost( ModuleComponentIdentifier arg0 ) + { + return MetadataFetchingCost.CHEAP; } } diff --git a/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/XMvnGradlePlugin.java b/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/XMvnGradlePlugin.java index 2646f098..c3250e3c 100644 --- a/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/XMvnGradlePlugin.java +++ b/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/XMvnGradlePlugin.java @@ -15,9 +15,11 @@ */ package org.fedoraproject.xmvn.connector.gradle; +import groovy.lang.Closure; +import groovy.lang.GroovyShell; import org.gradle.api.Plugin; import org.gradle.api.Task; -import org.gradle.api.artifacts.repositories.ArtifactRepository; +import org.gradle.api.artifacts.dsl.RepositoryHandler; import org.gradle.api.invocation.Gradle; /** @@ -26,15 +28,17 @@ import org.gradle.api.invocation.Gradle; public class XMvnGradlePlugin implements Plugin { + private void configureRepositories( RepositoryHandler repositories ) + { + repositories.configure( (Closure) new GroovyShell().evaluate( "{ it -> xmvn() }" ) ); + } + @Override public void apply( Gradle gradle ) { - ArtifactRepository repo = new GradleResolver(); - repo.setName( "xmvn" ); - gradle.allprojects( project -> { - project.getRepositories().addFirst( repo ); - project.getBuildscript().getRepositories().addFirst( repo ); + configureRepositories( project.getRepositories() ); + configureRepositories( project.getBuildscript().getRepositories() ); Task upload = project.getTasks().create( "xmvnInstall", XMvnInstallTask.class ); upload.setDescription( "Installs all artifacts through XMvn" ); diff --git a/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/XMvnInstallTask.java b/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/XMvnInstallTask.java index 196f4a5b..07905f1f 100644 --- a/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/XMvnInstallTask.java +++ b/xmvn-connector-gradle/src/main/java/org/fedoraproject/xmvn/connector/gradle/XMvnInstallTask.java @@ -17,6 +17,7 @@ package org.fedoraproject.xmvn.connector.gradle; import java.nio.file.Files; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -32,7 +33,7 @@ import org.gradle.api.artifacts.PublishArtifact; import org.gradle.api.artifacts.PublishException; import org.gradle.api.component.SoftwareComponent; import org.gradle.api.internal.component.SoftwareComponentInternal; -import org.gradle.api.internal.component.Usage; +import org.gradle.api.internal.component.UsageContext; import org.gradle.api.tasks.TaskAction; import org.fedoraproject.xmvn.artifact.Artifact; @@ -83,7 +84,7 @@ class XMvnInstallTask Project dependencyProject = projectDependency.getDependencyProject(); Stream components = dependencyProject.getComponents().stream(); Stream internalComponents = components.map( c -> (SoftwareComponentInternal) c ); - Stream usages = internalComponents.flatMap( ic -> ic.getUsages().stream() ); + Stream usages = internalComponents.flatMap( ic -> ic.getUsages().stream() ); Stream publishArtifacts = usages.flatMap( usage -> usage.getArtifacts().stream() ); Stream artifacts = publishArtifacts.map( pa -> getPublishArtifact( dependencyProject, pa ) ); return artifacts.collect( Collectors.toList() ); @@ -144,7 +145,13 @@ class XMvnInstallTask } } - DeploymentResult result = getDeployer().deploy( request ); + DeploymentResult result; + + // prevent parallel access to installation plan + synchronized ( XMvnInstallTask.class ) + { + result = getDeployer().deploy( request ); + } if ( result.getException() != null ) { @@ -155,17 +162,22 @@ class XMvnInstallTask @TaskAction protected void deployProject() { + Set seenArtifacts = new HashSet<>(); + for ( SoftwareComponent component : getProject().getComponents() ) { SoftwareComponentInternal internalComponent = (SoftwareComponentInternal) component; - for ( Usage usage : internalComponent.getUsages() ) + for ( UsageContext usage : internalComponent.getUsages() ) { Set dependencies = usage.getDependencies(); for ( PublishArtifact artifact : usage.getArtifacts() ) { - deploy( artifact, dependencies ); + if ( seenArtifacts.add( artifact ) ) + { + deploy( artifact, dependencies ); + } } } } diff --git a/xmvn-parent/pom.xml b/xmvn-parent/pom.xml index 661cc24d..7e7a6d94 100644 --- a/xmvn-parent/pom.xml +++ b/xmvn-parent/pom.xml @@ -84,7 +84,7 @@ 1 2.4.0 1.64 - 2.13-rc-1 + 4.2.1 2.4.10 2.2 1.0.3 @@ -278,11 +278,21 @@ org.gradle + gradle-core-api + ${gradleVersion} + + + org.gradle gradle-core ${gradleVersion} org.gradle + gradle-model-core + ${gradleVersion} + + + org.gradle gradle-dependency-management ${gradleVersion} @@ -292,6 +302,11 @@ ${gradleVersion} + org.gradle + gradle-logging + ${gradleVersion} + + org.codehaus.groovy groovy-all ${groovyVersion} -- 2.13.6