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

Move the last pieces of cache infrastructure to the extension #7

Merged
merged 4 commits into from
Feb 25, 2024
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
16 changes: 16 additions & 0 deletions src/main/java/io/quarkus/develocity/project/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ public static void error(String message) {
LOGGER.error(message);
}

public static void error(String message, Throwable e) {
LOGGER.error(message, e);
}

public static void warn(String message) {
LOGGER.warn(message);
}

public static void warn(String message, Throwable e) {
LOGGER.warn(message, e);
}

public static void info(String message) {
LOGGER.info(message);
}
Expand All @@ -39,10 +47,18 @@ public static void error(String pluginName, String message) {
LOGGER.error("[" + pluginName + "] " + message);
}

public static void error(String pluginName, String message, Throwable e) {
LOGGER.error("[" + pluginName + "] " + message, e);
}

public static void warn(String pluginName, String message) {
LOGGER.warn("[" + pluginName + "] " + message);
}

public static void warn(String pluginName, String message, Throwable e) {
LOGGER.warn("[" + pluginName + "] " + message, e);
}

public static void info(String pluginName, String message) {
LOGGER.info("[" + pluginName + "] " + message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkus.develocity.project;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

Expand All @@ -9,18 +12,21 @@
import com.gradle.maven.extension.api.GradleEnterpriseApi;
import com.gradle.maven.extension.api.GradleEnterpriseListener;
import com.gradle.maven.extension.api.cache.BuildCacheApi;

import io.quarkus.develocity.project.goals.CompilerConfiguredPlugin;
import io.quarkus.develocity.project.goals.EnforcerConfiguredPlugin;
import io.quarkus.develocity.project.goals.FailsafeConfiguredPlugin;
import io.quarkus.develocity.project.goals.FormatterConfiguredPlugin;
import io.quarkus.develocity.project.goals.ImpsortConfiguredPlugin;
import io.quarkus.develocity.project.goals.KotlinConfiguredPlugin;
import io.quarkus.develocity.project.goals.QuarkusConfiguredPlugin;
import io.quarkus.develocity.project.goals.SourceConfiguredPlugin;
import io.quarkus.develocity.project.goals.SpotlessConfiguredPlugin;
import io.quarkus.develocity.project.goals.SurefireConfiguredPlugin;
import io.quarkus.develocity.project.util.Matchers;
import com.gradle.maven.scan.extension.internal.api.BuildScanApiInternal;

import io.quarkus.develocity.project.normalization.Normalization;
import io.quarkus.develocity.project.plugins.CompilerConfiguredPlugin;
import io.quarkus.develocity.project.plugins.EnforcerConfiguredPlugin;
import io.quarkus.develocity.project.plugins.FailsafeConfiguredPlugin;
import io.quarkus.develocity.project.plugins.FormatterConfiguredPlugin;
import io.quarkus.develocity.project.plugins.ImpsortConfiguredPlugin;
import io.quarkus.develocity.project.plugins.KotlinConfiguredPlugin;
import io.quarkus.develocity.project.plugins.QuarkusConfiguredPlugin;
import io.quarkus.develocity.project.plugins.SourceConfiguredPlugin;
import io.quarkus.develocity.project.plugins.SpotlessConfiguredPlugin;
import io.quarkus.develocity.project.plugins.SurefireConfiguredPlugin;
import io.quarkus.develocity.project.scan.BuildScanMetadata;
import io.quarkus.develocity.project.scan.MavenVersionChecker;

@SuppressWarnings("deprecation")
@Component(role = GradleEnterpriseListener.class, hint = "quarkus-project-build-cache", description = "Configures the build cache of the Quarkus project")
Expand All @@ -29,60 +35,48 @@ public class QuarkusProjectBuildCacheGradleEnterpriseListener implements GradleE
private static final String QUICKLY = "-Dquickly";
private static final String DASH = "-";

private static final List<String> NESTED_PROJECTS_PATHS = List.of(
File.separator + "target" + File.separator + "codestart-test" + File.separator,
File.separator + "target" + File.separator + "it" + File.separator,
File.separator + "target" + File.separator + "test-classes" + File.separator,
File.separator + "target" + File.separator + "test-project" + File.separator);

@Override
public void configure(GradleEnterpriseApi gradleEnterpriseApi, MavenSession mavenSession) throws Exception {
if (ignoreProject(mavenSession)) {
// do not publish a build scan for test builds
Log.debug("Disabling build scan publication and build cache for nested project: "
+ mavenSession.getRequest().getBaseDirectory());

gradleEnterpriseApi.getBuildScan().publishAlwaysIf(false);
gradleEnterpriseApi.getBuildScan().publishOnFailureIf(false);
gradleEnterpriseApi.getBuildCache().getLocal().setEnabled(false);
gradleEnterpriseApi.getBuildCache().getLocal().setStoreEnabled(false);
gradleEnterpriseApi.getBuildCache().getRemote().setEnabled(false);
gradleEnterpriseApi.getBuildCache().getRemote().setStoreEnabled(false);

if (System.getenv("GITHUB_ACTIONS") != null) {
try {
Path storageLocationTmpDir = Files.createTempDirectory(Path.of(System.getenv("RUNNER_TEMP")),
"buildScanTmp");
Log.debug("Update storage location to " + storageLocationTmpDir);
gradleEnterpriseApi.setStorageDirectory(storageLocationTmpDir);
} catch (IOException e) {
Log.error("Temporary storage location directory cannot be created, the Build Scan will be published", e);
}
}

return;
}

gradleEnterpriseApi.getBuildScan().publishAlways();
((BuildScanApiInternal) gradleEnterpriseApi.getBuildScan()).publishIfAuthenticated();
BuildScanMetadata.addMetadataToBuildScan(gradleEnterpriseApi.getBuildScan());
MavenVersionChecker.checkRuntimeMavenVersion(gradleEnterpriseApi.getBuildScan(), mavenSession);

workaroundQuickly(gradleEnterpriseApi.getBuildCache());

// System properties
gradleEnterpriseApi.getBuildCache().registerNormalizationProvider(
context -> context.configureSystemPropertiesNormalization(s -> {
s.addIgnoredKeys("maven.repo.local", "maven.settings");

if (Matchers.directory(context, Path.of("docs"))) {
s.addIgnoredKeys("vale.dir", "git.dir");
}

if (Matchers.directory(context, Path.of("independent-projects", "arc", "tcks", "cdi-tck-runner"))) {
s.addIgnoredKeys("org.jboss.cdi.tck.libraryDirectory");
}

if (Matchers.directory(context, Path.of("integration-tests"))) {
s.addIgnoredKeys("native.image.path", "quarkus.kubernetes-service-binding.root");
}

if (Matchers.module(context, "quarkus-integration-test-rest-client")) {
s.addIgnoredKeys("javax.net.ssl.trustStore", "rest-client.trustStore");
}

if (Matchers.module(context, "quarkus-integration-test-test-extension")) {
s.addIgnoredKeys("classpathEntriesRecordingFile");
}
}));

// Application.properties
gradleEnterpriseApi.getBuildCache().registerNormalizationProvider(
context -> context.configureRuntimeClasspathNormalization(c -> {
c.addIgnoredFiles("META-INF/ide-deps/**");

if (Matchers.module(context, "quarkus-integration-test-rest-client-reactive")) {
c.addPropertiesNormalization("application.properties", "quarkus.rest-client.self-signed.trust-store",
"quarkus.rest-client.wrong-host.trust-store",
"quarkus.rest-client.wrong-host-rejected.trust-store");
}

if (Matchers.module(context, "quarkus-integration-test-oidc-client-reactive")) {
c.addPropertiesNormalization("application.properties", "quarkus.keycloak.devservices.realm-path");
}

if (Matchers.module(context, "quarkus-integration-test-test-extension")) {
c.addPropertiesNormalization("application.properties", "quarkus.bt.classpath-recording.record-file",
"%test.quarkus.bt.classpath-recording.record-file");
}

if (Matchers.module(context, "quarkus-integration-test-gradle-plugin")) {
c.addIgnoredFiles(".quarkus/config.yml");
}
}));
Normalization.configureNormalization(gradleEnterpriseApi.getBuildCache());

List<ConfiguredPlugin> configuredGoals = List.of(
new CompilerConfiguredPlugin(),
Expand Down Expand Up @@ -145,4 +139,18 @@ private static void workaroundQuickly(BuildCacheApi buildCacheApi) {
buildCacheApi.setRequireClean(false);
}
}

private static boolean ignoreProject(MavenSession mavenSession) {
if (mavenSession == null || mavenSession.getRequest() == null || mavenSession.getRequest().getBaseDirectory() == null) {
return false;
}

for (String nestedProjectsPath : NESTED_PROJECTS_PATHS) {
if (mavenSession.getRequest().getBaseDirectory().contains(nestedProjectsPath)) {
return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ public abstract class SimpleQuarkusConfiguredPlugin implements ConfiguredPlugin

@Override
public void configureBuildCache(GradleEnterpriseApi gradleEnterpriseApi, MavenSession mavenSession) {
NormalizationProvider normalizationProvider = getNormalizationProvider();

if (normalizationProvider != null) {
gradleEnterpriseApi.getBuildCache().registerNormalizationProvider(context -> {
if (!isBuildCacheEnabled(context.getProject())) {
Log.debug(getPluginName(), "Build cache is disabled.");
return;
} else {
Log.debug(getPluginName(), "Build cache is enabled. Configuring normalization provider.");
}
normalizationProvider.configureNormalization(context);
});
}
gradleEnterpriseApi.getBuildCache().registerMojoMetadataProvider(context -> {
context.withPlugin(getPluginName(), () -> {
if (!isBuildCacheEnabled(context.getProject())) {
Expand Down Expand Up @@ -58,10 +45,6 @@ protected boolean isBuildCacheEnabled(MavenProject project) {
return true;
}

protected NormalizationProvider getNormalizationProvider() {
return null;
}

protected abstract Map<String, GoalMetadataProvider> getGoalMetadataProviders();

protected static void dependsOnGav(MojoMetadataProvider.Context.Inputs inputs, MojoMetadataProvider.Context context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.quarkus.develocity.project.normalization;

import java.nio.file.Path;

import com.gradle.maven.extension.api.cache.BuildCacheApi;

import io.quarkus.develocity.project.util.Matchers;

public final class Normalization {

private Normalization() {
}

public static void configureNormalization(BuildCacheApi buildCacheApi) {
// System properties
buildCacheApi.registerNormalizationProvider(
context -> context.configureSystemPropertiesNormalization(s -> {
s.addIgnoredKeys("maven.repo.local", "maven.settings");

if (Matchers.directory(context, Path.of("docs"))) {
s.addIgnoredKeys("vale.dir", "git.dir");
}

if (Matchers.directory(context, Path.of("independent-projects", "arc", "tcks", "cdi-tck-runner"))) {
s.addIgnoredKeys("org.jboss.cdi.tck.libraryDirectory");
}

if (Matchers.directory(context, Path.of("integration-tests"))) {
s.addIgnoredKeys("native.image.path", "quarkus.kubernetes-service-binding.root");
}

if (Matchers.module(context, "quarkus-integration-test-rest-client")) {
s.addIgnoredKeys("javax.net.ssl.trustStore", "rest-client.trustStore");
}

if (Matchers.module(context, "quarkus-integration-test-test-extension")) {
s.addIgnoredKeys("classpathEntriesRecordingFile");
}
}));

// Application.properties
buildCacheApi.registerNormalizationProvider(
context -> context.configureRuntimeClasspathNormalization(c -> {
c.addIgnoredFiles("META-INF/ide-deps/**");

if (Matchers.module(context, "quarkus-integration-test-rest-client-reactive")) {
c.addPropertiesNormalization("application.properties", "quarkus.rest-client.self-signed.trust-store",
"quarkus.rest-client.wrong-host.trust-store",
"quarkus.rest-client.wrong-host-rejected.trust-store");
}

if (Matchers.module(context, "quarkus-integration-test-oidc-client-reactive")) {
c.addPropertiesNormalization("application.properties", "quarkus.keycloak.devservices.realm-path");
}

if (Matchers.module(context, "quarkus-integration-test-test-extension")) {
c.addPropertiesNormalization("application.properties", "quarkus.bt.classpath-recording.record-file",
"%test.quarkus.bt.classpath-recording.record-file");
}

if (Matchers.module(context, "quarkus-integration-test-gradle-plugin")) {
c.addIgnoredFiles(".quarkus/config.yml");
}
}));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.nio.file.Path;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.util.Map;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.nio.file.Path;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.util.Map;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.util.Map;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.develocity.project.goals;
package io.quarkus.develocity.project.plugins;

import java.nio.file.Path;
import java.util.Map;
Expand Down
Loading