diff --git a/docs/src/main/asciidoc/spring-cloud-releaser.adoc b/docs/src/main/asciidoc/spring-cloud-releaser.adoc index 1e8f2e7b..1997bb7c 100644 --- a/docs/src/main/asciidoc/spring-cloud-releaser.adoc +++ b/docs/src/main/asciidoc/spring-cloud-releaser.adoc @@ -35,7 +35,7 @@ cd spring-cloud-sleuth java -jar ~/path/to/cloned/releaser/releaser-spring/target/releaser-spring-0.0.1.BUILD-SNAPSHOT.jar ---- -You'll be asked to press `Enter` to continue (to check whether you're running it from a proper path). +The application will start running from your working directory. == Future plans diff --git a/releaser-core/src/main/java/org/springframework/cloud/release/internal/PomUpdater.java b/releaser-core/src/main/java/org/springframework/cloud/release/internal/PomUpdater.java index 32b0ab2a..145947c1 100644 --- a/releaser-core/src/main/java/org/springframework/cloud/release/internal/PomUpdater.java +++ b/releaser-core/src/main/java/org/springframework/cloud/release/internal/PomUpdater.java @@ -262,12 +262,18 @@ class PomWriter { class PropertyVersionChanger extends AbstractVersionChanger { private final Versions versions; - private final Log log; + private final PropertyStorer propertyStorer; - public PropertyVersionChanger(ModelWrapper wrapper, Versions versions, ModifiedPomXMLEventReader pom, Log log) { + PropertyVersionChanger(ModelWrapper wrapper, Versions versions, ModifiedPomXMLEventReader pom, Log log) { super(wrapper.model, pom, log); this.versions = versions; - this.log = log; + this.propertyStorer = new PropertyStorer(log, pom); + } + + PropertyVersionChanger(ModelWrapper wrapper, Versions versions, ModifiedPomXMLEventReader pom, Log log, PropertyStorer propertyStorer) { + super(wrapper.model, pom, log); + this.versions = versions; + this.propertyStorer = propertyStorer; } @Override public void apply(final VersionChange versionChange) throws XMLStreamException { @@ -282,13 +288,30 @@ class PropertyVersionChanger extends AbstractVersionChanger { String version = properties.getProperty(projectVersionKey); return !version.equals(project.version); }) - .forEach(project -> { - String propertyName = propertyName(project); - if (setPropertyVersion(propertyName, project.version)) { - info(" Updating property " + propertyName); - info(" to version " + project.version); - } - }); + .forEach(this.propertyStorer::setPropertyVersionIfApplicable); + } + + private String propertyName(Project project) { + return project.name + ".version"; + } +} + +class PropertyStorer { + + private final Log log; + private final ModifiedPomXMLEventReader pom; + + PropertyStorer(Log log, ModifiedPomXMLEventReader pom) { + this.log = log; + this.pom = pom; + } + + void setPropertyVersionIfApplicable(Project project) { + String propertyName = propertyName(project); + if (setPropertyVersion(propertyName, project.version)) { + log.info(" Updating property " + propertyName); + log.info(" to version " + project.version); + } } private String propertyName(Project project) { @@ -297,7 +320,7 @@ class PropertyVersionChanger extends AbstractVersionChanger { private boolean setPropertyVersion(String propertyName, String version) { try { - return PomHelper.setPropertyVersion(getPom(), null, propertyName, version); + return PomHelper.setPropertyVersion(this.pom, null, propertyName, version); } catch (XMLStreamException e) { this.log.error("Exception occurred while trying to set property version", e); diff --git a/releaser-core/src/test/java/org/springframework/cloud/release/internal/LoggerToMavenLogTests.java b/releaser-core/src/test/java/org/springframework/cloud/release/internal/LoggerToMavenLogTests.java new file mode 100644 index 00000000..62eae4fc --- /dev/null +++ b/releaser-core/src/test/java/org/springframework/cloud/release/internal/LoggerToMavenLogTests.java @@ -0,0 +1,118 @@ +package org.springframework.cloud.release.internal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.slf4j.Logger; + +import static org.mockito.BDDMockito.then; + +/** + * @author Marcin Grzejszczak + */ +@RunWith(MockitoJUnitRunner.class) +public class LoggerToMavenLogTests { + + @Mock Logger logger; + @InjectMocks LoggerToMavenLog loggerToMavenLog; + RuntimeException exception = new RuntimeException(); + + @Test public void isDebugEnabled() throws Exception { + this.loggerToMavenLog.isDebugEnabled(); + + then(this.logger).should().isDebugEnabled(); + } + + @Test public void debug() throws Exception { + this.loggerToMavenLog.debug("foo"); + + then(this.logger).should().debug("foo"); + } + + @Test public void debug1() throws Exception { + this.loggerToMavenLog.debug("foo", this.exception); + + then(this.logger).should().debug("foo", this.exception); + } + + @Test public void debug2() throws Exception { + this.loggerToMavenLog.debug(exception); + + then(this.logger).should().debug("Exception occurred", this.exception); + } + + @Test public void isInfoEnabled() throws Exception { + this.loggerToMavenLog.isInfoEnabled(); + + then(this.logger).should().isInfoEnabled(); + } + + @Test public void info() throws Exception { + this.loggerToMavenLog.info("foo"); + + then(this.logger).should().info("foo"); + } + + @Test public void info1() throws Exception { + this.loggerToMavenLog.info("foo", this.exception); + + then(this.logger).should().info("foo", this.exception); + } + + @Test public void info2() throws Exception { + this.loggerToMavenLog.info(exception); + + then(this.logger).should().info("Exception occurred", this.exception); + } + + @Test public void isWarnEnabled() throws Exception { + this.loggerToMavenLog.isWarnEnabled(); + + then(this.logger).should().isWarnEnabled(); + } + + @Test public void warn() throws Exception { + this.loggerToMavenLog.warn("foo"); + + then(this.logger).should().warn("foo"); + } + + @Test public void warn1() throws Exception { + this.loggerToMavenLog.warn("foo", this.exception); + + then(this.logger).should().warn("foo", this.exception); + } + + @Test public void warn2() throws Exception { + this.loggerToMavenLog.warn(exception); + + then(this.logger).should().warn("Exception occurred", this.exception); + } + + @Test public void isErrorEnabled() throws Exception { + this.loggerToMavenLog.isErrorEnabled(); + + then(this.logger).should().isErrorEnabled(); + } + + @Test public void error() throws Exception { + this.loggerToMavenLog.error("foo"); + + then(this.logger).should().error("foo"); + } + + @Test public void error1() throws Exception { + this.loggerToMavenLog.error("foo", this.exception); + + then(this.logger).should().error("foo", this.exception); + } + + @Test public void error2() throws Exception { + this.loggerToMavenLog.error(exception); + + then(this.logger).should().error("Exception occurred", this.exception); + } + +} \ No newline at end of file diff --git a/releaser-core/src/test/java/org/springframework/cloud/release/internal/PropertyVersionChangerTests.java b/releaser-core/src/test/java/org/springframework/cloud/release/internal/PropertyVersionChangerTests.java new file mode 100644 index 00000000..f48cd9da --- /dev/null +++ b/releaser-core/src/test/java/org/springframework/cloud/release/internal/PropertyVersionChangerTests.java @@ -0,0 +1,105 @@ +package org.springframework.cloud.release.internal; + +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import org.apache.maven.model.Model; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import edu.emory.mathcs.backport.java.util.Arrays; + +import static org.mockito.BDDMockito.then; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.never; + +/** + * @author Marcin Grzejszczak + */ +@RunWith(MockitoJUnitRunner.class) +public class PropertyVersionChangerTests { + + @Mock PropertyStorer propertyStorer; + + @Test + public void should_set_version_when_project_matches_property_name() throws Exception { + PropertyVersionChanger changer = new PropertyVersionChanger(model(), versions(), null, null, this.propertyStorer); + + changer.apply(null); + + then(this.propertyStorer).should().setPropertyVersionIfApplicable(project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT")); + } + + @Test + public void should_not_set_version_when_project_doesnt_match_property_name() throws Exception { + PropertyVersionChanger changer = new PropertyVersionChanger(nonMatchingModel(), versions(), null, null, this.propertyStorer); + + changer.apply(null); + + then(this.propertyStorer).should(never()).setPropertyVersionIfApplicable(any(Project.class)); + } + + @Test + public void should_not_set_version_when_project_matches_property_name_and_versions_are_the_same() throws Exception { + PropertyVersionChanger changer = new PropertyVersionChanger(modelWithSameValues(), versions(), null, null, this.propertyStorer); + + changer.apply(null); + + then(this.propertyStorer).should(never()).setPropertyVersionIfApplicable(any(Project.class)); + } + + Versions versions() { + return new Versions("", "", allProjects()); + } + + @SuppressWarnings("unchecked") + private Set allProjects() { + return new HashSet<>(Arrays.asList(new Project[] { + project("spring-cloud-aws", "1.2.0.BUILD-SNAPSHOT"), + project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT") + })); + } + + Project project(String name, String value) { + return new Project(name, value); + } + + ModelWrapper model() { + Model model = new Model(); + model.setProperties(properties()); + return new ModelWrapper(model); + } + + Properties properties() { + Properties properties = new Properties(); + properties.setProperty("spring-cloud-sleuth.version", "1.0.0.RELEASE"); + return properties; + } + + ModelWrapper modelWithSameValues() { + Model model = new Model(); + model.setProperties(propertiesWithSameValues()); + return new ModelWrapper(model); + } + + Properties propertiesWithSameValues() { + Properties properties = new Properties(); + properties.setProperty("spring-cloud-sleuth.version", "1.2.0.BUILD-SNAPSHOT"); + return properties; + } + + ModelWrapper nonMatchingModel() { + Model model = new Model(); + model.setProperties(nonMatchingProperties()); + return new ModelWrapper(model); + } + + Properties nonMatchingProperties() { + Properties properties = new Properties(); + properties.setProperty("spring-cloud-non-matching.version", "1.0.0.RELEASE"); + return properties; + } +} \ No newline at end of file diff --git a/releaser-spring/src/main/java/org/springframework/cloud/release/ReleaserApplication.java b/releaser-spring/src/main/java/org/springframework/cloud/release/ReleaserApplication.java index 1016acbb..8057ead5 100644 --- a/releaser-spring/src/main/java/org/springframework/cloud/release/ReleaserApplication.java +++ b/releaser-spring/src/main/java/org/springframework/cloud/release/ReleaserApplication.java @@ -41,8 +41,6 @@ public class ReleaserApplication implements CommandLineRunner { @Override public void run(String... strings) throws Exception { String workingDir = System.getProperty("user.dir"); log.info("Will run the application for root folder [{}]", workingDir); - log.info("Press Enter to continue..."); - System.in.read(); this.projectUpdater.updateProject(new File(workingDir)); System.exit(0); }