Skip to content

Commit

Permalink
new remapper finally working
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolMineman committed Dec 30, 2022
1 parent 118ef1d commit 577bf3f
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ netbeans
.project
.classpath
.settings
todo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -158,9 +157,14 @@ public Map<BuildModule, ProcessingSource> getRemappedClasses(BuildModule... modu
});
r.put(fm, s);
}
ArrayList<Path> remapDeps = new ArrayList<>();
remapDeps.add(namedJar.get().jar);
for (ModDependency dep : remappedModDependencies.get()) {
if (dep.flags.contains(ModDependencyFlag.COMPILE)) remapDeps.add(dep.jarDependency.jar);
}
new ProcessorChain(
new RemapperProcessor(
getCompileDependencies(),
remapDeps,
compmappings,
compmappings.getNamespaceId(Namespaces.NAMED),
compmappings.getNamespaceId(Namespaces.INTERMEDIARY),
Expand Down Expand Up @@ -391,9 +395,6 @@ class RemapInfo {
try (AtomicDirectory a = new AtomicDirectory(resultdir)) {
ArrayList<Path> cp = new ArrayList<>();
cp.add(intermediaryjar.get().jar);
for (JavaJarDependency dep : mcClasspath.get()) {
cp.add(dep.jar);
}
HashMap<ProcessingSource, ZipProcessingSink> b = new HashMap<>();
HashMap<ProcessingSource, MavenId> c = new HashMap<>();
try (CloseableArrayList toClose = new CloseableArrayList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public class RemapperProcessor implements Processor {
final MappingTree mappingTree;
final int src;
final int dst;
final boolean replaceLvt;
final boolean isNamedMc;

public RemapperProcessor(List<Path> classpath, MappingTree mappingTree, int src, int dst, boolean replaceLvt) {
public RemapperProcessor(List<Path> classpath, MappingTree mappingTree, int src, int dst, boolean isNamedMc) {
this.classpath = classpath;
this.mappingTree = mappingTree;
this.src = src;
this.dst = dst;
this.replaceLvt = replaceLvt;
this.isNamedMc = isNamedMc;
}

@Override
Expand Down Expand Up @@ -116,8 +116,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
RecombobulatorRemapper remapper = new RecombobulatorRemapper();
remapper.setClasses(ins);
remapper.setMappings(mappings);
if (replaceLvt) {
if (isNamedMc) {
remapper.replaceLvtAndParams();
remapper.fixSourceFiles();
MappingIoMappings mim = (MappingIoMappings) mappings;
mim.addClassMapping(new Mutf8Slice("javax/annotation/Nullable"), new Mutf8Slice("org/jetbrains/annotations/Nullable"));
mim.addClassMapping(new Mutf8Slice("javax/annotation/Nonnull"), new Mutf8Slice("org/jetbrains/annotations/NotNull"));
mim.addClassMapping(new Mutf8Slice("javax/annotation/concurrent/Immutable"), new Mutf8Slice("org/jetbrains/annotations/Unmodifiable"));
}
ConcurrentLinkedQueue<ProcessingEntry> o = new ConcurrentLinkedQueue<>();
remapper.setOutput(new RemapperOutputConsumer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void getModDependencies(ModDependencyCollector d) {
jij(d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-game-rule-api-v1", "1.0.13+d7c144a860"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE));
jij(d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-registry-sync-v0", "0.9.8+0d9ab37260"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.ini4j:ini4j:0.5.4"), ModDependencyFlag.RUNTIME, ModDependencyFlag.COMPILE));
d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.antlr:antlr4-runtime:4.11.1"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME);
};

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void compile() {
long s2 = System.currentTimeMillis() - s;
System.out.println(s2);
// Seems to work accross java versions for now
TestUtil.assertSha256(b.jar, "fdfeb367b463839e2207b0c8bc887f1879b2157da838e51b1b0e98487c86e6ce");
TestUtil.assertSha256(b.jar, "51f89d5ffdbae7c6a861168d12f7a4b852dbbd2ad2778342fe97224b12da454b");
} catch (Exception e) {
e.printStackTrace();
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.util.Collections;
import java.util.Comparator;
import java.util.stream.Stream;

Expand Down Expand Up @@ -48,13 +49,13 @@ public static void main(Path root, String[] localLibs, String[] mavenLibs) throw
Stream<Path> b = Files.walk(a, 1);
Path jar =
b.filter(p -> p.toString().endsWith(".jar") && !p.toString().endsWith("-sources.jar") && !p.toString().endsWith("-test.jar"))
.sorted(Comparator.comparingLong(p -> {
.sorted(Collections.reverseOrder(Comparator.comparingLong(p -> {
try {
return Files.getLastModifiedTime(p).toMillis();
} catch (IOException e) {
throw new RuntimeException(e);
}
})).findFirst()
}))).findFirst()
.orElseThrow(() -> new RuntimeException(lib));
b.close();
Path sources = jar.getParent().resolve(jar.getFileName().toString().replace(".jar", "-sources.jar"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ class IntNameDescPairPair {
if (conflict) throw new RuntimeException("Mapping conflict");
}

//3am hack
public void addClassMapping(Mutf8Slice src, Mutf8Slice dst) {
classMap.put(src, dst);
}

@Override
public Mutf8Slice mapClass(Mutf8Slice srcCls) {
return classMap.getOrDefault(srcCls, srcCls);
Expand Down
Loading

0 comments on commit 577bf3f

Please sign in to comment.