Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle plugin: optionally respect non-quarkus.* cache-relevant properties #35003

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RegularFile;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
Expand Down Expand Up @@ -254,6 +255,10 @@ public MapProperty<String, String> getQuarkusBuildProperties() {
return quarkusBuildProperties;
}

public ListProperty<String> getCachingRelevantProperties() {
return cachingRelevantProperties;
}

public void set(String name, @Nullable String value) {
quarkusBuildProperties.put(String.format("quarkus.%s", name), value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class AbstractQuarkusExtension {
protected final Property<String> finalName;
private final MapProperty<String, String> forcedPropertiesProperty;
protected final MapProperty<String, String> quarkusBuildProperties;
protected final ListProperty<String> cachingRelevantProperties;
private final ListProperty<String> ignoredEntries;
private final FileCollection classpath;
private final Property<BaseConfig> baseConfig;
Expand All @@ -52,6 +53,7 @@ protected AbstractQuarkusExtension(Project project) {
this.finalName.convention(project.provider(() -> String.format("%s-%s", project.getName(), project.getVersion())));
this.forcedPropertiesProperty = project.getObjects().mapProperty(String.class, String.class);
this.quarkusBuildProperties = project.getObjects().mapProperty(String.class, String.class);
this.cachingRelevantProperties = project.getObjects().listProperty(String.class).value(List.of("quarkus[.].*"));
this.ignoredEntries = project.getObjects().listProperty(String.class);
this.ignoredEntries.convention(
project.provider(() -> baseConfig().packageConfig().userConfiguredIgnoredEntries.orElse(emptyList())));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.quarkus.gradle.tasks;

import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import io.quarkus.deployment.pkg.PackageConfig;
Expand All @@ -18,7 +21,7 @@
final class BaseConfig {
private final Manifest manifest;
private final PackageConfig packageConfig;
private final Map<String, String> quarkusProperties;
private final Map<String, String> configMap;

// Note: EffectiveConfig has all the code to load the configurations from all the sources.
BaseConfig(EffectiveConfig config) {
Expand All @@ -31,8 +34,7 @@ final class BaseConfig {
manifest.attributes(packageConfig.manifest.attributes);
packageConfig.manifest.manifestSections.forEach((section, attribs) -> manifest.attributes(attribs, section));

this.quarkusProperties = config.configMap().entrySet().stream().filter(e -> e.getKey().startsWith("quarkus."))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
configMap = config.configMap();
}

PackageConfig packageConfig() {
Expand All @@ -47,7 +49,12 @@ Manifest manifest() {
return manifest;
}

Map<String, String> quarkusProperties() {
return quarkusProperties;
Map<String, String> cachingRelevantProperties(List<String> propertyPatterns) {
List<Pattern> patterns = propertyPatterns.stream().map(s -> "^(" + s + ")$").map(Pattern::compile)
.collect(Collectors.toList());
Predicate<Map.Entry<String, ?>> keyPredicate = e -> patterns.stream().anyMatch(p -> p.matcher(e.getKey()).matches());
return configMap.entrySet().stream()
.filter(keyPredicate)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ static Map<String, String> generateFullConfigMap(SmallRyeConfig config) {
static SmallRyeConfig buildConfig(String profile, List<ConfigSource> configSources) {
return ConfigUtils.emptyConfigBuilder()
.setAddDiscoveredSecretKeysHandlers(false)
// We add our own sources for environment, system-properties and microprofile-config.properties,
// no need to include those twice.
.setAddDefaultSources(false)
.withSources(configSources)
.withProfile(profile)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.gradle.api.file.FileCopyDetails;
import org.gradle.api.file.FileSystemOperations;
import org.gradle.api.logging.LogLevel;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.StopExecutionException;
Expand Down Expand Up @@ -57,7 +58,8 @@ public FileCollection getClasspath() {

@Input
public Map<String, String> getCachingRelevantInput() {
return extension().baseConfig().quarkusProperties();
ListProperty<String> vars = extension().getCachingRelevantProperties();
return extension().baseConfig().cachingRelevantProperties(vars.get());
}

PackageConfig.BuiltInType packageType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.CompileClasspath;
import org.gradle.api.tasks.Input;
Expand Down Expand Up @@ -65,7 +66,17 @@ public void setCompileClasspath(Configuration compileClasspath) {

@Input
public Map<String, String> getCachingRelevantInput() {
return extension().baseConfig().quarkusProperties();
ListProperty<String> vars = extension().getCachingRelevantProperties();
return extension().baseConfig().cachingRelevantProperties(vars.get());
}

@Input
Map<String, String> getInternalTaskConfig() {
// Necessary to distinguish the different `quarkusGenerateCode*` tasks, because the task path is _not_
// an input to the cache key. We need to declare these properties as inputs, because those influence the
// execution.
// Documented here: https://docs.gradle.org/current/userguide/build_cache.html#sec:task_output_caching_inputs
return Map.of("launchMode", launchMode.name(), "inputSourceSetName", inputSourceSetName);
}

@InputFiles
Expand Down
Loading