Skip to content

Commit

Permalink
Merge pull request quarkusio#33673 from geoand/fernflower
Browse files Browse the repository at this point in the history
Remove the last traces of Fernflower
  • Loading branch information
geoand authored May 29, 2023
2 parents 2c376be + 72ff30b commit 3e5167e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 71 deletions.
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

0 comments on commit 3e5167e

Please sign in to comment.