Added systemProps resolution; fixes #47
This commit is contained in:
@@ -211,6 +211,7 @@ we will go through to find the matching milestone. Defaults to `10`
|
||||
- `releaser.maven.deploy-command` - Command to be executed to deploy a built project". Defaults to `./mvnw deploy -DskipTests -Pfast`
|
||||
- `releaser.maven.publish-docs-commands` - Command to be executed to deploy a built project. If present `{{version}}` will be replaced by the proper version.
|
||||
Defaults to the standard Spring Cloud wget and execution of ghpages.
|
||||
- `releaser.maven.system-properties` - Additional system properties that should be passed to any commands. If present `{{systemProps}}` will be replaced by the contents of this property.
|
||||
- `releaser.maven.wait-time-in-minutes` - Max wait time in minutes for the process to finish. Defaults to `20`
|
||||
- `releaser.gradle.gradle-props-substitution` - a map containing a `key` which is a property key inside `gradle.properties` and a `value` of
|
||||
a project name. E.g. in `gradle.properties` you have `foo=1.0.0.BUILD-SNAPSHOT` and you would like `spring-cloud-contract` version to
|
||||
|
||||
@@ -139,12 +139,12 @@ public class ReleaserProperties {
|
||||
/**
|
||||
* Command to be executed to build the project
|
||||
*/
|
||||
private String buildCommand = "./mvnw clean install -Pdocs";
|
||||
private String buildCommand = "./mvnw clean install -Pdocs {{systemProps}}";
|
||||
|
||||
/**
|
||||
* Command to be executed to deploy a built project
|
||||
*/
|
||||
private String deployCommand = "./mvnw deploy -DskipTests -Pfast";
|
||||
private String deployCommand = "./mvnw deploy -DskipTests -Pfast {{systemProps}}";
|
||||
|
||||
/**
|
||||
* Command to be executed to deploy a built project. If present "{{version}}" will be replaced by the
|
||||
@@ -157,6 +157,14 @@ public class ReleaserProperties {
|
||||
"./target/gh-pages.sh -v {{version}} -c"
|
||||
};
|
||||
|
||||
public static final String SYSTEM_PROPS_PLACEHOLDER = "{{systemProps}}";
|
||||
|
||||
/**
|
||||
* Additional system properties that should be passed to the build / deploy commands.
|
||||
* If present in other commands "{{systemProps}}" will be substituted with this property.
|
||||
*/
|
||||
private String systemProperties = "";
|
||||
|
||||
/**
|
||||
* Max wait time in minutes for the process to finish
|
||||
*/
|
||||
@@ -194,6 +202,13 @@ public class ReleaserProperties {
|
||||
this.publishDocsCommands = publishDocsCommands;
|
||||
}
|
||||
|
||||
public String getSystemProperties() {
|
||||
return this.systemProperties;
|
||||
}
|
||||
|
||||
public void setSystemProperties(String systemProperties) {
|
||||
this.systemProperties = systemProperties;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Gradle {
|
||||
|
||||
@@ -8,7 +8,9 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -76,8 +78,9 @@ public class ProjectBuilder {
|
||||
}
|
||||
|
||||
private void runCommand(String[] commands) {
|
||||
String[] substitutedCommands = substituteSystemProps(commands);
|
||||
long waitTimeInMinutes = this.properties.getMaven().getWaitTimeInMinutes();
|
||||
this.executor.runCommand(commands, waitTimeInMinutes);
|
||||
this.executor.runCommand(substitutedCommands, waitTimeInMinutes);
|
||||
}
|
||||
|
||||
public void publishDocs(String version) {
|
||||
@@ -98,6 +101,16 @@ public class ProjectBuilder {
|
||||
File dir = new File(workingDir);
|
||||
this.pomUpdater.updatePomsForRootVersion(dir, version);
|
||||
}
|
||||
|
||||
private String[] substituteSystemProps(String... commands) {
|
||||
return Arrays.stream(commands).map(s -> {
|
||||
if (s.contains(ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER)) {
|
||||
return s.replace(ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER,
|
||||
this.properties.getMaven().getSystemProperties());
|
||||
}
|
||||
return s;
|
||||
}).collect(Collectors.toList()).toArray(new String[commands.length]);
|
||||
}
|
||||
}
|
||||
|
||||
class ProcessExecutor {
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.cloud.release.internal.PomUpdateAcceptanceTests;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectVersion;
|
||||
@@ -30,6 +31,7 @@ public class ProjectBuilderTests {
|
||||
TestPomReader reader = new TestPomReader();
|
||||
@Rule public TemporaryFolder tmp = new TemporaryFolder();
|
||||
File temporaryFolder;
|
||||
@Rule public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
@Before
|
||||
public void checkOs() throws Exception {
|
||||
@@ -52,6 +54,20 @@ public class ProjectBuilderTests {
|
||||
.contains("resolved.log");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.getMaven().setBuildCommand("echo {{systemProps}}");
|
||||
properties.getMaven().setSystemProperties("hello world");
|
||||
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
|
||||
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
|
||||
|
||||
builder.build();
|
||||
|
||||
then(asString(tmpFile("/builder/resolved/resolved.log")))
|
||||
.contains("hello world");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_throw_exception_when_after_running_there_is_an_html_file_with_unresolved_tag() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
@@ -86,6 +102,20 @@ public class ProjectBuilderTests {
|
||||
.contains("resolved.log");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_successfully_execute_a_deploy_command_with_sys_props_placeholder() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.getMaven().setDeployCommand("echo \"{{systemProps}}\"");
|
||||
properties.getMaven().setSystemProperties("hello world");
|
||||
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
|
||||
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
|
||||
|
||||
builder.deploy();
|
||||
|
||||
then(asString(tmpFile("/builder/resolved/resolved.log")))
|
||||
.contains("hello world");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_throw_exception_when_deploy_command_took_too_long_to_execute() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
@@ -112,6 +142,25 @@ public class ProjectBuilderTests {
|
||||
then(executor.counter).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_successfully_execute_a_publish_docs_command_with_sys_props_placeholder() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.getMaven().setPublishDocsCommands(new String[] { "echo {{systemProps}}1", "echo {{systemProps}}2" });
|
||||
properties.getMaven().setSystemProperties("hello world");
|
||||
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
|
||||
TestProcessExecutor executor = executor(properties);
|
||||
ProjectBuilder builder = new ProjectBuilder(properties, executor);
|
||||
|
||||
builder.publishDocs("");
|
||||
|
||||
then(asString(tmpFile("/builder/resolved/resolved.log")))
|
||||
.contains("hello world2");
|
||||
then(outputCapture.toString())
|
||||
.contains("Will run the build via [echo, hello world1]")
|
||||
.contains("Will run the build via [echo, hello world2]");
|
||||
then(executor.counter).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_successfully_execute_a_publish_docs_command_and_substitute_the_version() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
|
||||
Reference in New Issue
Block a user