Skip to content

Commit

Permalink
Merge pull request #28641 from gsmet/2.13.3-backports-1
Browse files Browse the repository at this point in the history
2.13.3 backports 1
  • Loading branch information
gsmet committed Oct 18, 2022
2 parents aff3ad2 + 20eee46 commit 73c77d0
Show file tree
Hide file tree
Showing 349 changed files with 1,852 additions and 881 deletions.
12 changes: 9 additions & 3 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<smallrye-reactive-streams-operators.version>1.0.13</smallrye-reactive-streams-operators.version>
<smallrye-reactive-types-converter.version>2.7.0</smallrye-reactive-types-converter.version>
<smallrye-mutiny-vertx-binding.version>2.27.0</smallrye-mutiny-vertx-binding.version>
<smallrye-reactive-messaging.version>3.20.0</smallrye-reactive-messaging.version>
<smallrye-reactive-messaging.version>3.21.0</smallrye-reactive-messaging.version>
<smallrye-stork.version>1.1.2</smallrye-stork.version>
<jakarta.activation.version>1.2.1</jakarta.activation.version>
<jakarta.annotation-api.version>1.3.5</jakarta.annotation-api.version>
Expand Down Expand Up @@ -83,7 +83,7 @@
<graal-sdk.version>22.2.0</graal-sdk.version>
<graal-svm.version>${graal-sdk.version}</graal-svm.version>
<gizmo.version>1.1.1.Final</gizmo.version>
<jackson-bom.version>2.13.4</jackson-bom.version>
<jackson-bom.version>2.13.4.20221013</jackson-bom.version>
<commons-logging-jboss-logging.version>1.0.0.Final</commons-logging-jboss-logging.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<commons-codec.version>1.15</commons-codec.version>
Expand Down Expand Up @@ -150,7 +150,7 @@
<azure-functions-java-library.version>1.4.2</azure-functions-java-library.version>
<kotlin.version>1.7.20</kotlin.version>
<kotlin.coroutine.version>1.6.4</kotlin.coroutine.version>
<kotlin-serialization.version>1.4.0</kotlin-serialization.version>
<kotlin-serialization.version>1.4.1</kotlin-serialization.version>
<kubernetes-client.version>5.12.4</kubernetes-client.version> <!-- Please check with Java Operator SDK team before updating -->
<dekorate.version>2.11.3</dekorate.version> <!-- Please check with Java Operator SDK team before updating -->
<maven-invoker.version>3.2.0</maven-invoker.version>
Expand Down Expand Up @@ -187,6 +187,7 @@
<picocli.version>4.6.3</picocli.version>
<google-cloud-functions.version>1.0.4</google-cloud-functions.version>
<commons-compress.version>1.21</commons-compress.version>
<commons-text.version>1.10.0</commons-text.version>
<gson.version>2.9.1</gson.version>
<log4j2-jboss-logmanager.version>1.1.1.Final</log4j2-jboss-logmanager.version>
<log4j2-api.version>2.19.0</log4j2-api.version>
Expand Down Expand Up @@ -3126,6 +3127,11 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.function.Consumer;

import org.eclipse.microprofile.config.Config;

import io.quarkus.bootstrap.classloading.ClassPathElement;
import io.quarkus.bootstrap.classloading.FilteredClassPathElement;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.prebuild.CodeGenException;
import io.quarkus.deployment.codegen.CodeGenData;
Expand All @@ -19,25 +25,35 @@
import io.quarkus.paths.PathCollection;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigUtils;
import io.smallrye.config.KeyMap;
import io.smallrye.config.KeyMapBackedConfigSource;
import io.smallrye.config.NameIterator;
import io.smallrye.config.PropertiesConfigSource;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SysPropConfigSource;

/**
* A set of methods to initialize and execute {@link CodeGenProvider}s.
*/
public class CodeGenerator {

private static final String MP_CONFIG_SPI_CONFIG_SOURCE_PROVIDER = "META-INF/services/org.eclipse.microprofile.config.spi.ConfigSourceProvider";

// used by Gradle and Maven
public static void initAndRun(ClassLoader classLoader,
public static void initAndRun(QuarkusClassLoader classLoader,
PathCollection sourceParentDirs, Path generatedSourcesDir, Path buildDir,
Consumer<Path> sourceRegistrar, ApplicationModel appModel, Properties properties,
String launchMode, boolean test) throws CodeGenException {
final List<CodeGenData> generators = init(classLoader, sourceParentDirs, generatedSourcesDir, buildDir,
sourceRegistrar);
if (generators.isEmpty()) {
return;
}
final LaunchMode mode = LaunchMode.valueOf(launchMode);
final Config config = getConfig(appModel, mode, properties, classLoader);
for (CodeGenData generator : generators) {
generator.setRedirectIO(true);
trigger(classLoader, generator, appModel, properties, LaunchMode.valueOf(launchMode), test);
trigger(classLoader, generator, appModel, config, test);
}
}

Expand All @@ -51,7 +67,7 @@ private static List<CodeGenData> init(ClassLoader deploymentClassLoader,
if (codeGenProviders.isEmpty()) {
return List.of();
}
List<CodeGenData> result = new ArrayList<>();
final List<CodeGenData> result = new ArrayList<>(codeGenProviders.size());
for (CodeGenProvider provider : codeGenProviders) {
Path outputDir = codeGenOutDir(generatedSourcesDir, provider, sourceRegistrar);
for (Path sourceParentDir : sourceParentDirs) {
Expand Down Expand Up @@ -144,23 +160,9 @@ private static <T> T callWithClassloader(ClassLoader deploymentClassLoader, Code
public static boolean trigger(ClassLoader deploymentClassLoader,
CodeGenData data,
ApplicationModel appModel,
Properties properties,
LaunchMode launchMode,
Config config,
boolean test) throws CodeGenException {
return callWithClassloader(deploymentClassLoader, () -> {

final PropertiesConfigSource pcs = new PropertiesConfigSource(properties, "Build system");
final SysPropConfigSource spcs = new SysPropConfigSource();

// Discovered Config classes may cause issues here, because this goal runs before compile
final SmallRyeConfig config = ConfigUtils.configBuilder(false, false, launchMode)
.setAddDiscoveredSources(false)
.setAddDiscoveredInterceptors(false)
.setAddDiscoveredConverters(false)
.withProfile(launchMode.getDefaultProfile())
.withSources(pcs, spcs)
.build();

CodeGenProvider provider = data.provider;
return provider.shouldRun(data.sourceDir, config)
&& provider.trigger(
Expand All @@ -169,6 +171,47 @@ public static boolean trigger(ClassLoader deploymentClassLoader,
});
}

public static Config getConfig(ApplicationModel appModel, LaunchMode launchMode, Properties buildSystemProps,
QuarkusClassLoader deploymentClassLoader) throws CodeGenException {
// Config instance that is returned by this method should be as close to the one built in the ExtensionLoader as possible
if (appModel.getAppArtifact().getContentTree()
.contains(MP_CONFIG_SPI_CONFIG_SOURCE_PROVIDER)) {
final List<ClassPathElement> allElements = ((QuarkusClassLoader) deploymentClassLoader).getAllElements(false);
// we don't want to load config sources from the current module because they haven't been compiled yet
final QuarkusClassLoader.Builder configClBuilder = QuarkusClassLoader
.builder("CodeGenerator Config ClassLoader", QuarkusClassLoader.getSystemClassLoader(), false);
final Collection<Path> appRoots = appModel.getAppArtifact().getContentTree().getRoots();
for (ClassPathElement e : allElements) {
if (appRoots.contains(e.getRoot())) {
configClBuilder.addElement(new FilteredClassPathElement(e, List.of(MP_CONFIG_SPI_CONFIG_SOURCE_PROVIDER)));
} else {
configClBuilder.addElement(e);
}
}
deploymentClassLoader = configClBuilder.build();
}
final SmallRyeConfigBuilder builder = ConfigUtils.configBuilder(false, launchMode)
.forClassLoader(deploymentClassLoader);
final PropertiesConfigSource pcs = new PropertiesConfigSource(buildSystemProps, "Build system");
final SysPropConfigSource spcs = new SysPropConfigSource();

final Map<String, String> platformProperties = appModel.getPlatformProperties();
if (platformProperties.isEmpty()) {
builder.withSources(pcs, spcs);
} else {
final KeyMap<String> props = new KeyMap<>(platformProperties.size());
for (Map.Entry<String, String> prop : platformProperties.entrySet()) {
props.findOrAdd(new NameIterator(prop.getKey())).putRootValue(prop.getValue());
}
final KeyMapBackedConfigSource platformConfigSource = new KeyMapBackedConfigSource("Quarkus platform",
// Our default value configuration source is using an ordinal of Integer.MIN_VALUE
// (see io.quarkus.deployment.configuration.DefaultValuesConfigurationSource)
Integer.MIN_VALUE + 1000, props);
builder.withSources(platformConfigSource, pcs, spcs);
}
return builder.build();
}

private static Path codeGenOutDir(Path generatedSourcesDir,
CodeGenProvider provider,
Consumer<Path> sourceRegistrar) throws CodeGenException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Properties;

import org.eclipse.microprofile.config.Config;
import org.jboss.logging.Logger;

import io.quarkus.bootstrap.app.CuratedApplication;
Expand Down Expand Up @@ -33,13 +34,15 @@ class CodeGenWatcher {
final Collection<FSWatchUtil.Watcher> watchers = new ArrayList<>(codeGens.size());
final Properties properties = new Properties();
properties.putAll(context.getBuildSystemProperties());
final Config config = CodeGenerator.getConfig(curatedApplication.getApplicationModel(), LaunchMode.DEVELOPMENT,
properties, deploymentClassLoader);
for (CodeGenData codeGen : codeGens) {
watchers.add(new FSWatchUtil.Watcher(codeGen.sourceDir, codeGen.provider.inputExtension(),
modifiedPaths -> {
try {
CodeGenerator.trigger(deploymentClassLoader,
codeGen,
curatedApplication.getApplicationModel(), properties, LaunchMode.DEVELOPMENT, false);
curatedApplication.getApplicationModel(), config, false);
} catch (Exception any) {
log.warn("Code generation failed", any);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ public List<String> args() {
return args;
}

public Boolean getDebugPortOk() {
return debugPortOk;
}

protected abstract boolean isDebugEnabled();

protected void debug(Object msg, Object... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public static boolean isSubclassOf(IndexView index, ClassInfo info, DotName pare
return isSubclassOf(index, superClass, parentName);
}

@Deprecated(forRemoval = true, since = "2.13.3.Final")
@SuppressWarnings("incomplete-switch")
public static String getBoxedTypeName(Type type) {
switch (type.kind()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.function.Consumer;
Expand All @@ -29,6 +27,7 @@
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.deployment.CodeGenerator;
import io.quarkus.paths.PathCollection;
import io.quarkus.paths.PathList;
import io.quarkus.runtime.LaunchMode;

Expand Down Expand Up @@ -125,14 +124,17 @@ public void prepareQuarkus() {
QuarkusClassLoader deploymentClassLoader = appCreationContext.createDeploymentClassLoader();
Class<?> codeGenerator = deploymentClassLoader.loadClass(CodeGenerator.class.getName());

Optional<Method> initAndRun = Arrays.stream(codeGenerator.getMethods())
.filter(m -> m.getName().equals(INIT_AND_RUN))
.findAny();
if (initAndRun.isEmpty()) {
throw new GradleException("Failed to find " + INIT_AND_RUN + " method in " + CodeGenerator.class.getName());
Method initAndRun;
try {
initAndRun = codeGenerator.getMethod(INIT_AND_RUN, QuarkusClassLoader.class, PathCollection.class,
Path.class, Path.class,
Consumer.class, ApplicationModel.class, Properties.class, String.class,
boolean.class);
} catch (Exception e) {
throw new GradleException("Quarkus code generation phase has failed", e);
}

initAndRun.get().invoke(null, deploymentClassLoader,
initAndRun.invoke(null, deploymentClassLoader,
PathList.from(sourcesDirectories),
paths.get(0),
buildDir,
Expand Down
20 changes: 9 additions & 11 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.BuildBase;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.Profile;
Expand Down Expand Up @@ -121,8 +120,6 @@
@Mojo(name = "dev", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
public class DevMojo extends AbstractMojo {

private static final String EXT_PROPERTIES_PATH = "META-INF/quarkus-extension.properties";

private static final String KOTLIN_MAVEN_PLUGIN_GA = "org.jetbrains.kotlin:kotlin-maven-plugin";

/**
Expand Down Expand Up @@ -441,7 +438,7 @@ public void execute() throws MojoFailureException, MojoExecutionException {
try {
triggerCompile(false, false);
triggerCompile(true, false);
newRunner = new DevModeRunner();
newRunner = new DevModeRunner(runner.launcher.getDebugPortOk());
} catch (Exception e) {
getLog().info("Could not load changed pom.xml file, changes not applied", e);
continue;
Expand Down Expand Up @@ -892,7 +889,11 @@ private class DevModeRunner {
private Process process;

private DevModeRunner() throws Exception {
launcher = newLauncher();
launcher = newLauncher(null);
}

private DevModeRunner(Boolean debugPortOk) throws Exception {
launcher = newLauncher(debugPortOk);
}

Collection<Path> pomFiles() {
Expand Down Expand Up @@ -946,7 +947,7 @@ void stop() throws InterruptedException {
}
}

private QuarkusDevModeLauncher newLauncher() throws Exception {
private QuarkusDevModeLauncher newLauncher(Boolean debugPortOk) throws Exception {
String java = null;
// See if a toolchain is configured
if (toolchainManager != null) {
Expand All @@ -965,6 +966,7 @@ private QuarkusDevModeLauncher newLauncher() throws Exception {
.debug(debug)
.debugHost(debugHost)
.debugPort(debugPort)
.debugPortOk(debugPortOk)
.deleteDevJar(deleteDevJar);

setJvmArgs(builder);
Expand Down Expand Up @@ -1081,11 +1083,7 @@ private QuarkusDevModeLauncher newLauncher() throws Exception {
mvnConfig.setRepositorySystemSession(repoSession).setRepositorySystem(repoSystem);
// there could be Maven extensions manipulating the project versions and models
// the ones returned from the Maven API could be different from the original pom.xml files
final Map<Path, Model> projectModels = new HashMap<>(session.getAllProjects().size());
for (MavenProject mp : session.getAllProjects()) {
projectModels.put(mp.getBasedir().toPath(), mp.getOriginalModel());
}
mvnConfig.setProjectModelProvider(projectModels::get);
mvnConfig.setProjectModelProvider(QuarkusBootstrapProvider.getProjectMap(session)::get);
}

final BootstrapMavenContext mvnCtx = new BootstrapMavenContext(mvnConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void generateCode(PathCollection sourceParents,
Thread.currentThread().setContextClassLoader(deploymentClassLoader);

final Class<?> codeGenerator = deploymentClassLoader.loadClass("io.quarkus.deployment.CodeGenerator");
final Method initAndRun = codeGenerator.getMethod("initAndRun", ClassLoader.class, PathCollection.class,
final Method initAndRun = codeGenerator.getMethod("initAndRun", QuarkusClassLoader.class, PathCollection.class,
Path.class, Path.class,
Consumer.class, ApplicationModel.class, Properties.class, String.class,
boolean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private void resolveAppModel(final MavenArtifactResolver resolver, final Artifac
private MavenArtifactResolver getResolver() throws MojoExecutionException {
try {
return MavenArtifactResolver.builder()
.setCurrentProject(project.getBasedir().toString())
.setRemoteRepositoryManager(remoteRepositoryManager)
.setRemoteRepositories(repos)
.setPreferPomsFromWorkspace(true)
Expand Down
Loading

0 comments on commit 73c77d0

Please sign in to comment.