Skip to content

Commit

Permalink
Merge pull request #38 from gsmet/prepare-new-extension-annotation-pr…
Browse files Browse the repository at this point in the history
…ocessor

Prepare the extension for the new extension annotation processor
  • Loading branch information
gsmet authored Aug 9, 2024
2 parents eddfc85 + 6e9b8d6 commit 975e7c6
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.quarkus.develocity.project;

import org.apache.maven.project.MavenProject;

import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider;
import com.gradle.develocity.agent.maven.api.scan.BuildScanApi;

import io.quarkus.develocity.project.util.MavenMojoExecutionConfig;
import io.quarkus.develocity.project.util.MavenProperties;

@FunctionalInterface
public interface GoalMetadataProvider {

void configure(Context context);

class Context {
private final BuildScanApi buildScanApi;
private final MojoMetadataProvider.Context metadataContext;
private final MavenProperties properties;
private final MavenMojoExecutionConfig configuration;

public Context(BuildScanApi buildScanApi, MojoMetadataProvider.Context metadataContext) {
this.buildScanApi = buildScanApi;
this.metadataContext = metadataContext;
this.properties = new MavenProperties(metadataContext.getSession(), metadataContext.getMojoExecution());
this.configuration = new MavenMojoExecutionConfig(metadataContext.getMojoExecution());
}

public BuildScanApi buildScan() {
return buildScanApi;
}

public MojoMetadataProvider.Context metadata() {
return metadataContext;
}

public MavenProject project() {
return metadataContext.getProject();
}

public MavenProperties properties() {
return properties;
}

public MavenMojoExecutionConfig configuration() {
return configuration;
}

public void buildScanDeduplicatedValue(String key, String value) {
buildScanApi.executeOnce(key + value, ignored -> buildScanApi.value(key, value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import com.gradle.develocity.agent.maven.api.DevelocityApi;
import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider;
import com.gradle.develocity.agent.maven.api.cache.NormalizationProvider;

public abstract class SimpleQuarkusConfiguredPlugin implements ConfiguredPlugin {

Expand All @@ -31,7 +30,7 @@ public void configureBuildCache(DevelocityApi develocityApi, MavenSession mavenS

for (Entry<String, GoalMetadataProvider> goalMetadataProviderEntry : goalMetadataProviders.entrySet()) {
if (goalMetadataProviderEntry.getKey().equalsIgnoreCase(context.getMojoExecution().getGoal())) {
goalMetadataProviderEntry.getValue().configure(context);
goalMetadataProviderEntry.getValue().configure(new GoalMetadataProvider.Context(develocityApi.getBuildScan(), context));
}
}
});
Expand Down Expand Up @@ -69,16 +68,4 @@ protected void addClasspathInput(MojoMetadataProvider.Context context, MojoMetad
throw new IllegalStateException("Classpath can't be resolved");
}
}

@FunctionalInterface
public interface PluginNormalizationProvider {

void configure(NormalizationProvider.Context context);
}

@FunctionalInterface
public interface GoalMetadataProvider {

void configure(MojoMetadataProvider.Context context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.nio.file.Path;
import java.util.Map;

import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider;
import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider.Context.FileSet.NormalizationStrategy;

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

Expand All @@ -18,24 +18,33 @@ protected String getPluginName() {

@Override
protected Map<String, GoalMetadataProvider> getGoalMetadataProviders() {
return Map.of(
"compile", CompilerConfiguredPlugin::configureCompile);
return Map.of("compile", CompilerConfiguredPlugin::configureCompile);
}

private static void configureCompile(MojoMetadataProvider.Context context) {
if (Matchers.directory(context, Path.of("integration-tests"))) {
context.inputs(inputs -> inputs.fileSet("specs",
context.getProject().getBasedir() + "/disable-unbind-executions",
fs -> fs.normalizationStrategy(NormalizationStrategy.RELATIVE_PATH)));
private static void configureCompile(GoalMetadataProvider.Context context) {
if (Matchers.directory(context.metadata(), Path.of("integration-tests"))) {
context.metadata().inputs(inputs -> {
inputs.fileSet("specs",
context.project().getBasedir() + "/disable-unbind-executions",
fs -> fs.normalizationStrategy(NormalizationStrategy.RELATIVE_PATH));
});
}

context.outputs(outputs -> {
if (Matchers.directory(context, Path.of("extensions")) ||
Matchers.directory(context, Path.of("test-framework", "jacoco")) ||
Matchers.directory(context, Path.of("core", "runtime")) ||
Matchers.directory(context, Path.of("core", "deployment"))) {
outputs.notCacheableBecause("The extension config doc generation tool shares data across all extensions");
}
// for extensions, we need to add skipDocs/quickly as an input as it affects the annotation processor
if (Matchers.directory(context.metadata(), Path.of("extensions")) ||
Matchers.directory(context.metadata(), Path.of("test-framework", "jacoco")) ||
Matchers.directory(context.metadata(), Path.of("core", "runtime")) ||
Matchers.directory(context.metadata(), Path.of("core", "deployment"))) {

context.metadata().inputs(inputs -> {
boolean skipDocs = context.properties().getBoolean("skipDocs") || context.properties().getBoolean("quickly");
inputs.property("skipDocs", skipDocs);
});
}

context.metadata().outputs(outputs -> {
// cache the config doc output of the extension annotation processor
outputs.directory("quarkusConfigDoc", context.project().getBuild().getDirectory() + "/quarkus-config-doc");
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import java.util.Map;
import java.util.stream.Collectors;

import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider;

import io.quarkus.develocity.project.GoalMetadataProvider;
import io.quarkus.develocity.project.SimpleQuarkusConfiguredPlugin;

public class EnforcerConfiguredPlugin extends SimpleQuarkusConfiguredPlugin {
Expand All @@ -20,15 +19,15 @@ protected Map<String, GoalMetadataProvider> getGoalMetadataProviders() {
"enforce", EnforcerConfiguredPlugin::configureEnforce);
}

private static void configureEnforce(MojoMetadataProvider.Context context) {
context.inputs(inputs -> {
dependsOnGav(inputs, context);
private static void configureEnforce(GoalMetadataProvider.Context context) {
context.metadata().inputs(inputs -> {
dependsOnGav(inputs, context.metadata());
inputs.properties("skip", "fail", "failFast", "failIfNoRules", "rules", "rulesToExecute", "rulesToSkip",
"ignoreCache");
dependsOnOs(inputs);
dependsOnJavaVersion(inputs);

String dependencies = context.getProject().getArtifacts().stream()
String dependencies = context.project().getArtifacts().stream()
.map(a -> a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion() + ":" + a.getClassifier())
.sorted()
.collect(Collectors.joining("\n"));
Expand All @@ -38,7 +37,7 @@ private static void configureEnforce(MojoMetadataProvider.Context context) {
inputs.ignore("project", "mojoExecution", "session");
});

context.outputs(outputs -> {
context.metadata().outputs(outputs -> {
outputs.cacheable("If the inputs and dependencies are identical, we should have the same output");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.nio.file.Path;
import java.util.Map;

import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider;
import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider.Context.FileSet.NormalizationStrategy;

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

Expand All @@ -22,24 +22,24 @@ protected Map<String, GoalMetadataProvider> getGoalMetadataProviders() {
"integration-test", FailsafeConfiguredPlugin::configureIntegrationTest);
}

private static void configureIntegrationTest(MojoMetadataProvider.Context context) {
context.inputs(inputs -> {
inputs.fileSet("quarkus-dependencies", context.getProject().getBuild().getDirectory(), fs -> fs
private static void configureIntegrationTest(GoalMetadataProvider.Context context) {
context.metadata().inputs(inputs -> {
inputs.fileSet("quarkus-dependencies", context.project().getBuild().getDirectory(), fs -> fs
.include("quarkus-*-dependencies.txt").normalizationStrategy(NormalizationStrategy.CLASSPATH));
// for compatibility with older versions but this is deprecated
inputs.fileSet("quarkus-dependency-checksums", context.getProject().getBuild().getDirectory(), fs -> fs
inputs.fileSet("quarkus-dependency-checksums", context.project().getBuild().getDirectory(), fs -> fs
.include("quarkus-*-dependency-checksums.txt").normalizationStrategy(NormalizationStrategy.RELATIVE_PATH));

if (Matchers.directory(context, Path.of("integration-tests"))) {
inputs.fileSet("native-runner", context.getProject().getBuild().getDirectory(),
if (Matchers.directory(context.metadata(), Path.of("integration-tests"))) {
inputs.fileSet("native-runner", context.project().getBuild().getDirectory(),
fs -> fs.include("*-runner").normalizationStrategy(NormalizationStrategy.RELATIVE_PATH));
}
});

context.outputs(outputs -> {
if (Matchers.directory(context, Path.of("integration-tests", "devtools")) ||
Matchers.directory(context, Path.of("integration-tests", "gradle")) ||
Matchers.directory(context, Path.of("integration-tests", "maven"))) {
context.metadata().outputs(outputs -> {
if (Matchers.directory(context.metadata(), Path.of("integration-tests", "devtools")) ||
Matchers.directory(context.metadata(), Path.of("integration-tests", "gradle")) ||
Matchers.directory(context.metadata(), Path.of("integration-tests", "maven"))) {
outputs.notCacheableBecause("It is too hard to figure out the dependency tree of these modules");
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.util.Map;

import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider;
import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider.Context.FileSet.EmptyDirectoryHandling;
import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider.Context.FileSet.NormalizationStrategy;

import io.quarkus.develocity.project.GoalMetadataProvider;
import io.quarkus.develocity.project.SimpleQuarkusConfiguredPlugin;

public class FormatterConfiguredPlugin extends SimpleQuarkusConfiguredPlugin {
Expand All @@ -21,9 +21,9 @@ protected Map<String, GoalMetadataProvider> getGoalMetadataProviders() {
"format", FormatterConfiguredPlugin::configureFormat);
}

private static void configureFormat(MojoMetadataProvider.Context context) {
context.inputs(inputs -> {
dependsOnGav(inputs, context);
private static void configureFormat(GoalMetadataProvider.Context context) {
context.metadata().inputs(inputs -> {
dependsOnGav(inputs, context.metadata());

inputs.properties("includes", "excludes", "compilerSource", "compilerCompliance", "compilerTargetPlatform", "lineEnding", "configFile",
"configJsFile", "configHtmlFile", "configXmlFile", "configJsonFile", "configCssFile", "skipFormattingCache",
Expand All @@ -40,9 +40,9 @@ private static void configureFormat(MojoMetadataProvider.Context context) {
inputs.ignore("project", "targetDirectory", "basedir");
});

context.nested("encoding", c -> c.inputs(inputs -> inputs.properties("displayName")));
context.metadata().nested("encoding", c -> c.inputs(inputs -> inputs.properties("displayName")));

context.outputs(outputs -> {
context.metadata().outputs(outputs -> {
outputs.cacheable("If the inputs and dependencies are identical, we should have the same output");

outputs.directory("cachedir");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.util.Map;

import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider;
import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider.Context.FileSet.EmptyDirectoryHandling;
import com.gradle.develocity.agent.maven.api.cache.MojoMetadataProvider.Context.FileSet.NormalizationStrategy;

import io.quarkus.develocity.project.GoalMetadataProvider;
import io.quarkus.develocity.project.SimpleQuarkusConfiguredPlugin;

public class ImpsortConfiguredPlugin extends SimpleQuarkusConfiguredPlugin {
Expand All @@ -21,9 +21,9 @@ protected Map<String, GoalMetadataProvider> getGoalMetadataProviders() {
"sort", ImpsortConfiguredPlugin::configureSort);
}

private static void configureSort(MojoMetadataProvider.Context context) {
context.inputs(inputs -> {
dependsOnGav(inputs, context);
private static void configureSort(GoalMetadataProvider.Context context) {
context.metadata().inputs(inputs -> {
dependsOnGav(inputs, context.metadata());

inputs.properties("sourceEncoding", "skip", "staticGroups", "groups", "staticAfter", "joinStaticWithNonStatic",
"includes", "excludes", "removeUnused", "treatSamePackageAsUnused", "breadthFirstComparator",
Expand All @@ -41,7 +41,7 @@ private static void configureSort(MojoMetadataProvider.Context context) {
"cachedir");
});

context.outputs(outputs -> {
context.metadata().outputs(outputs -> {
outputs.cacheable("If the inputs and dependencies are identical, we should have the same output");

// For now we don't want to output the cachedir as it contains absolute paths
Expand Down
Loading

0 comments on commit 975e7c6

Please sign in to comment.