Skip to content

Commit

Permalink
Merge pull request #24043 from gsmet/2.7.3-backports-2
Browse files Browse the repository at this point in the history
2.7.3 backports 2
  • Loading branch information
gsmet committed Mar 2, 2022
2 parents 33a8552 + 2349a0c commit 99d643d
Show file tree
Hide file tree
Showing 36 changed files with 607 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;

import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
Expand All @@ -21,6 +22,7 @@
import org.eclipse.aether.repository.RemoteRepository;

import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.maven.components.BootstrapSessionListener;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.Dependency;
import io.quarkus.runtime.LaunchMode;
Expand All @@ -30,6 +32,9 @@ public abstract class QuarkusBootstrapMojo extends AbstractMojo {
@Component
protected QuarkusBootstrapProvider bootstrapProvider;

@Component(hint = "quarkus-bootstrap", role = AbstractMavenLifecycleParticipant.class)
private BootstrapSessionListener bootstrapSessionListener;

/**
* The current repository/network configuration of Maven.
*
Expand Down Expand Up @@ -122,7 +127,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (!beforeExecute()) {
return;
}
doExecute();
try {
doExecute();
} finally {
if (!bootstrapSessionListener.isEnabled()) {
bootstrapProvider.bootstrapper(this).close();
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class QuarkusBootstrapProvider implements Closeable {
@Requirement(role = RemoteRepositoryManager.class, optional = false)
protected RemoteRepositoryManager remoteRepoManager;

private final Cache<String, QuarkusAppBootstrapProvider> appBootstrapProviders = CacheBuilder.newBuilder()
private final Cache<String, QuarkusMavenAppBootstrap> appBootstrapProviders = CacheBuilder.newBuilder()
.concurrencyLevel(4).softValues().initialCapacity(10).build();

static ArtifactKey getProjectId(MavenProject project) {
Expand All @@ -64,25 +64,26 @@ public RemoteRepositoryManager remoteRepositoryManager() {
return remoteRepoManager;
}

private QuarkusAppBootstrapProvider provider(ArtifactKey projectId, String executionId) {
public QuarkusMavenAppBootstrap bootstrapper(QuarkusBootstrapMojo mojo) {
try {
return appBootstrapProviders.get(String.format("%s-%s", projectId, executionId), QuarkusAppBootstrapProvider::new);
return appBootstrapProviders.get(String.format("%s-%s", mojo.projectId(), mojo.executionId()),
QuarkusMavenAppBootstrap::new);
} catch (ExecutionException e) {
throw new IllegalStateException("Failed to cache a new instance of " + QuarkusAppBootstrapProvider.class.getName(),
throw new IllegalStateException("Failed to cache a new instance of " + QuarkusMavenAppBootstrap.class.getName(),
e);
}
}

public CuratedApplication bootstrapApplication(QuarkusBootstrapMojo mojo, LaunchMode mode)
throws MojoExecutionException {
return provider(mojo.projectId(), mojo.executionId()).bootstrapApplication(mojo, mode);
return bootstrapper(mojo).bootstrapApplication(mojo, mode);
}

public ApplicationModel getResolvedApplicationModel(ArtifactKey projectId, LaunchMode mode) {
if (appBootstrapProviders.size() == 0) {
return null;
}
final QuarkusAppBootstrapProvider provider = appBootstrapProviders.getIfPresent(projectId + "-null");
final QuarkusMavenAppBootstrap provider = appBootstrapProviders.getIfPresent(projectId + "-null");
if (provider == null) {
return null;
}
Expand All @@ -100,7 +101,7 @@ public void close() throws IOException {
if (appBootstrapProviders.size() == 0) {
return;
}
for (QuarkusAppBootstrapProvider p : appBootstrapProviders.asMap().values()) {
for (QuarkusMavenAppBootstrap p : appBootstrapProviders.asMap().values()) {
try {
p.close();
} catch (Exception e) {
Expand All @@ -109,7 +110,7 @@ public void close() throws IOException {
}
}

private class QuarkusAppBootstrapProvider implements Closeable {
public class QuarkusMavenAppBootstrap implements Closeable {

private CuratedApplication prodApp;
private CuratedApplication devApp;
Expand All @@ -132,7 +133,7 @@ private MavenArtifactResolver artifactResolver(QuarkusBootstrapMojo mojo, Launch
}
}

protected CuratedApplication doBootstrap(QuarkusBootstrapMojo mojo, LaunchMode mode)
private CuratedApplication doBootstrap(QuarkusBootstrapMojo mojo, LaunchMode mode)
throws MojoExecutionException {
final Properties projectProperties = mojo.mavenProject().getProperties();
final Properties effectiveProperties = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class BootstrapSessionListener extends AbstractMavenLifecycleParticipant
@Requirement(optional = false)
protected QuarkusBootstrapProvider bootstrapProvider;

private boolean enabled;

@Override
public void afterSessionEnd(MavenSession session) throws MavenExecutionException {
try {
Expand All @@ -24,4 +26,15 @@ public void afterSessionEnd(MavenSession session) throws MavenExecutionException
e.printStackTrace();
}
}

@Override
public void afterProjectsRead(MavenSession session)
throws MavenExecutionException {
// if this method is called then Maven plugin extensions are enabled
enabled = true;
}

public boolean isEnabled() {
return enabled;
}
}
25 changes: 24 additions & 1 deletion docs/src/main/asciidoc/deploying-to-kubernetes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,12 @@ The generated service can be customized using the following properties:
| quarkus.knative.readiness-probe | Probe | | ( see Probe )
| quarkus.knative.sidecars | Map<String, Container> | |
| quarkus.knative.revision-name | String | |
| quarkus.knative.traffic | Traffic[] | | ( see Traffic)
| quarkus.knative.traffic | Traffic[] | | ( see Traffic )
| quarkus.knative.min-scale | int | See link:https://knative.dev/docs/serving/autoscaling/scale-bounds/#lower-bound[link] |
| quarkus.knative.max-scale | int | See link:https://knative.dev/docs/serving/autoscaling/scale-bounds/#upper-bound[link] |
| quarkus.knative.scale-to-zero-enabled | boolean | See link:https://knative.dev/docs/serving/autoscaling/scale-to-zero/#enable-scale-to-zero[link] | true
| quarkus.knative.revision-auto-scaling | AutoScalingConfig | | ( see AutoScalingConfig )
| quarkus.knative.global-auto-scaling | GlobalAutoScalingConfig | | ( see GlobalAutoScalingConfig )
|====

.Traffic
Expand All @@ -1103,6 +1108,24 @@ The generated service can be customized using the following properties:
| percent | Logn | Indicates the percent of traffic that is be routed to this revision | 100
|====

.AutoScalingConfig
|====
| Property | Type | Description | Default Value
| auto-scaler-class | String | The auto-scaler class. Possible values: `kpa` for Knative Pod Autoscaler, `hpa` for Horizontal Pod Autoscaler | kpa
| metric | String | The autoscaling metric to use. Possible values (concurency, rps, cpu) |
| target | int | This value specifies the autoscaling target |
| container-concurrency | int | The exact amount of requests allowed to the replica at a time |
| target-utilization-percentage | int | This value specifies a percentage of the target to actually be targeted by the autoscaler |
|====

.GlobalAutoScalingConfig
|====
| Property | Type | Description | Default Value
| auto-scaler-class | String | The auto-scaler class. Possible values: `kpa` for Knative Pod Autoscaler, `hpa` for Horizontal Pod Autoscaler | kpa
| container-concurrency | int | The exact amount of requests allowed to the replica at a time |
| target-utilization-percentage | int | This value specifies a percentage of the target to actually be targeted by the autoscaler |
| requests-per-second | Logn | The requests per second per replica |
|====

=== Deployment targets

Expand Down
10 changes: 5 additions & 5 deletions docs/src/main/asciidoc/gradle-tooling.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,13 @@ Configuring the `quarkusBuild` task can be done as following:
quarkusBuild {
nativeArgs {
containerBuild = true <1>
buildImage = "quay.io/quarkus/ubi-quarkus-native-image:{graalvm-flavor}" <2>
builderImage = "quay.io/quarkus/ubi-quarkus-native-image:{graalvm-flavor}" <2>
}
}
----
<1> Set `quarkus.native.container-build` property to `true`
<2> Set `quarkus.native.build-image` property to `quay.io/quarkus/ubi-quarkus-native-image:{graalvm-flavor}`
<2> Set `quarkus.native.builder-image` property to `quay.io/quarkus/ubi-quarkus-native-image:{graalvm-flavor}`
****

[role="secondary asciidoc-tabs-sync-kotlin"]
Expand All @@ -420,13 +420,13 @@ quarkusBuild {
tasks.quarkusBuild {
nativeArgs {
"container-build" to true <1>
"build-image" to "quay.io/quarkus/ubi-quarkus-native-image:{graalvm-flavor}" <2>
"builder-image" to "quay.io/quarkus/ubi-quarkus-native-image:{graalvm-flavor}" <2>
}
}
----
<1> Set `quarkus.native.container-build` property to `true`
<2> Set `quarkus.native.build-image` property to `quay.io/quarkus/ubi-quarkus-native-image:{graalvm-flavor}`
<2> Set `quarkus.native.builder-image` property to `quay.io/quarkus/ubi-quarkus-native-image:{graalvm-flavor}`
****

[WARNING]
Expand Down Expand Up @@ -570,4 +570,4 @@ tasks.withType<GenerateModuleMetadata>().configureEach {
suppressedValidationErrors.add("enforced-platform")
}
----
****
****
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.grpc.runtime.supports.context;

import static io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle.setContextSafe;

import java.util.function.Supplier;

import javax.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -39,6 +41,7 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, Re
if (capturedVertxContext != null) {
// If we are not on a duplicated context, create and switch.
Context local = VertxContext.getOrCreateDuplicatedContext(capturedVertxContext);
setContextSafe(local, true);

// Must be sure to call next.startCall on the right context
return new ListenedOnDuplicatedContext<>(() -> next.startCall(call, headers), local);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ private static void injectRuntimeConfiguration(String persistenceUnitName,
runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_HALT_ON_ERROR, "true");
}

//Never append on existing scripts:
runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_SCRIPTS_CREATE_APPEND, "false");

runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_SCRIPTS_ACTION,
persistenceUnitConfig.scripts.generation.generation);

if (persistenceUnitConfig.scripts.generation.createTarget.isPresent()) {
runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_SCRIPTS_CREATE_TARGET,
persistenceUnitConfig.scripts.generation.createTarget.get());
}

if (persistenceUnitConfig.scripts.generation.dropTarget.isPresent()) {
runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_SCRIPTS_DROP_TARGET,
persistenceUnitConfig.scripts.generation.dropTarget.get());
}

persistenceUnitConfig.database.defaultCatalog.ifPresent(
catalog -> runtimeSettingsBuilder.put(AvailableSettings.DEFAULT_CATALOG, catalog));

Expand All @@ -295,6 +311,11 @@ private static void injectRuntimeConfiguration(String persistenceUnitName,
runtimeSettingsBuilder.put(AvailableSettings.LOG_JDBC_WARNINGS,
persistenceUnitConfig.log.jdbcWarnings.get().toString());
}

if (persistenceUnitConfig.log.queriesSlowerThanMs.isPresent()) {
runtimeSettingsBuilder.put(AvailableSettings.LOG_SLOW_QUERY,
persistenceUnitConfig.log.queriesSlowerThanMs.get());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.quarkus.hibernate.validator.test;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.Set;

import javax.inject.Inject;
import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.ConstraintViolation;
import javax.validation.Payload;
import javax.validation.Validator;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

public class ConstraintExpressionLanguageFeatureLevelTest {

@RegisterExtension
static final QuarkusUnitTest test = new QuarkusUnitTest().setArchiveProducer(() -> ShrinkWrap
.create(JavaArchive.class)
.addClasses(BeanMethodsConstraint.class, BeanMethodsConstraintStringValidator.class, BeanMethodsBean.class)
.add(new StringAsset(
"quarkus.hibernate-validator.expression-language.constraint-expression-feature-level=bean-methods"),
"application.properties"));

@Inject
Validator validator;

@Test
public void testConstraintExpressionFeatureLevel() {
Set<ConstraintViolation<BeanMethodsBean>> violations = validator.validate(new BeanMethodsBean());
assertEquals("Method execution: a", violations.iterator().next().getMessage());
}

@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = { BeanMethodsConstraintStringValidator.class })
private @interface BeanMethodsConstraint {
String message() default "Method execution: ${'aaaa'.substring(0, 1)}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}

public static class BeanMethodsConstraintStringValidator implements ConstraintValidator<BeanMethodsConstraint, String> {

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
return false;
}
}

public static class BeanMethodsBean {

@BeanMethodsConstraint
public String value;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.quarkus.hibernate.validator.runtime;

import java.util.Optional;

import org.hibernate.validator.messageinterpolation.ExpressionLanguageFeatureLevel;

import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
Expand All @@ -22,6 +26,12 @@ public class HibernateValidatorBuildTimeConfig {
@ConfigDocSection
public HibernateValidatorMethodBuildTimeConfig methodValidation;

/**
* Expression Language.
*/
@ConfigDocSection
public HibernateValidatorExpressionLanguageBuildTimeConfig expressionLanguage;

@ConfigGroup
public static class HibernateValidatorMethodBuildTimeConfig {

Expand Down Expand Up @@ -72,4 +82,22 @@ public static class HibernateValidatorMethodBuildTimeConfig {
@ConfigItem(defaultValue = "false")
public boolean allowMultipleCascadedValidationOnReturnValues;
}

@ConfigGroup
public static class HibernateValidatorExpressionLanguageBuildTimeConfig {

/**
* Configure the Expression Language feature level for constraints, allowing the selection of
* Expression Language features available for message interpolation.
* <p>
* This property only affects the EL feature level of "static" constraint violation messages set through the
* <code>message</code> attribute of constraint annotations.
* <p>
* In particular, it doesn't affect the default EL feature level for custom violations
* created programmatically in validator implementations.
* The feature level for those can only be configured directly in the validator implementation.
*/
@ConfigItem(defaultValueDocumentation = "bean-properties")
public Optional<ExpressionLanguageFeatureLevel> constraintExpressionFeatureLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public void created(BeanContainer container) {
.defaultLocale(localesBuildTimeConfig.defaultLocale)
.beanMetaDataClassNormalizer(new ArcProxyBeanMetaDataClassNormalizer());

if (hibernateValidatorBuildTimeConfig.expressionLanguage.constraintExpressionFeatureLevel.isPresent()) {
configuration.constraintExpressionLanguageFeatureLevel(
hibernateValidatorBuildTimeConfig.expressionLanguage.constraintExpressionFeatureLevel.get());
}

InstanceHandle<ConstraintValidatorFactory> configuredConstraintValidatorFactory = Arc.container()
.instance(ConstraintValidatorFactory.class);
if (configuredConstraintValidatorFactory.isAvailable()) {
Expand Down

0 comments on commit 99d643d

Please sign in to comment.