Adding profiles to commands

fixes gh-68
This commit is contained in:
Marcin Grzejszczak
2018-02-02 19:46:01 +01:00
parent bd0681fe53
commit 6cfc436eaa
4 changed files with 152 additions and 27 deletions

View File

@@ -60,8 +60,8 @@ public class Releaser {
log.info("\n\nProject was successfully updated to [{}]", changedVersion);
}
public void buildProject() {
this.projectBuilder.build();
public void buildProject(ProjectVersion versionFromScRelease) {
this.projectBuilder.build(versionFromScRelease);
log.info("\nProject was successfully built");
}
@@ -70,8 +70,8 @@ public class Releaser {
log.info("\nCommit was made and tag was pushed successfully");
}
public void deploy() {
this.projectBuilder.deploy();
public void deploy(ProjectVersion versionFromScRelease) {
this.projectBuilder.deploy(versionFromScRelease);
log.info("\nThe artifact was deployed successfully");
}

View File

@@ -19,6 +19,7 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.ReleaserProperties;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
import org.springframework.util.StringUtils;
/**
@@ -42,10 +43,10 @@ public class ProjectBuilder {
this.executor = executor;
}
public void build() {
public void build(ProjectVersion versionFromScRelease) {
try {
String[] commands = commandWithSystemProps(this.properties.getMaven().getBuildCommand())
.split(" ");
String[] commands = commandWithSystemProps(this.properties.getMaven().getBuildCommand(),
versionFromScRelease).split(" ");
runCommand(commands);
assertNoHtmlFilesInDocsContainUnresolvedTags();
log.info("No HTML files from docs contain unresolved tags");
@@ -54,11 +55,26 @@ public class ProjectBuilder {
}
}
private String commandWithSystemProps(String command) {
private String commandWithSystemProps(String command,
ProjectVersion version) {
if (command.contains(ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER)) {
return command;
return appendProfile(command, version);
}
return command.trim() + " " + ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER;
return appendProfile(command, version) + " " + ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER;
}
private String appendProfile(String command, ProjectVersion version) {
String trimmedCommand = command.trim();
if (version.isMilestone() || version.isRc()) {
log.info("Adding the milestone profile to the Maven build");
return trimmedCommand + " -Pmilestone";
} else if (version.isRelease() || version.isServiceRelease()) {
log.info("Adding the central profile to the Maven build");
return trimmedCommand + " -Pcentral";
} else {
log.info("The build is a snapshot one - will not add any profiles");
}
return trimmedCommand;
}
private void assertNoHtmlFilesInDocsContainUnresolvedTags() {
@@ -75,10 +91,10 @@ public class ProjectBuilder {
}
}
public void deploy() {
public void deploy(ProjectVersion version) {
try {
String[] commands = commandWithSystemProps(this.properties.getMaven().getDeployCommand())
.split(" ");
String[] commands = commandWithSystemProps(this.properties.getMaven().getDeployCommand(),
version).split(" ");
runCommand(commands);
log.info("The project has successfully been deployed");
} catch (Exception e) {

View File

@@ -18,6 +18,7 @@ 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;
import org.springframework.cloud.release.internal.pom.TestPomReader;
import org.springframework.cloud.release.internal.pom.TestUtils;
import org.springframework.util.FileSystemUtils;
@@ -46,12 +47,64 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build();
builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("resolved.log");
}
@Test
public void should_successfully_execute_a_build_command_for_milestone_version() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build(new ProjectVersion("foo", "1.0.0.M1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone");
}
@Test
public void should_successfully_execute_a_build_command_for_rc_version() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build(new ProjectVersion("foo", "1.0.0.RC1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone");
}
@Test
public void should_successfully_execute_a_build_command_for_release_version() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build(new ProjectVersion("foo", "1.0.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pcentral");
}
@Test
public void should_successfully_execute_a_build_command_for_sr_version() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setBuildCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build(new ProjectVersion("foo", "1.0.0.SR1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pcentral");
}
@Test
public void should_successfully_execute_a_command_when_system_props_placeholder_is_present() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
@@ -60,7 +113,7 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build();
builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=world -Dfoo=bar");
@@ -74,7 +127,7 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build();
builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("hello=world foo=bar");
@@ -88,7 +141,7 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build();
builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=world -Dfoo=bar bar");
@@ -102,7 +155,7 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.build();
builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("bar -Dhello=world -Dfoo=bar");
@@ -115,7 +168,8 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
thenThrownBy(builder::build).hasMessageContaining("contains a tag that wasn't resolved properly");
thenThrownBy(() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining("contains a tag that wasn't resolved properly");
}
@Test
@@ -126,7 +180,8 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
thenThrownBy(builder::build).hasMessageContaining("Process waiting time of [0] minutes exceeded");
thenThrownBy(() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining("Process waiting time of [0] minutes exceeded");
}
@Test
@@ -136,12 +191,64 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.deploy();
builder.deploy(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("resolved.log");
}
@Test
public void should_successfully_execute_a_deploy_command_for_milestone_version() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.deploy(new ProjectVersion("foo", "1.0.0.M1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone");
}
@Test
public void should_successfully_execute_a_deploy_command_for_rc_version() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.deploy(new ProjectVersion("foo", "1.0.0.RC1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone");
}
@Test
public void should_successfully_execute_a_deploy_command_for_release_version() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.deploy(new ProjectVersion("foo", "1.0.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pcentral");
}
@Test
public void should_successfully_execute_a_deploy_command_for_sr_version() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo foo");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.deploy(new ProjectVersion("foo", "1.0.0.SR1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pcentral");
}
@Test
public void should_successfully_execute_a_deploy_command_with_sys_props_placeholder() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
@@ -150,7 +257,7 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.deploy();
builder.deploy(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=hello-world");
@@ -164,7 +271,7 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.deploy();
builder.deploy(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=hello-world");
@@ -178,7 +285,8 @@ public class ProjectBuilderTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
thenThrownBy(builder::deploy).hasMessageContaining("Process waiting time of [0] minutes exceeded");
thenThrownBy(() -> builder.deploy(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining("Process waiting time of [0] minutes exceeded");
}
@Test
@@ -248,7 +356,8 @@ public class ProjectBuilderTests {
}
});
thenThrownBy(builder::build).hasMessageContaining("The process has exited with exit code [1]");
thenThrownBy(() -> builder.build(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")))
.hasMessageContaining("The process has exited with exit code [1]");
}
private Process processWithInvalidExitCode() {

View File

@@ -18,7 +18,7 @@ class Tasks {
static Task BUILD_PROJECT = task("build", "b",
"BUILD PROJECT",
"Build the project",
args -> args.releaser.buildProject());
args -> args.releaser.buildProject(args.versionFromScRelease));
static Task COMMIT = task("commit", "c",
"COMMITTING (ALL) AND PUSHING TAGS (NON-SNAPSHOTS)",
"Commit, tag and push the tag",
@@ -26,7 +26,7 @@ class Tasks {
static Task DEPLOY = task("deploy", "d",
"ARTIFACT DEPLOYMENT",
"Deploy the artifacts",
args -> args.releaser.deploy());
args -> args.releaser.deploy(args.versionFromScRelease));
static Task PUBLISH_DOCS = task("docs", "o",
"PUBLISHING DOCS",
"Publish the docs",