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
|
||||
*/
|
||||
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");
|
||||
}
|
||||
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("}");
|
||||
return contains(builder.toString());
|
||||
}
|
||||
|
||||
protected abstract String quote(String value);
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,11 @@ public class GroovyDslGradleBuildAssert extends GradleBuildAssert<GroovyDslGradl
|
||||
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.
|
||||
* @param id the id of the plugin
|
||||
@ -42,7 +47,7 @@ public class GroovyDslGradleBuildAssert extends GradleBuildAssert<GroovyDslGradl
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @author Prithvi singh
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradleBuildAssert> {
|
||||
|
||||
@ -35,6 +36,11 @@ public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradl
|
||||
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.
|
||||
* @param id the id of the plugin
|
||||
@ -42,7 +48,7 @@ public class KotlinDslGradleBuildAssert extends GradleBuildAssert<KotlinDslGradl
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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 {
|
||||
id('com.example') version '1.0.0.RELEASE'
|
||||
id('java')
|
||||
id("com.example") version "1.0.0.RELEASE"
|
||||
id("java")
|
||||
}
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
group = "com.example"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
sourceCompatibility = "1.8"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
ext {
|
||||
set('acmeVersion', "Brussels.SR2")
|
||||
set("acmeVersion", "Brussels.SR2")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.example.acme:library'
|
||||
testImplementation 'com.example.acme:library-test'
|
||||
implementation "com.example.acme:library"
|
||||
testImplementation "com.example.acme:library-test"
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
|
Loading…
Reference in New Issue
Block a user