-
Notifications
You must be signed in to change notification settings - Fork 2
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
23 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
configurations.configureEach { | ||
transitive = false | ||
} | ||
|
||
dependencies { | ||
gradleApi() | ||
implementation("org.ow2.asm:asm:9.3") | ||
implementation("org.ow2.asm:asm-tree:9.3") | ||
implementation("org.ow2.asm:asm-commons:9.3") | ||
} |
17 changes: 17 additions & 0 deletions
17
buildSrc/src/main/java/me/xfl03/morecrashinfo/gradle/GradlePlugin.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,17 @@ | ||
package me.xfl03.morecrashinfo.gradle; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
|
||
public class GradlePlugin implements Plugin<Project> { | ||
@Override | ||
public void apply(Project project) { | ||
//Is not root project | ||
if (!project.getRootProject().equals(project)) { | ||
return; | ||
} | ||
|
||
//Only apply to root project | ||
project.getTasks().create("remap", RemapTask.class, task -> task.rootProject = project.getRootProject()); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
buildSrc/src/main/java/me/xfl03/morecrashinfo/gradle/JarRemapper.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,69 @@ | ||
package me.xfl03.morecrashinfo.gradle; | ||
|
||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.commons.ClassRemapper; | ||
import org.objectweb.asm.commons.Remapper; | ||
import org.objectweb.asm.commons.SimpleRemapper; | ||
import org.objectweb.asm.tree.ClassNode; | ||
|
||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Enumeration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
public class JarRemapper { | ||
private final Remapper remapper; | ||
|
||
public JarRemapper() { | ||
Map<String, String> mapping = new HashMap<>(); | ||
mapping.put("me/xfl03/morecrashinfo/modlauncher/TransformerService.beginScanningLegacy(Lcpw/mods/modlauncher/api/IEnvironment;)V", "beginScanning"); | ||
remapper = new SimpleRemapper(mapping); | ||
} | ||
|
||
public byte[] process(InputStream is) throws Exception { | ||
ClassReader cr = new ClassReader(is); | ||
ClassNode cn = new ClassNode(); | ||
ClassRemapper cv = new ClassRemapper(cn, remapper); | ||
cr.accept(cv, 0); | ||
ClassWriter cw = new ClassWriter(0); | ||
cn.accept(cw); | ||
System.out.printf("Remapped %s\n", cn.name); | ||
return cw.toByteArray(); | ||
} | ||
|
||
public void processJar(Path inFile, Path outFile) { | ||
try (ZipFile zf = new ZipFile(inFile.toFile())) { | ||
ZipOutputStream zos = new ZipOutputStream(Files.newOutputStream(outFile)); | ||
for (Enumeration<? extends ZipEntry> e = zf.entries(); e.hasMoreElements(); ) { | ||
ZipEntry ze = e.nextElement(); | ||
String name = ze.getName(); | ||
zos.putNextEntry(new ZipEntry(name)); | ||
InputStream is = zf.getInputStream(ze); | ||
if (name.endsWith(".class")) { | ||
//Remap class file | ||
zos.write(process(is)); | ||
} else { | ||
//Copy other file | ||
byte[] cache = new byte[1024]; | ||
int len; | ||
while ((len = is.read(cache)) > 0) { | ||
zos.write(cache, 0, len); | ||
} | ||
} | ||
zos.closeEntry(); | ||
} | ||
zos.close(); | ||
System.out.printf("Remapped %s to %s\n", inFile, outFile); | ||
} catch (Exception e) { | ||
System.err.printf("Error remapping jar %s to %s\n", inFile, outFile); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
buildSrc/src/main/java/me/xfl03/morecrashinfo/gradle/RemapTask.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,29 @@ | ||
package me.xfl03.morecrashinfo.gradle; | ||
|
||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
public class RemapTask extends DefaultTask { | ||
public Project rootProject; | ||
public JarRemapper remapper = new JarRemapper(); | ||
|
||
@TaskAction | ||
public void run() { | ||
File loaderLibs = rootProject.file("2Loader/build/libs"); | ||
File[] files = loaderLibs.listFiles(); | ||
if (files == null) { | ||
System.err.println("Cannot find build libs."); | ||
return; | ||
} | ||
Arrays.stream(files).forEach(this::remap); | ||
} | ||
|
||
private void remap(File inFile) { | ||
File rootLibs = rootProject.file("build/libs"); | ||
remapper.processJar(inFile.toPath(), rootLibs.toPath().resolve(inFile.getName())); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
buildSrc/src/main/resources/META-INF/gradle-plugins/morecrashinfo.properties
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 @@ | ||
implementation-class=me.xfl03.morecrashinfo.gradle.GradlePlugin |
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