|
|
@ -17,6 +17,7 @@
|
|
|
|
package org.springframework.boot.testsupport.gradle.testkit;
|
|
|
|
package org.springframework.boot.testsupport.gradle.testkit;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
@ -28,6 +29,7 @@ import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
import java.util.jar.JarFile;
|
|
|
|
import java.util.jar.JarFile;
|
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonView;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonView;
|
|
|
@ -57,6 +59,7 @@ import org.springframework.util.FileCopyUtils;
|
|
|
|
import org.springframework.util.FileSystemUtils;
|
|
|
|
import org.springframework.util.FileSystemUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A {@code GradleBuild} is used to run a Gradle build using {@link GradleRunner}.
|
|
|
|
* A {@code GradleBuild} is used to run a Gradle build using {@link GradleRunner}.
|
|
|
@ -176,6 +179,11 @@ public class GradleBuild {
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GradleBuild scriptPropertyFrom(File propertiesFile, String key) {
|
|
|
|
|
|
|
|
this.scriptProperties.put(key, getProperty(propertiesFile, key));
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BuildResult build(String... arguments) {
|
|
|
|
public BuildResult build(String... arguments) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
BuildResult result = prepareRunner(arguments).build();
|
|
|
|
BuildResult result = prepareRunner(arguments).build();
|
|
|
@ -291,4 +299,23 @@ public class GradleBuild {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getProperty(File propertiesFile, String key) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
assertThat(propertiesFile).withFailMessage("Expecting properties file to exist at path '%s'",
|
|
|
|
|
|
|
|
propertiesFile.getCanonicalFile()).exists();
|
|
|
|
|
|
|
|
Properties properties = new Properties();
|
|
|
|
|
|
|
|
try (FileInputStream input = new FileInputStream(propertiesFile)) {
|
|
|
|
|
|
|
|
properties.load(input);
|
|
|
|
|
|
|
|
String value = properties.getProperty(key);
|
|
|
|
|
|
|
|
assertThat(value).withFailMessage("Expecting properties file '%s' to contain the key '%s'",
|
|
|
|
|
|
|
|
propertiesFile.getCanonicalFile(), key).isNotEmpty();
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
|
|
|
fail("Error reading properties file '" + propertiesFile + "'");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|