Skip to content

Commit

Permalink
fix: support old ConfigPhase.BOOTSRAP + enum like ConfigPhase.BOOTSRAP
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 10, 2024
1 parent 32d3e65 commit 226177a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,19 @@ public static String getAnnotationMemberValue(PsiAnnotation annotation, String m
return null;
}
if (member instanceof PsiEnumConstant) {
// ex : @ConfigRoot(phase = BUILD_AND_RUN_TIME_FIXED)
// returns BUILD_AND_RUN_TIME_FIXED
return member.getText();
}
if (member instanceof PsiReference reference) {
// ex: @Path(MY_CONSTANTS) where MY_CONSTANTS is a Java field.
member = reference.resolve();
}
if (member instanceof PsiEnumConstant) {
// ex : @ConfigRoot(phase = io.quarkus.runtime.annotations.ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
// returns BUILD_AND_RUN_TIME_FIXED
return member.getText();
}
if (member instanceof PsiField field) {
// ex: private static final String MY_CONSTANTS = "foo";
member = field.getInitializer();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.redhat.microprofile.psi.internal.quarkus.core.properties;

/**
* Copy/Paste from ConfigPhase from Quarkus IO to support
* old Quarkus application which defined BOOTSRAP which was removed
* in the new version of Quarkus.
*/
public enum ConfigPhase {
/**
* Values are read and available for usage at build time.
*/
BUILD_TIME(true, false, false, "Build time"),
/**
* Values are read and available for usage at build time, and available on a read-only basis at run time.
*/
BUILD_AND_RUN_TIME_FIXED(true, true, false, "Build time and run time fixed"),

/**
* Values are read and available for usage at run time and are re-read on each program execution. These values
* are used to configure ConfigSourceProvider implementations
*
* @deprecated Please use {@link io.smallrye.config.ConfigSourceFactory.ConfigurableConfigSourceFactory} and
* register it in a {@link io.quarkus.runtime.configuration.ConfigBuilder}.
*/
@Deprecated
BOOTSTRAP(false, true, true, "Bootstrap"),

/**
* Values are read and available for usage at run time and are re-read on each program execution.
*/
RUN_TIME(false, true, true, "Run time"),
;

private final boolean availableAtBuild;
private final boolean availableAtRun;
private final boolean readAtMain;
private final String name;

ConfigPhase(final boolean availableAtBuild, final boolean availableAtRun, final boolean readAtMain, final String name) {
this.availableAtBuild = availableAtBuild;
this.availableAtRun = availableAtRun;
this.readAtMain = readAtMain;
this.name = name;
}

public boolean isAvailableAtBuild() {
return availableAtBuild;
}

public boolean isAvailableAtRun() {
return availableAtRun;
}

public boolean isReadAtStaticInit() {
return isAvailableAtBuild() && isAvailableAtRun();
}

public boolean isReadAtMain() {
return readAtMain;
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils;
import org.eclipse.lsp4mp.commons.metadata.ItemMetadata;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -59,8 +58,6 @@
*/
public class QuarkusConfigRootProvider extends AbstractAnnotationTypeReferencePropertiesProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(QuarkusConfigRootProvider.class);

private static final String[] ANNOTATION_NAMES = { QuarkusConstants.CONFIG_ROOT_ANNOTATION };

private static final String JAVADOC_CACHE_KEY = QuarkusConfigRootProvider.class.getName() + "#javadoc";
Expand Down Expand Up @@ -197,6 +194,10 @@ private static String getExtensionName(String configRootClassSimpleName, String
"Run", "Time", "Config"),
"Configuration"),
"Config");
} else if (configPhase == ConfigPhase.BOOTSTRAP) {
trimmedSegments = withoutSuffix(withoutSuffix(
withoutSuffix(withoutSuffix(segments, "Bootstrap", "Configuration"), "Bootstrap", "Config"),
"Configuration"), "Config");
} else {
trimmedSegments = withoutSuffix(withoutSuffix(
withoutSuffix(withoutSuffix(segments, "Build", "Time", "Configuration"), "Build", "Time", "Config"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

/**
* Properties provider that provides static Quarkus properties
*
*
* @author Angelo ZERR
*
* @see https://github.com/eclipse/microprofile-health/blob/master/spec/src/main/asciidoc/protocol-wireformat.adoc
*
* @see <a href="https://github.com/eclipse/microprofile-health/blob/master/spec/src/main/asciidoc/protocol-wireformat.adoc">GitHub</a>
*
*/
public class QuarkusCoreProvider extends AbstractStaticQuarkusPropertiesProvider {
Expand Down

0 comments on commit 226177a

Please sign in to comment.