Skip to content

Commit

Permalink
Gradle 8.9 Closes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Jul 22, 2024
1 parent dbda891 commit bb5e654
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
20 changes: 18 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import net.minecraftforge.artifactural.buildscript.JarTransformationTask
import net.minecraftforge.artifactural.buildscript.SoftwareComponentFactoryGrabber
import org.objectweb.asm.Label
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.InsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.*

plugins {
id 'java-library'
Expand Down Expand Up @@ -88,6 +87,23 @@ tasks.register('transformJar', JarTransformationTask) {
}

addTransformer('net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter$1$1') { clazz ->
// Gradle [8.9) - resolveArtifactsWithType changed parameter types
{
final mtd = 'resolveArtifactsWithType'
final desc = '(Lorg/gradle/internal/component/model/ComponentArtifactResolveMetadata;Lorg/gradle/api/internal/component/ArtifactType;Lorg/gradle/internal/resolve/result/BuildableArtifactSetResolveResult;)V'
clazz.methods.find { it.name == mtd && it.desc == desc }.tap {

// null -> first parameter
final aconst_null = it.instructions.find { it.opcode == Opcodes.ACONST_NULL }
it.instructions.insertBefore(aconst_null, new VarInsnNode(Opcodes.ALOAD, 1))
it.instructions.remove(aconst_null)

// Change target desc
final invoke = it.instructions.find { it instanceof MethodInsnNode && it.name == mtd }
invoke.desc = desc
}
}

// Gradle [???,8.2)
{
clazz.methods.find {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.gradle.internal.component.external.model.ModuleDependencyMetadata;
import org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata;
import org.gradle.internal.component.model.ComponentArtifactMetadata;
import org.gradle.internal.component.model.ComponentArtifactResolveMetadata;
import org.gradle.internal.component.model.ComponentOverrideMetadata;
import org.gradle.internal.component.model.ComponentResolveMetadata;
import org.gradle.internal.component.model.ModuleSources;
Expand Down Expand Up @@ -160,6 +161,7 @@ public String getDisplayName() {
}

@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public ConfiguredModuleComponentRepository createResolver() {
MavenResolver resolver = (MavenResolver)local.createResolver();

Expand All @@ -176,7 +178,6 @@ public ConfiguredModuleComponentRepository createResolver() {
ReflectionUtils.alter(resolver, "cachingResourceAccessor.this$0.repository", prev -> repo);
ReflectionUtils.alter(resolver, "cachingResourceAccessor.delegate.delegate", prev -> repo);

//noinspection unchecked,rawtypes
return new ConfiguredModuleComponentRepository() {
private final ModuleComponentRepositoryAccess local = wrap(resolver.getLocalAccess());
private final ModuleComponentRepositoryAccess remote = wrap(resolver.getRemoteAccess());
Expand All @@ -197,11 +198,9 @@ public Instantiator getComponentMetadataInstantiator() {
}

private ModuleComponentRepositoryAccess wrap(ModuleComponentRepositoryAccess delegate) {
//noinspection rawtypes
return new ModuleComponentRepositoryAccess() {
@Override
public void resolveComponentMetaData(ModuleComponentIdentifier moduleComponentIdentifier, ComponentOverrideMetadata requestMetaData, BuildableModuleComponentMetaDataResolveResult result) {
//noinspection unchecked
delegate.resolveComponentMetaData(moduleComponentIdentifier, requestMetaData, result);
if (result.getState() == BuildableModuleComponentMetaDataResolveResult.State.Resolved) {
ModuleComponentResolveMetadata meta = getMetadata(result);
Expand All @@ -222,14 +221,12 @@ private void setResultResolved(BuildableModuleComponentMetaDataResolveResult res
}
}

@SuppressWarnings("unchecked")
private void setResultResolvedGradle8_2Above(BuildableModuleComponentMetaDataResolveResult result, ModuleComponentResolveMetadata meta) {
result.resolved(meta);
}

// DO NOT TOUCH
// This method is modified by ASM in build.gradle
@SuppressWarnings("unchecked")
private void setResultResolvedGradle8_1Below(BuildableModuleComponentMetaDataResolveResult result, ModuleComponentResolveMetadata meta) {
// Descriptor of resolved is changed to (Lorg/gradle/internal/component/external/model/ModuleComponentResolveMetadata;)V
result.resolved(meta);
Expand Down Expand Up @@ -264,6 +261,15 @@ public void resolveArtifactsWithType(ComponentResolveMetadata component, Artifac
delegate.resolveArtifactsWithType(component, artifactType, result);
}

// DO NOT TOUCH
// Gradle 8.9 changed the first argument from ComponentResolveMetadata to ComponentArtifactResolveMetadata
// https://github.com/gradle/gradle/commit/90f772b5d4b5599653d435e9f10d364a5599608d
@SuppressWarnings("unused")
public void resolveArtifactsWithType(ComponentArtifactResolveMetadata component, ArtifactType artifactType, BuildableArtifactSetResolveResult result) {
//ASM In build.gradle changes the first parameter and method descriptor
delegate.resolveArtifactsWithType(null/*component*/, artifactType, result);
}

@Override
public void resolveArtifact(ComponentArtifactMetadata componentArtifactMetadata, ModuleSources moduleSources, BuildableArtifactFileResolveResult buildableArtifactFileResolveResult) {
delegate.resolveArtifact(componentArtifactMetadata, moduleSources, buildableArtifactFileResolveResult);
Expand Down

0 comments on commit bb5e654

Please sign in to comment.