Polish
This commit is contained in:
@@ -15,18 +15,13 @@ import org.springframework.cloud.release.internal.pom.ProjectVersion;
|
||||
*/
|
||||
public class Releaser {
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
private static final String MSG = "'q' to quit and 's' to skip\n\n";
|
||||
private static final String SKIP = "s";
|
||||
private static final String QUIT = "q";
|
||||
|
||||
private final ReleaserProperties properties;
|
||||
private final ProjectPomUpdater projectPomUpdater;
|
||||
private final ProjectBuilder projectBuilder;
|
||||
private final ProjectGitUpdater projectGitUpdater;
|
||||
|
||||
public Releaser(ReleaserProperties properties, ProjectPomUpdater projectPomUpdater,
|
||||
public Releaser(ProjectPomUpdater projectPomUpdater,
|
||||
ProjectBuilder projectBuilder, ProjectGitUpdater projectGitUpdater) {
|
||||
this.properties = properties;
|
||||
this.projectPomUpdater = projectPomUpdater;
|
||||
this.projectBuilder = projectBuilder;
|
||||
this.projectGitUpdater = projectGitUpdater;
|
||||
@@ -70,62 +65,4 @@ public class Releaser {
|
||||
this.projectGitUpdater.pushCurrentBranch(project);
|
||||
log.info("\nSuccessfully pushed current branch");
|
||||
}
|
||||
|
||||
public void release() {
|
||||
String workingDir = this.properties.getWorkingDir();
|
||||
File project = new File(workingDir);
|
||||
log.info("\n\n\n=== UPDATING POMS ===\n\nWill run the application "
|
||||
+ "for root folder [{}]. \n\nPress ENTER to continue {}", workingDir, MSG);
|
||||
boolean skipPoms = skipStep();
|
||||
ProjectVersion originalVersion = new ProjectVersion(project);
|
||||
ProjectVersion changedVersion = new ProjectVersion(project);
|
||||
if (!skipPoms) {
|
||||
changedVersion = this.updateProjectFromScRelease(project);
|
||||
}
|
||||
log.info("\n\n\n=== BUILD PROJECT ===\n\nPress ENTER to build the project {}", MSG);
|
||||
boolean skipBuild = skipStep();
|
||||
if (!skipBuild) {
|
||||
this.buildProject();
|
||||
}
|
||||
log.info("\n\n\n=== COMMITTING AND PUSHING TAGS ===\n\nPress ENTER to commit, tag and push the tag {}", MSG);
|
||||
boolean skipCommit = skipStep();
|
||||
if (!skipCommit) {
|
||||
this.commitAndPushTags(project, changedVersion);
|
||||
}
|
||||
log.info("\n\n\n=== ARTIFACT DEPLOYMENT ===\n\nPress ENTER to deploy the artifacts {}", MSG);
|
||||
boolean skipDeployment = skipStep();
|
||||
if (!skipDeployment) {
|
||||
this.deploy();
|
||||
}
|
||||
log.info("\n\n\n=== PUBLISHING DOCS ===\n\nPress ENTER to deploy the artifacts {}", MSG);
|
||||
boolean skipDocs = skipStep();
|
||||
if (!skipDocs) {
|
||||
this.publishDocs(changedVersion);
|
||||
}
|
||||
if (!changedVersion.isSnapshot()) {
|
||||
log.info("\n\n\n=== REVERTING CHANGES & BUMPING VERSION===\n\nPress ENTER to go back to snapshots and bump originalVersion by patch {}", MSG);
|
||||
boolean skipRevert = skipStep();
|
||||
if (!skipRevert) {
|
||||
rollbackReleaseVersion(project, originalVersion, changedVersion);
|
||||
}
|
||||
}
|
||||
log.info("\n\n\n=== PUSHING CHANGES===\n\nPress ENTER to push the commits {}", MSG);
|
||||
boolean skipPush = skipStep();
|
||||
if (!skipPush) {
|
||||
this.pushCurrentBranch(project);
|
||||
}
|
||||
}
|
||||
|
||||
boolean skipStep() {
|
||||
String input = System.console().readLine();
|
||||
switch (input.toLowerCase()) {
|
||||
case SKIP:
|
||||
return true;
|
||||
case QUIT:
|
||||
System.exit(0);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
package org.springframework.cloud.release.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.cloud.release.internal.git.GitRepoTests;
|
||||
import org.springframework.cloud.release.internal.git.ProjectGitUpdater;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
|
||||
import org.springframework.cloud.release.internal.pom.TestPomReader;
|
||||
import org.springframework.cloud.release.internal.pom.TestUtils;
|
||||
import org.springframework.cloud.release.internal.project.ProjectBuilder;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.cloud.release.internal.git.GitTestUtils.clonedProject;
|
||||
import static org.springframework.cloud.release.internal.git.GitTestUtils.openGitProject;
|
||||
import static org.springframework.cloud.release.internal.git.GitTestUtils.setOriginOnProjectToTmp;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class AcceptanceTests {
|
||||
|
||||
@Rule public TemporaryFolder tmp = new TemporaryFolder();
|
||||
TestPomReader testPomReader = new TestPomReader();
|
||||
File springCloudConsulProject;
|
||||
File temporaryFolder;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
this.temporaryFolder = this.tmp.newFolder();
|
||||
this.springCloudConsulProject = new File(GitRepoTests.class.getResource("/projects/spring-cloud-consul").toURI());
|
||||
TestUtils.prepareLocalRepo();
|
||||
FileSystemUtils.copyRecursively(file("/projects/"), this.temporaryFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_perform_a_release_of_consul() throws Exception {
|
||||
File origin = clonedProject(this.tmp.newFolder(), this.springCloudConsulProject);
|
||||
pomVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT");
|
||||
pomParentVersionIsEqualTo(origin, "1.2.0.BUILD-SNAPSHOT");
|
||||
File project = clonedProject(this.tmp.newFolder(), tmpFile("spring-cloud-consul"));
|
||||
setOriginOnProjectToTmp(origin, project);
|
||||
Releaser releaser = releaser(project);
|
||||
|
||||
releaser.release();
|
||||
|
||||
Iterable<RevCommit> commits = listOfCommits(project);
|
||||
Iterator<RevCommit> iterator = commits.iterator();
|
||||
tagIsPresentInOrigin(origin);
|
||||
commitIsPresent(iterator, "Bumping versions to 1.2.1.BUILD-SNAPSHOT after release");
|
||||
commitIsPresent(iterator, "Going back to snapshots");
|
||||
commitIsPresent(iterator, "Update SNAPSHOT to 1.1.2.RELEASE");
|
||||
pomVersionIsEqualTo(project, "1.2.1.BUILD-SNAPSHOT");
|
||||
pomParentVersionIsEqualTo(project, "1.2.1.BUILD-SNAPSHOT");
|
||||
}
|
||||
|
||||
private Iterable<RevCommit> listOfCommits(File project) throws GitAPIException {
|
||||
return openGitProject(project).log().call();
|
||||
}
|
||||
|
||||
private void pomParentVersionIsEqualTo(File project, String expected) {
|
||||
then(pom(new File(project, "spring-cloud-starter-consul")).getParent()
|
||||
.getVersion()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void pomVersionIsEqualTo(File project, String expected) {
|
||||
then(pom(project).getVersion()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void commitIsPresent(Iterator<RevCommit> iterator,
|
||||
String expected) {
|
||||
RevCommit commit = iterator.next();
|
||||
then(commit.getShortMessage()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void tagIsPresentInOrigin(File origin) throws GitAPIException {
|
||||
then(openGitProject(origin).tagList().call().iterator().next().getName()).endsWith("v1.1.2.RELEASE");
|
||||
}
|
||||
|
||||
private Model pom(File dir) {
|
||||
return this.testPomReader.readPom(new File(dir, "pom.xml"));
|
||||
}
|
||||
|
||||
private ReleaserProperties releaserProperties(File project) throws URISyntaxException {
|
||||
ReleaserProperties releaserProperties = new ReleaserProperties();
|
||||
releaserProperties.getGit().setSpringCloudReleaseGitUrl(file("/projects/spring-cloud-release/").toURI().getPath());
|
||||
releaserProperties.getPom().setBranch("vCamden.SR5");
|
||||
releaserProperties.setWorkingDir(project.getPath());
|
||||
releaserProperties.getMaven().setBuildCommand("touch build");
|
||||
releaserProperties.getMaven().setDeployCommand("touch deploy");
|
||||
releaserProperties.getMaven().setPublishDocsCommands(new String[] { "touch docs"} );
|
||||
return releaserProperties;
|
||||
}
|
||||
|
||||
private Releaser releaser(File projectFile) throws Exception {
|
||||
ReleaserProperties properties = releaserProperties(projectFile);
|
||||
ProjectPomUpdater pomUpdater = new ProjectPomUpdater(properties);
|
||||
ProjectBuilder projectBuilder = new ProjectBuilder(properties, pomUpdater);
|
||||
ProjectGitUpdater gitUpdater = new ProjectGitUpdater(properties);
|
||||
return new Releaser(properties, pomUpdater, projectBuilder, gitUpdater) {
|
||||
@Override boolean skipStep() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private File tmpFile(String relativePath) {
|
||||
return new File(this.temporaryFolder, relativePath);
|
||||
}
|
||||
|
||||
private File file(String relativePath) throws URISyntaxException {
|
||||
return new File(AcceptanceTests.class.getResource(relativePath).toURI());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user