forked from FabricMC/fabric-loom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/net/fabricmc/loom/api/remapping/RemapperContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.fabricmc.loom.api.remapping; | ||
|
||
import org.objectweb.asm.commons.Remapper; | ||
|
||
public interface RemapperContext { | ||
Remapper getRemapper(); | ||
|
||
String sourceNamespace(); | ||
|
||
String targetNamespace(); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/net/fabricmc/loom/api/remapping/RemapperExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package net.fabricmc.loom.api.remapping; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
|
||
public interface RemapperExtension<T extends RemapperParameters> { | ||
@Inject | ||
T getParameters(); | ||
|
||
ClassVisitor insertVisitor(String className, RemapperContext remapperContext, ClassVisitor classVisitor); | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/net/fabricmc/loom/api/remapping/RemapperParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package net.fabricmc.loom.api.remapping; | ||
|
||
public interface RemapperParameters { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/net/fabricmc/loom/extension/RemapperExtensionHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package net.fabricmc.loom.extension; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.Nested; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.commons.Remapper; | ||
|
||
import net.fabricmc.loom.api.remapping.RemapperContext; | ||
import net.fabricmc.loom.api.remapping.RemapperExtension; | ||
import net.fabricmc.loom.api.remapping.RemapperParameters; | ||
import net.fabricmc.tinyremapper.TinyRemapper; | ||
import net.fabricmc.tinyremapper.api.TrClass; | ||
|
||
public abstract class RemapperExtensionHolder { | ||
private final RemapperParameters remapperParameters; | ||
|
||
@Inject | ||
public RemapperExtensionHolder(RemapperParameters remapperParameters) { | ||
this.remapperParameters = remapperParameters; | ||
} | ||
|
||
@Input | ||
public abstract Property<String> getRemapperExtensionClassName(); | ||
|
||
@Nested | ||
public RemapperParameters getRemapperParameters() { | ||
return remapperParameters; | ||
} | ||
|
||
public void apply(TinyRemapper.Builder tinyRemapperBuilder) { | ||
RemapperExtension<?> remapperExtension = newInstance(); | ||
|
||
tinyRemapperBuilder.extraPostApplyVisitor(new RemapperExtensionImpl(remapperExtension)); | ||
|
||
if (remapperExtension instanceof TinyRemapper.AnalyzeVisitorProvider analyzeVisitorProvider) { | ||
tinyRemapperBuilder.extraAnalyzeVisitor(analyzeVisitorProvider); | ||
} | ||
|
||
if (remapperExtension instanceof TinyRemapper.ApplyVisitorProvider applyVisitorProvider) { | ||
// TODO allow having a pre apply visitor? | ||
tinyRemapperBuilder.extraPostApplyVisitor(applyVisitorProvider); | ||
} | ||
} | ||
|
||
private RemapperExtension<?> newInstance() { | ||
try { | ||
return Class.forName(getRemapperExtensionClassName().get()) | ||
.asSubclass(RemapperExtension.class) | ||
.getConstructor() | ||
.newInstance(); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to create remapper extension", e); | ||
} | ||
} | ||
|
||
private record RemapperExtensionImpl(RemapperExtension<?> remapperExtension) implements TinyRemapper.ApplyVisitorProvider { | ||
@Override | ||
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) { | ||
return remapperExtension.insertVisitor(cls.getName(), new RemapperContext() { | ||
// TODO dont create a new instance of this for every class | ||
@Override | ||
public Remapper getRemapper() { | ||
return cls.getEnvironment().getRemapper(); | ||
} | ||
|
||
@Override | ||
public String sourceNamespace() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String targetNamespace() { | ||
return null; | ||
} | ||
}, next); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters