-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
eb27f9c
commit 1e2e8e7
Showing
9 changed files
with
237 additions
and
22 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
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
90 changes: 90 additions & 0 deletions
90
src/main/java/com/wildermods/workspace/decomp/DecompilerBuilder.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,90 @@ | ||
package com.wildermods.workspace.decomp; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
|
||
import org.gradle.api.Task; | ||
|
||
import com.wildermods.workspace.util.GradlePrintStreamLogger; | ||
|
||
import net.fabricmc.loom.api.decompilers.DecompilationMetadata; | ||
import net.fabricmc.loom.util.IOStringConsumer; | ||
|
||
public class DecompilerBuilder { | ||
|
||
private int numberOfThreads = 4; | ||
private Path javadocs; | ||
private Path decompDest; | ||
private Collection<Path> jarsToDecomp = new HashSet<Path>(); | ||
private Collection<Path> libraries = new HashSet<Path>(); | ||
private IOStringConsumer logger; | ||
private Map<String, String> options = new HashMap<>(); | ||
|
||
public DecompilerBuilder() {} | ||
|
||
public DecompilerBuilder(Task task) { | ||
setLogger(new GradlePrintStreamLogger(task)); | ||
} | ||
|
||
public DecompilerBuilder setThreadCount(int threadCount) { | ||
if(threadCount > 0 && threadCount <= Runtime.getRuntime().availableProcessors()) { | ||
numberOfThreads = threadCount; | ||
} | ||
return this; | ||
} | ||
|
||
public DecompilerBuilder setJavadocs(Path javadocs) { | ||
this.javadocs = javadocs; | ||
return this; | ||
} | ||
|
||
public DecompilerBuilder setDecompDest(Path decompDest) { | ||
this.decompDest = decompDest; | ||
return this; | ||
} | ||
|
||
public DecompilerBuilder addJarsToDecomp(Path... jars) { | ||
this.jarsToDecomp.addAll(Arrays.asList(jars)); | ||
return this; | ||
} | ||
|
||
public DecompilerBuilder addLibraries(Path... libraries) { | ||
this.libraries.addAll(Arrays.asList(libraries)); | ||
return this; | ||
} | ||
|
||
public DecompilerBuilder setLogger(IOStringConsumer logger) { | ||
this.logger = logger; | ||
return this; | ||
} | ||
|
||
public DecompilerBuilder setOption(String key, String value) { | ||
options.put(key, value); | ||
return this; | ||
} | ||
|
||
public DecompilationMetadata getMetaData() { | ||
return new DecompilationMetadata(numberOfThreads, javadocs, libraries, logger, options); | ||
} | ||
|
||
public Collection<Path> getJarsToDecomp() { | ||
return jarsToDecomp; | ||
} | ||
|
||
public Path getDecompDest() { | ||
return decompDest; | ||
} | ||
|
||
public Path getLinemapDest() { | ||
return decompDest.getParent().resolve("linemaps"); | ||
} | ||
|
||
public WilderWorkspaceDecompiler build() { | ||
decompDest.getClass(); //throw if null | ||
return new WilderWorkspaceDecompiler(this); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/wildermods/workspace/decomp/WilderWorkspaceDecompiler.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,61 @@ | ||
package com.wildermods.workspace.decomp; | ||
|
||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.jetbrains.java.decompiler.main.Fernflower; | ||
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; | ||
import org.jetbrains.java.decompiler.main.extern.IResultSaver; | ||
|
||
import com.wildermods.workspace.util.GradlePrintStreamLogger; | ||
|
||
import net.fabricmc.loom.decompilers.vineflower.ThreadSafeResultSaver; | ||
import net.fabricmc.loom.api.decompilers.DecompilationMetadata; | ||
|
||
public class WilderWorkspaceDecompiler { | ||
|
||
private final Fernflower ff; | ||
private final DecompilerBuilder builder; | ||
private final DecompilationMetadata metaData; | ||
|
||
WilderWorkspaceDecompiler(DecompilerBuilder builder) { | ||
this.builder = builder; | ||
this.metaData = builder.getMetaData(); | ||
|
||
final Map<String, Object> options = new HashMap<>( | ||
Map.of( | ||
IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1", | ||
IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1", | ||
IFernflowerPreferences.REMOVE_SYNTHETIC, "1", | ||
IFernflowerPreferences.LOG_LEVEL, "trace", | ||
IFernflowerPreferences.THREADS, String.valueOf(metaData.numberOfThreads()), | ||
IFernflowerPreferences.INDENT_STRING, "\t" | ||
//IFabricJavadocProvider.PROPERTY_NAME, new WilderWorkspaceJavadocProvider(metaData.javaDocs().toFile()) | ||
) | ||
); | ||
|
||
options.putAll(metaData.options()); | ||
|
||
IResultSaver saver = new ThreadSafeResultSaver(builder.getDecompDest()::toFile, builder.getLinemapDest()::toFile); | ||
ff = new Fernflower(saver, options, (GradlePrintStreamLogger)metaData.logger()); | ||
|
||
for(Path library : metaData.libraries()) { | ||
ff.addLibrary(library.toFile()); | ||
} | ||
|
||
for(Path compiledJar : builder.getJarsToDecomp()) { | ||
ff.addSource(compiledJar.toFile()); | ||
} | ||
|
||
} | ||
|
||
public void decompile() { | ||
try { | ||
ff.decompileContext(); | ||
} | ||
finally { | ||
ff.clearContext(); | ||
} | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/wildermods/workspace/decomp/WilderWorkspaceJavadocProvider.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,51 @@ | ||
package com.wildermods.workspace.decomp; | ||
|
||
import java.io.File; | ||
|
||
import org.jetbrains.java.decompiler.struct.StructClass; | ||
import org.jetbrains.java.decompiler.struct.StructField; | ||
import org.jetbrains.java.decompiler.struct.StructMethod; | ||
|
||
import net.fabricmc.loom.decompilers.vineflower.TinyJavadocProvider; | ||
|
||
public class WilderWorkspaceJavadocProvider extends TinyJavadocProvider { | ||
|
||
private final TinyJavadocProvider parent; | ||
|
||
public WilderWorkspaceJavadocProvider(File tinyFile) { | ||
super(tinyFile); | ||
if(tinyFile == null) { | ||
parent = null; | ||
} | ||
else { | ||
parent = new TinyJavadocProvider(tinyFile); | ||
} | ||
} | ||
|
||
@Override | ||
public String getClassDoc(StructClass structClass) { | ||
if(parent == null) { | ||
return ""; | ||
} | ||
return parent.getClassDoc(structClass); | ||
} | ||
|
||
@Override | ||
public String getFieldDoc(StructClass structClass, StructField structField) { | ||
if(parent == null) { | ||
return ""; | ||
} | ||
return parent.getFieldDoc(structClass, structField); | ||
} | ||
|
||
@Override | ||
public String getMethodDoc(StructClass structClass, StructMethod structMethod) { | ||
if(parent == null) { | ||
return ""; | ||
} | ||
return parent.getMethodDoc(structClass, structMethod); | ||
} | ||
|
||
|
||
|
||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/wildermods/workspace/tasks/GenerateSourcesTask.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,7 @@ | ||
package com.wildermods.workspace.tasks; | ||
|
||
import org.gradle.api.DefaultTask; | ||
|
||
public class GenerateSourcesTask extends DefaultTask { | ||
|
||
} |
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