Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the last traces of Fernflower #33673

Merged
merged 1 commit into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public static class QuiltFlowerConfig {
public String version;

/**
* The directory into which to save the fernflower tool if it doesn't exist
* The directory into which to save the Quiltflower tool if it doesn't exist
*/
@ConfigItem(defaultValue = "${user.home}/.quarkus")
public String jarDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,76 +1571,6 @@ public Context(String versionStr, Path jarLocation, Path decompiledOutputDir) {

}

class FernflowerDecompiler implements Decompiler {

private Context context;
private Path decompilerJar;

@Override
public void init(Context context) {
this.context = context;
this.decompilerJar = context.jarLocation.resolve(String.format("fernflower-%s.jar", context.versionStr));
}

@Override
public boolean downloadIfNecessary() {
if (Files.exists(decompilerJar)) {
return true;
}
String downloadURL = String.format("https://jitpack.io/com/github/fesh0r/fernflower/%s/fernflower-%s.jar",
context.versionStr, context.versionStr);
try (BufferedInputStream in = new BufferedInputStream(new URL(downloadURL).openStream());
FileOutputStream fileOutputStream = new FileOutputStream(decompilerJar.toFile())) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
return true;
} catch (IOException e) {
log.error("Unable to download Fernflower from " + downloadURL, e);
return false;
}
}

@Override
public boolean decompile(Path jarToDecompile) {
int exitCode;
try {
ProcessBuilder processBuilder = new ProcessBuilder(
Arrays.asList("java", "-jar", decompilerJar.toAbsolutePath().toString(),
jarToDecompile.toAbsolutePath().toString(),
context.decompiledOutputDir.toAbsolutePath().toString()));
if (log.isDebugEnabled()) {
processBuilder.inheritIO();
} else {
processBuilder.redirectError(ProcessBuilder.Redirect.DISCARD.file())
.redirectOutput(ProcessBuilder.Redirect.DISCARD.file());
}
exitCode = processBuilder.start().waitFor();
} catch (Exception e) {
log.error("Failed to launch decompiler.", e);
return false;
}

if (exitCode != 0) {
log.errorf("Fernflower decompiler exited with error code: %d.", exitCode);
return false;
}

String jarFileName = jarToDecompile.getFileName().toString();
Path decompiledJar = context.decompiledOutputDir.resolve(jarFileName);
try {
ZipUtils.unzip(decompiledJar, context.decompiledOutputDir.resolve(jarFileName.replace(DOT_JAR, "")));
Files.deleteIfExists(decompiledJar);
} catch (IOException ignored) {
// it doesn't really matter if we can't unzip the jar as we do it merely for user convenience
}

return true;
}
}

class QuiltflowerDecompiler implements Decompiler {

private Context context;
Expand Down