mirror of
https://gitee.com/dcren/initializr.git
synced 2025-08-20 00:44:24 +08:00
Fix Gradle build with Kotlin DSL assertions
Closes gh-1448
This commit is contained in:
parent
6303ff725e
commit
0be9637bc4
@ -57,7 +57,7 @@ public abstract class GradleBuildAssert<SELF extends GradleBuildAssert<SELF>> ex
|
|||||||
* @return {@code this} assertion object
|
* @return {@code this} assertion object
|
||||||
*/
|
*/
|
||||||
public SELF hasProperty(String name, String value) {
|
public SELF hasProperty(String name, String value) {
|
||||||
return contains(String.format("%s = '%s'", name, value));
|
return contains(String.format("%s = %s", name, quote(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,10 +71,12 @@ public abstract class GradleBuildAssert<SELF extends GradleBuildAssert<SELF>> ex
|
|||||||
throw new IllegalArgumentException("Size must be even, it is a set of property=value pairs");
|
throw new IllegalArgumentException("Size must be even, it is a set of property=value pairs");
|
||||||
}
|
}
|
||||||
for (int i = 0; i < values.length; i += 2) {
|
for (int i = 0; i < values.length; i += 2) {
|
||||||
builder.append(String.format("\tset('%s', \"%s\")%n", values[i], values[i + 1]));
|
builder.append(String.format("\tset(%s, \"%s\")%n", quote(values[i]), values[i + 1]));
|
||||||
}
|
}
|
||||||
builder.append("}");
|
builder.append("}");
|
||||||
return contains(builder.toString());
|
return contains(builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract String quote(String value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,11 @@ public class GroovyDslGradleBuildAssert extends GradleBuildAssert<GroovyDslGradl
|
|||||||
this(TextTestUtils.readContent(buildGradleFile));
|
this(TextTestUtils.readContent(buildGradleFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String quote(String value) {
|
||||||
|
return "'" + value + "'";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert {@code build.gradle} defines a plugin with the specified id and version.
|
* Assert {@code build.gradle} defines a plugin with the specified id and version.
|
||||||
* @param id the id of the plugin
|
* @param id the id of the plugin
|
||||||
@ -42,7 +47,7 @@ public class GroovyDslGradleBuildAssert extends GradleBuildAssert<GroovyDslGradl
|
|||||||
* @return {@code this} assertion object
|
* @return {@code this} assertion object
|
||||||
*/
|
*/
|
||||||
public GroovyDslGradleBuildAssert hasPlugin(String id, String version) {
|
public GroovyDslGradleBuildAssert hasPlugin(String id, String version) {
|
||||||
return contains(String.format("id '%s' version '%s'", id, version));
|
return contains(String.format("id %s version %s", quote(id), quote(version)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +56,7 @@ public class GroovyDslGradleBuildAssert extends GradleBuildAssert<GroovyDslGradl
|
|||||||
* @return {@code this} assertion object
|
* @return {@code this} assertion object
|
||||||
*/
|
*/
|
||||||
public GroovyDslGradleBuildAssert hasPlugin(String id) {
|
public GroovyDslGradleBuildAssert hasPlugin(String id) {
|
||||||
return contains(String.format("id '%s'", id));
|
return contains(String.format("id %s", quote(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import io.spring.initializr.generator.test.io.TextTestUtils;
|
|||||||
* Simple assertions for a kotlin build using the kotlin DSL.
|
* Simple assertions for a kotlin build using the kotlin DSL.
|
||||||
*
|
*
|
||||||
* @author Prithvi singh
|
* @author Prithvi singh
|
||||||
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradleBuildAssert> {
|
public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradleBuildAssert> {
|
||||||
|
|
||||||
@ -35,6 +36,11 @@ public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradl
|
|||||||
this(TextTestUtils.readContent(buildGradleFile));
|
this(TextTestUtils.readContent(buildGradleFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String quote(String value) {
|
||||||
|
return "\"" + value + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert {@code build.gradle.kts} defines a plugin with the specified id and version.
|
* Assert {@code build.gradle.kts} defines a plugin with the specified id and version.
|
||||||
* @param id the id of the plugin
|
* @param id the id of the plugin
|
||||||
@ -42,7 +48,7 @@ public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradl
|
|||||||
* @return {@code this} assertion object
|
* @return {@code this} assertion object
|
||||||
*/
|
*/
|
||||||
public KotlinDslGradleBuildAssert hasPlugin(String id, String version) {
|
public KotlinDslGradleBuildAssert hasPlugin(String id, String version) {
|
||||||
return contains(String.format("id('%s') version '%s'", id, version));
|
return contains(String.format("id(%s) version %s", quote(id), quote(version)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +57,7 @@ public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradl
|
|||||||
* @return {@code this} assertion object
|
* @return {@code this} assertion object
|
||||||
*/
|
*/
|
||||||
public KotlinDslGradleBuildAssert hasPlugin(String id) {
|
public KotlinDslGradleBuildAssert hasPlugin(String id) {
|
||||||
return contains(String.format("id('%s')", id));
|
return contains(String.format("id(%s)", quote(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,23 +1,23 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id('com.example') version '1.0.0.RELEASE'
|
id("com.example") version "1.0.0.RELEASE"
|
||||||
id('java')
|
id("java")
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'com.example'
|
group = "com.example"
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = "0.0.1-SNAPSHOT"
|
||||||
sourceCompatibility = '1.8'
|
sourceCompatibility = "1.8"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
set('acmeVersion', "Brussels.SR2")
|
set("acmeVersion", "Brussels.SR2")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.example.acme:library'
|
implementation "com.example.acme:library"
|
||||||
testImplementation 'com.example.acme:library-test'
|
testImplementation "com.example.acme:library-test"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyManagement {
|
dependencyManagement {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user