-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1412 from prithvitewatia
* pr/1412: Polish "Add build assertion support for Gradle with the Kotlin DSL" Add build assertion support for Gradle with the Kotlin DSL Closes gh-1412
- Loading branch information
Showing
12 changed files
with
467 additions
and
75 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
...c/main/java/io/spring/initializr/generator/test/buildsystem/gradle/GradleBuildAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2012-2023 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 io.spring.initializr.generator.test.buildsystem.gradle; | ||
|
||
import io.spring.initializr.generator.test.io.AbstractTextAssert; | ||
|
||
/** | ||
* Base class for Gradle build assertions. | ||
* | ||
* @param <SELF> the type of the concrete assert implementations | ||
* @author Stephane Nicoll | ||
*/ | ||
public abstract class GradleBuildAssert<SELF extends GradleBuildAssert<SELF>> extends AbstractTextAssert<SELF> { | ||
|
||
protected GradleBuildAssert(String content, Class<?> selfType) { | ||
super(content, selfType); | ||
} | ||
|
||
/** | ||
* Assert the Gradle {@code build} uses the specified {@code version}. | ||
* @param version the version of the build | ||
* @return {@code this} assertion object | ||
*/ | ||
public SELF hasVersion(String version) { | ||
return hasProperty("version", version); | ||
} | ||
|
||
/** | ||
* Assert the Gradle {@code build} uses a source compatibility for the specified java | ||
* version. | ||
* @param javaVersion the java version | ||
* @return {@code this} assertion object | ||
*/ | ||
public SELF hasSourceCompatibility(String javaVersion) { | ||
return hasProperty("sourceCompatibility", javaVersion); | ||
} | ||
|
||
/** | ||
* Assert the Gradle {@code build} defines a top-level property with the specified | ||
* name and value. | ||
* @param name the name of the property | ||
* @param value the value | ||
* @return {@code this} assertion object | ||
*/ | ||
public SELF hasProperty(String name, String value) { | ||
return contains(String.format("%s = '%s'", name, value)); | ||
} | ||
|
||
/** | ||
* Assert the Gradle {@code build} contains only the specified properties. | ||
* @param values the property value pairs | ||
* @return {@code this} assertion object | ||
*/ | ||
public SELF containsOnlyExtProperties(String... values) { | ||
StringBuilder builder = new StringBuilder(String.format("ext {%n")); | ||
if (values.length % 2 == 1) { | ||
throw new IllegalArgumentException("Size must be even, it is a set of property=value pairs"); | ||
} | ||
for (int i = 0; i < values.length; i += 2) { | ||
builder.append(String.format("\tset('%s', \"%s\")%n", values[i], values[i + 1])); | ||
} | ||
builder.append("}"); | ||
return contains(builder.toString()); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...ain/java/io/spring/initializr/generator/test/buildsystem/gradle/GradleSettingsAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2012-2023 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 io.spring.initializr.generator.test.buildsystem.gradle; | ||
|
||
import io.spring.initializr.generator.test.io.AbstractTextAssert; | ||
|
||
/** | ||
* Base class for Gradle settings assertions. | ||
* | ||
* @param <SELF> the type of the concrete assert implementations | ||
* @author Stephane Nicoll | ||
*/ | ||
public class GradleSettingsAssert<SELF extends GradleSettingsAssert<SELF>> extends AbstractTextAssert<SELF> { | ||
|
||
protected GradleSettingsAssert(String actual, Class<?> selfType) { | ||
super(actual, selfType); | ||
} | ||
|
||
/** | ||
* Assert the Gradle {@code settings} defines the specified project name. | ||
* @param name the name of the project | ||
* @return {@code this} assertion object | ||
*/ | ||
public SELF hasProjectName(String name) { | ||
return hasProperty("rootProject.name", name); | ||
} | ||
|
||
/** | ||
* Assert the Gradle {@code settings} defines a property with the specified name and | ||
* value. | ||
* @param name the name of the property | ||
* @param value the value | ||
* @return {@code this} assertion object | ||
*/ | ||
public SELF hasProperty(String name, String value) { | ||
return contains(String.format("%s = '%s", name, value)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...va/io/spring/initializr/generator/test/buildsystem/gradle/KotlinDslGradleBuildAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2012-2023 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 io.spring.initializr.generator.test.buildsystem.gradle; | ||
|
||
import java.nio.file.Path; | ||
|
||
import io.spring.initializr.generator.test.io.TextTestUtils; | ||
|
||
/** | ||
* Simple assertions for a kotlin build using the kotlin DSL. | ||
* | ||
* @author Prithvi singh | ||
*/ | ||
public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradleBuildAssert> { | ||
|
||
public KotlinDslGradleBuildAssert(String content) { | ||
super(content, KotlinDslGradleBuildAssert.class); | ||
} | ||
|
||
public KotlinDslGradleBuildAssert(Path buildGradleFile) { | ||
this(TextTestUtils.readContent(buildGradleFile)); | ||
} | ||
|
||
/** | ||
* Assert {@code build.gradle.kts} defines a plugin with the specified id and version. | ||
* @param id the id of the plugin | ||
* @param version the version of the plugin | ||
* @return {@code this} assertion object | ||
*/ | ||
public KotlinDslGradleBuildAssert hasPlugin(String id, String version) { | ||
return contains(String.format("id('%s') version '%s'", id, version)); | ||
} | ||
|
||
/** | ||
* Assert {@code build.gradle.kts} defines a plugin with the specified id. | ||
* @param id the id of the plugin | ||
* @return {@code this} assertion object | ||
*/ | ||
public KotlinDslGradleBuildAssert hasPlugin(String id) { | ||
return contains(String.format("id('%s')", id)); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...io/spring/initializr/generator/test/buildsystem/gradle/KotlinDslGradleSettingsAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2012-2023 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 io.spring.initializr.generator.test.buildsystem.gradle; | ||
|
||
/** | ||
* Simple assertions for a gradle settings using the Kotlin DSL. | ||
* | ||
* @author Prithvi singh | ||
*/ | ||
public class KotlinDslGradleSettingsAssert extends GradleSettingsAssert<KotlinDslGradleSettingsAssert> { | ||
|
||
protected KotlinDslGradleSettingsAssert(String content) { | ||
super(content, KotlinDslGradleSettingsAssert.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.