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

Work around -Dquickly missing the clean goal explicitly #3

Merged
merged 1 commit into from
Feb 20, 2024
Merged
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 @@ -7,6 +7,7 @@

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.EnforcerConfiguredPlugin;
import io.quarkus.develocity.project.goals.FormatterConfiguredPlugin;
Expand All @@ -22,8 +23,13 @@
)
public class QuarkusProjectBuildCacheGradleEnterpriseListener implements GradleEnterpriseListener {

private static final String QUICKLY = "-Dquickly";
private static final String DASH = "-";

@Override
public void configure(GradleEnterpriseApi gradleEnterpriseApi, MavenSession mavenSession) throws Exception {
workaroundQuickly(gradleEnterpriseApi.getBuildCache());

List<ConfiguredPlugin> configuredGoals = List.of(
new EnforcerConfiguredPlugin(),
new QuarkusConfiguredPlugin(),
Expand All @@ -37,4 +43,43 @@ public void configure(GradleEnterpriseApi gradleEnterpriseApi, MavenSession mave
configuredGoal.configureBuildCache(gradleEnterpriseApi, mavenSession);
}
}

private static void workaroundQuickly(BuildCacheApi buildCacheApi) {
String mavenCommandLine = System.getenv("MAVEN_CMD_LINE_ARGS");
if (mavenCommandLine == null || mavenCommandLine.isBlank()) {
return;
}

mavenCommandLine = mavenCommandLine.trim();

String[] segments = mavenCommandLine.split(" ");

boolean hasQuickly = false;
boolean hasGoals = false;

for (String segment : segments) {
segment = segment.trim();
if (segment.isEmpty()) {
continue;
}
if (QUICKLY.equals(segment)) {
hasQuickly = true;
continue;
}
// any option
if (segment.startsWith(DASH)) {
continue;
}
// when using -T 6/-T 6C as it works
if (Character.isDigit(segment.charAt(0))) {
continue;
}

hasGoals = true;
}

if (hasQuickly && !hasGoals) {
buildCacheApi.setRequireClean(false);
}
}
}