Skip to content

Commit

Permalink
Merge pull request #43197 from gsmet/3.14.3-backports-3
Browse files Browse the repository at this point in the history
[3.14] 3.14.3 backports 3
  • Loading branch information
gsmet authored Sep 11, 2024
2 parents 2ab6439 + db0dfde commit 8f048ef
Show file tree
Hide file tree
Showing 28 changed files with 224 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BootstrapConfig {
boolean disableJarCache;

/**
* A temporary option introduced to avoid a logging warning when {@code }-Dquarkus.bootstrap.incubating-model-resolver}
* A temporary option introduced to avoid a logging warning when {@code -Dquarkus.bootstrap.incubating-model-resolver}
* is added to the build command line.
* This option enables an incubating implementation of the Quarkus Application Model resolver.
* This option will be removed as soon as the incubating implementation becomes the default one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public static void dumpCurrentConfigValues(ApplicationModel appModel, String lau
if (previouslyRecordedProperties.isEmpty()) {
try {
readConfig(appModel, mode, buildSystemProps, deploymentClassLoader, configReader -> {
var config = configReader.initConfiguration(mode, buildSystemProps, appModel.getPlatformProperties());
var config = configReader.initConfiguration(mode, buildSystemProps, new Properties(),
appModel.getPlatformProperties());
final Map<String, String> allProps = new HashMap<>();
for (String name : config.getPropertyNames()) {
allProps.put(name, ConfigTrackingValueTransformer.asString(config.getConfigValue(name)));
Expand Down Expand Up @@ -287,7 +288,8 @@ public static void dumpCurrentConfigValues(ApplicationModel appModel, String lau
public static Config getConfig(ApplicationModel appModel, LaunchMode launchMode, Properties buildSystemProps,
QuarkusClassLoader deploymentClassLoader) throws CodeGenException {
return readConfig(appModel, launchMode, buildSystemProps, deploymentClassLoader,
configReader -> configReader.initConfiguration(launchMode, buildSystemProps, appModel.getPlatformProperties()));
configReader -> configReader.initConfiguration(launchMode, buildSystemProps, new Properties(),
appModel.getPlatformProperties()));
}

public static <T> T readConfig(ApplicationModel appModel, LaunchMode launchMode, Properties buildSystemProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ private static boolean isRecorder(AnnotatedElement element) {
* @throws IOException if the class loader could not load a resource
* @throws ClassNotFoundException if a build step class is not found
*/
public static Consumer<BuildChainBuilder> loadStepsFrom(ClassLoader classLoader, Properties buildSystemProps,
public static Consumer<BuildChainBuilder> loadStepsFrom(ClassLoader classLoader,
Properties buildSystemProps, Properties runtimeProperties,
ApplicationModel appModel, LaunchMode launchMode, DevModeType devModeType)
throws IOException, ClassNotFoundException {

final BuildTimeConfigurationReader reader = new BuildTimeConfigurationReader(classLoader);
final SmallRyeConfig src = reader.initConfiguration(launchMode, buildSystemProps, appModel.getPlatformProperties());
final SmallRyeConfig src = reader.initConfiguration(launchMode, buildSystemProps, runtimeProperties,
appModel.getPlatformProperties());
// install globally
QuarkusConfigFactory.setConfig(src);
final BuildTimeConfigurationReader.ReadResult readResult = reader.readConfiguration(src);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class QuarkusAugmentor {
private final Collection<Path> excludedFromIndexing;
private final LiveReloadBuildItem liveReloadBuildItem;
private final Properties buildSystemProperties;
private final Properties runtimeProperties;
private final Path targetDir;
private final ApplicationModel effectiveModel;
private final Supplier<DependencyInfoProvider> depInfoProvider;
Expand All @@ -75,6 +76,7 @@ public class QuarkusAugmentor {
this.excludedFromIndexing = builder.excludedFromIndexing;
this.liveReloadBuildItem = builder.liveReloadState;
this.buildSystemProperties = builder.buildSystemProperties;
this.runtimeProperties = builder.runtimeProperties;
this.targetDir = builder.targetDir;
this.effectiveModel = builder.effectiveModel;
this.baseName = builder.baseName;
Expand Down Expand Up @@ -102,13 +104,9 @@ public BuildResult run() throws Exception {
final BuildChainBuilder chainBuilder = BuildChain.builder();
chainBuilder.setClassLoader(deploymentClassLoader);

//provideCapabilities(chainBuilder);

//TODO: we load everything from the deployment class loader
//this allows the deployment config (application.properties) to be loaded, but in theory could result
//in additional stuff from the deployment leaking in, this is unlikely but has a bit of a smell.
ExtensionLoader.loadStepsFrom(deploymentClassLoader,
buildSystemProperties == null ? new Properties() : buildSystemProperties,
runtimeProperties == null ? new Properties() : runtimeProperties,
effectiveModel, launchMode, devModeType)
.accept(chainBuilder);

Expand Down Expand Up @@ -210,6 +208,7 @@ public static final class Builder {
LaunchMode launchMode = LaunchMode.NORMAL;
LiveReloadBuildItem liveReloadState = new LiveReloadBuildItem();
Properties buildSystemProperties;
Properties runtimeProperties;

ApplicationModel effectiveModel;
String baseName = QUARKUS_APPLICATION;
Expand Down Expand Up @@ -322,6 +321,15 @@ public Builder setBuildSystemProperties(final Properties buildSystemProperties)
return this;
}

public Properties getRuntimeProperties() {
return runtimeProperties;
}

public Builder setRuntimeProperties(final Properties runtimeProperties) {
this.runtimeProperties = runtimeProperties;
return this;
}

public Builder setRebuild(boolean rebuild) {
this.rebuild = rebuild;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public final class ReflectiveFieldBuildItem extends MultiBuildItem {
final String reason;

public ReflectiveFieldBuildItem(String reason, FieldInfo field) {
this.reason = reason;
this.name = field.name();
this.declaringClass = field.declaringClass().name().toString();
this(reason, field.declaringClass().name().toString(), field.name());
}

public ReflectiveFieldBuildItem(FieldInfo field) {
Expand All @@ -27,9 +25,13 @@ public ReflectiveFieldBuildItem(Field field) {
}

public ReflectiveFieldBuildItem(String reason, Field field) {
this(reason, field.getDeclaringClass().getName(), field.getName());
}

public ReflectiveFieldBuildItem(String reason, String declaringClass, String fieldName) {
this.reason = reason;
this.name = field.getName();
this.declaringClass = field.getDeclaringClass().getName();
this.name = fieldName;
this.declaringClass = declaringClass;
}

public String getDeclaringClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,25 +380,25 @@ public List<ConfigClassWithPrefix> getBuildTimeVisibleMappings() {
* @param platformProperties Quarkus platform properties to add as a configuration source
* @return configuration instance
*/
public SmallRyeConfig initConfiguration(LaunchMode launchMode, Properties buildSystemProps,
public SmallRyeConfig initConfiguration(LaunchMode launchMode, Properties buildSystemProps, Properties runtimeProperties,
Map<String, String> platformProperties) {
// now prepare & load the build configuration
SmallRyeConfigBuilder builder = ConfigUtils.configBuilder(false, launchMode);
if (classLoader != null) {
builder.forClassLoader(classLoader);
}

DefaultValuesConfigurationSource ds1 = new DefaultValuesConfigurationSource(getBuildTimePatternMap());
DefaultValuesConfigurationSource ds2 = new DefaultValuesConfigurationSource(getBuildTimeRunTimePatternMap());
PropertiesConfigSource pcs = new PropertiesConfigSource(buildSystemProps, "Build system");
if (platformProperties.isEmpty()) {
builder.withSources(ds1, ds2, pcs);
} else {
builder
.withSources(new DefaultValuesConfigurationSource(getBuildTimePatternMap()))
.withSources(new DefaultValuesConfigurationSource(getBuildTimeRunTimePatternMap()))
.withSources(new PropertiesConfigSource(buildSystemProps, "Build system"))
.withSources(new PropertiesConfigSource(runtimeProperties, "Runtime Properties"));

if (!platformProperties.isEmpty()) {
// Our default value configuration source is using an ordinal of Integer.MIN_VALUE
// (see io.quarkus.deployment.configuration.DefaultValuesConfigurationSource)
DefaultValuesConfigSource platformConfigSource = new DefaultValuesConfigSource(platformProperties,
"Quarkus platform", Integer.MIN_VALUE + 1000);
builder.withSources(ds1, ds2, platformConfigSource, pcs);
builder.withSources(
new DefaultValuesConfigSource(platformProperties, "Quarkus platform", Integer.MIN_VALUE + 1000));
}

for (ConfigClassWithPrefix mapping : getBuildTimeVisibleMappings()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ protected QuarkusFileManager(StandardJavaFileManager fileManager, Context contex
this.fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, List.of(context.getGeneratedSourcesDirectory()));
}
if (context.getAnnotationProcessorPaths() != null) {
// Paths might be missing! (see: https://github.com/quarkusio/quarkus/issues/42908)
ensureDirectories(context.getAnnotationProcessorPaths());
this.fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, context.getAnnotationProcessorPaths());
}
} catch (IOException e) {
Expand All @@ -39,13 +41,26 @@ public void reset(Context context) {
this.fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, List.of(context.getGeneratedSourcesDirectory()));
}
if (context.getAnnotationProcessorPaths() != null) {
// Paths might be missing! (see: https://github.com/quarkusio/quarkus/issues/42908)
ensureDirectories(context.getAnnotationProcessorPaths());
this.fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, context.getAnnotationProcessorPaths());
}
} catch (IOException e) {
throw new RuntimeException("Cannot reset file manager", e);
}
}

private void ensureDirectories(Iterable<File> directories) {
for (File directory : directories) {
if (!directory.exists()) {
final boolean success = directory.mkdirs();
if (!success) {
throw new RuntimeException("Cannot create directory " + directory);
}
}
}
}

@Override
public void close() throws IOException {
super.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void accept(CuratedApplication curatedApplication, Map<String, Object> re
.setTargetDir(quarkusBootstrap.getTargetDirectory())
.setDeploymentClassLoader(curatedApplication.createDeploymentClassLoader())
.setBuildSystemProperties(quarkusBootstrap.getBuildSystemProperties())
.setRuntimeProperties(quarkusBootstrap.getRuntimeProperties())
.setEffectiveModel(curatedApplication.getApplicationModel());
if (quarkusBootstrap.getBaseName() != null) {
builder.setBaseName(quarkusBootstrap.getBaseName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveFieldBuildItem;
import io.quarkus.deployment.configuration.RunTimeConfigurationGenerator;
import io.quarkus.deployment.naming.NamingConfig;
import io.quarkus.deployment.pkg.PackageConfig;
Expand Down Expand Up @@ -96,6 +97,9 @@ public class MainClassBuildStep {
static final String STARTUP_CONTEXT = "STARTUP_CONTEXT";
static final String LOG = "LOG";
static final String JAVA_LIBRARY_PATH = "java.library.path";
// This is declared as a constant so that it can be grepped for in the native-image binary using `strings`, e.g.:
// strings ./target/quarkus-runner | grep "__quarkus_analytics__quarkus.version="
public static final String QUARKUS_ANALYTICS_QUARKUS_VERSION = "__QUARKUS_ANALYTICS_QUARKUS_VERSION";

public static final String GENERATE_APP_CDS_SYSTEM_PROPERTY = "quarkus.appcds.generate";

Expand Down Expand Up @@ -155,6 +159,9 @@ void build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
FieldCreator scField = file.getFieldCreator(STARTUP_CONTEXT_FIELD);
scField.setModifiers(Modifier.PUBLIC | Modifier.STATIC);

FieldCreator quarkusVersionField = file.getFieldCreator(QUARKUS_ANALYTICS_QUARKUS_VERSION, String.class)
.setModifiers(Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL);

MethodCreator ctor = file.getMethodCreator("<init>", void.class);
ctor.invokeSpecialMethod(ofMethod(Application.class, "<init>", void.class, boolean.class),
ctor.getThis(), ctor.load(launchMode.isAuxiliaryApplication()));
Expand Down Expand Up @@ -192,6 +199,10 @@ void build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
mv.writeStaticField(logField.getFieldDescriptor(), mv.invokeStaticMethod(
ofMethod(Logger.class, "getLogger", Logger.class, String.class), mv.load("io.quarkus.application")));

// Init the __QUARKUS_ANALYTICS_QUARKUS_VERSION field
mv.writeStaticField(quarkusVersionField.getFieldDescriptor(),
mv.load("__quarkus_analytics__quarkus.version=" + Version.getVersion()));

ResultHandle startupContext = mv.newInstance(ofConstructor(StartupContext.class));
mv.writeStaticField(scField.getFieldDescriptor(), startupContext);
TryBlock tryBlock = mv.tryBlock();
Expand Down Expand Up @@ -703,4 +714,10 @@ private static Result invalid() {
}
}

@BuildStep
ReflectiveFieldBuildItem setupVersionField() {
return new ReflectiveFieldBuildItem(
"Ensure it's included in the executable to be able to grep the quarkus version",
Application.APP_CLASS_NAME, QUARKUS_ANALYTICS_QUARKUS_VERSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import io.quarkus.bootstrap.BootstrapConstants;

Expand Down Expand Up @@ -46,6 +47,7 @@ public static Map<String, Object> postBuild(Path appClasses, Path pomFile, List<
return ret;
}

Properties configurationProperties = new Properties();
for (String comment : comments) {
//we allow config to be provided via //Q:CONFIG name=value
if (comment.startsWith(CONFIG)) {
Expand All @@ -54,7 +56,7 @@ public static Map<String, Object> postBuild(Path appClasses, Path pomFile, List<
if (equals == -1) {
throw new RuntimeException("invalid config " + comment);
}
System.setProperty(conf.substring(0, equals), conf.substring(equals + 1));
configurationProperties.setProperty(conf.substring(0, equals), conf.substring(equals + 1));
}
}

Expand Down Expand Up @@ -117,12 +119,15 @@ public Enumeration<URL> getResources(String name) throws IOException {
Thread.currentThread().setContextClassLoader(loader);
Class<?> launcher = loader.loadClass("io.quarkus.bootstrap.jbang.JBangBuilderImpl");
return (Map<String, Object>) launcher
.getDeclaredMethod("postBuild", Path.class, Path.class, List.class, List.class, boolean.class).invoke(
.getDeclaredMethod("postBuild", Path.class, Path.class, List.class, List.class, Properties.class,
boolean.class)
.invoke(
null,
appClasses,
pomFile,
repositories,
dependencies,
configurationProperties,
nativeImage);
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static ResolvedType makeMap(TypeMirror type, ResolvedType unwrappedResolv
return new ResolvedType(type, unwrappedResolvedType.unwrappedType,
unwrappedResolvedType.binaryName, unwrappedResolvedType.qualifiedName, unwrappedResolvedType.simplifiedName,
unwrappedResolvedType.isPrimitive,
true, unwrappedResolvedType.isList,
true, false,
unwrappedResolvedType.isOptional,
unwrappedResolvedType.isDeclared, unwrappedResolvedType.isInterface, unwrappedResolvedType.isClass,
unwrappedResolvedType.isEnum, unwrappedResolvedType.isDuration, unwrappedResolvedType.isConfigGroup);
Expand Down
8 changes: 4 additions & 4 deletions docs/src/main/asciidoc/ide-tooling.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ In addition, IntelliJ IDEA has additional support for Quarkus in their Ultimate
The table below gives an overview of the current IDEs with links and a high-level overview of their features.

:vscode-logo: https://simpleicons.org/icons/visualstudiocode.svg
:eclipse-logo: https://simpleicons.org/icons/eclipseide.svg
:intellij-logo: https://simpleicons.org/icons/intellijidea.svg
:che-logo: https://simpleicons.org/icons/eclipseche.svg
:vscode-logo: visualstudiocode.svg
:eclipse-logo: eclipseide.svg
:intellij-logo: intellijidea.svg
:che-logo: eclipseche.svg
[cols="6*^", header]
|===
| .
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/images/eclipseche.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/images/eclipseide.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8f048ef

Please sign in to comment.