Added full cycle
This commit is contained in:
@@ -7,9 +7,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.release.internal.project.Project;
|
||||
import org.springframework.cloud.release.internal.git.ProjectGitUpdater;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectUpdater;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectVersion;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
@@ -21,14 +20,14 @@ public class Releaser {
|
||||
private static final String QUIT = "q";
|
||||
|
||||
private final ReleaserProperties properties;
|
||||
private final ProjectUpdater projectUpdater;
|
||||
private final ProjectPomUpdater projectPomUpdater;
|
||||
private final Project project;
|
||||
private final ProjectGitUpdater projectGitUpdater;
|
||||
|
||||
public Releaser(ReleaserProperties properties, ProjectUpdater projectUpdater,
|
||||
public Releaser(ReleaserProperties properties, ProjectPomUpdater projectPomUpdater,
|
||||
Project project, ProjectGitUpdater projectGitUpdater) {
|
||||
this.properties = properties;
|
||||
this.projectUpdater = projectUpdater;
|
||||
this.projectPomUpdater = projectPomUpdater;
|
||||
this.project = project;
|
||||
this.projectGitUpdater = projectGitUpdater;
|
||||
}
|
||||
@@ -41,7 +40,7 @@ public class Releaser {
|
||||
boolean skipPoms = skipStep();
|
||||
ProjectVersion version = new ProjectVersion(project);
|
||||
if (!skipPoms) {
|
||||
this.projectUpdater.updateProject(project);
|
||||
this.projectPomUpdater.updateProject(project);
|
||||
log.info("\n\nProject was successfully updated");
|
||||
}
|
||||
log.info("\n\n\n=== BUILD PROJECT ===\n\nPress ENTER to build the project {}", MSG);
|
||||
@@ -65,6 +64,19 @@ public class Releaser {
|
||||
if (!skipDocs) {
|
||||
this.project.publishDocs();
|
||||
}
|
||||
if (!version.isSnapshot()) {
|
||||
log.info("\n\n\n=== REVERTING CHANGES & BUMPING VERSION===\n\nPress ENTER to go back to snapshots and bump version by patch {}", MSG);
|
||||
boolean skipRevert = skipStep();
|
||||
if (!skipRevert) {
|
||||
this.projectGitUpdater.revertChangesIfApplicable(project, version);
|
||||
this.project.bumpVersions(version.bumpedVersion());
|
||||
}
|
||||
}
|
||||
log.info("\n\n\n=== PUSHING CHANGES===\n\nPress ENTER to push the commits {}", MSG);
|
||||
boolean skipPush = skipStep();
|
||||
if (!skipPush) {
|
||||
this.projectGitUpdater.pushCurrentBranch(project);
|
||||
}
|
||||
}
|
||||
|
||||
boolean skipStep() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.cloud.release.internal.git;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.URI;
|
||||
@@ -28,6 +29,7 @@ import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.ListBranchCommand;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.RefSpec;
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -40,7 +42,7 @@ import org.springframework.util.ResourceUtils;
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class GitRepo {
|
||||
class GitRepo {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
@@ -48,7 +50,7 @@ public class GitRepo {
|
||||
|
||||
private final File basedir;
|
||||
|
||||
public GitRepo(File basedir) {
|
||||
GitRepo(File basedir) {
|
||||
this.basedir = basedir;
|
||||
this.gitFactory = new GitRepo.JGitFactory();
|
||||
}
|
||||
@@ -63,7 +65,7 @@ public class GitRepo {
|
||||
* @param projectUri - URI of the project
|
||||
* @return file where the project was cloned
|
||||
*/
|
||||
public File cloneProject(URI projectUri) {
|
||||
File cloneProject(URI projectUri) {
|
||||
try {
|
||||
log.info("Cloning repo from [{}] to [{}]", projectUri, this.basedir);
|
||||
Git git = cloneToBasedir(projectUri, this.basedir);
|
||||
@@ -84,7 +86,7 @@ public class GitRepo {
|
||||
* @param project - a Git project
|
||||
* @param branch - branch to check out
|
||||
*/
|
||||
public void checkout(File project, String branch) {
|
||||
void checkout(File project, String branch) {
|
||||
try {
|
||||
log.info("Checking out branch [{}] for repo [{}] to [{}]", this.basedir, branch);
|
||||
checkoutBranch(project, branch);
|
||||
@@ -100,8 +102,8 @@ public class GitRepo {
|
||||
* @param project - a Git project
|
||||
* @param message - commit message
|
||||
*/
|
||||
public void commit(File project, String message) {
|
||||
try(Git git = this.gitFactory.open(ResourceUtils.getFile(project.toURI()).getAbsoluteFile())) {
|
||||
void commit(File project, String message) {
|
||||
try(Git git = this.gitFactory.open(file(project))) {
|
||||
git.commit().setMessage(message).call();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
@@ -113,8 +115,8 @@ public class GitRepo {
|
||||
* @param project
|
||||
* @param tagName
|
||||
*/
|
||||
public void tag(File project, String tagName) {
|
||||
try(Git git = this.gitFactory.open(ResourceUtils.getFile(project.toURI()).getAbsoluteFile())) {
|
||||
void tag(File project, String tagName) {
|
||||
try(Git git = this.gitFactory.open(file(project))) {
|
||||
git.tag().setName(tagName).call();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
@@ -126,8 +128,8 @@ public class GitRepo {
|
||||
* @param project - Git project
|
||||
* @param branch - remote branch to which the code should be pushed
|
||||
*/
|
||||
public void pushBranch(File project, String branch) {
|
||||
try(Git git = this.gitFactory.open(ResourceUtils.getFile(project.toURI()).getAbsoluteFile())) {
|
||||
void pushBranch(File project, String branch) {
|
||||
try(Git git = this.gitFactory.open(file(project))) {
|
||||
String localBranch = git.getRepository().getFullBranch();
|
||||
RefSpec refSpec = new RefSpec(localBranch + ":" + branch);
|
||||
git.push().setPushTags().setRefSpecs(refSpec).call();
|
||||
@@ -136,13 +138,25 @@ public class GitRepo {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes the commits od current branch
|
||||
* @param project - Git project
|
||||
*/
|
||||
void pushCurrentBranch(File project) {
|
||||
try(Git git = this.gitFactory.open(file(project))) {
|
||||
git.push().call();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes the commits to {@code origin} remote tag
|
||||
* @param project - Git project
|
||||
* @param tagName - remote tag to which the code should be pushed
|
||||
*/
|
||||
public void pushTag(File project, String tagName) {
|
||||
try(Git git = this.gitFactory.open(ResourceUtils.getFile(project.toURI()).getAbsoluteFile())) {
|
||||
void pushTag(File project, String tagName) {
|
||||
try(Git git = this.gitFactory.open(file(project))) {
|
||||
String localBranch = git.getRepository().getFullBranch();
|
||||
RefSpec refSpec = new RefSpec(localBranch + ":" + "refs/tags/" + tagName);
|
||||
git.push().setPushTags().setRefSpecs(refSpec).call();
|
||||
@@ -151,6 +165,20 @@ public class GitRepo {
|
||||
}
|
||||
}
|
||||
|
||||
void revert(File project, String message) {
|
||||
try(Git git = this.gitFactory.open(file(project))) {
|
||||
RevCommit commit = git.log().setMaxCount(1).call().iterator().next();
|
||||
git.revert().include(commit).call();
|
||||
git.commit().setAmend(true).setMessage(message).call();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private File file(File project) throws FileNotFoundException {
|
||||
return ResourceUtils.getFile(project.toURI()).getAbsoluteFile();
|
||||
}
|
||||
|
||||
private Git cloneToBasedir(URI projectUrl, File destinationFolder)
|
||||
throws GitAPIException {
|
||||
CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository()
|
||||
|
||||
@@ -2,9 +2,12 @@ package org.springframework.cloud.release.internal.git;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectVersion;
|
||||
|
||||
/**
|
||||
@@ -18,6 +21,13 @@ public class ProjectGitUpdater {
|
||||
|
||||
private static final String MSG = "Bumping versions";
|
||||
private static final String PRE_RELEASE_MSG = "Bumping versions before release";
|
||||
private static final String POST_RELEASE_MSG = "Going back to snapshots";
|
||||
|
||||
private final ReleaserProperties properties;
|
||||
|
||||
public ProjectGitUpdater(ReleaserProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public void commitAndTagIfApplicable(File project, ProjectVersion version) {
|
||||
GitRepo gitRepo = gitRepo(project);
|
||||
@@ -33,6 +43,35 @@ public class ProjectGitUpdater {
|
||||
}
|
||||
}
|
||||
|
||||
public File cloneScReleaseProject() {
|
||||
try {
|
||||
File destinationDir = properties.getGit().getCloneDestinationDir() != null ?
|
||||
new File(properties.getGit().getCloneDestinationDir()) :
|
||||
Files.createTempDirectory("releaser").toFile();
|
||||
return gitRepo(destinationDir).cloneProject(
|
||||
URI.create(this.properties.getGit().getSpringCloudReleaseGitUrl()));
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkout(File project, String branch) {
|
||||
gitRepo(project).checkout(project, branch);
|
||||
|
||||
}
|
||||
|
||||
public void revertChangesIfApplicable(File project, ProjectVersion version) {
|
||||
if (version.isSnapshot()) {
|
||||
log.info("Won't revert a snapshot version");
|
||||
return;
|
||||
}
|
||||
gitRepo(project).revert(project, POST_RELEASE_MSG);
|
||||
}
|
||||
|
||||
public void pushCurrentBranch(File project) {
|
||||
gitRepo(project).pushCurrentBranch(project);
|
||||
}
|
||||
|
||||
GitRepo gitRepo(File workingDir) {
|
||||
return new GitRepo(workingDir);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.release.internal.pom;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -28,31 +27,22 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.git.GitRepo;
|
||||
import org.springframework.cloud.release.internal.git.ProjectGitUpdater;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ProjectUpdater {
|
||||
public class ProjectPomUpdater {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
private final File destinationDir;
|
||||
private final ReleaserProperties properties;
|
||||
private final GitRepo gitRepo;
|
||||
private final ProjectGitUpdater gitRepo;
|
||||
private final PomUpdater pomUpdater = new PomUpdater();
|
||||
|
||||
public ProjectUpdater(ReleaserProperties properties) {
|
||||
try {
|
||||
this.destinationDir = properties.getGit().getCloneDestinationDir() != null ?
|
||||
new File(properties.getGit().getCloneDestinationDir()) :
|
||||
Files.createTempDirectory("releaser").toFile();
|
||||
this.properties = properties;
|
||||
this.gitRepo = new GitRepo(this.destinationDir);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to create a temporary folder", e);
|
||||
}
|
||||
public ProjectPomUpdater(ReleaserProperties properties) {
|
||||
this.properties = properties;
|
||||
this.gitRepo = new ProjectGitUpdater(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,8 +52,7 @@ public class ProjectUpdater {
|
||||
* @param projectRoot - root folder with project to update
|
||||
*/
|
||||
public void updateProject(File projectRoot) {
|
||||
File clonedScRelease = this.gitRepo.cloneProject(
|
||||
URI.create(this.properties.getGit().getSpringCloudReleaseGitUrl()));
|
||||
File clonedScRelease = this.gitRepo.cloneScReleaseProject();
|
||||
this.gitRepo.checkout(clonedScRelease, this.properties.getPom().getBranch());
|
||||
SCReleasePomParser sCReleasePomParser = new SCReleasePomParser(clonedScRelease);
|
||||
Versions versions = sCReleasePomParser.allVersions();
|
||||
@@ -10,8 +10,6 @@ import java.io.File;
|
||||
*/
|
||||
public class ProjectVersion {
|
||||
|
||||
public static ProjectVersion NO_VERSION = new ProjectVersion("");
|
||||
|
||||
public final String version;
|
||||
private final PomReader pomReader = new PomReader();
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
public class Project {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
private static final String BUMP_VERSIONS = "./mvnw versions:set -DnewVersion=%s";
|
||||
|
||||
private final ReleaserProperties properties;
|
||||
private final ProcessExecutor executor;
|
||||
@@ -81,6 +82,21 @@ public class Project {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void bumpVersions(String version) {
|
||||
try {
|
||||
log.info("Bumping versions to [{}]", version);
|
||||
String[] commands = String.format(bumpVersionsCommand(), version).split(" ");
|
||||
runCommand(commands);
|
||||
log.info("Versions successfully bumped");
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
String bumpVersionsCommand() {
|
||||
return BUMP_VERSIONS;
|
||||
}
|
||||
}
|
||||
|
||||
class ProcessExecutor {
|
||||
@@ -128,6 +144,7 @@ class HtmlFileWalker extends SimpleFileVisitor<Path> {
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
private String asString(File file) {
|
||||
try {
|
||||
return new String(Files.readAllBytes(file.toPath()));
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectUpdater;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.pom.TestPomReader;
|
||||
import org.springframework.cloud.release.internal.pom.TestUtils;
|
||||
@@ -37,9 +37,10 @@ public class AcceptanceTests {
|
||||
@Test
|
||||
public void should_update_all_versions_for_a_release_train() throws Exception {
|
||||
ReleaserProperties releaserProperties = releaserProperties();
|
||||
ProjectUpdater projectUpdater = new ProjectUpdater(releaserProperties);
|
||||
ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties);
|
||||
|
||||
projectUpdater.updateProject(new File(this.temporaryFolder, "/spring-cloud-sleuth"));
|
||||
projectPomUpdater
|
||||
.updateProject(new File(this.temporaryFolder, "/spring-cloud-sleuth"));
|
||||
|
||||
then(this.temporaryFolder).exists();
|
||||
Model rootPom = this.testPomReader.readPom(tmpFile("/spring-cloud-sleuth/pom.xml"));
|
||||
@@ -61,10 +62,10 @@ public class AcceptanceTests {
|
||||
@Test
|
||||
public void should_not_update_a_project_that_is_not_on_the_list() throws Exception {
|
||||
ReleaserProperties releaserProperties = releaserProperties();
|
||||
ProjectUpdater projectUpdater = new ProjectUpdater(releaserProperties);
|
||||
ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties);
|
||||
File beforeProcessing = pom("/projects/project/");
|
||||
|
||||
projectUpdater.updateProject(tmpFile("/project/"));
|
||||
projectPomUpdater.updateProject(tmpFile("/project/"));
|
||||
|
||||
then(this.temporaryFolder).exists();
|
||||
File afterProcessing = tmpFile("/project/pom.xml");
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class GitProjectRepoTests {
|
||||
public class GitRepoTests {
|
||||
|
||||
@Rule public TemporaryFolder tmp = new TemporaryFolder();
|
||||
File springCloudReleaseProject;
|
||||
@@ -40,7 +40,7 @@ public class GitProjectRepoTests {
|
||||
@Before
|
||||
public void setup() throws IOException, URISyntaxException {
|
||||
this.tmpFolder = this.tmp.newFolder();
|
||||
this.springCloudReleaseProject = new File(GitProjectRepoTests.class.getResource("/projects/spring-cloud-release").toURI());
|
||||
this.springCloudReleaseProject = new File(GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI());
|
||||
TestUtils.prepareLocalRepo();
|
||||
this.gitRepo = new GitRepo(this.tmpFolder);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class GitProjectRepoTests {
|
||||
@Test
|
||||
public void should_throw_exception_when_there_is_no_repo() throws IOException, URISyntaxException {
|
||||
thenThrownBy(() -> this.gitRepo
|
||||
.cloneProject(GitProjectRepoTests.class.getResource("/projects/").toURI()))
|
||||
.cloneProject(GitRepoTests.class.getResource("/projects/").toURI()))
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessageContaining("Exception occurred while cloning repo");
|
||||
}
|
||||
@@ -147,6 +147,22 @@ public class GitProjectRepoTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_push_changes_to_current_branch() throws Exception {
|
||||
File origin = clonedProject();
|
||||
File project = this.gitRepo.cloneProject(this.springCloudReleaseProject.toURI());
|
||||
setOriginOnProjectToTmp(origin, project);
|
||||
createNewFile(project);
|
||||
this.gitRepo.commit(project, "some message");
|
||||
|
||||
this.gitRepo.pushCurrentBranch(project);
|
||||
|
||||
try(Git git = openGitProject(origin)) {
|
||||
RevCommit revCommit = git.log().call().iterator().next();
|
||||
then(revCommit.getShortMessage()).isEqualTo("some message");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_push_a_tag_to_new_branch_in_origin() throws Exception {
|
||||
File origin = clonedProject();
|
||||
@@ -202,6 +218,18 @@ public class GitProjectRepoTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_revert_changes() throws Exception {
|
||||
File project = this.gitRepo.cloneProject(this.springCloudReleaseProject.toURI());
|
||||
|
||||
this.gitRepo.revert(project, "some message");
|
||||
|
||||
try(Git git = openGitProject(project)) {
|
||||
RevCommit revCommit = git.log().call().iterator().next();
|
||||
then(revCommit.getShortMessage()).isEqualTo("some message");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ExceptionThrowingJGitFactory extends GitRepo.JGitFactory {
|
||||
@@ -6,6 +6,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectVersion;
|
||||
|
||||
import static org.mockito.BDDMockito.then;
|
||||
@@ -21,7 +22,7 @@ import static org.mockito.Mockito.never;
|
||||
public class ProjectGitUpdaterTests {
|
||||
|
||||
@Mock GitRepo gitRepo;
|
||||
ProjectGitUpdater updater = new ProjectGitUpdater() {
|
||||
ProjectGitUpdater updater = new ProjectGitUpdater(new ReleaserProperties()) {
|
||||
@Override GitRepo gitRepo(File workingDir) {
|
||||
return ProjectGitUpdaterTests.this.gitRepo;
|
||||
}
|
||||
@@ -30,18 +31,39 @@ public class ProjectGitUpdaterTests {
|
||||
|
||||
@Test
|
||||
public void should_only_commit_without_pushing_changes_when_version_is_snapshot() {
|
||||
this.updater.commitAndTagIfApplicable(file, new ProjectVersion("1.0.0.BUILD-SNAPSHOT"));
|
||||
this.updater.commitAndTagIfApplicable(this.file, new ProjectVersion("1.0.0.BUILD-SNAPSHOT"));
|
||||
|
||||
then(this.gitRepo).should().commit(any(File.class), anyString());
|
||||
then(this.gitRepo).should().commit(any(File.class), eq("Bumping versions"));
|
||||
then(this.gitRepo).should(never()).tag(any(File.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_commit_tag_and_push_tag_when_version_is_not_snapshot() {
|
||||
this.updater.commitAndTagIfApplicable(file, new ProjectVersion("1.0.0.RELEASE"));
|
||||
this.updater.commitAndTagIfApplicable(this.file, new ProjectVersion("1.0.0.RELEASE"));
|
||||
|
||||
then(this.gitRepo).should().commit(any(File.class), anyString());
|
||||
then(this.gitRepo).should().commit(any(File.class), eq("Bumping versions before release"));
|
||||
then(this.gitRepo).should().tag(any(File.class), eq("v1.0.0.RELEASE"));
|
||||
then(this.gitRepo).should().pushTag(any(File.class), eq("v1.0.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_not_revert_changes_for_snapshots() {
|
||||
this.updater.revertChangesIfApplicable(this.file, new ProjectVersion("1.0.0.BUILD-SNAPSHOT"));
|
||||
|
||||
then(this.gitRepo).should(never()).revert(any(File.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_revert_changes_when_version_is_not_snapshot() {
|
||||
this.updater.revertChangesIfApplicable(this.file, new ProjectVersion("1.0.0.RELEASE"));
|
||||
|
||||
then(this.gitRepo).should().revert(any(File.class), eq("Going back to snapshots"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_push_current_branch() {
|
||||
this.updater.pushCurrentBranch(this.file);
|
||||
|
||||
then(this.gitRepo).should().pushCurrentBranch(any(File.class));
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import org.apache.maven.model.Model;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.release.internal.git.GitProjectRepoTests;
|
||||
import org.springframework.cloud.release.internal.git.GitRepoTests;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
|
||||
@@ -42,7 +42,7 @@ public class PomReaderTests {
|
||||
|
||||
@Before
|
||||
public void setup() throws URISyntaxException {
|
||||
URI scRelease = GitProjectRepoTests.class.getResource("/projects/spring-cloud-release").toURI();
|
||||
URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI();
|
||||
this.springCloudReleaseProject = new File(scRelease);
|
||||
this.springCloudReleaseProjectPom = new File(scRelease.getPath(), "pom.xml");
|
||||
this.licenseFile = new File(scRelease.getPath(), "LICENSE.txt");
|
||||
|
||||
@@ -30,7 +30,7 @@ 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.git.GitProjectRepoTests;
|
||||
import org.springframework.cloud.release.internal.git.GitRepoTests;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
/**
|
||||
@@ -282,7 +282,7 @@ public class PomUpdaterTests {
|
||||
}
|
||||
|
||||
private File file(String relativePath) throws URISyntaxException {
|
||||
return new File(GitProjectRepoTests.class.getResource(relativePath).toURI());
|
||||
return new File(GitRepoTests.class.getResource(relativePath).toURI());
|
||||
}
|
||||
|
||||
private File pom(String relativePath) throws URISyntaxException {
|
||||
@@ -290,7 +290,7 @@ public class PomUpdaterTests {
|
||||
}
|
||||
|
||||
private File pom(String relativePath, String pomName) throws URISyntaxException {
|
||||
return new File(new File(GitProjectRepoTests.class.getResource(relativePath).toURI()), pomName);
|
||||
return new File(new File(GitRepoTests.class.getResource(relativePath).toURI()), pomName);
|
||||
}
|
||||
|
||||
private String asString(File file) throws IOException {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.release.internal.git.GitProjectRepoTests;
|
||||
import org.springframework.cloud.release.internal.git.GitRepoTests;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
|
||||
@@ -20,7 +20,7 @@ public class ProjectVersionTests {
|
||||
|
||||
@Before
|
||||
public void setup() throws URISyntaxException {
|
||||
URI scRelease = GitProjectRepoTests.class.getResource("/projects/spring-cloud-release").toURI();
|
||||
URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI();
|
||||
this.springCloudReleaseProject = new File(scRelease.getPath(), "pom.xml");
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.release.internal.git.GitProjectRepoTests;
|
||||
import org.springframework.cloud.release.internal.git.GitRepoTests;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
|
||||
@@ -20,7 +20,7 @@ public class SCReleasePomParserTests {
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException, URISyntaxException {
|
||||
this.springCloudReleaseProject = new File(GitProjectRepoTests.class.getResource("/projects/spring-cloud-release").toURI());
|
||||
this.springCloudReleaseProject = new File(GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,7 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy;
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ProjectBuilderTests {
|
||||
public class ProjectTests {
|
||||
|
||||
@Before
|
||||
public void checkOs() {
|
||||
@@ -107,6 +107,36 @@ public class ProjectBuilderTests {
|
||||
thenThrownBy(builder::publishDocs).hasMessageContaining("Process waiting time of [0] minutes exceeded");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_successfully_execute_a_bump_versions_command() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.setWorkingDir(file("/projects/builder/resolved").getPath());
|
||||
Project builder = new Project(properties, executor(properties)) {
|
||||
@Override String bumpVersionsCommand() {
|
||||
return "%s";
|
||||
}
|
||||
};
|
||||
|
||||
builder.bumpVersions("ls -al");
|
||||
|
||||
then(asString(file("/projects/builder/resolved/resolved.log")))
|
||||
.contains("file.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_throw_exception_when_bump_command_took_too_long_to_execute() throws Exception {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.getMaven().setWaitTimeInMinutes(0);
|
||||
properties.setWorkingDir(file("/projects/builder/unresolved").getPath());
|
||||
Project builder = new Project(properties, executor(properties)) {
|
||||
@Override String bumpVersionsCommand() {
|
||||
return "echo '%s'";
|
||||
}
|
||||
};
|
||||
|
||||
thenThrownBy(() -> builder.bumpVersions("1.0.0")).hasMessageContaining("Process waiting time of [0] minutes exceeded");
|
||||
}
|
||||
|
||||
private TestProcessExecutor executor(ReleaserProperties properties) {
|
||||
return new TestProcessExecutor(properties);
|
||||
}
|
||||
@@ -128,7 +158,7 @@ public class ProjectBuilderTests {
|
||||
|
||||
private File file(String relativePath) {
|
||||
try {
|
||||
File root = new File(ProjectBuilderTests.class.getResource("/").toURI());
|
||||
File root = new File(ProjectTests.class.getResource("/").toURI());
|
||||
File file = new File(root, relativePath);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
@@ -20,7 +20,7 @@ import org.springframework.cloud.release.internal.Releaser;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.project.Project;
|
||||
import org.springframework.cloud.release.internal.git.ProjectGitUpdater;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectUpdater;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectPomUpdater;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
class ReleaserConfiguration {
|
||||
|
||||
@Bean Releaser releaser(ReleaserProperties properties) {
|
||||
return new Releaser(properties, new ProjectUpdater(properties),
|
||||
new Project(properties), new ProjectGitUpdater());
|
||||
return new Releaser(properties, new ProjectPomUpdater(properties),
|
||||
new Project(properties), new ProjectGitUpdater(properties));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user