diff --git a/rewrite-core/src/main/java/org/openrewrite/remote/Remote.java b/rewrite-core/src/main/java/org/openrewrite/remote/Remote.java index f405714a134..52c708b40e8 100644 --- a/rewrite-core/src/main/java/org/openrewrite/remote/Remote.java +++ b/rewrite-core/src/main/java/org/openrewrite/remote/Remote.java @@ -105,6 +105,20 @@ static Builder builder(UUID id, Path sourcePath, Markers markers, URI uri) { return new Builder(id, sourcePath, markers, uri); } + @Override + default
TreeVisitor, PrintOutputCapture
> printer(Cursor cursor) {
+ return new TreeVisitor p) {
+ ExecutionContext ctx = p.getContext() instanceof ExecutionContext ? (ExecutionContext) p.getContext() :
+ new InMemoryExecutionContext();
+ HttpSender sender = HttpSenderExecutionContextView.view(ctx).getHttpSender();
+ p.out.append(StringUtils.readFully(getInputStream(sender), StandardCharsets.UTF_8));
+ return sourceFile;
+ }
+ };
+ }
+
class Builder {
protected final UUID id;
protected final Path sourcePath;
diff --git a/rewrite-core/src/main/java/org/openrewrite/remote/RemoteArchive.java b/rewrite-core/src/main/java/org/openrewrite/remote/RemoteArchive.java
index 3208734e82a..b72f6fc2e26 100644
--- a/rewrite-core/src/main/java/org/openrewrite/remote/RemoteArchive.java
+++ b/rewrite-core/src/main/java/org/openrewrite/remote/RemoteArchive.java
@@ -18,9 +18,9 @@
import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.With;
+import org.apache.tools.ant.taskdefs.Exec;
import org.intellij.lang.annotations.Language;
-import org.openrewrite.FileAttributes;
-import org.openrewrite.PathUtils;
+import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.ipc.http.HttpSender;
import org.openrewrite.marker.Markers;
diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/AddGradleWrapper.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/AddGradleWrapper.java
index bdd4f77ce16..70ec1ccad5f 100644
--- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/AddGradleWrapper.java
+++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/AddGradleWrapper.java
@@ -90,7 +90,7 @@ public AddGradleWrapper(String version, String distribution) {
@Override
protected TreeVisitor, ExecutionContext> getApplicableTest() {
- return new HasSourcePath<>("regex", ".+\\.gradle(\\.kts)?$");
+ return new IsBuildGradle<>();
}
@Override
diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java
index 83a5d78026c..245d80d8cc5 100644
--- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java
+++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/Assertions.java
@@ -40,7 +40,7 @@ public static SourceSpecs buildGradle(@Language("groovy") @Nullable String befor
}
public static SourceSpecs buildGradle(@Language("groovy") @Nullable String before, Consumer extends JavaIsoVisitor {
@Override
public JavaSourceFile visitJavaSourceFile(JavaSourceFile cu, P p) {
- if (cu.getSourcePath().toString().endsWith(".gradle") &&
- !cu.getSourcePath().toString().endsWith("settings.gradle")) {
+ if ((cu.getSourcePath().toString().endsWith(".gradle") ||
+ cu.getSourcePath().toString().endsWith(".gradle.kts")) &&
+ !(cu.getSourcePath().toString().endsWith("settings.gradle") ||
+ cu.getSourcePath().toString().endsWith("settings.gradle.kts"))) {
return SearchResult.found(cu);
}
return super.visitJavaSourceFile(cu, p);
diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/IsSettingsGradle.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/IsSettingsGradle.java
index 671b93e6a6a..21c86d209f9 100644
--- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/IsSettingsGradle.java
+++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/IsSettingsGradle.java
@@ -19,12 +19,12 @@
import org.openrewrite.java.tree.JavaSourceFile;
import org.openrewrite.marker.SearchResult;
-import java.nio.file.Paths;
-
public class IsSettingsGradle extends JavaIsoVisitor {
+
@Override
public JavaSourceFile visitJavaSourceFile(JavaSourceFile cu, P p) {
- if (cu.getSourcePath().toString().endsWith("settings.gradle")) {
+ if (cu.getSourcePath().toString().endsWith("settings.gradle") ||
+ cu.getSourcePath().toString().endsWith("settings.gradle.kts")) {
return SearchResult.found(cu);
}
return super.visitJavaSourceFile(cu, p);
diff --git a/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpdateGradleWrapper.java b/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpdateGradleWrapper.java
index 947732c542e..57b9adb1431 100755
--- a/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpdateGradleWrapper.java
+++ b/rewrite-gradle/src/main/java/org/openrewrite/gradle/UpdateGradleWrapper.java
@@ -33,9 +33,11 @@
import org.openrewrite.quark.Quark;
import org.openrewrite.text.PlainText;
+import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import java.util.List;
+import static java.util.Objects.requireNonNull;
import static org.openrewrite.PathUtils.equalIgnoringSeparators;
import static org.openrewrite.gradle.util.GradleWrapper.*;
@@ -102,7 +104,7 @@ public Properties visitEntry(Properties.Entry entry, ExecutionContext context) {
return entry;
}
- GradleWrapper gradleWrapper = validate(context).getValue();
+ GradleWrapper gradleWrapper = requireNonNull(validate(context).getValue());
// Typical example: https://services.gradle.org/distributions/gradle-7.4-all.zip
String currentDistributionUrl = entry.getValue().getText();
@@ -122,7 +124,8 @@ protected List
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+import org.openrewrite.test.TypeValidation;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+import static org.openrewrite.properties.Assertions.properties;
+import static org.openrewrite.test.SourceSpecs.other;
+
+class ActivateStyleTest implements RewriteTest {
+
+ @Override
+ public void defaults(RecipeSpec spec) {
+ spec.recipe(new ActivateStyle("org.openrewrite.java.IntelliJ", true))
+ .typeValidationOptions(TypeValidation.none());
+ }
+
+ @Test
+ void addToRewriteDsl() {
+ rewriteRun(
+ buildGradle(
+ """
+ plugins {
+ id("java")
+ id("org.openrewrite.rewrite")
+ }
+
+ rewrite {
+ activeRecipe("org.openrewrite.java.format.AutoFormat")
+ }
+ """,
+ """
+ plugins {
+ id("java")
+ id("org.openrewrite.rewrite")
+ }
+
+ rewrite {
+ activeRecipe("org.openrewrite.java.format.AutoFormat")
+ activeStyle("org.openrewrite.java.IntelliJ")
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void addToRewriteDslExistingStyle() {
+ rewriteRun(
+ spec -> spec.recipe(new ActivateStyle("org.openrewrite.java.IntelliJ", false)),
+ buildGradle(
+ """
+ plugins {
+ id("java")
+ id("org.openrewrite.rewrite")
+ }
+
+ rewrite {
+ activeRecipe("org.openrewrite.java.format.AutoFormat")
+ activeStyle("otherStyle")
+ }
+ """,
+ """
+ plugins {
+ id("java")
+ id("org.openrewrite.rewrite")
+ }
+
+ rewrite {
+ activeRecipe("org.openrewrite.java.format.AutoFormat")
+ activeStyle("otherStyle", "org.openrewrite.java.IntelliJ")
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void addToRewriteDslOverwriteStyle() {
+ rewriteRun(
+ buildGradle(
+ """
+ plugins {
+ id("java")
+ id("org.openrewrite.rewrite")
+ }
+
+ rewrite {
+ activeRecipe("org.openrewrite.java.format.AutoFormat")
+ activeStyle("com.your.Style")
+ }
+ """,
+ """
+ plugins {
+ id("java")
+ id("org.openrewrite.rewrite")
+ }
+
+ rewrite {
+ activeRecipe("org.openrewrite.java.format.AutoFormat")
+ activeStyle("org.openrewrite.java.IntelliJ")
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void addToProperties() {
+ rewriteRun(
+ other("", spec -> spec.path(".gradle.kts")),
+ properties(
+ """
+ org.gradle.someProp=true
+ """,
+ """
+ org.gradle.someProp=true
+ systemProp.rewrite.activeStyles=org.openrewrite.java.IntelliJ
+ """,
+ spec -> spec.path("gradle.properties")
+ )
+ );
+ }
+
+ @Test
+ void addToPropertiesStyles() {
+ rewriteRun(
+ spec -> spec.recipe(new ActivateStyle("org.openrewrite.java.IntelliJ", false)),
+ other("", spec -> spec.path(".gradle.kts")),
+ properties(
+ """
+ org.gradle.someProp=true
+ systemProp.rewrite.activeStyles=org.openrewrite.java.Other
+ """,
+ """
+ org.gradle.someProp=true
+ systemProp.rewrite.activeStyles=org.openrewrite.java.Other,org.openrewrite.java.IntelliJ
+ """,
+ spec -> spec.path("gradle.properties")
+ )
+ );
+ }
+
+ @Test
+ void overwritePropertiesStyles() {
+ rewriteRun(
+ other("", spec -> spec.path(".gradle.kts")),
+ properties(
+ """
+ org.gradle.someProp=true
+ systemProp.rewrite.activeStyles=org.openrewrite.java.Other
+ """,
+ """
+ org.gradle.someProp=true
+ systemProp.rewrite.activeStyles=org.openrewrite.java.IntelliJ
+ """,
+ spec -> spec.path("gradle.properties")
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/AddDelegatesToGradleApiTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/AddDelegatesToGradleApiTest.java
new file mode 100644
index 00000000000..f18b7ec95bb
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/AddDelegatesToGradleApiTest.java
@@ -0,0 +1,269 @@
+/*
+ * Copyright 2022 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.java.JavaParser;
+import org.openrewrite.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.java.Assertions.java;
+
+class AddDelegatesToGradleApiTest implements RewriteTest {
+
+ @Override
+ public void defaults(RecipeSpec spec) {
+ spec
+ .parser(JavaParser.fromJavaVersion().classpath("groovy", "gradle-base-services"))
+ .recipe(new AddDelegatesToGradleApi());
+ }
+
+ @Test
+ void simpleMethod() {
+ rewriteRun(
+ java(
+ """
+ package org.gradle.example;
+
+ import groovy.lang.Closure;
+ import org.gradle.api.Action;
+
+ class A {
+ void someMethod(Action
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.intellij.lang.annotations.Language;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.openrewrite.PathUtils;
+import org.openrewrite.RecipeRun;
+import org.openrewrite.Result;
+import org.openrewrite.SourceFile;
+import org.openrewrite.remote.Remote;
+import org.openrewrite.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+import org.openrewrite.text.PlainText;
+
+import java.io.ByteArrayInputStream;
+import java.net.URI;
+import java.nio.file.Paths;
+import java.util.Objects;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.openrewrite.gradle.Assertions.buildGradle;
+import static org.openrewrite.gradle.util.GradleWrapper.WRAPPER_JAR_LOCATION;
+import static org.openrewrite.maven.Assertions.pomXml;
+import static org.openrewrite.properties.Assertions.properties;
+import static org.openrewrite.test.SourceSpecs.dir;
+import static org.openrewrite.test.SourceSpecs.other;
+
+@SuppressWarnings("UnusedProperty")
+class AddGradleWrapperTest implements RewriteTest {
+ @Language("properties")
+ private static final String GRADLE_WRAPPER_PROPERTIES = """
+ distributionBase=GRADLE_USER_HOME
+ distributionPath=wrapper/dists
+ distributionUrl=https\\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
+ zipStoreBase=GRADLE_USER_HOME
+ zipStorePath=wrapper/dists
+ """;
+
+ @Override
+ public void defaults(RecipeSpec spec) {
+ spec.recipe(
+ //language=yaml
+ new ByteArrayInputStream(
+ """
+ ---
+ type: specs.openrewrite.org/v1beta/recipe
+ name: org.openrewrite.test.AddGradleWrapper
+ displayName: Adds a Gradle wrapper
+ description: Add wrapper for gradle version 7.4.2
+ recipeList:
+ - org.openrewrite.gradle.AddGradleWrapper:
+ version: "7.4.2"
+ """.getBytes()
+ ),
+ "org.openrewrite.test.AddGradleWrapper"
+ );
+ }
+
+ private
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class ChangeDependencyArtifactIdTest implements RewriteTest {
+
+ @Test
+ void worksWithEmptyStringConfig() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyArtifactId("org.springframework.boot", "spring-boot-starter", "new-starter", "")),
+ buildGradle(
+ """
+ dependencies {
+ rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
+ implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
+ implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
+ implementation 'org.springframework.boot:spring-boot-starter:2.5.4'
+ implementation 'commons-lang:commons-lang:2.6'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
+ }
+ """,
+ """
+ dependencies {
+ rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
+ implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
+ implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
+ implementation 'org.springframework.boot:new-starter:2.5.4'
+ implementation 'commons-lang:commons-lang:2.6'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyArtifactId(group, artifact, "dewrite-core", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release'
+ api "org.openrewrite:rewrite-core:latest.release"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:dewrite-core:latest.release'
+ api "org.openrewrite:dewrite-core:latest.release"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findMapStyleDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyArtifactId(group, artifact, "dewrite-core", null)),
+ buildGradle(
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
+ }
+ """,
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'dewrite-core', version: 'latest.release'
+ api group: "org.openrewrite", name: "dewrite-core", version: "latest.release"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value ={"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithoutVersion(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyArtifactId(group, artifact, "dewrite-core", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core'
+ api "org.openrewrite:rewrite-core"
+ api group: 'org.openrewrite', name: 'dewrite-core'
+ api group: "org.openrewrite", name: "dewrite-core"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:dewrite-core'
+ api "org.openrewrite:dewrite-core"
+ api group: 'org.openrewrite', name: 'dewrite-core'
+ api group: "org.openrewrite", name: "dewrite-core"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value ={"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithClassifier(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyArtifactId(group, artifact, "dewrite-core", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classifier'
+ api "org.openrewrite:rewrite-core:latest.release:classifier"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:dewrite-core:latest.release:classifier'
+ api "org.openrewrite:dewrite-core:latest.release:classifier"
+ api group: 'org.openrewrite', name: 'dewrite-core', version: 'latest.release', classifier: 'classifier'
+ api group: "org.openrewrite", name: "dewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value ={"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithExt(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyArtifactId(group, artifact, "dewrite-core", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core@ext'
+ api "org.openrewrite:rewrite-core@ext"
+ api 'org.openrewrite:rewrite-core:latest.release@ext'
+ api "org.openrewrite:rewrite-core:latest.release@ext"
+ api 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
+ api "org.openrewrite:rewrite-core:latest.release:classifier@ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", extension: "ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", extension: "ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:dewrite-core@ext'
+ api "org.openrewrite:dewrite-core@ext"
+ api 'org.openrewrite:dewrite-core:latest.release@ext'
+ api "org.openrewrite:dewrite-core:latest.release@ext"
+ api 'org.openrewrite:dewrite-core:latest.release:classifier@ext'
+ api "org.openrewrite:dewrite-core:latest.release:classifier@ext"
+ api group: 'org.openrewrite', name: 'dewrite-core', extension: 'ext'
+ api group: "org.openrewrite", name: "dewrite-core", extension: "ext"
+ api group: 'org.openrewrite', name: 'dewrite-core', version: 'latest.release', extension: 'ext'
+ api group: "org.openrewrite", name: "dewrite-core", version: "latest.release", extension: "ext"
+ api group: 'org.openrewrite', name: 'dewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
+ api group: "org.openrewrite", name: "dewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyClassifierTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyClassifierTest.java
new file mode 100644
index 00000000000..f329b9e5b4a
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyClassifierTest.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class ChangeDependencyClassifierTest implements RewriteTest {
+ @Test
+ void worksWithEmptyStringConfig() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyClassifier("org.openrewrite", "*", "classified", "")),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-gradle:latest.release:classifier'
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-gradle:latest.release:classified'
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyClassifier(group, artifact, "classified", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classifier'
+ api "org.openrewrite:rewrite-core:latest.release:classifier"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classified'
+ api "org.openrewrite:rewrite-core:latest.release:classified"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findMapStyleDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyClassifier(group, artifact, "classified", null)),
+ buildGradle(
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """,
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classified'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classified"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithoutVersion(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyClassifier(group, artifact, "classified", null)),
+ buildGradle(
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", classifier: "classifier"
+ }
+ """,
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', classifier: 'classified'
+ api group: "org.openrewrite", name: "rewrite-core", classifier: "classified"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithClassifier(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyClassifier(group, artifact, "classified", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classifier'
+ api "org.openrewrite:rewrite-core:latest.release:classifier"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classified'
+ api "org.openrewrite:rewrite-core:latest.release:classified"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classified'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classified"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithExt(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyClassifier(group, artifact, "classified", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
+ api "org.openrewrite:rewrite-core:latest.release:classifier@ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", classifier: "classifier"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classified@ext'
+ api "org.openrewrite:rewrite-core:latest.release:classified@ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', classifier: 'classified'
+ api group: "org.openrewrite", name: "rewrite-core", classifier: "classified"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classified'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classified"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classified', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classified", extension: "ext"
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyConfigurationTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyConfigurationTest.java
new file mode 100644
index 00000000000..523c1e405a7
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyConfigurationTest.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class ChangeDependencyConfigurationTest implements RewriteTest {
+ @Test
+ void worksWithEmptyStringConfig() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyConfiguration("org.openrewrite", "*", "implementation", "")),
+ buildGradle(
+ """
+ dependencies {
+ compile 'org.openrewrite:rewrite-gradle:latest.release'
+ }
+ """,
+ """
+ dependencies {
+ implementation 'org.openrewrite:rewrite-gradle:latest.release'
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyConfiguration(group, artifact, "implementation", null)),
+ buildGradle(
+ """
+ dependencies {
+ compile 'org.openrewrite:rewrite-core:latest.release'
+ compile "org.openrewrite:rewrite-core:latest.release"
+ }
+ """,
+ """
+ dependencies {
+ implementation 'org.openrewrite:rewrite-core:latest.release'
+ implementation "org.openrewrite:rewrite-core:latest.release"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findMapStyleDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyConfiguration(group, artifact, "implementation", null)),
+ buildGradle(
+ """
+ dependencies {
+ compile group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
+ compile group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
+ }
+ """,
+ """
+ dependencies {
+ implementation group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
+ implementation group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
+ }
+ """
+ )
+ );
+ }
+
+ @Disabled
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void withoutVersionShouldNotChange(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyConfiguration(group, artifact, "implementation", null)),
+ buildGradle(
+ """
+ dependencies {
+ compile 'org.openrewrite:rewrite-core'
+ compile "org.openrewrite:rewrite-core"
+ compile group: 'org.openrewrite', name: 'rewrite-core'
+ compile group: "org.openrewrite", name: "rewrite-core"
+ }
+ """,
+ """
+ dependencies {
+ implementation 'org.openrewrite:rewrite-core'
+ implementation "org.openrewrite:rewrite-core"
+ implementation group: 'org.openrewrite', name: 'rewrite-core'
+ implementation group: "org.openrewrite", name: "rewrite-core"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithClassifier(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyConfiguration(group, artifact, "implementation", null)),
+ buildGradle(
+ """
+ dependencies {
+ compile 'org.openrewrite:rewrite-core:latest.release:classifier'
+ compile "org.openrewrite:rewrite-core:latest.release:classifier"
+ compile group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ compile group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """,
+ """
+ dependencies {
+ implementation 'org.openrewrite:rewrite-core:latest.release:classifier'
+ implementation "org.openrewrite:rewrite-core:latest.release:classifier"
+ implementation group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ implementation group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithExt(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyConfiguration(group, artifact, "implementation", null)),
+ buildGradle(
+ """
+ dependencies {
+ compile 'org.openrewrite:rewrite-core@ext'
+ compile "org.openrewrite:rewrite-core@ext"
+ compile 'org.openrewrite:rewrite-core:latest.release@ext'
+ compile "org.openrewrite:rewrite-core:latest.release@ext"
+ compile 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
+ compile "org.openrewrite:rewrite-core:latest.release:classifier@ext"
+ compile group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
+ compile group: "org.openrewrite", name: "rewrite-core", extension: "ext"
+ compile group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', extension: 'ext'
+ compile group: "org.openrewrite", name: "rewrite-core", version: "latest.release", extension: "ext"
+ compile group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
+ compile group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
+ }
+ """,
+ """
+ dependencies {
+ implementation 'org.openrewrite:rewrite-core@ext'
+ implementation "org.openrewrite:rewrite-core@ext"
+ implementation 'org.openrewrite:rewrite-core:latest.release@ext'
+ implementation "org.openrewrite:rewrite-core:latest.release@ext"
+ implementation 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
+ implementation "org.openrewrite:rewrite-core:latest.release:classifier@ext"
+ implementation group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
+ implementation group: "org.openrewrite", name: "rewrite-core", extension: "ext"
+ implementation group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', extension: 'ext'
+ implementation group: "org.openrewrite", name: "rewrite-core", version: "latest.release", extension: "ext"
+ implementation group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
+ implementation group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyExtensionTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyExtensionTest.java
new file mode 100644
index 00000000000..a55f5896d5e
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyExtensionTest.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class ChangeDependencyExtensionTest implements RewriteTest {
+ @Test
+ void worksWithEmptyStringConfig() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyExtension("org.openrewrite", "*", "jar", "")),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-gradle:latest.integration@war'
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-gradle:latest.integration@jar'
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyExtension(group, artifact, "jar", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release@war'
+ api "org.openrewrite:rewrite-core:latest.release@war"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release@jar'
+ api "org.openrewrite:rewrite-core:latest.release@jar"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findMapStyleDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyExtension(group, artifact, "jar", null)),
+ buildGradle(
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', ext: 'war'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", ext: "war"
+ }
+ """,
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', ext: 'jar'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", ext: "jar"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithoutVersion(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyExtension(group, artifact, "jar", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core@war'
+ api "org.openrewrite:rewrite-core@war"
+ api group: 'org.openrewrite', name: 'rewrite-core', ext: 'war'
+ api group: "org.openrewrite", name: "rewrite-core", ext: "war"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core@jar'
+ api "org.openrewrite:rewrite-core@jar"
+ api group: 'org.openrewrite', name: 'rewrite-core', ext: 'jar'
+ api group: "org.openrewrite", name: "rewrite-core", ext: "jar"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithClassifier(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyExtension(group, artifact, "jar", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classifier@war'
+ api "org.openrewrite:rewrite-core:latest.release:classifier@war"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', ext: 'war'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", ext: "war"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classifier@jar'
+ api "org.openrewrite:rewrite-core:latest.release:classifier@jar"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', ext: 'jar'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", ext: "jar"
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyGroupIdTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyGroupIdTest.java
new file mode 100755
index 00000000000..ceb9c71e1cc
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyGroupIdTest.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class ChangeDependencyGroupIdTest implements RewriteTest {
+
+ @Test
+ void worksWithEmptyStringConfig() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyGroupId("org.springframework.boot", "spring-boot-starter", "org.newboot", "")),
+ buildGradle(
+ """
+ dependencies {
+ rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
+ implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
+ implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
+ implementation 'org.springframework.boot:spring-boot-starter:2.5.4'
+ implementation 'commons-lang:commons-lang:2.6'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
+ }
+ """,
+ """
+ dependencies {
+ rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
+ implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
+ implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
+ implementation 'org.newboot:spring-boot-starter:2.5.4'
+ implementation 'commons-lang:commons-lang:2.6'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyGroupId(group, artifact, "org.dewrite", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release'
+ api "org.openrewrite:rewrite-core:latest.release"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.dewrite:rewrite-core:latest.release'
+ api "org.dewrite:rewrite-core:latest.release"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findMapStyleDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyGroupId(group, artifact, "org.dewrite", null)),
+ buildGradle(
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
+ }
+ """,
+ """
+ dependencies {
+ api group: 'org.dewrite', name: 'rewrite-core', version: 'latest.release'
+ api group: "org.dewrite", name: "rewrite-core", version: "latest.release"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithoutVersion(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyGroupId(group, artifact, "org.dewrite", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core'
+ api "org.openrewrite:rewrite-core"
+ api group: 'org.openrewrite', name: 'rewrite-core'
+ api group: "org.openrewrite", name: "rewrite-core"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.dewrite:rewrite-core'
+ api "org.dewrite:rewrite-core"
+ api group: 'org.dewrite', name: 'rewrite-core'
+ api group: "org.dewrite", name: "rewrite-core"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithClassifier(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyGroupId(group, artifact, "org.dewrite", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classifier'
+ api "org.openrewrite:rewrite-core:latest.release:classifier"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.dewrite:rewrite-core:latest.release:classifier'
+ api "org.dewrite:rewrite-core:latest.release:classifier"
+ api group: 'org.dewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ api group: "org.dewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithExt(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyGroupId(group, artifact, "org.dewrite", null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core@ext'
+ api "org.openrewrite:rewrite-core@ext"
+ api 'org.openrewrite:rewrite-core:latest.release@ext'
+ api "org.openrewrite:rewrite-core:latest.release@ext"
+ api 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
+ api "org.openrewrite:rewrite-core:latest.release:classifier@ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', ext: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", ext: "ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', ext: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", ext: "ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', ext: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", ext: "ext"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.dewrite:rewrite-core@ext'
+ api "org.dewrite:rewrite-core@ext"
+ api 'org.dewrite:rewrite-core:latest.release@ext'
+ api "org.dewrite:rewrite-core:latest.release@ext"
+ api 'org.dewrite:rewrite-core:latest.release:classifier@ext'
+ api "org.dewrite:rewrite-core:latest.release:classifier@ext"
+ api group: 'org.dewrite', name: 'rewrite-core', ext: 'ext'
+ api group: "org.dewrite", name: "rewrite-core", ext: "ext"
+ api group: 'org.dewrite', name: 'rewrite-core', version: 'latest.release', ext: 'ext'
+ api group: "org.dewrite", name: "rewrite-core", version: "latest.release", ext: "ext"
+ api group: 'org.dewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', ext: 'ext'
+ api group: "org.dewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", ext: "ext"
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyVersionTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyVersionTest.java
new file mode 100755
index 00000000000..be238891ab6
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeDependencyVersionTest.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class ChangeDependencyVersionTest implements RewriteTest {
+
+ @Test
+ void worksWithEmptyStringConfig() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyVersion("org.springframework.boot", "*", "2.5.5", null, "")),
+ buildGradle(
+ """
+ dependencies {
+ rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
+ implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
+ implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
+ implementation 'org.springframework.boot:spring-boot-starter:2.5.4'
+ implementation 'commons-lang:commons-lang:2.6'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
+ }
+ """,
+ """
+ dependencies {
+ rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
+ implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
+ implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
+ implementation 'org.springframework.boot:spring-boot-starter:2.5.5'
+ implementation 'commons-lang:commons-lang:2.6'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyVersion(group, artifact, "latest.integration", null, null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release'
+ api "org.openrewrite:rewrite-core:latest.release"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.integration'
+ api "org.openrewrite:rewrite-core:latest.integration"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void findMapStyleDependency(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyVersion(group, artifact, "latest.integration", null, null)),
+ buildGradle(
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
+ }
+ """,
+ """
+ dependencies {
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.integration'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.integration"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void withoutVersionShouldNotChange(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyVersion(group, artifact, "latest.integration", null, null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core'
+ api "org.openrewrite:rewrite-core"
+ api group: 'org.openrewrite', name: 'rewrite-core'
+ api group: "org.openrewrite", name: "rewrite-core"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithClassifier(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyVersion(group, artifact, "latest.integration", null, null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release:classifier'
+ api "org.openrewrite:rewrite-core:latest.release:classifier"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.integration:classifier'
+ api "org.openrewrite:rewrite-core:latest.integration:classifier"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.integration', classifier: 'classifier'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.integration", classifier: "classifier"
+ }
+ """
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @CsvSource(value = {"org.openrewrite:rewrite-core", "*:*"}, delimiterString = ":")
+ void worksWithExt(String group, String artifact) {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeDependencyVersion(group, artifact, "latest.integration", null, null)),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core@ext'
+ api "org.openrewrite:rewrite-core@ext"
+ api 'org.openrewrite:rewrite-core:latest.release@ext'
+ api "org.openrewrite:rewrite-core:latest.release@ext"
+ api 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
+ api "org.openrewrite:rewrite-core:latest.release:classifier@ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", extension: "ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", extension: "ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
+ }
+ """,
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core@ext'
+ api "org.openrewrite:rewrite-core@ext"
+ api 'org.openrewrite:rewrite-core:latest.integration@ext'
+ api "org.openrewrite:rewrite-core:latest.integration@ext"
+ api 'org.openrewrite:rewrite-core:latest.integration:classifier@ext'
+ api "org.openrewrite:rewrite-core:latest.integration:classifier@ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", extension: "ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.integration', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.integration", extension: "ext"
+ api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.integration', classifier: 'classifier', extension: 'ext'
+ api group: "org.openrewrite", name: "rewrite-core", version: "latest.integration", classifier: "classifier", extension: "ext"
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeJavaCompatibilityTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeJavaCompatibilityTest.java
new file mode 100644
index 00000000000..58eff6a6890
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/ChangeJavaCompatibilityTest.java
@@ -0,0 +1,441 @@
+/*
+ * Copyright 2022 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class ChangeJavaCompatibilityTest implements RewriteTest {
+ @Nested
+ @DisplayName("When requested version is an integer")
+ class NewInteger extends BaseTest {
+ NewInteger() {
+ super("8");
+ }
+ }
+
+ @Nested
+ @DisplayName("When requested version is a double")
+ class NewDouble extends BaseTest {
+ NewDouble() {
+ super("1.8");
+ }
+ }
+
+ @Nested
+ @DisplayName("When requested version is a string (double quotes)")
+ class NewStringDoubleQuoted extends BaseTest {
+ NewStringDoubleQuoted() {
+ super("\"1.8\"");
+ }
+ }
+
+ @Nested
+ @DisplayName("When requested version is a string (single quotes -tmp)")
+ class NewStringSingleQuoted extends BaseTest {
+ NewStringSingleQuoted() {
+ super("'1.8'");
+ }
+ }
+
+ @Nested
+ @DisplayName("When requested version is an enum (shorthand)")
+ class NewEnumShorthand extends BaseTest {
+ NewEnumShorthand() {
+ super("VERSION_1_8");
+ }
+ }
+
+ @Nested
+ @DisplayName("When requested version is an enum")
+ class NewEnum extends BaseTest {
+ NewEnum() {
+ super("JavaVersion.VERSION_1_8");
+ }
+ }
+}
+
+@SuppressWarnings("GroovyUnusedAssignment")
+abstract class BaseTest implements RewriteTest {
+ private final String newVersion;
+
+ BaseTest(String newVersion) {
+ this.newVersion = newVersion;
+ }
+
+ @Test
+ void changeSourceCompatibility() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "source")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ sourceCompatibility = 7
+ """,
+ """
+ plugins {
+ java
+ }
+
+ sourceCompatibility = %s
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeTargetCompatibility() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "target")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ targetCompatibility = '7'
+ """,
+ """
+ plugins {
+ java
+ }
+
+ targetCompatibility = %s
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeSetSourceCompatibility() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "source")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ setSourceCompatibility "7"
+ """,
+ """
+ plugins {
+ java
+ }
+
+ setSourceCompatibility %s
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeSetTargetCompatibility() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "target")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ setTargetCompatibility 1.7
+ """,
+ """
+ plugins {
+ java
+ }
+
+ setTargetCompatibility %s
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeSourceCompatibility_JavaPluginExtension() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "source")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ java {
+ sourceCompatibility = "1.7"
+ }
+ """,
+ """
+ plugins {
+ java
+ }
+
+ java {
+ sourceCompatibility = %s
+ }
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeTargetCompatibility_JavaPluginExtension() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "target")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ java {
+ targetCompatibility = '1.7'
+ }
+ """,
+ """
+ plugins {
+ java
+ }
+
+ java {
+ targetCompatibility = %s
+ }
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeSourceCompatibility_CompileJava() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "source")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ compileJava {
+ sourceCompatibility = JavaVersion.VERSION_1_7
+ }
+ """,
+ """
+ plugins {
+ java
+ }
+
+ compileJava {
+ sourceCompatibility = %s
+ }
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeTargetCompatibility_CompileJava() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "target")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ compileJava {
+ targetCompatibility = "1.7"
+ }
+ """,
+ """
+ plugins {
+ java
+ }
+
+ compileJava {
+ targetCompatibility = %s
+ }
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeSourceCompatibility_TasksNamedCompileJava() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "source")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ tasks.named("compileJava") {
+ sourceCompatibility = "1.7"
+ }
+ """,
+ """
+ plugins {
+ java
+ }
+
+ tasks.named("compileJava") {
+ sourceCompatibility = %s
+ }
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeTargetCompatibility_TasksNamedCompileJava() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "target")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ tasks.named("compileJava") {
+ targetCompatibility = "1.7"
+ }
+ """,
+ """
+ plugins {
+ java
+ }
+
+ tasks.named("compileJava") {
+ targetCompatibility = %s
+ }
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeSourceCompatibility_TasksWithTypeJavaCompile() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "source")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ tasks.withType(JavaCompile).configureEach {
+ sourceCompatibility = "1.7"
+ }
+ """,
+ """
+ plugins {
+ java
+ }
+
+ tasks.withType(JavaCompile).configureEach {
+ sourceCompatibility = %s
+ }
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeTargetCompatibility_TasksWithTypeJavaCompile() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "target")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ tasks.withType(JavaCompile).configureEach {
+ targetCompatibility = "1.7"
+ }
+ """,
+ """
+ plugins {
+ java
+ }
+
+ tasks.withType(JavaCompile).configureEach {
+ targetCompatibility = %s
+ }
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeSourceCompatibility_JavaPluginExtensionFieldAccess() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "source")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ java.sourceCompatibility = "1.7"
+ """,
+ """
+ plugins {
+ java
+ }
+
+ java.sourceCompatibility = %s
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ @Test
+ void changeTargetCompatibility_JavaPluginExtensionFieldAccess() {
+ rewriteRun(
+ spec -> spec.recipe(new ChangeJavaCompatibility(newVersion, "target")),
+ buildGradle(
+ """
+ plugins {
+ java
+ }
+
+ java.targetCompatibility = "1.7"
+ """,
+ """
+ plugins {
+ java
+ }
+
+ java.targetCompatibility = %s
+ """.formatted(coerce(newVersion))
+ )
+ );
+ }
+
+ private String coerce(String version) {
+ return version.startsWith("VERSION_") ?
+ "JavaVersion." + version : version;
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/DependencyUseMapNotationTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/DependencyUseMapNotationTest.java
new file mode 100755
index 00000000000..e16f56d28e6
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/DependencyUseMapNotationTest.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class DependencyUseMapNotationTest implements RewriteTest {
+
+ @Override
+ public void defaults(RecipeSpec spec) {
+ spec.recipe(new DependencyUseMapNotation());
+ }
+
+ @Test
+ void basicString() {
+ rewriteRun(
+ buildGradle(
+ """
+ dependencies {
+ api('org.openrewrite:rewrite-core:latest.release')
+ implementation "group:artifact:version"
+ }
+ """,
+ """
+ dependencies {
+ api(group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release')
+ implementation group: 'group', name: 'artifact', version: 'version'
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void withGString() {
+ rewriteRun(
+ buildGradle(
+ """
+ def version = "latest.release"
+ dependencies {
+ api("org.openrewrite:rewrite-core:$version")
+ implementation "group:artifact:$version"
+ }
+ """,
+ """
+ def version = "latest.release"
+ dependencies {
+ api(group: 'org.openrewrite', name: 'rewrite-core', version: version)
+ implementation group: 'group', name: 'artifact', version: version
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void withExclusion() {
+ rewriteRun(
+ buildGradle(
+ """
+ dependencies {
+ api("org.openrewrite:rewrite-core:latest.release") {
+ exclude group: "group", module: "artifact"
+ }
+ implementation "group:artifact:version", {
+ exclude group: "group2", module: "artifact2"
+ }
+ }
+ """,
+ """
+ dependencies {
+ api(group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release') {
+ exclude group: "group", module: "artifact"
+ }
+ implementation group: 'group', name: 'artifact', version: 'version', {
+ exclude group: "group2", module: "artifact2"
+ }
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void withGStringAndExclusion() {
+ rewriteRun(
+ buildGradle(
+ """
+ dependencies {
+ api("org.openrewrite:rewrite-core:$version") {
+ exclude group: "group", module: "artifact"
+ }
+ implementation "group:artifact:$version", {
+ exclude group: "group2", module: "artifact2"
+ }
+ }
+ """,
+ """
+ dependencies {
+ api(group: 'org.openrewrite', name: 'rewrite-core', version: version) {
+ exclude group: "group", module: "artifact"
+ }
+ implementation group: 'group', name: 'artifact', version: version, {
+ exclude group: "group2", module: "artifact2"
+ }
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/DependencyUseStringNotationTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/DependencyUseStringNotationTest.java
new file mode 100644
index 00000000000..d0c32baa2b0
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/DependencyUseStringNotationTest.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class DependencyUseStringNotationTest implements RewriteTest {
+
+ @Override
+ public void defaults(RecipeSpec spec) {
+ spec.recipe(new DependencyUseStringNotation());
+ }
+
+ @Test
+ void basicMap() {
+ rewriteRun(
+ buildGradle(
+ """
+ dependencies {
+ api(group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release')
+ implementation group: 'group', name: 'artifact', version: 'version'
+ }
+ """,
+ """
+ dependencies {
+ api("org.openrewrite:rewrite-core:latest.release")
+ implementation "group:artifact:version"
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void basicMapLiteral() {
+ rewriteRun(
+ buildGradle(
+ """
+ dependencies {
+ api([group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'])
+ }
+ """,
+ """
+ dependencies {
+ api("org.openrewrite:rewrite-core:latest.release")
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void withGString() {
+ rewriteRun(
+ buildGradle(
+ """
+ def version = "latest.release"
+ dependencies {
+ api(group: 'org.openrewrite', name: 'rewrite-core', version: version)
+ implementation group: 'group', name: 'artifact', version: version
+ }
+ """,
+ """
+ def version = "latest.release"
+ dependencies {
+ api("org.openrewrite:rewrite-core:$version")
+ implementation "group:artifact:$version"
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void withoutVersion() {
+ rewriteRun(
+ buildGradle(
+ """
+ dependencies {
+ api(group: "org.openrewrite", name: "rewrite-core")
+ implementation group: "group", name: "artifact"
+ }
+ """,
+ """
+ dependencies {
+ api("org.openrewrite:rewrite-core")
+ implementation "group:artifact"
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void withExclusion() {
+ rewriteRun(
+ buildGradle(
+ """
+ dependencies {
+ api(group: "org.openrewrite", name: "rewrite-core", version: "latest.release") {
+ exclude group: "group", module: "artifact"
+ }
+ }
+ """,
+ """
+ dependencies {
+ api("org.openrewrite:rewrite-core:latest.release") {
+ exclude group: "group", module: "artifact"
+ }
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void withGStringExclusion() {
+ rewriteRun(
+ buildGradle(
+ """
+ def version = "latest.release"
+ dependencies {
+ api(group: "org.openrewrite", name: "rewrite-core", version: version) {
+ exclude group: "group", module: "artifact"
+ }
+ }
+ """,
+ """
+ def version = "latest.release"
+ dependencies {
+ api("org.openrewrite:rewrite-core:$version") {
+ exclude group: "group", module: "artifact"
+ }
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/GradleParserTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/GradleParserTest.java
index e490cc073ce..95bc6fadfdc 100644
--- a/rewrite-gradle/src/test/java/org/openrewrite/gradle/GradleParserTest.java
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/GradleParserTest.java
@@ -18,23 +18,22 @@
import org.junit.jupiter.api.Test;
import org.openrewrite.test.RewriteTest;
-import static org.openrewrite.gradle.Assertions.buildGradle;
import static org.openrewrite.gradle.Assertions.settingsGradle;
public class GradleParserTest implements RewriteTest {
@Test
- void buildAndSettingsGradle() {
+ void buildGradleAndSettingsGradle() {
rewriteRun(
settingsGradle(
"""
plugins {
id 'com.gradle.enterprise' version '3.11.3'
}
-
+
gradleEnterprise {
server = 'https://enterprise-samples.gradle.com'
-
+
buildScan {
publishAlways()
}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/FindDependencyTest.kt b/rewrite-gradle/src/test/java/org/openrewrite/gradle/RemoveRepositoryTest.java
similarity index 51%
rename from rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/FindDependencyTest.kt
rename to rewrite-gradle/src/test/java/org/openrewrite/gradle/RemoveRepositoryTest.java
index 4398f712c29..1d98557cfc6 100755
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/FindDependencyTest.kt
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/RemoveRepositoryTest.java
@@ -13,25 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.openrewrite.gradle.search
+package org.openrewrite.gradle;
-import org.junit.jupiter.api.Test
-import org.openrewrite.gradle.GradleRecipeTest
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RewriteTest;
-class FindDependencyTest : GradleRecipeTest {
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class RemoveRepositoryTest implements RewriteTest {
@Test
- fun findDependency() = assertChanged(
- recipe = FindDependency("org.openrewrite", "rewrite-core", "api"),
- before = """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release'
- }
- """,
- after = """
- dependencies {
- /*~~>*/api 'org.openrewrite:rewrite-core:latest.release'
- }
- """
- )
+ void removeJcenter() {
+ rewriteRun(
+ spec -> spec.recipe(new RemoveRepository("jcenter")),
+ buildGradle(
+ """
+ repositories {
+ jcenter()
+ }
+ """,
+ """
+ repositories {
+ \s
+ }
+ """
+ )
+ );
+ }
}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpdateGradleWrapperTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpdateGradleWrapperTest.java
new file mode 100755
index 00000000000..26ed3ee4bf9
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpdateGradleWrapperTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2022 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.openrewrite.PathUtils;
+import org.openrewrite.RecipeRun;
+import org.openrewrite.Result;
+import org.openrewrite.SourceFile;
+import org.openrewrite.internal.lang.Nullable;
+import org.openrewrite.remote.Remote;
+import org.openrewrite.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+import org.openrewrite.test.SourceSpecs;
+import org.openrewrite.text.PlainText;
+
+import java.net.URI;
+import java.util.Objects;
+import java.util.function.UnaryOperator;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.openrewrite.gradle.util.GradleWrapper.*;
+import static org.openrewrite.properties.Assertions.properties;
+import static org.openrewrite.test.SourceSpecs.other;
+import static org.openrewrite.test.SourceSpecs.text;
+
+@SuppressWarnings("UnusedProperty")
+class UpdateGradleWrapperTest implements RewriteTest {
+ private final UnaryOperator<@Nullable String> notEmpty = actual -> {
+ assertThat(actual).isNotNull();
+ return actual + "\n";
+ };
+
+ private final SourceSpecs gradlew = text("", notEmpty, spec -> spec.path(WRAPPER_SCRIPT_LOCATION));
+ private final SourceSpecs gradlewBat = text("", notEmpty, spec -> spec.path(WRAPPER_BATCH_LOCATION));
+ private final SourceSpecs gradleWrapperJarQuark = other("", spec -> spec.path(WRAPPER_JAR_LOCATION));
+
+ @Override
+ public void defaults(RecipeSpec spec) {
+ spec.recipe(new UpdateGradleWrapper("7.4.2", null));
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"gradle\\wrapper\\gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.properties"})
+ void updateVersionAndDistribution(String osPath) {
+ rewriteRun(
+ spec -> spec.afterRecipe(run -> {
+ var gradleSh = result(run, PlainText.class, "gradlew");
+ assertThat(gradleSh.getText()).isNotBlank();
+
+ var gradleBat = result(run, PlainText.class, "gradlew.bat");
+ assertThat(gradleBat.getText()).isNotBlank();
+
+ var gradleWrapperJar = result(run, Remote.class, "gradle-wrapper.jar");
+ assertThat(PathUtils.equalIgnoringSeparators(gradleWrapperJar.getSourcePath(), WRAPPER_JAR_LOCATION)).isTrue();
+ assertThat(gradleWrapperJar.getUri()).isEqualTo(URI.create("https://services.gradle.org/distributions/gradle-7.4.2-bin.zip"));
+ }),
+ properties(
+ """
+ distributionBase=GRADLE_USER_HOME
+ distributionPath=wrapper/dists
+ distributionUrl=https\\://services.gradle.org/distributions/gradle-7.4-all.zip
+ zipStoreBase=GRADLE_USER_HOME
+ zipStorePath=wrapper/dists
+ """,
+ """
+ distributionBase=GRADLE_USER_HOME
+ distributionPath=wrapper/dists
+ distributionUrl=https\\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
+ zipStoreBase=GRADLE_USER_HOME
+ zipStorePath=wrapper/dists
+ """,
+ spec -> spec.path(osPath)
+ ),
+ gradlew,
+ gradlewBat,
+ gradleWrapperJarQuark
+ );
+ }
+
+ private
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.gradle.plugins.UpgradePluginVersion;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class UpgradePluginVersionTest implements RewriteTest {
+
+ @Test
+ void upgradePlugin() {
+ rewriteRun(
+ spec -> spec.recipe(new UpgradePluginVersion("com.jfrog.bintray", "latest.patch", null)),
+ buildGradle(
+ """
+ plugins {
+ id 'com.jfrog.bintray' version '1.7.0'
+ id 'com.github.johnrengelman.shadow' version '6.1.0'
+ }
+ """,
+ """
+ plugins {
+ id 'com.jfrog.bintray' version '1.7.3'
+ id 'com.github.johnrengelman.shadow' version '6.1.0'
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void upgradePluginGlob() {
+ rewriteRun(
+ spec -> spec.recipe(new UpgradePluginVersion("com.jfrog.*", "1.8.X", null)),
+ buildGradle(
+ """
+ plugins {
+ id 'com.jfrog.bintray' version '1.8.2'
+ }
+ """,
+ """
+ plugins {
+ id 'com.jfrog.bintray' version '1.8.5'
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void exactVersionDoesNotHaveToBeResolvable() {
+ rewriteRun(
+ spec -> spec.recipe(new UpgradePluginVersion("com.madeup.doesnotexist", "2.0", null)),
+ buildGradle(
+ """
+ plugins {
+ id 'com.madeup.doesnotexist' version '1.0'
+ }
+ """,
+ """
+ plugins {
+ id 'com.madeup.doesnotexist' version '2.0'
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/package-info.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/package-info.java
similarity index 100%
rename from rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/package-info.java
rename to rewrite-gradle/src/test/java/org/openrewrite/gradle/package-info.java
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindDependencyHandlerTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindDependencyHandlerTest.java
new file mode 100644
index 00000000000..1ae10ec24ba
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindDependencyHandlerTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle.search;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+import static org.openrewrite.test.RewriteTest.fromRuntimeClasspath;
+
+class FindDependencyHandlerTest implements RewriteTest {
+ @Test
+ void findDependenciesBlock() {
+ rewriteRun(
+ spec -> spec.recipe(fromRuntimeClasspath("org.openrewrite.gradle.search.FindDependencyHandler")),
+ buildGradle(
+ """
+ dependencies {
+ api 'com.google.guava:guava:23.0'
+ }
+ """,
+ """
+ /*~~>*/dependencies {
+ api 'com.google.guava:guava:23.0'
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindDependencyTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindDependencyTest.java
new file mode 100755
index 00000000000..4f107b62987
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindDependencyTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle.search;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class FindDependencyTest implements RewriteTest {
+
+ @Test
+ void findDependency() {
+ rewriteRun(
+ spec -> spec.recipe(new FindDependency("org.openrewrite", "rewrite-core", "api")),
+ buildGradle(
+ """
+ dependencies {
+ api 'org.openrewrite:rewrite-core:latest.release'
+ }
+ """,
+ """
+ dependencies {
+ /*~~>*/api 'org.openrewrite:rewrite-core:latest.release'
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindGradleProjectTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindGradleProjectTest.java
index f5ecaf19dce..521ab0738e5 100644
--- a/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindGradleProjectTest.java
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindGradleProjectTest.java
@@ -51,8 +51,8 @@ void isGradleGroovyProject() {
@Test
void isGradleKotlinProject() {
rewriteRun(
- //language=kotlin
text(
+ //language=kotlin
"""
plugins {
id("java")
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindPluginsTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindPluginsTest.java
index edec8ef3be8..81551764af0 100644
--- a/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindPluginsTest.java
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/search/FindPluginsTest.java
@@ -31,7 +31,8 @@ public void defaults(RecipeSpec spec) {
@Test
void findPlugin() {
rewriteRun(
- buildGradle("""
+ buildGradle(
+ """
plugins {
id 'com.jfrog.bintray' version '1.8.5'
}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/security/UseHttpsForRepositoriesTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/security/UseHttpsForRepositoriesTest.java
new file mode 100644
index 00000000000..49b063abb31
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/security/UseHttpsForRepositoriesTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2022 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle.security;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+@SuppressWarnings("HttpUrlsUsage")
+class UseHttpsForRepositoriesTest implements RewriteTest {
+
+ @Override
+ public void defaults(RecipeSpec spec) {
+ spec.recipe(new UseHttpsForRepositories());
+ }
+
+ @Test
+ void unchangedUseOfHttps() {
+ rewriteRun(
+ buildGradle(
+ """
+ repositories {
+ maven { url 'https://repo.spring.example.com/libs-release-local' }
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void updateUnwrappedInvocationToUseHttpsSingleQuote() {
+ rewriteRun(
+ buildGradle(
+ """
+ repositories {
+ maven { url 'http://repo.spring.example.com/libs-release-local' }
+ }
+ """,
+ """
+ repositories {
+ maven { url 'https://repo.spring.example.com/libs-release-local' }
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void updateUnwrappedInvocationToUseHttpsDoubleQuote() {
+ rewriteRun(
+ buildGradle(
+ """
+ repositories {
+ maven { url "http://repo.spring.example.com/libs-release-local" }
+ }
+ """,
+ """
+ repositories {
+ maven { url "https://repo.spring.example.com/libs-release-local" }
+ }
+ """
+ )
+ );
+ }
+
+ @Test
+ void updateUnwrappedInvocationToUseHttpsGString() {
+ rewriteRun(
+ buildGradle(
+ """
+ repositories {
+ maven {
+ def subRepo = properties.snapshot ? 'snapshot' : 'release'
+ url "http://repo.spring.example.com/libs-release-local/$subRepo"
+ }
+ }
+ """,
+ """
+ repositories {
+ maven {
+ def subRepo = properties.snapshot ? 'snapshot' : 'release'
+ url "https://repo.spring.example.com/libs-release-local/$subRepo"
+ }
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/BuildscriptTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/BuildscriptTest.java
new file mode 100755
index 00000000000..2ae98a462d3
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/BuildscriptTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle.tree;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class BuildscriptTest implements RewriteTest {
+
+ @Test
+ void buildscriptWithDependencies() {
+ rewriteRun(
+ buildGradle(
+ """
+ buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.netflix.nebula:nebula-dependency-recommender:9.1.1'
+ classpath 'com.netflix.nebula:gradle-netflixoss-project-plugin:9.1.0'
+ }
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/ExtTest.kt b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/ExtTest.java
similarity index 63%
rename from rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/ExtTest.kt
rename to rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/ExtTest.java
index cde9a16f883..b2c6501960d 100755
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/ExtTest.kt
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/ExtTest.java
@@ -13,24 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.openrewrite.gradle.tree
+package org.openrewrite.gradle.tree;
-import org.junit.jupiter.api.Test
-import org.openrewrite.Issue
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
+import org.junit.jupiter.api.Test;
+import org.openrewrite.Issue;
+import org.openrewrite.test.RewriteTest;
-class ExtTest : RewriteTest {
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class ExtTest implements RewriteTest {
@Issue("https://github.com/openrewrite/rewrite/issues/1236")
@Test
- fun basicExt() = rewriteRun(
- buildGradle(
- """
- ext {
- foo = "bar"
- }
+ void basicExt() {
+ rewriteRun(
+ buildGradle(
"""
- )
- )
+ ext {
+ foo = "bar"
+ }
+ """
+ )
+ );
+ }
}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/PluginsTest.kt b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/PluginsTest.java
similarity index 56%
rename from rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/PluginsTest.kt
rename to rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/PluginsTest.java
index 5296bea1f00..60e6d922fbc 100755
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/PluginsTest.kt
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/PluginsTest.java
@@ -13,22 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.openrewrite.gradle.tree
+package org.openrewrite.gradle.tree;
-import org.junit.jupiter.api.Test
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class PluginsTest implements RewriteTest {
-class PluginsTest : RewriteTest {
@Test
- fun applySomePlugins() = rewriteRun(
- buildGradle(
- """
- plugins {
- id 'me.champeau.gradle.jmh' version '0.5.2'
- id "com.github.spotbugs" version "4.6.0" apply false
- }
+ void applySomePlugins() {
+ rewriteRun(
+ buildGradle(
"""
- )
- )
+ plugins {
+ id 'me.champeau.gradle.jmh' version '0.5.2'
+ id "com.github.spotbugs" version "4.6.0" apply false
+ }
+ """
+ )
+ );
+ }
}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/RepositoryTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/RepositoryTest.java
new file mode 100755
index 00000000000..7d340703343
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/RepositoryTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle.tree;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.Issue;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class RepositoryTest implements RewriteTest {
+
+ @Test
+ void builtInFunctions() {
+ rewriteRun(
+ buildGradle(
+ """
+ repositories {
+ mavenCentral()
+ mavenLocal()
+ }
+ """
+ )
+ );
+ }
+
+ @Issue("https://github.com/openrewrite/rewrite/issues/1253")
+ @Test
+ void customMavenRepo() {
+ rewriteRun(
+ buildGradle(
+ """
+ repositories {
+ maven {
+ url "https://repo.spring.io/release"
+ }
+ maven {
+ setUrl("https://repo.spring.io/release")
+ }
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/TaskTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/TaskTest.java
new file mode 100755
index 00000000000..bd3ada9fb02
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/TaskTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle.tree;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.Issue;
+import org.openrewrite.test.RewriteTest;
+import org.openrewrite.test.TypeValidation;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class TaskTest implements RewriteTest {
+
+ @Issue("https://github.com/openrewrite/rewrite/issues/1236")
+ @Test
+ void declareTaskOldStyle() {
+ rewriteRun(
+ spec -> spec.typeValidationOptions(TypeValidation.none()),
+ buildGradle(
+ """
+ task(testWithCloud, type: Test) {
+ useTestNG()
+ options.excludeGroups = [] as Set
+ }
+ """
+ )
+ );
+ }
+
+ @Issue("https://github.com/openrewrite/rewrite/issues/1929")
+ @Test
+ void testDsl() {
+ rewriteRun(
+ spec -> spec.typeValidationOptions(TypeValidation.none()),
+ buildGradle(
+ """
+ test {
+ // Ex: -PexcludeTests=com/google/cloud/healthcare/etl/runner/hl7v2tofhir/integ/*
+ if (project.hasProperty('excludeTests')) {
+ exclude project.property('excludeTests') as String
+ }
+ dependsOn('buildDeps')
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/TestTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/TestTest.java
new file mode 100755
index 00000000000..eed8bf6428e
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/tree/TestTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openrewrite.gradle.tree;
+
+import org.junit.jupiter.api.Test;
+import org.openrewrite.test.RewriteTest;
+
+import static org.openrewrite.gradle.Assertions.buildGradle;
+
+class TestTest implements RewriteTest {
+
+ @Test
+ void testDsl() {
+ rewriteRun(
+ buildGradle(
+ """
+ test {
+ useJUnit()
+ useTestNG()
+ useJUnitPlatform()
+ systemProperty 'some.prop', 'value'
+ include 'org/foo/**'
+ exclude 'org/boo/**'
+ testLogging.showStandardStreams = true
+ minHeapSize = "128m"
+ maxHeapSize = "512m"
+ jvmArgs '-XX:MaxPermSize=256m'
+ failFast = true
+ }
+ """
+ )
+ );
+ }
+}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ActivateStyleTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ActivateStyleTest.kt
deleted file mode 100644
index fb3b4b15e3e..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ActivateStyleTest.kt
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2022 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-@file:Suppress("UnusedProperty")
-
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.properties.Assertions.properties
-import org.openrewrite.test.RecipeSpec
-import org.openrewrite.test.RewriteTest
-import org.openrewrite.test.SourceSpecs.other
-import org.openrewrite.test.TypeValidation
-
-class ActivateStyleTest : RewriteTest {
-
- override fun defaults(spec: RecipeSpec) {
- spec.recipe(ActivateStyle("org.openrewrite.java.IntelliJ", true))
- .typeValidationOptions(TypeValidation.none())
- }
-
- @Test
- fun addToRewriteDsl() = rewriteRun(
- buildGradle("""
- plugins {
- id("java")
- id("org.openrewrite.rewrite")
- }
-
- rewrite {
- activeRecipe("org.openrewrite.java.format.AutoFormat")
- }
- """,
- """
- plugins {
- id("java")
- id("org.openrewrite.rewrite")
- }
-
- rewrite {
- activeRecipe("org.openrewrite.java.format.AutoFormat")
- activeStyle("org.openrewrite.java.IntelliJ")
- }
- """)
- )
-
- @Test
- fun addToRewriteDslExistingStyle() = rewriteRun(
- { spec -> spec.recipe(ActivateStyle("org.openrewrite.java.IntelliJ", false)) },
- buildGradle("""
- plugins {
- id("java")
- id("org.openrewrite.rewrite")
- }
-
- rewrite {
- activeRecipe("org.openrewrite.java.format.AutoFormat")
- activeStyle("otherStyle")
- }
- """,
- """
- plugins {
- id("java")
- id("org.openrewrite.rewrite")
- }
-
- rewrite {
- activeRecipe("org.openrewrite.java.format.AutoFormat")
- activeStyle("otherStyle", "org.openrewrite.java.IntelliJ")
- }
- """)
- )
-
- @Test
- fun addToRewriteDslOverwriteStyle() = rewriteRun(
- buildGradle("""
- plugins {
- id("java")
- id("org.openrewrite.rewrite")
- }
-
- rewrite {
- activeRecipe("org.openrewrite.java.format.AutoFormat")
- activeStyle("com.your.Style")
- }
- """,
- """
- plugins {
- id("java")
- id("org.openrewrite.rewrite")
- }
-
- rewrite {
- activeRecipe("org.openrewrite.java.format.AutoFormat")
- activeStyle("org.openrewrite.java.IntelliJ")
- }
- """)
- )
-
- @Test
- fun addToProperties() = rewriteRun(
- other("") { spec -> spec.path("build.gradle.kts") },
- properties("""
- org.gradle.someProp=true
- """,
- """
- org.gradle.someProp=true
- systemProp.rewrite.activeStyles=org.openrewrite.java.IntelliJ
- """) { spec -> spec.path("gradle.properties") }
- )
-
- @Test
- fun addToPropertiesStyles() = rewriteRun(
- { spec -> spec.recipe(ActivateStyle("org.openrewrite.java.IntelliJ", false)) },
- other("") { spec -> spec.path("build.gradle.kts") },
- properties(
- """
- org.gradle.someProp=true
- systemProp.rewrite.activeStyles=org.openrewrite.java.Other
- """,
- """
- org.gradle.someProp=true
- systemProp.rewrite.activeStyles=org.openrewrite.java.Other,org.openrewrite.java.IntelliJ
- """
- ) { spec -> spec.path("gradle.properties") }
- )
-
- @Test
- fun overwritePropertiesStyles() = rewriteRun(
- other("") { spec -> spec.path("build.gradle.kts") },
- properties(
- """
- org.gradle.someProp=true
- systemProp.rewrite.activeStyles=org.openrewrite.java.Other
- """,
- """
- org.gradle.someProp=true
- systemProp.rewrite.activeStyles=org.openrewrite.java.IntelliJ
- """
- ) { spec -> spec.path("gradle.properties") }
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/AddDelegatesToGradleApiTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/AddDelegatesToGradleApiTest.kt
deleted file mode 100644
index 544a03cbc98..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/AddDelegatesToGradleApiTest.kt
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Copyright 2022 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.java.Assertions.java
-import org.openrewrite.java.JavaParser
-import org.openrewrite.test.RecipeSpec
-import org.openrewrite.test.RewriteTest
-
-class AddDelegatesToGradleApiTest : RewriteTest {
-
- override fun defaults(spec: RecipeSpec) {
- spec.parser( JavaParser.fromJavaVersion().classpath("groovy", "gradle-base-services") )
- .recipe(AddDelegatesToGradleApi())
- }
-
- @Test
- fun simpleMethod() = rewriteRun(
- java("""
- package org.gradle.example;
-
- import groovy.lang.Closure;
- import org.gradle.api.Action;
-
- class A {
- void someMethod(Action
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-import org.openrewrite.PathUtils
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.gradle.util.GradleWrapper.WRAPPER_JAR_LOCATION
-import org.openrewrite.maven.Assertions.pomXml
-import org.openrewrite.properties.Assertions.properties
-import org.openrewrite.remote.Remote
-import org.openrewrite.test.RecipeSpec
-import org.openrewrite.test.RewriteTest
-import org.openrewrite.test.SourceSpecs.dir
-import org.openrewrite.test.SourceSpecs.other
-import org.openrewrite.text.PlainText
-import java.net.URI
-import java.nio.file.Paths
-
-@Suppress("UnusedProperty")
-class AddGradleWrapperTest : RewriteTest {
- companion object {
- const val GRADLE_WRAPPER_PROPERTIES = """
- distributionBase=GRADLE_USER_HOME
- distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
- zipStoreBase=GRADLE_USER_HOME
- zipStorePath=wrapper/dists
- """
- }
-
- override fun defaults(spec: RecipeSpec) {
- spec.recipe(
- //language=yaml
- """
- ---
- type: specs.openrewrite.org/v1beta/recipe
- name: org.openrewrite.test.AddGradleWrapper
- displayName: Adds a Gradle wrapper
- description: Add wrapper for gradle version 7.4.2
- recipeList:
- - org.openrewrite.gradle.AddGradleWrapper:
- version: "7.4.2"
- """.trimIndent().byteInputStream(), "org.openrewrite.test.AddGradleWrapper"
- )
- }
-
- @Test
- fun addWrapper() = rewriteRun(
- { spec ->
- spec.afterRecipe { run ->
- val gradleSh =
- run.results.map { it.after }.filterIsInstance
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.CsvSource
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class ChangeDependencyArtifactIdTest : RewriteTest {
-
- @Test
- fun worksWithEmptyStringConfig() = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyArtifactId("org.springframework.boot", "spring-boot-starter", "new-starter", ""))
- },
- buildGradle(
- """
- dependencies {
- rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
- implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
- implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
- implementation 'org.springframework.boot:spring-boot-starter:2.5.4'
- implementation 'commons-lang:commons-lang:2.6'
- testImplementation 'org.springframework.boot:spring-boot-starter-test'
- }
- """,
- """
- dependencies {
- rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
- implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
- implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
- implementation 'org.springframework.boot:new-starter:2.5.4'
- implementation 'commons-lang:commons-lang:2.6'
- testImplementation 'org.springframework.boot:spring-boot-starter-test'
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyArtifactId(group, artifact, "dewrite-core", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release'
- api "org.openrewrite:rewrite-core:latest.release"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:dewrite-core:latest.release'
- api "org.openrewrite:dewrite-core:latest.release"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findMapStyleDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyArtifactId(group, artifact, "dewrite-core", null))
- },
- buildGradle(
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
- }
- """,
- """
- dependencies {
- api group: 'org.openrewrite', name: 'dewrite-core', version: 'latest.release'
- api group: "org.openrewrite", name: "dewrite-core", version: "latest.release"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithoutVersion(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyArtifactId(group, artifact, "dewrite-core", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core'
- api "org.openrewrite:rewrite-core"
- api group: 'org.openrewrite', name: 'dewrite-core'
- api group: "org.openrewrite", name: "dewrite-core"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:dewrite-core'
- api "org.openrewrite:dewrite-core"
- api group: 'org.openrewrite', name: 'dewrite-core'
- api group: "org.openrewrite", name: "dewrite-core"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithClassifier(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyArtifactId(group, artifact, "dewrite-core", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classifier'
- api "org.openrewrite:rewrite-core:latest.release:classifier"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:dewrite-core:latest.release:classifier'
- api "org.openrewrite:dewrite-core:latest.release:classifier"
- api group: 'org.openrewrite', name: 'dewrite-core', version: 'latest.release', classifier: 'classifier'
- api group: "org.openrewrite", name: "dewrite-core", version: "latest.release", classifier: "classifier"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithExt(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyArtifactId(group, artifact, "dewrite-core", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core@ext'
- api "org.openrewrite:rewrite-core@ext"
- api 'org.openrewrite:rewrite-core:latest.release@ext'
- api "org.openrewrite:rewrite-core:latest.release@ext"
- api 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
- api "org.openrewrite:rewrite-core:latest.release:classifier@ext"
- api group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", extension: "ext"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", extension: "ext"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:dewrite-core@ext'
- api "org.openrewrite:dewrite-core@ext"
- api 'org.openrewrite:dewrite-core:latest.release@ext'
- api "org.openrewrite:dewrite-core:latest.release@ext"
- api 'org.openrewrite:dewrite-core:latest.release:classifier@ext'
- api "org.openrewrite:dewrite-core:latest.release:classifier@ext"
- api group: 'org.openrewrite', name: 'dewrite-core', extension: 'ext'
- api group: "org.openrewrite", name: "dewrite-core", extension: "ext"
- api group: 'org.openrewrite', name: 'dewrite-core', version: 'latest.release', extension: 'ext'
- api group: "org.openrewrite", name: "dewrite-core", version: "latest.release", extension: "ext"
- api group: 'org.openrewrite', name: 'dewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
- api group: "org.openrewrite", name: "dewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyClassifierTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyClassifierTest.kt
deleted file mode 100644
index 513c3ce4914..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyClassifierTest.kt
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.CsvSource
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class ChangeDependencyClassifierTest : RewriteTest {
- @Test
- fun worksWithEmptyStringConfig() = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyClassifier("org.openrewrite", "*", "classified", ""))
- },
- buildGradle("""
- dependencies {
- api 'org.openrewrite:rewrite-gradle:latest.release:classifier'
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-gradle:latest.release:classified'
- }
- """)
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyClassifier(group, artifact, "classified", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classifier'
- api "org.openrewrite:rewrite-core:latest.release:classifier"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classified'
- api "org.openrewrite:rewrite-core:latest.release:classified"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findMapStyleDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyClassifier(group, artifact, "classified", null))
- },
- buildGradle(
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- }
- """,
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classified'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classified"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithoutVersion(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyClassifier(group, artifact, "classified", null))
- },
- buildGradle(
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", classifier: "classifier"
- }
- """,
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', classifier: 'classified'
- api group: "org.openrewrite", name: "rewrite-core", classifier: "classified"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithClassifier(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyClassifier(group, artifact, "classified", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classifier'
- api "org.openrewrite:rewrite-core:latest.release:classifier"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classified'
- api "org.openrewrite:rewrite-core:latest.release:classified"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classified'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classified"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithExt(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyClassifier(group, artifact, "classified", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
- api "org.openrewrite:rewrite-core:latest.release:classifier@ext"
- api group: 'org.openrewrite', name: 'rewrite-core', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", classifier: "classifier"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classified@ext'
- api "org.openrewrite:rewrite-core:latest.release:classified@ext"
- api group: 'org.openrewrite', name: 'rewrite-core', classifier: 'classified'
- api group: "org.openrewrite", name: "rewrite-core", classifier: "classified"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classified'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classified"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classified', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classified", extension: "ext"
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyConfigurationTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyConfigurationTest.kt
deleted file mode 100644
index 391ded6ce7d..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyConfigurationTest.kt
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Disabled
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.CsvSource
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class ChangeDependencyConfigurationTest : RewriteTest {
- @Test
- fun worksWithEmptyStringConfig() = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyConfiguration("org.openrewrite", "*", "implementation", ""))
- },
- buildGradle("""
- dependencies {
- compile 'org.openrewrite:rewrite-gradle:latest.release'
- }
- """,
- """
- dependencies {
- implementation 'org.openrewrite:rewrite-gradle:latest.release'
- }
- """)
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyConfiguration(group, artifact, "implementation", null))
- },
- buildGradle(
- """
- dependencies {
- compile 'org.openrewrite:rewrite-core:latest.release'
- compile "org.openrewrite:rewrite-core:latest.release"
- }
- """,
- """
- dependencies {
- implementation 'org.openrewrite:rewrite-core:latest.release'
- implementation "org.openrewrite:rewrite-core:latest.release"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findMapStyleDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyConfiguration(group, artifact, "implementation", null))
- },
- buildGradle(
- """
- dependencies {
- compile group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
- compile group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
- }
- """,
- """
- dependencies {
- implementation group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
- implementation group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
- }
- """
- )
- )
-
- @Disabled
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun withoutVersionShouldNotChange(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyConfiguration(group, artifact, "implementation", null))
- },
- buildGradle(
- """
- dependencies {
- compile 'org.openrewrite:rewrite-core'
- compile "org.openrewrite:rewrite-core"
- compile group: 'org.openrewrite', name: 'rewrite-core'
- compile group: "org.openrewrite", name: "rewrite-core"
- }
- """,
- """
- dependencies {
- implementation 'org.openrewrite:rewrite-core'
- implementation "org.openrewrite:rewrite-core"
- implementation group: 'org.openrewrite', name: 'rewrite-core'
- implementation group: "org.openrewrite", name: "rewrite-core"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithClassifier(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyConfiguration(group, artifact, "implementation", null))
- },
- buildGradle(
- """
- dependencies {
- compile 'org.openrewrite:rewrite-core:latest.release:classifier'
- compile "org.openrewrite:rewrite-core:latest.release:classifier"
- compile group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- compile group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- }
- """,
- """
- dependencies {
- implementation 'org.openrewrite:rewrite-core:latest.release:classifier'
- implementation "org.openrewrite:rewrite-core:latest.release:classifier"
- implementation group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- implementation group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithExt(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyConfiguration(group, artifact, "implementation", null))
- },
- buildGradle(
- """
- dependencies {
- compile 'org.openrewrite:rewrite-core@ext'
- compile "org.openrewrite:rewrite-core@ext"
- compile 'org.openrewrite:rewrite-core:latest.release@ext'
- compile "org.openrewrite:rewrite-core:latest.release@ext"
- compile 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
- compile "org.openrewrite:rewrite-core:latest.release:classifier@ext"
- compile group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
- compile group: "org.openrewrite", name: "rewrite-core", extension: "ext"
- compile group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', extension: 'ext'
- compile group: "org.openrewrite", name: "rewrite-core", version: "latest.release", extension: "ext"
- compile group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
- compile group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
- }
- """,
- """
- dependencies {
- implementation 'org.openrewrite:rewrite-core@ext'
- implementation "org.openrewrite:rewrite-core@ext"
- implementation 'org.openrewrite:rewrite-core:latest.release@ext'
- implementation "org.openrewrite:rewrite-core:latest.release@ext"
- implementation 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
- implementation "org.openrewrite:rewrite-core:latest.release:classifier@ext"
- implementation group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
- implementation group: "org.openrewrite", name: "rewrite-core", extension: "ext"
- implementation group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', extension: 'ext'
- implementation group: "org.openrewrite", name: "rewrite-core", version: "latest.release", extension: "ext"
- implementation group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
- implementation group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyExtensionTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyExtensionTest.kt
deleted file mode 100644
index 5574e25aa67..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyExtensionTest.kt
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.CsvSource
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class ChangeDependencyExtensionTest : RewriteTest {
- @Test
- fun worksWithEmptyStringConfig() = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyExtension("org.openrewrite", "*", "jar", ""))
- },
- buildGradle("""
- dependencies {
- api 'org.openrewrite:rewrite-gradle:latest.integration@war'
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-gradle:latest.integration@jar'
- }
- """)
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyExtension(group, artifact, "jar", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release@war'
- api "org.openrewrite:rewrite-core:latest.release@war"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release@jar'
- api "org.openrewrite:rewrite-core:latest.release@jar"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findMapStyleDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyExtension(group, artifact, "jar", null))
- },
- buildGradle(
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', ext: 'war'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", ext: "war"
- }
- """,
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', ext: 'jar'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", ext: "jar"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithoutVersion(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyExtension(group, artifact, "jar", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core@war'
- api "org.openrewrite:rewrite-core@war"
- api group: 'org.openrewrite', name: 'rewrite-core', ext: 'war'
- api group: "org.openrewrite", name: "rewrite-core", ext: "war"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core@jar'
- api "org.openrewrite:rewrite-core@jar"
- api group: 'org.openrewrite', name: 'rewrite-core', ext: 'jar'
- api group: "org.openrewrite", name: "rewrite-core", ext: "jar"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithClassifier(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyExtension(group, artifact, "jar", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classifier@war'
- api "org.openrewrite:rewrite-core:latest.release:classifier@war"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', ext: 'war'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", ext: "war"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classifier@jar'
- api "org.openrewrite:rewrite-core:latest.release:classifier@jar"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', ext: 'jar'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", ext: "jar"
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyGroupIdTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyGroupIdTest.kt
deleted file mode 100755
index dff50300613..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyGroupIdTest.kt
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.CsvSource
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class ChangeDependencyGroupIdTest : RewriteTest {
- @Test
- fun worksWithEmptyStringConfig() = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyGroupId("org.springframework.boot", "spring-boot-starter", "org.newboot", ""))
- },
- buildGradle(
- """
- dependencies {
- rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
- implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
- implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
- implementation 'org.springframework.boot:spring-boot-starter:2.5.4'
- implementation 'commons-lang:commons-lang:2.6'
- testImplementation 'org.springframework.boot:spring-boot-starter-test'
- }
- """,
- """
- dependencies {
- rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
- implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
- implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
- implementation 'org.newboot:spring-boot-starter:2.5.4'
- implementation 'commons-lang:commons-lang:2.6'
- testImplementation 'org.springframework.boot:spring-boot-starter-test'
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyGroupId(group, artifact, "org.dewrite", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release'
- api "org.openrewrite:rewrite-core:latest.release"
- }
- """,
- """
- dependencies {
- api 'org.dewrite:rewrite-core:latest.release'
- api "org.dewrite:rewrite-core:latest.release"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findMapStyleDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyGroupId(group, artifact, "org.dewrite", null))
- },
- buildGradle(
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
- }
- """,
- """
- dependencies {
- api group: 'org.dewrite', name: 'rewrite-core', version: 'latest.release'
- api group: "org.dewrite", name: "rewrite-core", version: "latest.release"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithoutVersion(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyGroupId(group, artifact, "org.dewrite", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core'
- api "org.openrewrite:rewrite-core"
- api group: 'org.openrewrite', name: 'rewrite-core'
- api group: "org.openrewrite", name: "rewrite-core"
- }
- """,
- """
- dependencies {
- api 'org.dewrite:rewrite-core'
- api "org.dewrite:rewrite-core"
- api group: 'org.dewrite', name: 'rewrite-core'
- api group: "org.dewrite", name: "rewrite-core"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithClassifier(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyGroupId(group, artifact, "org.dewrite", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classifier'
- api "org.openrewrite:rewrite-core:latest.release:classifier"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- }
- """,
- """
- dependencies {
- api 'org.dewrite:rewrite-core:latest.release:classifier'
- api "org.dewrite:rewrite-core:latest.release:classifier"
- api group: 'org.dewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- api group: "org.dewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithExt(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyGroupId(group, artifact, "org.dewrite", null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core@ext'
- api "org.openrewrite:rewrite-core@ext"
- api 'org.openrewrite:rewrite-core:latest.release@ext'
- api "org.openrewrite:rewrite-core:latest.release@ext"
- api 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
- api "org.openrewrite:rewrite-core:latest.release:classifier@ext"
- api group: 'org.openrewrite', name: 'rewrite-core', ext: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", ext: "ext"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', ext: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", ext: "ext"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', ext: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", ext: "ext"
- }
- """,
- """
- dependencies {
- api 'org.dewrite:rewrite-core@ext'
- api "org.dewrite:rewrite-core@ext"
- api 'org.dewrite:rewrite-core:latest.release@ext'
- api "org.dewrite:rewrite-core:latest.release@ext"
- api 'org.dewrite:rewrite-core:latest.release:classifier@ext'
- api "org.dewrite:rewrite-core:latest.release:classifier@ext"
- api group: 'org.dewrite', name: 'rewrite-core', ext: 'ext'
- api group: "org.dewrite", name: "rewrite-core", ext: "ext"
- api group: 'org.dewrite', name: 'rewrite-core', version: 'latest.release', ext: 'ext'
- api group: "org.dewrite", name: "rewrite-core", version: "latest.release", ext: "ext"
- api group: 'org.dewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', ext: 'ext'
- api group: "org.dewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", ext: "ext"
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyVersionTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyVersionTest.kt
deleted file mode 100755
index 319d2c086c6..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeDependencyVersionTest.kt
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.CsvSource
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class ChangeDependencyVersionTest : RewriteTest {
- @Test
- fun worksWithEmptyStringConfig() = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyVersion("org.springframework.boot", "*", "2.5.5", null, ""))
- },
- buildGradle("""
- dependencies {
- rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
- implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
- implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
- implementation 'org.springframework.boot:spring-boot-starter:2.5.4'
- implementation 'commons-lang:commons-lang:2.6'
- testImplementation 'org.springframework.boot:spring-boot-starter-test'
- }
- """,
- """
- dependencies {
- rewrite 'org.openrewrite:rewrite-gradle:latest.integration'
- implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
- implementation 'org.springframework.integration:spring-integration-ftp:5.5.1'
- implementation 'org.springframework.boot:spring-boot-starter:2.5.5'
- implementation 'commons-lang:commons-lang:2.6'
- testImplementation 'org.springframework.boot:spring-boot-starter-test'
- }
- """)
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyVersion(group, artifact, "latest.integration", null, null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release'
- api "org.openrewrite:rewrite-core:latest.release"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.integration'
- api "org.openrewrite:rewrite-core:latest.integration"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun findMapStyleDependency(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyVersion(group, artifact, "latest.integration", null, null))
- },
- buildGradle(
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release"
- }
- """,
- """
- dependencies {
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.integration'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.integration"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun withoutVersionShouldNotChange(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyVersion(group, artifact, "latest.integration", null, null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core'
- api "org.openrewrite:rewrite-core"
- api group: 'org.openrewrite', name: 'rewrite-core'
- api group: "org.openrewrite", name: "rewrite-core"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithClassifier(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyVersion(group, artifact, "latest.integration", null, null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.release:classifier'
- api "org.openrewrite:rewrite-core:latest.release:classifier"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core:latest.integration:classifier'
- api "org.openrewrite:rewrite-core:latest.integration:classifier"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.integration', classifier: 'classifier'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.integration", classifier: "classifier"
- }
- """
- )
- )
-
- @ParameterizedTest
- @CsvSource(value = ["org.openrewrite:rewrite-core", "*:*"], delimiterString = ":")
- fun worksWithExt(group: String, artifact: String) = rewriteRun(
- { spec ->
- spec.recipe(ChangeDependencyVersion(group, artifact, "latest.integration", null, null))
- },
- buildGradle(
- """
- dependencies {
- api 'org.openrewrite:rewrite-core@ext'
- api "org.openrewrite:rewrite-core@ext"
- api 'org.openrewrite:rewrite-core:latest.release@ext'
- api "org.openrewrite:rewrite-core:latest.release@ext"
- api 'org.openrewrite:rewrite-core:latest.release:classifier@ext'
- api "org.openrewrite:rewrite-core:latest.release:classifier@ext"
- api group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", extension: "ext"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", extension: "ext"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release', classifier: 'classifier', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.release", classifier: "classifier", extension: "ext"
- }
- """,
- """
- dependencies {
- api 'org.openrewrite:rewrite-core@ext'
- api "org.openrewrite:rewrite-core@ext"
- api 'org.openrewrite:rewrite-core:latest.integration@ext'
- api "org.openrewrite:rewrite-core:latest.integration@ext"
- api 'org.openrewrite:rewrite-core:latest.integration:classifier@ext'
- api "org.openrewrite:rewrite-core:latest.integration:classifier@ext"
- api group: 'org.openrewrite', name: 'rewrite-core', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", extension: "ext"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.integration', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.integration", extension: "ext"
- api group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.integration', classifier: 'classifier', extension: 'ext'
- api group: "org.openrewrite", name: "rewrite-core", version: "latest.integration", classifier: "classifier", extension: "ext"
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeJavaCompatibilityTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeJavaCompatibilityTest.kt
deleted file mode 100644
index 07f85de3b10..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/ChangeJavaCompatibilityTest.kt
+++ /dev/null
@@ -1,350 +0,0 @@
-/*
- * Copyright 2022 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.DisplayName
-import org.junit.jupiter.api.Nested
-import org.junit.jupiter.api.Test
-
-class ChangeJavaCompatibilityTest : GradleRecipeTest {
- @Nested
- @DisplayName("When requested version is an integer")
- class NewInteger : BaseTest("8")
-
- @Nested
- @DisplayName("When requested version is a double")
- class NewDouble : BaseTest("1.8")
-
- @Nested
- @DisplayName("When requested version is a string (double quotes)")
- class NewStringDoubleQuoted : BaseTest("\"1.8\"")
-
- @Nested
- @DisplayName("When requested version is a string (single quotes -tmp)")
- class NewStringSingleQuoted : BaseTest("'1.8'")
-
- @Nested
- @DisplayName("When requested version is an enum (shorthand)")
- class NewEnumShorthand : BaseTest("VERSION_1_8")
-
- @Nested
- @DisplayName("When requested version is an enum")
- class NewEnum : BaseTest("JavaVersion.VERSION_1_8")
-
- abstract class BaseTest(val newVersion: String) : GradleRecipeTest {
- @Test
- fun changeSourceCompatibility() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "source"),
- before = """
- plugins {
- java
- }
-
- sourceCompatibility = 7
- """,
- after = """
- plugins {
- java
- }
-
- sourceCompatibility = ${coerce(newVersion)}
- """
- )
-
- @Test
- fun changeTargetCompatibility() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "target"),
- before = """
- plugins {
- java
- }
-
- targetCompatibility = '7'
- """,
- after = """
- plugins {
- java
- }
-
- targetCompatibility = ${coerce(newVersion)}
- """
- )
-
- @Test
- fun changeSetSourceCompatibility() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "source"),
- before = """
- plugins {
- java
- }
-
- setSourceCompatibility "7"
- """,
- after = """
- plugins {
- java
- }
-
- setSourceCompatibility ${coerce(newVersion)}
- """
- )
-
- @Test
- fun changeSetTargetCompatibility() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "target"),
- before = """
- plugins {
- java
- }
-
- setTargetCompatibility 1.7
- """,
- after = """
- plugins {
- java
- }
-
- setTargetCompatibility ${coerce(newVersion)}
- """
- )
-
- @Test
- fun changeSourceCompatibility_JavaPluginExtension() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "source"),
- before = """
- plugins {
- java
- }
-
- java {
- sourceCompatibility = "1.7"
- }
- """,
- after = """
- plugins {
- java
- }
-
- java {
- sourceCompatibility = ${coerce(newVersion)}
- }
- """
- )
-
- @Test
- fun changeTargetCompatibility_JavaPluginExtension() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "target"),
- before = """
- plugins {
- java
- }
-
- java {
- targetCompatibility = '1.7'
- }
- """,
- after = """
- plugins {
- java
- }
-
- java {
- targetCompatibility = ${coerce(newVersion)}
- }
- """
- )
-
- @Test
- fun changeSourceCompatibility_CompileJava() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "source"),
- before = """
- plugins {
- java
- }
-
- compileJava {
- sourceCompatibility = JavaVersion.VERSION_1_7
- }
- """,
- after = """
- plugins {
- java
- }
-
- compileJava {
- sourceCompatibility = ${coerce(newVersion)}
- }
- """
- )
-
- @Test
- fun changeTargetCompatibility_CompileJava() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "target"),
- before = """
- plugins {
- java
- }
-
- compileJava {
- targetCompatibility = "1.7"
- }
- """,
- after = """
- plugins {
- java
- }
-
- compileJava {
- targetCompatibility = ${coerce(newVersion)}
- }
- """
- )
-
- @Test
- fun changeSourceCompatibility_TasksNamedCompileJava() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "source"),
- before = """
- plugins {
- java
- }
-
- tasks.named("compileJava") {
- sourceCompatibility = "1.7"
- }
- """,
- after = """
- plugins {
- java
- }
-
- tasks.named("compileJava") {
- sourceCompatibility = ${coerce(newVersion)}
- }
- """
- )
-
- @Test
- fun changeTargetCompatibility_TasksNamedCompileJava() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "target"),
- before = """
- plugins {
- java
- }
-
- tasks.named("compileJava") {
- targetCompatibility = "1.7"
- }
- """,
- after = """
- plugins {
- java
- }
-
- tasks.named("compileJava") {
- targetCompatibility = ${coerce(newVersion)}
- }
- """
- )
-
- @Test
- fun changeSourceCompatibility_TasksWithTypeJavaCompile() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "source"),
- before = """
- plugins {
- java
- }
-
- tasks.withType(JavaCompile).configureEach {
- sourceCompatibility = "1.7"
- }
- """,
- after = """
- plugins {
- java
- }
-
- tasks.withType(JavaCompile).configureEach {
- sourceCompatibility = ${coerce(newVersion)}
- }
- """
- )
-
- @Test
- fun changeTargetCompatibility_TasksWithTypeJavaCompile() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "target"),
- before = """
- plugins {
- java
- }
-
- tasks.withType(JavaCompile).configureEach {
- targetCompatibility = "1.7"
- }
- """,
- after = """
- plugins {
- java
- }
-
- tasks.withType(JavaCompile).configureEach {
- targetCompatibility = ${coerce(newVersion)}
- }
- """
- )
-
- @Test
- fun changeSourceCompatibility_JavaPluginExtensionFieldAccess() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "source"),
- before = """
- plugins {
- java
- }
-
- java.sourceCompatibility = "1.7"
- """,
- after = """
- plugins {
- java
- }
-
- java.sourceCompatibility = ${coerce(newVersion)}
- """
- )
-
- @Test
- fun changeTargetCompatibility_JavaPluginExtensionFieldAccess() = assertChanged(
- recipe = ChangeJavaCompatibility(newVersion, "target"),
- before = """
- plugins {
- java
- }
-
- java.targetCompatibility = "1.7"
- """,
- after = """
- plugins {
- java
- }
-
- java.targetCompatibility = ${coerce(newVersion)}
- """
- )
-
- private fun coerce(version: String): String {
- return if (version.startsWith("VERSION_")) "JavaVersion.$version" else version
- }
- }
-}
\ No newline at end of file
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/DependencyUseMapNotationTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/DependencyUseMapNotationTest.kt
deleted file mode 100755
index 38819e9f38a..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/DependencyUseMapNotationTest.kt
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.Recipe
-
-class DependencyUseMapNotationTest: GradleRecipeTest {
- override val recipe: Recipe
- get() = DependencyUseMapNotation()
-
- @Test
- fun basicString() = assertChanged(
- before = """
- dependencies {
- api('org.openrewrite:rewrite-core:latest.release')
- implementation "group:artifact:version"
- }
- """,
- after = """
- dependencies {
- api(group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release')
- implementation group: 'group', name: 'artifact', version: 'version'
- }
- """
- )
-
- @Test
- fun withGString() = assertChanged(
- before = """
- def version = "latest.release"
- dependencies {
- api("org.openrewrite:rewrite-core:${"$"}version")
- implementation "group:artifact:${"$"}version"
- }
- """,
- after = """
- def version = "latest.release"
- dependencies {
- api(group: 'org.openrewrite', name: 'rewrite-core', version: version)
- implementation group: 'group', name: 'artifact', version: version
- }
- """
- )
-
- @Test
- fun withExclusion() = assertChanged(
- before = """
- dependencies {
- api("org.openrewrite:rewrite-core:latest.release") {
- exclude group: "group", module: "artifact"
- }
- implementation "group:artifact:version", {
- exclude group: "group2", module: "artifact2"
- }
- }
- """,
- after = """
- dependencies {
- api(group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release') {
- exclude group: "group", module: "artifact"
- }
- implementation group: 'group', name: 'artifact', version: 'version', {
- exclude group: "group2", module: "artifact2"
- }
- }
- """
- )
-
- @Test
- fun withGStringAndExclusion() = assertChanged(
- before = """
- dependencies {
- api("org.openrewrite:rewrite-core:${"$"}version") {
- exclude group: "group", module: "artifact"
- }
- implementation "group:artifact:${"$"}version", {
- exclude group: "group2", module: "artifact2"
- }
- }
- """,
- after = """
- dependencies {
- api(group: 'org.openrewrite', name: 'rewrite-core', version: version) {
- exclude group: "group", module: "artifact"
- }
- implementation group: 'group', name: 'artifact', version: version, {
- exclude group: "group2", module: "artifact2"
- }
- }
- """
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/DependencyUseStringNotationTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/DependencyUseStringNotationTest.kt
deleted file mode 100644
index dedd0f714cf..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/DependencyUseStringNotationTest.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.Recipe
-
-class DependencyUseStringNotationTest: GradleRecipeTest {
- override val recipe: Recipe
- get() = DependencyUseStringNotation()
-
- @Test
- fun basicMap() = assertChanged(
- before = """
- dependencies {
- api(group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release')
- implementation group: 'group', name: 'artifact', version: 'version'
- }
- """,
- after = """
- dependencies {
- api("org.openrewrite:rewrite-core:latest.release")
- implementation "group:artifact:version"
- }
- """
- )
-
- @Test
- fun basicMapLiteral() = assertChanged(
- before = """
- dependencies {
- api([group: 'org.openrewrite', name: 'rewrite-core', version: 'latest.release'])
- }
- """,
- after = """
- dependencies {
- api("org.openrewrite:rewrite-core:latest.release")
- }
- """
- )
-
- @Test
- fun withGString() = assertChanged(
- before = """
- def version = "latest.release"
- dependencies {
- api(group: 'org.openrewrite', name: 'rewrite-core', version: version)
- implementation group: 'group', name: 'artifact', version: version
- }
- """,
- after = """
- def version = "latest.release"
- dependencies {
- api("org.openrewrite:rewrite-core:${"$"}version")
- implementation "group:artifact:${"$"}version"
- }
- """
- )
-
- @Test
- fun withoutVersion() = assertChanged(
- before = """
- dependencies {
- api(group: "org.openrewrite", name: "rewrite-core")
- implementation group: "group", name: "artifact"
- }
- """,
- after = """
- dependencies {
- api("org.openrewrite:rewrite-core")
- implementation "group:artifact"
- }
- """
- )
-
- @Test
- fun withExclusion() = assertChanged(
- before = """
- dependencies {
- api(group: "org.openrewrite", name: "rewrite-core", version: "latest.release") {
- exclude group: "group", module: "artifact"
- }
- }
- """,
- after = """
- dependencies {
- api("org.openrewrite:rewrite-core:latest.release") {
- exclude group: "group", module: "artifact"
- }
- }
- """
- )
-
- @Test
- fun withGStringExclusion() = assertChanged(
- before = """
- def version = "latest.release"
- dependencies {
- api(group: "org.openrewrite", name: "rewrite-core", version: version) {
- exclude group: "group", module: "artifact"
- }
- }
- """,
- after = """
- def version = "latest.release"
- dependencies {
- api("org.openrewrite:rewrite-core:${"$"}version") {
- exclude group: "group", module: "artifact"
- }
- }
- """
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/RemoveRepositoryTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/RemoveRepositoryTest.kt
deleted file mode 100755
index 8636c3c83ee..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/RemoveRepositoryTest.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-
-class RemoveRepositoryTest : GradleRecipeTest {
- @Test
- fun removeJcenter() = assertChanged(
- recipe = RemoveRepository("jcenter"),
- before = """
- repositories {
- jcenter()
- }
- """,
- after = """
- repositories {
-
- }
- """
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/UpdateGradleWrapperTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/UpdateGradleWrapperTest.kt
deleted file mode 100755
index 523fd07c39b..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/UpdateGradleWrapperTest.kt
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright 2022 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-import org.openrewrite.PathUtils
-import org.openrewrite.Tree.randomId
-import org.openrewrite.gradle.util.GradleWrapper.*
-import org.openrewrite.marker.Markers
-import org.openrewrite.properties.PropertiesParser
-import org.openrewrite.properties.tree.Properties
-import org.openrewrite.quark.Quark
-import org.openrewrite.remote.Remote
-import org.openrewrite.text.PlainText
-import java.net.URI
-import java.nio.file.Paths
-
-@Suppress("UnusedProperty")
-class UpdateGradleWrapperTest {
-
- private val gradlew = PlainText(randomId(), WRAPPER_SCRIPT_LOCATION, Markers.EMPTY,null, false, null, null,"")
- private val gradlewBat = PlainText(randomId(), WRAPPER_BATCH_LOCATION, Markers.EMPTY, null, false, null, null,"")
- private val gradleWrapperJarQuark = Quark(randomId(), WRAPPER_JAR_LOCATION, Markers.EMPTY, null, null)
-
- @Test
- fun updateVersionAndDistribution() {
- val gradleWrapperProps = PropertiesParser().parse(
- """
- distributionBase=GRADLE_USER_HOME
- distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
- zipStoreBase=GRADLE_USER_HOME
- zipStorePath=wrapper/dists
- """.trimIndent())[0]!!
- .withSourcePath(Paths.get("gradle", "wrapper", "gradle-wrapper.properties"))
-
- val result = UpdateGradleWrapper("7.4.2", null)
- .run(listOf(gradleWrapperProps, gradlew, gradlewBat, gradleWrapperJarQuark))
- .results
- .map { it.after }
- assertThat(result.size).isEqualTo(4)
-
- val props = result.filterIsInstance
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.gradle.plugins.UpgradePluginVersion
-import org.openrewrite.test.RewriteTest
-
-class UpgradePluginVersionTest : RewriteTest {
-
- @Test
- fun upgradePlugin() = rewriteRun(
- { spec -> spec.recipe(UpgradePluginVersion("com.jfrog.bintray", "latest.patch", null)) },
- buildGradle("""
- plugins {
- id 'com.jfrog.bintray' version '1.7.0'
- id 'com.github.johnrengelman.shadow' version '6.1.0'
- }
- """,
- """
- plugins {
- id 'com.jfrog.bintray' version '1.7.3'
- id 'com.github.johnrengelman.shadow' version '6.1.0'
- }
- """)
- )
-
- @Test
- fun upgradePluginGlob() = rewriteRun(
- { spec -> spec.recipe(UpgradePluginVersion("com.jfrog.*", "1.8.X", null)) },
- buildGradle("""
- plugins {
- id 'com.jfrog.bintray' version '1.8.2'
- }
- """,
- """
- plugins {
- id 'com.jfrog.bintray' version '1.8.5'
- }
- """)
- )
-
- @Test
- fun exactVersionDoesNotHaveToBeResolvable() = rewriteRun(
- { spec -> spec.recipe(UpgradePluginVersion("com.madeup.doesnotexist", "2.0", null)) },
- buildGradle("""
- plugins {
- id 'com.madeup.doesnotexist' version '1.0'
- }
- """,
- """
- plugins {
- id 'com.madeup.doesnotexist' version '2.0'
- }
- """)
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/FindDependencyHandlerTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/FindDependencyHandlerTest.kt
deleted file mode 100644
index 972833a96e1..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/FindDependencyHandlerTest.kt
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle.search
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.gradle.GradleRecipeTest
-
-class FindDependencyHandlerTest : GradleRecipeTest {
- @Test
- fun findDependenciesBlock() = assertChanged(
- recipe = fromRuntimeClasspath("org.openrewrite.gradle.search.FindDependencyHandler"),
- before = """
- dependencies {
- api 'com.google.guava:guava:23.0'
- }
- """,
- after = """
- /*~~>*/dependencies {
- api 'com.google.guava:guava:23.0'
- }
- """
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/package-info.java b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/package-info.java
deleted file mode 100755
index 390fa215651..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/search/package-info.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-@NonNullApi
-package org.openrewrite.gradle.search;
-
-import org.openrewrite.internal.lang.NonNullApi;
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/security/UseHttpsForRepositoriesTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/security/UseHttpsForRepositoriesTest.kt
deleted file mode 100644
index 7afa257ee59..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/security/UseHttpsForRepositoriesTest.kt
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2022 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle.security
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RecipeSpec
-import org.openrewrite.test.RewriteTest
-
-@Suppress("HttpUrlsUsage")
-class UseHttpsForRepositoriesTest : RewriteTest {
- override fun defaults(spec: RecipeSpec) {
- spec.recipe(UseHttpsForRepositories())
- }
-
- @Test
- fun unchangedUseOfHttps() = rewriteRun(
- buildGradle(
- """
- repositories {
- maven { url 'https://repo.spring.example.com/libs-release-local' }
- }
- """
- )
- )
-
- @Test
- fun updateUnwrappedInvocationToUseHttpsSingleQuote() = rewriteRun(
- buildGradle(
- """
- repositories {
- maven { url 'http://repo.spring.example.com/libs-release-local' }
- }
- """,
- """
- repositories {
- maven { url 'https://repo.spring.example.com/libs-release-local' }
- }
- """
- )
- )
-
- @Test
- fun updateUnwrappedInvocationToUseHttpsDoubleQuote() = rewriteRun(
- buildGradle(
- """
- repositories {
- maven { url "http://repo.spring.example.com/libs-release-local" }
- }
- """,
- """
- repositories {
- maven { url "https://repo.spring.example.com/libs-release-local" }
- }
- """
- )
- )
-
- @Test
- fun updateUnwrappedInvocationToUseHttpsGString() = rewriteRun(
- buildGradle(
- """
- repositories {
- maven {
- def subRepo = properties.snapshot ? 'snapshot' : 'release'
- url "http://repo.spring.example.com/libs-release-local/${'$'}subRepo"
- }
- }
- """,
- """
- repositories {
- maven {
- def subRepo = properties.snapshot ? 'snapshot' : 'release'
- url "https://repo.spring.example.com/libs-release-local/${'$'}subRepo"
- }
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/BuildscriptTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/BuildscriptTest.kt
deleted file mode 100755
index 5a6b577b720..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/BuildscriptTest.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle.tree
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class BuildscriptTest : RewriteTest {
-
- @Test
- fun buildscriptWithDependencies() = rewriteRun(
- buildGradle(
- """
- buildscript {
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath 'com.netflix.nebula:nebula-dependency-recommender:9.1.1'
- classpath 'com.netflix.nebula:gradle-netflixoss-project-plugin:9.1.0'
- }
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/RepositoryTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/RepositoryTest.kt
deleted file mode 100755
index 83370647ce1..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/RepositoryTest.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle.tree
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.Issue
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class RepositoryTest : RewriteTest {
-
- @Test
- fun builtInFunctions() = rewriteRun(
- buildGradle(
- """
- repositories {
- mavenCentral()
- mavenLocal()
- }
- """
- )
- )
-
- @Issue("https://github.com/openrewrite/rewrite/issues/1253")
- @Test
- fun customMavenRepo() = rewriteRun(
- buildGradle(
- """
- repositories {
- maven {
- url "https://repo.spring.io/release"
- }
- maven {
- setUrl("https://repo.spring.io/release")
- }
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/TaskTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/TaskTest.kt
deleted file mode 100755
index f85426bdf5c..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/TaskTest.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle.tree
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.Issue
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.TypeValidation
-import org.openrewrite.test.RewriteTest
-
-class TaskTest : RewriteTest {
-
- @Issue("https://github.com/openrewrite/rewrite/issues/1236")
- @Test
- fun declareTaskOldStyle() = rewriteRun(
- { spec -> spec.typeValidationOptions(TypeValidation.none()) },
- buildGradle(
- """
- task(testWithCloud, type: Test) {
- useTestNG()
- options.excludeGroups = [] as Set
- }
- """
- )
- )
-
- @Issue("https://github.com/openrewrite/rewrite/issues/1929")
- @Test
- fun testDsl() = rewriteRun(
- { spec -> spec.typeValidationOptions(TypeValidation.none()) },
- buildGradle(
- """
- test {
- // Ex: -PexcludeTests=com/google/cloud/healthcare/etl/runner/hl7v2tofhir/integ/*
- if (project.hasProperty('excludeTests')) {
- exclude project.property('excludeTests') as String
- }
- dependsOn('buildDeps')
- }
- """
- )
- )
-}
diff --git a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/TestTest.kt b/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/TestTest.kt
deleted file mode 100755
index 96f11c02420..00000000000
--- a/rewrite-gradle/src/test/kotlin/org/openrewrite/gradle/tree/TestTest.kt
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.openrewrite.gradle.tree
-
-import org.junit.jupiter.api.Test
-import org.openrewrite.gradle.Assertions.buildGradle
-import org.openrewrite.test.RewriteTest
-
-class TestTest : RewriteTest {
-
- @Test
- fun testDsl() = rewriteRun(
- buildGradle(
- """
- test {
- useJUnit()
- useTestNG()
- useJUnitPlatform()
- systemProperty 'some.prop', 'value'
- include 'org/foo/**'
- exclude 'org/boo/**'
- testLogging.showStandardStreams = true
- minHeapSize = "128m"
- maxHeapSize = "512m"
- jvmArgs '-XX:MaxPermSize=256m'
- failFast = true
- }
- """
- )
- )
-}
diff --git a/rewrite-groovy/src/main/java/org/openrewrite/groovy/Assertions.java b/rewrite-groovy/src/main/java/org/openrewrite/groovy/Assertions.java
index 334577a4299..443fc775ea4 100644
--- a/rewrite-groovy/src/main/java/org/openrewrite/groovy/Assertions.java
+++ b/rewrite-groovy/src/main/java/org/openrewrite/groovy/Assertions.java
@@ -36,7 +36,7 @@ public static SourceSpecs groovy(@Language("groovy") @Nullable String before) {
}
public static SourceSpecs groovy(@Language("groovy") @Nullable String before, Consumer S result(RecipeRun run, Class clazz, String endsWith) {
+ return run.getResults().stream()
+ .map(Result::getAfter)
+ .filter(Objects::nonNull)
+ .filter(r -> r.getSourcePath().endsWith(endsWith))
+ .findFirst()
+ .map(clazz::cast)
+ .orElseThrow();
+ }
+
+ @Test
+ void addWrapper() {
+ rewriteRun(
+ spec -> spec.afterRecipe(run -> {
+ var gradleSh = result(run, PlainText.class, "gradlew");
+ assertThat(gradleSh.getText()).isNotBlank();
+ assertThat(gradleSh.getFileAttributes()).isNotNull();
+ assertThat(gradleSh.getFileAttributes().isExecutable()).isTrue();
+
+ var gradleBat = result(run, PlainText.class, "gradlew.bat");
+ assertThat(gradleBat.getText()).isNotBlank();
+ assertThat(gradleBat.getFileAttributes()).isNotNull();
+ assertThat(gradleBat.getFileAttributes().isExecutable()).isTrue();
+
+ var gradleWrapperJar = result(run, Remote.class, "gradle-wrapper.jar");
+ assertThat(PathUtils.equalIgnoringSeparators(gradleWrapperJar.getSourcePath(), WRAPPER_JAR_LOCATION)).isTrue();
+ assertThat(gradleWrapperJar.getUri()).isEqualTo(URI.create("https://services.gradle.org/distributions/gradle-7.4.2-bin.zip"));
+ }),
+ buildGradle(""),
+ dir(
+ "gradle/wrapper",
+ properties(null, GRADLE_WRAPPER_PROPERTIES, spec -> spec.path(Paths.get("gradle-wrapper.properties")))
+ )
+ );
+ }
+
+ @Test
+ void addWrapperWhenIncomplete() {
+ rewriteRun(
+ spec -> spec.afterRecipe(run -> {
+ var gradleWrapperJar = result(run, Remote.class, "gradle-wrapper.jar");
+ assertThat(PathUtils.equalIgnoringSeparators(gradleWrapperJar.getSourcePath(), WRAPPER_JAR_LOCATION)).isTrue();
+ assertThat(gradleWrapperJar.getUri()).isEqualTo(URI.create("https://services.gradle.org/distributions/gradle-7.4.2-bin.zip"));
+ }).expectedCyclesThatMakeChanges(1),
+ other("", spec -> spec.path("gradlew")),
+ other("", spec -> spec.path("gradlew.bat")),
+ buildGradle("")
+ );
+ }
+
+ @Disabled
+ @Test
+ void addWrapperToGradleKotlin() {
+ rewriteRun(
+ spec -> spec.afterRecipe(run -> assertThat(run.getResults()).isNotEmpty())
+ .expectedCyclesThatMakeChanges(1),
+ other("", spec -> spec.path(".gradle.kts"))
+ );
+ }
+
+ @Test
+ void dontAddWrapperToMavenProject() {
+ rewriteRun(
+ spec -> spec.afterRecipe(run -> assertThat(run.getResults()).isEmpty()),
+ pomXml(
+ """
+ S result(RecipeRun run, Class clazz, String endsWith) {
+ return run.getResults().stream()
+ .map(Result::getAfter)
+ .filter(Objects::nonNull)
+ .filter(r -> r.getSourcePath().endsWith(endsWith))
+ .findFirst()
+ .map(clazz::cast)
+ .orElseThrow();
+ }
+}
diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradePluginVersionTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradePluginVersionTest.java
new file mode 100644
index 00000000000..504d641e133
--- /dev/null
+++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradePluginVersionTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2021 the original author or authors.
+ *