diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddDevelocityGradlePlugin.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddDevelocityGradlePlugin.java index dd6acd29960..96e304352c9 100644 --- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddDevelocityGradlePlugin.java +++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/plugins/AddDevelocityGradlePlugin.java @@ -144,7 +144,7 @@ public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionCon return cu; } // Don't modify an existing gradle enterprise DSL, only add one which is not already present - if (containsGradleEnterpriseDsl(cu)) { + if (containsGradleDevelocityDsl(cu)) { return cu; } @@ -156,7 +156,24 @@ public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionCon return cu; } GradleSettings gradleSettings = maybeGradleSettings.get(); - cu = withPlugin(cu, "com.gradle.enterprise", versionComparator, null, gradleSettings, ctx); + + try { + String newVersion = findNewerVersion(new DependencyVersionSelector(null, null, gradleSettings), ctx); + if (newVersion == null) { + return cu; + } + + String pluginId; + if (versionComparator.compare(null, newVersion, "3.17") >= 0) { + pluginId = "com.gradle.develocity"; + } else { + pluginId = "com.gradle.enterprise"; + } + + cu = withPlugin(cu, pluginId, newVersion, versionComparator, ctx); + } catch (MavenDownloadingException e) { + return e.warn(cu); + } } else if (!gradleSixOrLater && cu.getSourcePath().toString().equals("build.gradle")) { // Older than 6.0 goes in root build.gradle only, not in build.gradle of subprojects Optional maybeGradleProject = cu.getMarkers().findFirst(GradleProject.class); @@ -165,38 +182,47 @@ public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionCon } GradleProject gradleProject = maybeGradleProject.get(); - cu = withPlugin(cu, "com.gradle.build-scan", versionComparator, gradleProject, null, ctx); + try { + String newVersion = findNewerVersion(new DependencyVersionSelector(null, gradleProject, null), ctx); + if (newVersion == null) { + return cu; + } + + cu = withPlugin(cu, "com.gradle.build-scan", newVersion, versionComparator, ctx); + } catch (MavenDownloadingException e) { + return e.warn(cu); + } } return cu; } - }); - } - private G.CompilationUnit withPlugin(G.CompilationUnit cu, String pluginId, VersionComparator versionComparator, @Nullable GradleProject gradleProject, @Nullable GradleSettings gradleSettings, ExecutionContext ctx) { - try { - String newVersion = new DependencyVersionSelector(null, gradleProject, gradleSettings) - .select(new GroupArtifact("com.gradle.enterprise", "com.gradle.enterprise.gradle.plugin"), "classpath", version, null, ctx); - if (newVersion == null) { - return cu; + private @Nullable String findNewerVersion(DependencyVersionSelector versionSelector, ExecutionContext ctx) throws MavenDownloadingException { + String newVersion = versionSelector + .select(new GroupArtifact("com.gradle.develocity", "com.gradle.develocity.gradle.plugin"), "classpath", version, null, ctx); + if (newVersion == null) { + newVersion = versionSelector + .select(new GroupArtifact("com.gradle.enterprise", "com.gradle.enterprise.gradle.plugin"), "classpath", version, null, ctx); + } + return newVersion; } + }); + } - cu = (G.CompilationUnit) new AddPluginVisitor(pluginId, newVersion, null, null) - .visitNonNull(cu, ctx); - cu = (G.CompilationUnit) new UpgradePluginVersion(pluginId, newVersion, null).getVisitor() - .visitNonNull(cu, ctx); - J.MethodInvocation gradleEnterpriseInvocation = gradleEnterpriseDsl( - newVersion, - versionComparator, - getIndent(cu), - ctx); - return cu.withStatements(ListUtils.concat(cu.getStatements(), gradleEnterpriseInvocation)); - } catch (MavenDownloadingException e) { - return e.warn(cu); - } + private G.CompilationUnit withPlugin(G.CompilationUnit cu, String pluginId, String newVersion, VersionComparator versionComparator, ExecutionContext ctx) { + cu = (G.CompilationUnit) new AddPluginVisitor(pluginId, newVersion, null, null) + .visitNonNull(cu, ctx); + cu = (G.CompilationUnit) new UpgradePluginVersion(pluginId, newVersion, null).getVisitor() + .visitNonNull(cu, ctx); + J.MethodInvocation gradleEnterpriseInvocation = gradleEnterpriseDsl( + newVersion, + versionComparator, + getIndent(cu), + ctx); + return cu.withStatements(ListUtils.concat(cu.getStatements(), gradleEnterpriseInvocation)); } - private static boolean containsGradleEnterpriseDsl(JavaSourceFile cu) { + private static boolean containsGradleDevelocityDsl(JavaSourceFile cu) { AtomicBoolean found = new AtomicBoolean(false); new GroovyIsoVisitor() { @Override @@ -209,7 +235,7 @@ private static boolean containsGradleEnterpriseDsl(JavaSourceFile cu) { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, AtomicBoolean atomicBoolean) { - if (method.getSimpleName().equals("gradleEnterprise")) { + if (method.getSimpleName().equals("gradleEnterprise") || method.getSimpleName().equals("develocity")) { atomicBoolean.set(true); } return super.visitMethodInvocation(method, atomicBoolean); @@ -226,7 +252,13 @@ private J.MethodInvocation gradleEnterpriseDsl(String newVersion, VersionCompara } boolean versionIsAtLeast3_2 = versionComparator.compare(null, newVersion, "3.2") >= 0; boolean versionIsAtLeast3_7 = versionComparator.compare(null, newVersion, "3.7") >= 0; - StringBuilder ge = new StringBuilder("\ngradleEnterprise {\n"); + boolean versionIsAtLeast3_17 = versionComparator.compare(null, newVersion, "3.17") >= 0; + StringBuilder ge; + if (versionIsAtLeast3_17) { + ge = new StringBuilder("\ndevelocity {\n"); + } else { + ge = new StringBuilder("\ngradleEnterprise {\n"); + } if (server != null && !server.isEmpty()) { ge.append(indent).append("server = '").append(server).append("'\n"); } @@ -237,9 +269,17 @@ private J.MethodInvocation gradleEnterpriseDsl(String newVersion, VersionCompara ge.append(indent).append("buildScan {\n"); if (publishCriteria != null) { if (publishCriteria == PublishCriteria.Always) { - ge.append(indent).append(indent).append("publishAlways()\n"); + if (versionIsAtLeast3_17) { + ge.append(indent).append(indent).append("publishing.onlyIf { true }\n"); + } else { + ge.append(indent).append(indent).append("publishAlways()\n"); + } } else { - ge.append(indent).append(indent).append("publishOnFailure()\n"); + if (versionIsAtLeast3_17) { + ge.append(indent).append(indent).append("publishing.onlyIf { !it.buildResult.failures.empty }\n"); + } else { + ge.append(indent).append(indent).append("publishOnFailure()\n"); + } } } if (allowUntrustedServer != null && !versionIsAtLeast3_2) { @@ -251,7 +291,11 @@ private J.MethodInvocation gradleEnterpriseDsl(String newVersion, VersionCompara if (captureTaskInputFiles != null) { if (versionIsAtLeast3_7) { ge.append(indent).append(indent).append("capture {\n"); - ge.append(indent).append(indent).append(indent).append("taskInputFiles = ").append(captureTaskInputFiles).append("\n"); + if (versionIsAtLeast3_17) { + ge.append(indent).append(indent).append(indent).append("fileFingerprints = ").append(captureTaskInputFiles).append("\n"); + } else { + ge.append(indent).append(indent).append(indent).append("taskInputFiles = ").append(captureTaskInputFiles).append("\n"); + } ge.append(indent).append(indent).append("}\n"); } else { ge.append(indent).append(indent).append("captureTaskInputFiles = ").append(captureTaskInputFiles).append("\n"); diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/plugins/AddDevelocityGradlePluginTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/plugins/AddDevelocityGradlePluginTest.java index ff9bc6e20cf..1add0c40ef8 100644 --- a/rewrite-gradle/src/test/java/org/openrewrite/gradle/plugins/AddDevelocityGradlePluginTest.java +++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/plugins/AddDevelocityGradlePluginTest.java @@ -138,7 +138,7 @@ void addNewSettingsPluginsBlock() { """, interpolateResolvedVersion(""" plugins { - id 'com.gradle.enterprise' version '%s' + id 'com.gradle.develocity' version '%s' } rootProject.name = 'my-project' @@ -164,7 +164,7 @@ void addExistingSettingsPluginsBlock() { """, interpolateResolvedVersion(""" plugins { - id 'com.gradle.enterprise' version '%s' + id 'com.gradle.develocity' version '%s' } rootProject.name = 'my-project' @@ -176,10 +176,10 @@ void addExistingSettingsPluginsBlock() { @Issue("https://github.com/openrewrite/rewrite/issues/2697") @Test - void withConfigurationInSettings() { + void withGradleEnterpriseConfigurationInSettings() { rewriteRun( spec -> spec.allSources(s -> s.markers(new BuildTool(randomId(), BuildTool.Type.Gradle, "7.6.1"))) - .recipe(new AddDevelocityGradlePlugin("3.x", "https://ge.sam.com/", true, true, true, AddDevelocityGradlePlugin.PublishCriteria.Always)), + .recipe(new AddDevelocityGradlePlugin("3.16.x", "https://ge.sam.com/", true, true, true, AddDevelocityGradlePlugin.PublishCriteria.Always)), buildGradle( "" ), @@ -206,6 +206,37 @@ void withConfigurationInSettings() { ); } + @Test + void withDevelocityConfigurationInSettings() { + rewriteRun( + spec -> spec.allSources(s -> s.markers(new BuildTool(randomId(), BuildTool.Type.Gradle, "7.6.1"))) + .recipe(new AddDevelocityGradlePlugin("3.x", "https://ge.sam.com/", true, true, true, AddDevelocityGradlePlugin.PublishCriteria.Always)), + buildGradle( + "" + ), + settingsGradle( + "", + interpolateResolvedVersion(""" + plugins { + id 'com.gradle.develocity' version '%s' + } + develocity { + server = 'https://ge.sam.com/' + allowUntrustedServer = true + buildScan { + publishing.onlyIf { true } + uploadInBackground = true + capture { + fileFingerprints = true + } + } + } + """ + ) + ) + ); + } + @Issue("https://github.com/openrewrite/rewrite/issues/2697") @Test void withConfigurationOldInputCapture() { @@ -242,7 +273,7 @@ void defaultsToLatestRelease() { settingsGradle( "", spec -> spec.after(after -> { - Matcher versionMatcher = Pattern.compile("id 'com\\.gradle\\.enterprise' version '(.*?)'").matcher(after); + Matcher versionMatcher = Pattern.compile("id 'com\\.gradle\\.develocity' version '(.*?)'").matcher(after); assertThat(versionMatcher.find()).isTrue(); String version = versionMatcher.group(1); VersionComparator versionComparator = requireNonNull(Semver.validate("[3.14,)", null).getValue()); @@ -250,7 +281,7 @@ void defaultsToLatestRelease() { return """ plugins { - id 'com.gradle.enterprise' version '%s' + id 'com.gradle.develocity' version '%s' } """.formatted(version); }) @@ -279,7 +310,7 @@ void addNewSettingsPluginsBlockWithLicenseHeader() { */ plugins { - id 'com.gradle.enterprise' version '%s' + id 'com.gradle.develocity' version '%s' } rootProject.name = 'my-project' diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/AddDevelocityMavenExtension.java b/rewrite-maven/src/main/java/org/openrewrite/maven/AddDevelocityMavenExtension.java index 29df69f5be0..955b6933f5d 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/AddDevelocityMavenExtension.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/AddDevelocityMavenExtension.java @@ -34,6 +34,7 @@ import org.openrewrite.maven.tree.MavenMetadata; import org.openrewrite.maven.tree.MavenRepository; import org.openrewrite.semver.LatestRelease; +import org.openrewrite.semver.Semver; import org.openrewrite.semver.VersionComparator; import org.openrewrite.style.GeneralFormatStyle; import org.openrewrite.xml.AddToTagVisitor; @@ -52,8 +53,10 @@ @EqualsAndHashCode(callSuper = false) public class AddDevelocityMavenExtension extends ScanningRecipe { private static final String GRADLE_ENTERPRISE_MAVEN_EXTENSION_ARTIFACT_ID = "gradle-enterprise-maven-extension"; + private static final String DEVELOCITY_MAVEN_EXTENSION_ARTIFACT_ID = "develocity-maven-extension"; private static final String EXTENSIONS_XML_PATH = ".mvn/extensions.xml"; private static final String GRADLE_ENTERPRISE_XML_PATH = ".mvn/gradle-enterprise.xml"; + private static final String DEVELOCITY_XML_PATH = ".mvn/develocity.xml"; @Language("xml") private static final String EXTENSIONS_XML_FORMAT = "\n" + @@ -61,9 +64,9 @@ public class AddDevelocityMavenExtension extends ScanningRecipe"; @Language("xml") - private static final String ENTERPRISE_TAG_FORMAT = "\n" + + private static final String EXTENSION_TAG_FORMAT = "\n" + " com.gradle\n" + - " gradle-enterprise-maven-extension\n" + + " %s\n" + " %s\n" + ""; @@ -87,13 +90,13 @@ public class AddDevelocityMavenExtension extends ScanningRecipe getScanner(Accumulator acc) { acc.setMatchingExtensionsXmlFile(sourceFile.getSourcePath()); break; case GRADLE_ENTERPRISE_XML_PATH: + case DEVELOCITY_XML_PATH: acc.setMatchingGradleEnterpriseXmlFile(sourceFile.getSourcePath()); break; default: @@ -192,12 +196,29 @@ public Collection generate(Accumulator acc, ExecutionConte return Collections.emptyList(); } + VersionComparator versionComparator = Semver.validate("(,1.21)", null).getValue(); + if (versionComparator == null) { + return Collections.emptyList(); + } + + String newVersion = version != null ? version : getLatestVersion(ctx); List sources = new ArrayList<>(); - sources.add(createNewXml(GRADLE_ENTERPRISE_XML_PATH, gradleEnterpriseConfiguration(acc.isUseCRLFNewLines()))); + + if (versionComparator.compare(null, newVersion, "1.21") >= 0) { + BuildScanConfiguration buildScanConfiguration = buildScanConfiguration(true); + ServerConfiguration serverConfiguration = new ServerConfiguration(server, allowUntrustedServer); + DevelocityConfiguration develocityConfiguration = new DevelocityConfiguration(serverConfiguration, buildScanConfiguration); + sources.add(createNewXml(DEVELOCITY_XML_PATH, writeConfiguration(develocityConfiguration, acc.isUseCRLFNewLines()))); + } else { + BuildScanConfiguration buildScanConfiguration = buildScanConfiguration(false); + ServerConfiguration serverConfiguration = new ServerConfiguration(server, allowUntrustedServer); + GradleEnterpriseConfiguration gradleEnterpriseConfiguration = new GradleEnterpriseConfiguration(serverConfiguration, buildScanConfiguration); + sources.add(createNewXml(GRADLE_ENTERPRISE_XML_PATH, writeConfiguration(gradleEnterpriseConfiguration, acc.isUseCRLFNewLines()))); + } if (acc.getMatchingExtensionsXmlFile() == null) { Xml.Document extensionsXml = createNewXml(EXTENSIONS_XML_PATH, EXTENSIONS_XML_FORMAT); - extensionsXml = addEnterpriseExtension(extensionsXml, ctx); + extensionsXml = addExtension(extensionsXml, ctx); sources.add(extensionsXml); } @@ -221,13 +242,13 @@ public TreeVisitor getVisitor(Accumulator acc) { if (sourceFile.getSourcePath().equals(acc.getMatchingExtensionsXmlFile())) { Xml.Document extensionsXml = (Xml.Document) sourceFile; - // find `gradle-enterprise-maven-extension` extension, do nothing if it already exists, - boolean hasEnterpriseExtension = findExistingEnterpriseExtension(extensionsXml); + // find extension, do nothing if it already exists, + boolean hasEnterpriseExtension = findExistingExtension(extensionsXml); if (hasEnterpriseExtension) { return sourceFile; } - return addEnterpriseExtension(extensionsXml, ctx); + return addExtension(extensionsXml, ctx); } return tree; } @@ -243,6 +264,15 @@ private static class GradleEnterpriseConfiguration { BuildScanConfiguration buildScan; } + @JacksonXmlRootElement(localName = "develocity") + @Value + private static class DevelocityConfiguration { + ServerConfiguration server; + + @Nullable + BuildScanConfiguration buildScan; + } + @Value private static class ServerConfiguration { String url; @@ -259,36 +289,72 @@ private static class BuildScanConfiguration { @Nullable String publish; + @Nullable + PublishingConfiguration publishing; + @Nullable Capture capture; } + @Value + private static class PublishingConfiguration { + @Nullable + String onlyIf; + } + @Value private static class Capture { Boolean goalInputFiles; + Boolean fileFingerprints; } - private String gradleEnterpriseConfiguration(boolean useCRLFNewLines) { - BuildScanConfiguration buildScanConfiguration = buildScanConfiguration(); - ServerConfiguration serverConfiguration = new ServerConfiguration(server, allowUntrustedServer); + private String writeConfiguration(Object config, boolean useCRLFNewLines) { try { ObjectMapper objectMapper = MavenXmlMapper.writeMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT); PrettyPrinter pp = new DefaultXmlPrettyPrinter().withCustomNewLine(useCRLFNewLines ? "\r\n" : "\n"); - return objectMapper.writer(pp) - .writeValueAsString(new GradleEnterpriseConfiguration(serverConfiguration, buildScanConfiguration)); + return objectMapper.writer(pp).writeValueAsString(config); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } @Nullable - private BuildScanConfiguration buildScanConfiguration() { - if (uploadInBackground != null || publishCriteria != null || captureGoalInputFiles != null) { - return new BuildScanConfiguration(uploadInBackground, - publishCriteria != null ? publishCriteria.xmlName : null, - captureGoalInputFiles != null ? new Capture(captureGoalInputFiles) : null); + private BuildScanConfiguration buildScanConfiguration(boolean develocity) { + if (uploadInBackground != null || publishCriteria != null || fileFingerprints != null) { + if (develocity) { + PublishingConfiguration publishing = null; + if (publishCriteria != null) { + String onlyIf; + switch (publishCriteria) { + case Always: + onlyIf = "true"; + break; + case Failure: + onlyIf = "!buildResult.failures.empty"; + break; + case Demand: + onlyIf = "false"; + break; + default: + throw new IllegalStateException("All options exhausted"); + } + publishing = new PublishingConfiguration(onlyIf); + } + + return new BuildScanConfiguration( + uploadInBackground, + null, + publishing, + fileFingerprints != null ? new Capture(null, fileFingerprints) : null + ); + } else { + return new BuildScanConfiguration(uploadInBackground, + publishCriteria != null ? publishCriteria.xmlName : null, + null, + fileFingerprints != null ? new Capture(fileFingerprints, null) : null); + } } return null; } @@ -304,7 +370,7 @@ private static Xml.Document createNewXml(String filePath, @Language("xml") Strin /** * Return true if the `.mvn/extensions.xml` already includes `gradle-enterprise-maven-extension` */ - private boolean findExistingEnterpriseExtension(Xml.Document extensionsXml) { + private boolean findExistingExtension(Xml.Document extensionsXml) { XPathMatcher xPathMatcher = new XPathMatcher("/extensions/extension/artifactId"); return new XmlIsoVisitor() { @Override @@ -315,7 +381,7 @@ public Xml.Tag visitTag(Xml.Tag tag, AtomicBoolean found) { tag = super.visitTag(tag, found); if (xPathMatcher.matches(getCursor())) { Optional maybeArtifactId = tag.getValue(); - if (maybeArtifactId.isPresent() && maybeArtifactId.get().equals(GRADLE_ENTERPRISE_MAVEN_EXTENSION_ARTIFACT_ID)) { + if (maybeArtifactId.isPresent() && (maybeArtifactId.get().equals(GRADLE_ENTERPRISE_MAVEN_EXTENSION_ARTIFACT_ID) || maybeArtifactId.get().equals(DEVELOCITY_MAVEN_EXTENSION_ARTIFACT_ID))) { found.set(true); } } @@ -325,12 +391,25 @@ public Xml.Tag visitTag(Xml.Tag tag, AtomicBoolean found) { } /** - * Add `gradle-enterprise-maven-extension` to the file `.mvn/extensions.xml`, - * this method assumes that `gradle-enterprise-maven-extension` does not exist yet, and it should have been checked. + * Add `develocity-maven-extension` to the file `.mvn/extensions.xml`, + * this method assumes that `develocity-maven-extension` does not exist yet, and it should have been checked. */ - private Xml.Document addEnterpriseExtension(Xml.Document extensionsXml, ExecutionContext ctx) { + private Xml.Document addExtension(Xml.Document extensionsXml, ExecutionContext ctx) { + VersionComparator versionComparator = Semver.validate("(,1.21)", null).getValue(); + if (versionComparator == null) { + return extensionsXml; + } + + String newVersion = version != null ? version : getLatestVersion(ctx); + + String extension; + if (versionComparator.compare(null, newVersion, "1.21") >= 0) { + extension = "develocity-maven-extension"; + } else { + extension = "gradle-enterprise-maven-extension"; + } @Language("xml") - String tagSource = version != null ? String.format(ENTERPRISE_TAG_FORMAT, version) : String.format(ENTERPRISE_TAG_FORMAT, getLatestVersion(ctx)); + String tagSource = String.format(EXTENSION_TAG_FORMAT, extension, newVersion); AddToTagVisitor addToTagVisitor = new AddToTagVisitor<>( extensionsXml.getRoot(), Xml.Tag.build(tagSource)); @@ -341,15 +420,15 @@ private String getLatestVersion(ExecutionContext ctx) { MavenExecutionContextView mctx = MavenExecutionContextView.view(ctx); MavenPomDownloader pomDownloader = new MavenPomDownloader(Collections.emptyMap(), ctx, mctx.getSettings(), mctx.getActiveProfiles()); VersionComparator versionComparator = new LatestRelease(null); - GroupArtifact gradleEnterpriseExtension = new GroupArtifact("com.gradle", "gradle-enterprise-maven-extension"); + GroupArtifact develocityExtension = new GroupArtifact("com.gradle", DEVELOCITY_MAVEN_EXTENSION_ARTIFACT_ID); try { - MavenMetadata extensionMetadata = pomDownloader.downloadMetadata(gradleEnterpriseExtension, null, Collections.singletonList(MavenRepository.MAVEN_CENTRAL)); - return extensionMetadata.getVersioning() - .getVersions() - .stream() - .filter(v -> versionComparator.isValid(null, v)) - .max((v1, v2) -> versionComparator.compare(null, v1, v2)) - .orElseThrow(() -> new IllegalStateException("Expected to find at least one Gradle Enterprise Maven extension version to select from.")); + MavenMetadata extensionMetadata = pomDownloader.downloadMetadata(develocityExtension, null, Collections.singletonList(MavenRepository.MAVEN_CENTRAL)); + return extensionMetadata.getVersioning() + .getVersions() + .stream() + .filter(v -> versionComparator.isValid(null, v)) + .max((v1, v2) -> versionComparator.compare(null, v1, v2)) + .orElseThrow(() -> new IllegalStateException("Expected to find at least one Gradle Enterprise Maven extension version to select from.")); } catch (MavenDownloadingException e) { throw new IllegalStateException("Could not download Maven metadata", e); } diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/AddDevelocityMavenExtensionTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/AddDevelocityMavenExtensionTest.java index 01bb4016966..a0b4bde83ad 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/AddDevelocityMavenExtensionTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/AddDevelocityMavenExtensionTest.java @@ -141,7 +141,7 @@ void noVersionSpecified() { com.gradle - gradle-enterprise-maven-extension + develocity-maven-extension %s @@ -151,13 +151,13 @@ void noVersionSpecified() { xml( null, """ - + https://foo - + """, - spec -> spec.path(".mvn/gradle-enterprise.xml") + spec -> spec.path(".mvn/develocity.xml") ) ); } @@ -179,7 +179,22 @@ void noChangeIfGradleEnterpriseXmlExists() { } @Test - void allSettings() { + void noChangeIfDevelocityXmlExists() { + rewriteRun( + POM_XML_SOURCE_SPEC, + xml( + """ + + + + """, + spec -> spec.path(".mvn/develocity.xml") + ) + ); + } + + @Test + void allGradleEnterpriseSettings() { rewriteRun( spec -> spec.recipe(new AddDevelocityMavenExtension("1.17", "https://foo", true, true, false, AddDevelocityMavenExtension.PublishCriteria.Failure)), POM_XML_SOURCE_SPEC, @@ -219,4 +234,47 @@ void allSettings() { ); } + @Test + void allDevelocitySettings() { + rewriteRun( + spec -> spec.recipe(new AddDevelocityMavenExtension("1.21", "https://foo", true, true, false, AddDevelocityMavenExtension.PublishCriteria.Failure)), + POM_XML_SOURCE_SPEC, + xml( + null, + """ + + + + com.gradle + develocity-maven-extension + 1.21 + + + """, + spec -> spec.path(".mvn/extensions.xml") + ), + xml( + null, + """ + + + https://foo + true + + + false + + !buildResult.failures.empty + + + true + + + + """, + spec -> spec.path(".mvn/develocity.xml") + ) + ); + } + }