Skip to content

Commit

Permalink
Use relocation for changing config properties
Browse files Browse the repository at this point in the history
Follows up on quarkusio#37445
  • Loading branch information
dmlloyd committed Dec 22, 2023
1 parent 50a9264 commit 91db25c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 @@ -248,15 +247,6 @@ public static BuiltInType fromString(String value) {
@ConfigItem(defaultValue = "true")
public boolean includeDependencyList;

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

/**
* Decompiler configuration
*/
Expand Down Expand Up @@ -311,21 +301,22 @@ public String getRunnerSuffix() {
return addRunnerSuffix ? runnerSuffix : "";
}

/**
* The configuration for decompilation of generated bytecode.
*/
@ConfigGroup
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
@ConfigDocDefault("false")
public Optional<Boolean> enabled;
@ConfigItem(defaultValue = "false")
public boolean enabled;

/**
* The directory into which to save the Vineflower tool if it doesn't exist
* The directory into which to save the decompilation tool if it doesn't exist
*/
@ConfigItem
@ConfigDocDefault("${user.home}/.quarkus")
public Optional<String> jarDirectory;
@ConfigItem(defaultValue = "${user.home}/.quarkus")
public String jarDirectory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,8 @@ private JarBuildItem buildThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem,
Path decompiledOutputDir = null;
boolean wasDecompiledSuccessfully = true;
Decompiler decompiler = null;
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");

if (packageConfig.decompiler.enabled) {
String jarDirectoryStr = packageConfig.decompiler.jarDirectory;
decompiledOutputDir = buildDir.getParent().resolve("decompiled");
FileUtil.deleteDirectory(decompiledOutputDir);
Files.createDirectory(decompiledOutputDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.quarkus.runtime.configuration;

import java.io.Serial;
import java.util.Iterator;
import java.util.Map;
import java.util.stream.Collectors;

import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.RelocateConfigSourceInterceptor;

/**
* Central location for all relocated core configuration entries.
*/
public final class CoreRelocateConfigSourceInterceptor extends RelocateConfigSourceInterceptor {
@Serial
private static final long serialVersionUID = -3096467506527701713L;

private static final Map<String, String> MAPPINGS = Map.of(
// relocated in #37445
"quarkus.package.decompiler.enabled", "quarkus.package.vineflower.enabled",
"quarkus.package.decompiler.jar-directory", "quarkus.package.vineflower.jar-directory");

private static final Map<String, String> REV_MAPPINGS = MAPPINGS.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));

public CoreRelocateConfigSourceInterceptor() {
super(MAPPINGS);
}

public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
Iterator<String> itr = super.iterateNames(context);
return new Iterator<String>() {
public boolean hasNext() {
return itr.hasNext();
}

public String next() {
String next = itr.next();
return REV_MAPPINGS.getOrDefault(next, next);
}
};
}

public Iterator<ConfigValue> iterateValues(final ConfigSourceInterceptorContext context) {
Iterator<ConfigValue> itr = super.iterateValues(context);
return new Iterator<ConfigValue>() {
public boolean hasNext() {
return itr.hasNext();
}

public ConfigValue next() {
ConfigValue next = itr.next();
String name = next.getName();
String mapped = REV_MAPPINGS.getOrDefault(name, name);
return name.equals(mapped) ? next : next.withName(name);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.runtime.configuration.CoreRelocateConfigSourceInterceptor

0 comments on commit 91db25c

Please sign in to comment.