Skip to content

Commit

Permalink
Merge pull request quarkusio#37445 from geoand/quarkusio#37332
Browse files Browse the repository at this point in the history
Introduce quarkus.package.decompiler config
  • Loading branch information
geoand authored Dec 20, 2023
2 parents 0ae38d4 + fccdcb0 commit 683b16c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 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,20 @@ 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;
@ConfigItem
@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
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/writing-extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@ The only particular aspect of writing Quarkus extensions in Eclipse is that APT
Quarkus generates a lot of classes during the build phase and in many cases also transforms existing classes.
It is often extremely useful to see the generated bytecode and transformed classes during the development of an extension.

If you set the `quarkus.package.vineflower.enabled` property to `true` then Quarkus will download and invoke the https://github.com/Vineflower/vineflower[Vineflower decompiler] and dump the result in the `decompiled` directory of the build tool output (`target/decompiled` for Maven for example).
If you set the `quarkus.package.decompiler.enabled` property to `true` then Quarkus will download and invoke the https://github.com/Vineflower/vineflower[Vineflower decompiler] and dump the result in the `decompiled` directory of the build tool output (`target/decompiled` for Maven for example).

NOTE: This property only works during a normal production build (i.e. not for dev mode/tests) and when `fast-jar` packaging type is used (the default behavior).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.statistics=true
quarkus.hibernate-orm.metrics.enabled=true

quarkus.package.vineflower.enabled=true
quarkus.package.decompiler.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ mp.messaging.incoming.countries-t2-in.connector=smallrye-kafka
mp.messaging.incoming.countries-t2-in.topic=countries-t2
mp.messaging.incoming.countries-t2-in.auto.offset.reset=earliest

quarkus.package.vineflower.enabled=true
quarkus.package.decompiler.enabled=true

test.prop=test

0 comments on commit 683b16c

Please sign in to comment.