From 86fe50bd075b6e543d319fa9b99641812e1014fa Mon Sep 17 00:00:00 2001 From: matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Mon, 9 Jan 2023 00:58:52 +0200 Subject: Add compatibility with Gradle 7.6 (#5) Co-authored-by: SizableShrimp --- .../gradle/GradleRepositoryAdapter.java | 51 ++++++++++++---------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java index 0970397..7291731 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java @@ -34,6 +34,7 @@ import org.gradle.api.internal.artifacts.BaseRepositoryFactory; import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentResolvers; 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.strategy.VersionParser; 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.DefaultMavenLocalArtifactRepository; @@ -53,14 +54,12 @@ import org.gradle.internal.component.external.model.MutableModuleComponentResolv 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.ConfigurationMetadata; import org.gradle.internal.component.model.ModuleSources; import org.gradle.internal.nativeintegration.filesystem.FileSystem; import org.gradle.internal.nativeintegration.services.FileSystems; import org.gradle.internal.reflect.Instantiator; -import org.gradle.internal.resolve.result.BuildableArtifactResolveResult; +import org.gradle.internal.resolve.result.BuildableArtifactFileResolveResult; 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.ExternalResourceName; @@ -71,6 +70,7 @@ import org.gradle.internal.resource.local.LocalFileStandInExternalResource; import org.gradle.internal.resource.local.LocallyAvailableExternalResource; import org.gradle.internal.resource.metadata.ExternalResourceMetaData; import org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor; +import org.gradle.util.GradleVersion; import java.io.File; import java.io.IOException; @@ -96,9 +96,16 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen m.artifact(); }); - GradleRepositoryAdapter repo; + final GradleRepositoryAdapter repo; + + if (GradleVersion.current().compareTo(GradleVersion.version("7.6")) >= 0) { + // If we are on gradle 7.6+ we want to use the super constructor with 2 arguments (with the VersionParser) + repo = new GradleRepositoryAdapter(repository, maven, getVersionParser(maven)); + } else { + // If we are on gradle 4.10 - 7.5 we use the super constructor with only the ObjectFactory parameter + repo = new GradleRepositoryAdapter(repository, maven); + } - repo = new GradleRepositoryAdapter(repository, maven); repo.setName(name); handler.add(repo); return repo; @@ -112,28 +119,34 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen // This constructor is modified via bytecode manipulation in 'build.gradle' // DO NOT change this without modifying 'build.gradle' - // This contructor is used on Gradle 4.9 and below + // This constructor is used on Gradle 7.5.* and below + @Deprecated // TODO - remove this constructor when we can break ABI compatibility private GradleRepositoryAdapter(Repository repository, DefaultMavenLocalArtifactRepository local) { - // This is replaced with a call to 'super()', with no arguments - super(null); + // This is replaced with a call to 'super(getObjectFactory(local))' + super(getObjectFactory(local), null); this.repository = repository; this.local = local; this.root = cleanRoot(local.getUrl()); this.cache = new LocatedArtifactCache(new File(root)); } - - // This constructor is used on Gradle 4.10 and above - GradleRepositoryAdapter(ObjectFactory objectFactory, Repository repository, DefaultMavenLocalArtifactRepository local) { - super(objectFactory); - // This duplication from the above two-argument constructor is unfortunate, - // but unavoidable + // This constructor is used on Gradle 7.6 and above + private GradleRepositoryAdapter(Repository repository, DefaultMavenLocalArtifactRepository local, VersionParser versionParser) { + super(getObjectFactory(local), versionParser); this.repository = repository; this.local = local; this.root = cleanRoot(local.getUrl()); this.cache = new LocatedArtifactCache(new File(root)); } + private static ObjectFactory getObjectFactory(DefaultMavenLocalArtifactRepository maven) { + return ReflectionUtils.get(maven, "objectFactory"); + } + + private static VersionParser getVersionParser(DefaultMavenLocalArtifactRepository maven) { + return ReflectionUtils.get(maven, "versionParser"); + } + @Override public String getDisplayName() { return local.getDisplayName(); @@ -191,11 +204,6 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen } } - @Override - public void resolveArtifacts(ComponentResolveMetadata component, ConfigurationMetadata variant, BuildableComponentArtifactsResolveResult result) { - delegate.resolveArtifacts(component, variant, result); - } - @Override public void listModuleVersions(ModuleDependencyMetadata dependency, BuildableModuleVersionListingResolveResult result) { delegate.listModuleVersions(dependency, result); @@ -207,11 +215,10 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen } @Override - public void resolveArtifact(ComponentArtifactMetadata artifact, ModuleSources moduleSources, BuildableArtifactResolveResult result) { - delegate.resolveArtifact(artifact, moduleSources, result); + public void resolveArtifact(ComponentArtifactMetadata componentArtifactMetadata, ModuleSources moduleSources, BuildableArtifactFileResolveResult buildableArtifactFileResolveResult) { + delegate.resolveArtifact(componentArtifactMetadata, moduleSources, buildableArtifactFileResolveResult); } - @Override public MetadataFetchingCost estimateMetadataFetchingCost(ModuleComponentIdentifier moduleComponentIdentifier) { return delegate.estimateMetadataFetchingCost(moduleComponentIdentifier); -- cgit