Skip to content

Commit

Permalink
Introduce quarkus.package.decompiler config
Browse files Browse the repository at this point in the history
This is meant to be used instead of
quarkus.package.vineflower.
Furthermore, this removes the configurable
version property which was never being used.

Closes: quarkusio#37332
  • Loading branch information
geoand committed Dec 1, 2023
1 parent 8c08a65 commit 0a16875
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Optional;
import java.util.Set;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;
Expand Down Expand Up @@ -249,9 +250,18 @@ public static BuiltInType fromString(String value) {

/**
* Vineflower Decompiler configuration
*
* @Deprecated use {@code quarkus.package.decompiler} instead
*/
@ConfigItem
@Deprecated(forRemoval = true)
public DecompilerConfig vineflower;

/**
* Decompiler configuration
*/
@ConfigItem
public VineFlowerConfig vineflower;
public DecompilerConfig decompiler;

/**
* If set to {@code true}, it will result in the Quarkus writing the transformed application bytecode
Expand Down Expand Up @@ -302,24 +312,19 @@ public String getRunnerSuffix() {
}

@ConfigGroup
public static class VineFlowerConfig {
public static class DecompilerConfig {
/**
* An advanced option that will decompile generated and transformed bytecode into the 'decompiled' directory.
* This is only taken into account when fast-jar is used.
*/
@ConfigItem(defaultValue = "false")
public boolean enabled;

/**
* The version of Vineflower to use
*/
@ConfigItem(defaultValue = "1.9.3")
public String version;
@ConfigDocDefault("false")
public Optional<Boolean> enabled;

/**
* The directory into which to save the Vineflower tool if it doesn't exist
*/
@ConfigItem(defaultValue = "${user.home}/.quarkus")
public String jarDirectory;
@ConfigItem
@ConfigDocDefault("${user.home}/.quarkus")
public Optional<String> jarDirectory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public boolean test(String path) {
public static final String DEFAULT_FAST_JAR_DIRECTORY_NAME = "quarkus-app";

public static final String MP_CONFIG_FILE = "META-INF/microprofile-config.properties";
private static final String VINEFLOWER_VERSION = "1.9.3";

@BuildStep
OutputTargetBuildItem outputTarget(BuildSystemTargetBuildItem bst, PackageConfig packageConfig) {
Expand Down Expand Up @@ -603,19 +604,22 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,
Path decompiledOutputDir = null;
boolean wasDecompiledSuccessfully = true;
Decompiler decompiler = null;
if (packageConfig.vineflower.enabled) {
if (packageConfig.vineflower.enabled.orElse(false) || packageConfig.decompiler.enabled.orElse(false)) {
Optional<String> jarDirectoryStrOpt = packageConfig.vineflower.enabled.orElse(false)
? packageConfig.vineflower.jarDirectory
: packageConfig.decompiler.jarDirectory;
String jarDirectoryStr = jarDirectoryStrOpt.orElse(System.getProperty("user.home") + "/.quarkus");

decompiledOutputDir = buildDir.getParent().resolve("decompiled");
FileUtil.deleteDirectory(decompiledOutputDir);
Files.createDirectory(decompiledOutputDir);
if (packageConfig.vineflower.enabled) {
decompiler = new Decompiler.VineflowerDecompiler();
Path jarDirectory = Paths.get(packageConfig.vineflower.jarDirectory);
if (!Files.exists(jarDirectory)) {
Files.createDirectory(jarDirectory);
}
decompiler.init(new Decompiler.Context(packageConfig.vineflower.version, jarDirectory, decompiledOutputDir));
decompiler.downloadIfNecessary();
decompiler = new Decompiler.VineflowerDecompiler();
Path jarDirectory = Paths.get(jarDirectoryStr);
if (!Files.exists(jarDirectory)) {
Files.createDirectory(jarDirectory);
}
decompiler.init(new Decompiler.Context(VINEFLOWER_VERSION, jarDirectory, decompiledOutputDir));
decompiler.downloadIfNecessary();
}

FastJarJars.FastJarJarsBuilder fastJarJarsBuilder = new FastJarJars.FastJarJarsBuilder();
Expand Down

0 comments on commit 0a16875

Please sign in to comment.