mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-24 00:09:48 +00:00
Import targets from upstream jars, supported by MixinGradle
This commit is contained in:
1 parent
a8a9205491
commit
cce1039dc7
6 files changed
+57
-3
No files matched your search
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.tools.obfuscation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -161,6 +163,14 @@ class AnnotatedMixins implements IMixinAnnotationProcessor, ITokenProvider, ITyp
|
||||
protected TargetMap initTargetMap() {
|
||||
TargetMap targets = TargetMap.create(System.getProperty(AnnotatedMixins.MAPID_SYSTEM_PROPERTY));
|
||||
System.setProperty(AnnotatedMixins.MAPID_SYSTEM_PROPERTY, targets.getSessionId());
|
||||
String targetsFileName = this.getOption(SupportedOptions.DEPENDENCY_TARGETS_FILE);
|
||||
if (targetsFileName != null) {
|
||||
try {
|
||||
targets.readImports(new File(targetsFileName));
|
||||
} catch (IOException ex) {
|
||||
this.printMessage(Kind.WARNING, "Could not read from specified imports file: " + targetsFileName);
|
||||
}
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ public final class SupportedOptions {
|
||||
public static final String DISABLE_OVERWRITE_CHECKER = "disableOverwriteChecker";
|
||||
public static final String OVERWRITE_ERROR_LEVEL = "overwriteErrorLevel";
|
||||
public static final String DEFAULT_OBFUSCATION_ENV = "defaultObfuscationEnv";
|
||||
public static final String DEPENDENCY_TARGETS_FILE = "dependencyTargetsFile";
|
||||
|
||||
public static final Set<String> all = ImmutableSet.<String>of(
|
||||
SupportedOptions.TOKENS,
|
||||
@@ -61,7 +62,8 @@ public final class SupportedOptions {
|
||||
SupportedOptions.DISABLE_TARGET_EXPORT,
|
||||
SupportedOptions.DISABLE_OVERWRITE_CHECKER,
|
||||
SupportedOptions.OVERWRITE_ERROR_LEVEL,
|
||||
SupportedOptions.DEFAULT_OBFUSCATION_ENV
|
||||
SupportedOptions.DEFAULT_OBFUSCATION_ENV,
|
||||
SupportedOptions.DEPENDENCY_TARGETS_FILE
|
||||
);
|
||||
|
||||
private SupportedOptions() {}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -39,6 +40,8 @@ import java.util.Set;
|
||||
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* Serialisable map of classes to their associated mixins, used so that we can
|
||||
* pass target information for supermixins from one compiler session to another
|
||||
@@ -106,6 +109,16 @@ public class TargetMap extends HashMap<TypeReference, Set<TypeReference>> {
|
||||
this.addMixin(target.getReference(), mixin.getReference());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the specified mixin against the specified target
|
||||
*
|
||||
* @param target Target class
|
||||
* @param mixin Mixin class
|
||||
*/
|
||||
public void addMixin(String target, String mixin) {
|
||||
this.addMixin(new TypeReference(target), new TypeReference(mixin));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the specified mixin against the specified target
|
||||
*
|
||||
@@ -161,6 +174,25 @@ public class TargetMap extends HashMap<TypeReference, Set<TypeReference>> {
|
||||
}
|
||||
return mixins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read upstream library mixins from a file
|
||||
*
|
||||
* @param file File to read from
|
||||
* @throws IOException if an error occurs whilst reading the file
|
||||
*/
|
||||
public void readImports(File file) throws IOException {
|
||||
if (!file.isFile()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String line : Files.readLines(file, Charset.defaultCharset())) {
|
||||
String[] parts = line.split("\t");
|
||||
if (parts.length == 2) {
|
||||
this.addMixin(parts[1], parts[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this target map to temporary session file
|
||||
@@ -246,4 +278,5 @@ public class TargetMap extends HashMap<TypeReference, Set<TypeReference>> {
|
||||
File tempDir = new File(System.getProperty("java.io.tmpdir"));
|
||||
return new File(tempDir, String.format("mixin-targetdb-%s.tmp", sessionId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,6 +56,15 @@ public class TypeReference implements Serializable, Comparable<TypeReference> {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a type reference with no handle
|
||||
*
|
||||
* @param name Name of the type
|
||||
*/
|
||||
TypeReference(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name (internal format)
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user