diff --git a/pom.xml b/pom.xml index 29e92597..4fdaf3e9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.danielflower.mavenplugins multi-module-maven-release-plugin - 3.2-SNAPSHOT + 3.3-SNAPSHOT The Multi Module Maven Release Plugin A maven release plugin built for multi-maven-module git repositories allowing continuous deployment @@ -123,6 +123,15 @@ maven-invoker 3.0.1 + + + org.apache.commons + commons-lang3 + 3.4 + org.eclipse.jgit org.eclipse.jgit diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/AnnotatedTag.java b/src/main/java/com/github/danielflower/mavenplugins/release/AnnotatedTag.java index 4a54d350..1da566c7 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/AnnotatedTag.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/AnnotatedTag.java @@ -28,10 +28,10 @@ private AnnotatedTag(Ref ref, String name, JSONObject message) { this.message = message; } - public static AnnotatedTag create(String name, String version, long buildNumber) { + public static AnnotatedTag create(String name, String version, String buildNumber) { JSONObject message = new JSONObject(); message.put(VERSION, version); - message.put(BUILD_NUMBER, String.valueOf(buildNumber)); + message.put(BUILD_NUMBER, buildNumber); return new AnnotatedTag(null, name, message); } @@ -67,8 +67,8 @@ public String version() { return String.valueOf(message.get(VERSION)); } - public long buildNumber() { - return Long.parseLong(String.valueOf(message.get(BUILD_NUMBER))); + public String buildNumber() { + return String.valueOf(message.get(BUILD_NUMBER)); } public Ref saveAtHEAD(Git git) throws GitAPIException { diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/AnnotatedTagFinder.java b/src/main/java/com/github/danielflower/mavenplugins/release/AnnotatedTagFinder.java index 770e19c9..dd154e4f 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/AnnotatedTagFinder.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/AnnotatedTagFinder.java @@ -46,18 +46,12 @@ boolean isPotentiallySameVersionIgnoringBuildNumber(String versionWithoutBuildNu return buildNumberOf(versionWithoutBuildNumber, refName) != null; } - Long buildNumberOf(String versionWithoutBuildNumber, String refName) { + String buildNumberOf(String versionWithoutBuildNumber, String refName) { String tagName = AnnotatedTag.stripRefPrefix(refName); String prefix = versionWithoutBuildNumber + versionNamer.getDelimiter(); if (tagName.startsWith(prefix)) { - String end = tagName.substring(prefix.length()); - try { - return Long.parseLong(end); - } catch (NumberFormatException e) { - return null; - } + return tagName.substring(prefix.length()); } return null; } - } diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java b/src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java index 0a008357..750ae55c 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java @@ -1,11 +1,13 @@ package com.github.danielflower.mavenplugins.release; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Scm; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; @@ -43,16 +45,37 @@ public abstract class BaseMojo extends AbstractMojo { *

*

* By default, the plugin will automatically find a suitable build number. - * It will start at version 0 and increment this with each release. + * It will start at 0 and increment this with each release. *

*

- * This can be specified using a command line parameter ("-DbuildNumber=2") - * or in this plugin's configuration. + * This can be specified using a command line parameter (e.g. + * -DbuildNumber=2) or in this plugin's configuration. *

+ *

+ * null vs. "": if you do not define the build number it + * is treated as null and the plugin will start at 0. If you + * pass an empty string both the build number and the delimiter that + * precedes it will be omitted.
To define an empty string on the CLI use + * -DbuildNumber=''. For the same effect in the POM you can + * use <buildNumber>""</buildNumber> as Maven does + * not support empty strings for configuration properties. The plugin will + * convert this accordingly. + *

*/ + // Maven has historically never supported empty strings in XML plugin configuration (see + // http://mail-archives.apache.org/mod_mbox/maven-users/200708.mbox/%3C5a2cf1f60708090246l216f156esf46cc1e968b37ccd@mail.gmail.com%3E + // from 2007). Hence, if a project defines the property here will be null. However, + // Maven does support -DbuildNumber='' on the CLI. @Parameter(property = "buildNumber") - protected Long buildNumber; + protected String buildNumber; + public void setBuildNumber(String buildNumber) { + if ("\"\"".equals(buildNumber)) { + this.buildNumber = StringUtils.EMPTY; + } else { + this.buildNumber = buildNumber; + } + } /** *

@@ -252,5 +275,4 @@ protected static String getRemoteUrlOrNullIfNoneSet(Scm originalScm, Scm actualS } return GitHelper.scmUrlToRemote(remote); } - } diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/Reactor.java b/src/main/java/com/github/danielflower/mavenplugins/release/Reactor.java index b1422036..a9926204 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/Reactor.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/Reactor.java @@ -1,5 +1,6 @@ package com.github.danielflower.mavenplugins.release; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; @@ -28,7 +29,7 @@ public List getModulesInBuildOrder() { return modulesInBuildOrder; } - public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject rootProject, List projects, Long buildNumber, List modulesToForceRelease, NoChangesAction actionWhenNoChangesDetected, ResolverWrapper resolverWrapper, VersionNamer versionNamer) throws ValidationException, GitAPIException, MojoExecutionException { + public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject rootProject, List projects, String buildNumber, List modulesToForceRelease, NoChangesAction actionWhenNoChangesDetected, ResolverWrapper resolverWrapper, VersionNamer versionNamer) throws ValidationException, GitAPIException, MojoExecutionException { DiffDetector detector = new TreeWalkingDiffDetector(gitRepo.git.getRepository()); List modules = new ArrayList(); @@ -42,14 +43,14 @@ public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject r List previousTagsForThisModule = annotatedTagFinder.tagsForVersion(gitRepo.git, artifactId, versionWithoutBuildNumber); - Collection previousBuildNumbers = new ArrayList(); + Collection previousBuildNumbers = new ArrayList<>(); if (previousTagsForThisModule != null) { for (AnnotatedTag previousTag : previousTagsForThisModule) { previousBuildNumbers.add(previousTag.buildNumber()); } } - Collection remoteBuildNumbers = getRemoteBuildNumbers(gitRepo, artifactId, versionWithoutBuildNumber, versionNamer); + Collection remoteBuildNumbers = getRemoteBuildNumbers(gitRepo, artifactId, versionWithoutBuildNumber, versionNamer); previousBuildNumbers.addAll(remoteBuildNumbers); VersionName newVersion = versionNamer.name(project.getVersion(), buildNumber, previousBuildNumbers); @@ -145,14 +146,14 @@ private static boolean hasSameMavenGAByDependencyLocation(ReleasableModule modul return modelId[0].equals(module.getGroupId()) && modelId[1].equals(module.getArtifactId()); } - private static Collection getRemoteBuildNumbers(LocalGitRepo gitRepo, String artifactId, String versionWithoutBuildNumber, VersionNamer versionNamer) throws GitAPIException { + private static Collection getRemoteBuildNumbers(LocalGitRepo gitRepo, String artifactId, String versionWithoutBuildNumber, VersionNamer versionNamer) throws GitAPIException { Collection remoteTagRefs = gitRepo.allTags(); - Collection remoteBuildNumbers = new ArrayList(); + Collection remoteBuildNumbers = new ArrayList<>(); String tagWithoutBuildNumber = artifactId + "-" + versionWithoutBuildNumber; AnnotatedTagFinder annotatedTagFinder = new AnnotatedTagFinder(versionNamer); for (Ref remoteTagRef : remoteTagRefs) { String remoteTagName = remoteTagRef.getName(); - Long buildNumber = annotatedTagFinder.buildNumberOf(tagWithoutBuildNumber, remoteTagName); + String buildNumber = annotatedTagFinder.buildNumberOf(tagWithoutBuildNumber, remoteTagName); if (buildNumber != null) { remoteBuildNumbers.add(buildNumber); } @@ -190,20 +191,25 @@ static AnnotatedTag hasChangedSinceLastRelease(List previousTagsFo try { if (previousTagsForThisModule.size() == 0) return null; boolean hasChanged = detector.hasChangedSince(relativePathToModule, project.getModel().getModules(), previousTagsForThisModule); - return hasChanged ? null : tagWithHighestBuildNumber(previousTagsForThisModule); + return hasChanged ? null : findTagWithHighestBuildNumber(previousTagsForThisModule); } catch (Exception e) { throw new MojoExecutionException("Error while detecting whether or not " + project.getArtifactId() + " has changed since the last release", e); } } - private static AnnotatedTag tagWithHighestBuildNumber(List tags) { - AnnotatedTag cur = null; + // Ignores any tags with non-numeric build numbers and finds the one with the largest build number among the others. + // The tags are guaranteed to be for the same /business version/ i.e. it's likely a small list. + private static AnnotatedTag findTagWithHighestBuildNumber(List tags) { + AnnotatedTag tagWithHighestBuildNumber = null; for (AnnotatedTag tag : tags) { - if (cur == null || tag.buildNumber() > cur.buildNumber()) { - cur = tag; + if(StringUtils.isNumeric(tag.buildNumber())) { + if (tagWithHighestBuildNumber == null || + Long.parseLong(tag.buildNumber()) > Long.parseLong(tagWithHighestBuildNumber.buildNumber())) { + tagWithHighestBuildNumber = tag; + } } } - return cur; + return tagWithHighestBuildNumber; } public ReleasableModule findByLabel(String label) { diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/ReleasableModule.java b/src/main/java/com/github/danielflower/mavenplugins/release/ReleasableModule.java index d76f0cd5..a70fbe2c 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/ReleasableModule.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/ReleasableModule.java @@ -44,7 +44,7 @@ public String getVersion() { return version.businessVersion(); } - public long getBuildNumber() { + public String getBuildNumber() { return version.buildNumber(); } diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/VersionName.java b/src/main/java/com/github/danielflower/mavenplugins/release/VersionName.java index f6d13cad..01bdda80 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/VersionName.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/VersionName.java @@ -1,12 +1,15 @@ package com.github.danielflower.mavenplugins.release; +import org.apache.commons.lang3.StringUtils; + public class VersionName { private final String version; - private final long buildNumber; + private final String buildNumber; private final String developmentVersion; private final String delimiter; + private final String releaseVersion; - public VersionName(String developmentVersion, String version, long buildNumber, String delimiter) { + public VersionName(String developmentVersion, String version, String buildNumber, String delimiter) { Guard.notBlank("developmentVersion", developmentVersion); Guard.notBlank("version", version); Guard.notNull("buildNumber", buildNumber); @@ -14,20 +17,21 @@ public VersionName(String developmentVersion, String version, long buildNumber, this.buildNumber = buildNumber; this.developmentVersion = developmentVersion; this.delimiter = delimiter; + this.releaseVersion = buildNumber.length() > 0 ? version + delimiter + buildNumber : version; } - public VersionName(String developmentVersion, String version, long buildNumber) { + public VersionName(String developmentVersion, String version, String buildNumber) { this(developmentVersion, version, buildNumber, "."); } /** - * For example, "1.0" if the development version is "1.0-SNAPSHOT" + * For example, "1.0" if the development version is "1.0-SNAPSHOT". */ public String businessVersion() { return version; } - public long buildNumber() { + public String buildNumber() { return buildNumber; } @@ -42,6 +46,6 @@ public String developmentVersion() { * The business version with the build number appended, e.g. "1.0.1" */ public String releaseVersion() { - return version + delimiter + buildNumber; + return releaseVersion; } } diff --git a/src/main/java/com/github/danielflower/mavenplugins/release/VersionNamer.java b/src/main/java/com/github/danielflower/mavenplugins/release/VersionNamer.java index 3c9d77ff..7763539a 100644 --- a/src/main/java/com/github/danielflower/mavenplugins/release/VersionNamer.java +++ b/src/main/java/com/github/danielflower/mavenplugins/release/VersionNamer.java @@ -1,5 +1,6 @@ package com.github.danielflower.mavenplugins.release; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.plugins.annotations.Parameter; import org.eclipse.jgit.lib.Repository; @@ -33,35 +34,38 @@ public VersionNamer() { this("."); } - public VersionName name(String pomVersion, Long buildNumber, Collection previousBuildNumbers) throws ValidationException { - + public VersionName name(String pomVersion, String buildNumber, Collection previousBuildNumbers) throws ValidationException { + String effectiveBuildNumber = buildNumber; if (buildNumber == null) { - if (previousBuildNumbers.size() == 0) { - buildNumber = 0L; + if (previousBuildNumbers == null || previousBuildNumbers.isEmpty()) { + effectiveBuildNumber = "0"; } else { - buildNumber = nextBuildNumber(previousBuildNumbers); + effectiveBuildNumber = nextBuildNumber(previousBuildNumbers); } } - VersionName versionName = new VersionName(pomVersion, pomVersion.replace("-SNAPSHOT", ""), buildNumber, this.delimiter); + VersionName versionName = new VersionName(pomVersion, pomVersion.replace("-SNAPSHOT", ""), effectiveBuildNumber, this.delimiter); if (!Repository.isValidRefName("refs/tags/" + versionName.releaseVersion())) { String summary = "Sorry, '" + versionName.releaseVersion() + "' is not a valid version."; throw new ValidationException(summary, asList( summary, - "Version numbers are used in the Git tag, and so can only contain characters that are valid in git tags.", + "Version numbers are used in the Git tag, and so can only contain characters that are valid in Git tags.", "Please see https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html for tag naming rules." )); } return versionName; } - private static long nextBuildNumber(Collection previousBuildNumbers) { + // Increments the largest previous build number. Skips over any non-numeric previous build numbers. + private static String nextBuildNumber(Collection previousBuildNumbers) { long max = 0; - for (Long buildNumber : previousBuildNumbers) { - max = Math.max(max, buildNumber); + for (String buildNumber : previousBuildNumbers) { + if (StringUtils.isNumeric(buildNumber)) { + max = Math.max(max, Long.parseLong(buildNumber)); + } } - return max + 1; + return String.valueOf(max + 1); } String getDelimiter() { diff --git a/src/site/markdown/changelog.md b/src/site/markdown/changelog.md index 408c267a..b0d59c26 100644 --- a/src/site/markdown/changelog.md +++ b/src/site/markdown/changelog.md @@ -1,6 +1,10 @@ Changelog --------- +### 3.3.0 + +* Allow build numbers to be arbitrary strings or null, #75 + ### 3.2.0 * Added support for processing version properties e.g. `${foo.version}` diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/AnnotatedTagFinderTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/AnnotatedTagFinderTest.java index ff93802a..dc1e1a1e 100644 --- a/src/test/java/com/github/danielflower/mavenplugins/release/AnnotatedTagFinderTest.java +++ b/src/test/java/com/github/danielflower/mavenplugins/release/AnnotatedTagFinderTest.java @@ -22,22 +22,22 @@ public class AnnotatedTagFinderTest { public void findsTheLatestCommitWhereThereHaveBeenNoBranches() throws Exception { TestProject project = TestProject.independentVersionsProject(); - AnnotatedTag tag1 = saveFileInModule(project, "console-app", "1.2", 3); - AnnotatedTag tag2 = saveFileInModule(project, "core-utils", "2", 0); - AnnotatedTag tag3 = saveFileInModule(project, "console-app", "1.2", 4); + AnnotatedTag tag1 = saveFileInModule(project, "console-app", "1.2", "3"); + AnnotatedTag tag2 = saveFileInModule(project, "core-utils", "2", "0"); + AnnotatedTag tag3 = saveFileInModule(project, "console-app", "1.2", "4"); assertThat(annotatedTagFinder.tagsForVersion(project.local, "console-app", "1.3"), hasSize(0)); assertThat(annotatedTagFinder.tagsForVersion(project.local, "console-app", "1.2"), containsInAnyOrder(tag1, tag3)); assertThat(annotatedTagFinder.tagsForVersion(project.local, "core-utils", "2"), contains(tag2)); } - static AnnotatedTag saveFileInModule(TestProject project, String moduleName, String version, long buildNumber) throws IOException, GitAPIException { + static AnnotatedTag saveFileInModule(TestProject project, String moduleName, String version, String buildNumber) throws IOException, GitAPIException { project.commitRandomFile(moduleName); String nameForTag = moduleName.equals(".") ? "root" : moduleName; return tagLocalRepo(project, nameForTag + "-" + version + versionNamer.getDelimiter() + buildNumber, version, buildNumber); } - private static AnnotatedTag tagLocalRepo(TestProject project, String tagName, String version, long buildNumber) throws GitAPIException { + private static AnnotatedTag tagLocalRepo(TestProject project, String tagName, String version, String buildNumber) throws GitAPIException { AnnotatedTag tag = AnnotatedTag.create(tagName, version, buildNumber); tag.saveAtHEAD(project.local); return tag; @@ -54,10 +54,10 @@ public void canRecogniseTagsThatArePotentiallyOfTheSameVersion() { @Test public void returnsMultipleTagsOnASingleCommit() throws IOException, GitAPIException, MojoExecutionException { TestProject project = TestProject.independentVersionsProject(); - saveFileInModule(project, "console-app", "1.2", 1); - AnnotatedTag tag1 = tagLocalRepo(project, "console-app-1.1.1.1", "1.1.1", 1); - AnnotatedTag tag3 = tagLocalRepo(project, "console-app-1.1.1.3", "1.1.1", 3); - AnnotatedTag tag2 = tagLocalRepo(project, "console-app-1.1.1.2", "1.1.1", 2); + saveFileInModule(project, "console-app", "1.2", "1"); + AnnotatedTag tag1 = tagLocalRepo(project, "console-app-1.1.1.1", "1.1.1", "1"); + AnnotatedTag tag3 = tagLocalRepo(project, "console-app-1.1.1.3", "1.1.1", "3"); + AnnotatedTag tag2 = tagLocalRepo(project, "console-app-1.1.1.2", "1.1.1", "2"); List annotatedTags = annotatedTagFinder.tagsForVersion(project.local, "console-app", "1.1.1"); assertThat(annotatedTags, containsInAnyOrder(tag1, tag2, tag3)); } @@ -65,7 +65,7 @@ public void returnsMultipleTagsOnASingleCommit() throws IOException, GitAPIExcep @Test public void versionNamerCaresNotForOrderOfTags() throws ValidationException { VersionNamer versionNamer = new VersionNamer(); - VersionName name = versionNamer.name("1.1.1", null, asList(1L, 3L, 2L)); + VersionName name = versionNamer.name("1.1.1", null, asList("1", "3", "2")); assertThat(name.releaseVersion(), equalTo("1.1.1.4")); } @@ -76,15 +76,15 @@ public void respectDelimiterWhenExtractingBuildNumber() { // This should actually be implemented with a parameterized JUnit test but since this class isn't set up for // that yet we'll use our own data-driven harness. Arrays.asList(new Object[][]{ + new Object[]{"libs-1.0.0", refPrefix + "libs-1.0.0-1", "1"}, // proper match with expected delimiter + new Object[]{"libs-1.0.0", refPrefix + "libs-1.0.0-A", "A"}, // non-numeric build number new Object[]{"libs-1.0.0", refPrefix + "foo-1.0.0-1", null}, // artifact ID does not match -> expect null - new Object[]{"libs-1.0.0", refPrefix + "libs-1.0.0-1", 1L}, // proper match with expected delimiter new Object[]{"libs-1.0.0", refPrefix + "libs-1.0.0.1", null}, // no delimiter match new Object[]{"libs-1.0.0", refPrefix + "libs-1.0.0@1", null}, // no delimiter match - new Object[]{"libs-1.0.0", refPrefix + "libs-1.0.0-A", null} // format exception on build number }) .forEach(dataSet -> { final Object expectedBuildNumber = dataSet[2]; - final Long buildNumber = tagFinder.buildNumberOf(dataSet[0].toString(), dataSet[1].toString()); + final String buildNumber = tagFinder.buildNumberOf(dataSet[0].toString(), dataSet[1].toString()); assertThat(buildNumber, is(expectedBuildNumber)); }); } diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/AnnotatedTagTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/AnnotatedTagTest.java index 1abce6fa..7b68b8df 100644 --- a/src/test/java/com/github/danielflower/mavenplugins/release/AnnotatedTagTest.java +++ b/src/test/java/com/github/danielflower/mavenplugins/release/AnnotatedTagTest.java @@ -12,25 +12,25 @@ public class AnnotatedTagTest { @Test - public void gettersReturnValuesPassedIn() throws Exception { + public void gettersReturnValuesPassedIn() { // yep, testing getters... but only because it isn't a simple POJO - AnnotatedTag tag = AnnotatedTag.create("my-name", "the-version", 2134); + AnnotatedTag tag = AnnotatedTag.create("my-name", "the-version", "2134"); assertThat(tag.name(), equalTo("my-name")); assertThat(tag.version(), equalTo("the-version")); - assertThat(tag.buildNumber(), equalTo(2134L)); + assertThat(tag.buildNumber(), equalTo("2134")); } @Test public void aTagCanBeCreatedFromAGitTag() throws GitAPIException, IOException { TestProject project = TestProject.singleModuleProject(); - AnnotatedTag tag = AnnotatedTag.create("my-name", "the-version", 2134); + AnnotatedTag tag = AnnotatedTag.create("my-name", "the-version", "2134"); tag.saveAtHEAD(project.local); Ref ref = project.local.tagList().call().get(0); AnnotatedTag inflatedTag = AnnotatedTag.fromRef(project.local.getRepository(), ref); assertThat(inflatedTag.name(), equalTo("my-name")); assertThat(inflatedTag.version(), equalTo("the-version")); - assertThat(inflatedTag.buildNumber(), equalTo(2134L)); + assertThat(inflatedTag.buildNumber(), equalTo("2134")); } @Test @@ -42,7 +42,7 @@ public void ifATagIsSavedWithoutJsonThenTheVersionIsSetTo0Dot0() throws GitAPIEx AnnotatedTag inflatedTag = AnnotatedTag.fromRef(project.local.getRepository(), ref); assertThat(inflatedTag.name(), equalTo("my-name-1.0.2")); assertThat(inflatedTag.version(), equalTo("0")); - assertThat(inflatedTag.buildNumber(), equalTo(0L)); + assertThat(inflatedTag.buildNumber(), equalTo("0")); } } diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/DiffDetectorTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/DiffDetectorTest.java index d465d357..1570c27e 100644 --- a/src/test/java/com/github/danielflower/mavenplugins/release/DiffDetectorTest.java +++ b/src/test/java/com/github/danielflower/mavenplugins/release/DiffDetectorTest.java @@ -18,9 +18,9 @@ public class DiffDetectorTest { public void canDetectIfFilesHaveBeenChangedForAModuleSinceSomeSpecificTag() throws Exception { TestProject project = TestProject.independentVersionsProject(); - AnnotatedTag tag1 = saveFileInModule(project, "console-app", "1.2", 3); - AnnotatedTag tag2 = saveFileInModule(project, "core-utils", "2", 0); - AnnotatedTag tag3 = saveFileInModule(project, "console-app", "1.2", 4); + AnnotatedTag tag1 = saveFileInModule(project, "console-app", "1.2", "3"); + AnnotatedTag tag2 = saveFileInModule(project, "core-utils", "2", "0"); + AnnotatedTag tag3 = saveFileInModule(project, "console-app", "1.2", "4"); DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository()); @@ -32,12 +32,12 @@ public void canDetectIfFilesHaveBeenChangedForAModuleSinceSomeSpecificTag() thro @Test public void canDetectThingsInTheRoot() throws IOException, GitAPIException { TestProject simple = TestProject.singleModuleProject(); - AnnotatedTag tag1 = saveFileInModule(simple, ".", "1.0", 1); + AnnotatedTag tag1 = saveFileInModule(simple, ".", "1.0", "1"); simple.commitRandomFile("."); DiffDetector detector = new TreeWalkingDiffDetector(simple.local.getRepository()); assertThat(detector.hasChangedSince(".", noChildModules(), asList(tag1)), is(true)); - AnnotatedTag tag2 = saveFileInModule(simple, ".", "1.0", 2); + AnnotatedTag tag2 = saveFileInModule(simple, ".", "1.0", "2"); assertThat(detector.hasChangedSince(".", noChildModules(), asList(tag2)), is(false)); } @@ -45,9 +45,9 @@ public void canDetectThingsInTheRoot() throws IOException, GitAPIException { public void canDetectChangesAfterTheLastTag() throws IOException, GitAPIException { TestProject project = TestProject.independentVersionsProject(); - saveFileInModule(project, "console-app", "1.2", 3); - saveFileInModule(project, "core-utils", "2", 0); - AnnotatedTag tag3 = saveFileInModule(project, "console-app", "1.2", 4); + saveFileInModule(project, "console-app", "1.2", "3"); + saveFileInModule(project, "core-utils", "2", "0"); + AnnotatedTag tag3 = saveFileInModule(project, "console-app", "1.2", "4"); project.commitRandomFile("console-app"); DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository()); @@ -58,7 +58,7 @@ public void canDetectChangesAfterTheLastTag() throws IOException, GitAPIExceptio public void canIgnoreChangesInModuleFolders() throws IOException, GitAPIException { TestProject project = TestProject.nestedProject(); - AnnotatedTag tag1 = saveFileInModule(project, "server-modules", "1.0.2.4", 0); + AnnotatedTag tag1 = saveFileInModule(project, "server-modules", "1.0.2.4", "0"); project.commitRandomFile("server-modules/server-module-a"); DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository()); @@ -70,7 +70,7 @@ public void canIgnoreChangesInModuleFolders() throws IOException, GitAPIExceptio public void canDetectLocalChangesWithModuleFolders() throws IOException, GitAPIException { TestProject project = TestProject.nestedProject(); - AnnotatedTag tag1 = saveFileInModule(project, "server-modules", "1.0.2.4", 0); + AnnotatedTag tag1 = saveFileInModule(project, "server-modules", "1.0.2.4", "0"); project.commitRandomFile("server-modules"); DiffDetector detector = new TreeWalkingDiffDetector(project.local.getRepository()); diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/LocalGitRepoTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/LocalGitRepoTest.java index aa7ee251..e206fe4f 100644 --- a/src/test/java/com/github/danielflower/mavenplugins/release/LocalGitRepoTest.java +++ b/src/test/java/com/github/danielflower/mavenplugins/release/LocalGitRepoTest.java @@ -70,9 +70,9 @@ public void canHaveManyTags() throws GitAPIException { } private static List tags(String... tagNames) { - List tags = new ArrayList(); + List tags = new ArrayList<>(); for (String tagName : tagNames) { - tags.add(AnnotatedTag.create(tagName, "1", 0)); + tags.add(AnnotatedTag.create(tagName, "1", "0")); } return tags; } diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/ReactorTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/ReactorTest.java index 0ba29111..bb2e83b0 100644 --- a/src/test/java/com/github/danielflower/mavenplugins/release/ReactorTest.java +++ b/src/test/java/com/github/danielflower/mavenplugins/release/ReactorTest.java @@ -49,8 +49,8 @@ public void ifNotFoundThenAUnresolvedSnapshotDependencyExceptionIsThrown() throw @Test public void returnsTheLatestTagIfThereAreChanges() throws MojoExecutionException { - AnnotatedTag onePointNine = AnnotatedTag.create("whatever-1.1.9", "1.1", 9); - AnnotatedTag onePointTen = AnnotatedTag.create("whatever-1.1.10", "1.1", 10); + AnnotatedTag onePointNine = AnnotatedTag.create("whatever-1.1.9", "1.1", "9"); + AnnotatedTag onePointTen = AnnotatedTag.create("whatever-1.1.10", "1.1", "10"); assertThat(Reactor.hasChangedSinceLastRelease(asList(onePointNine, onePointTen), new NeverChanged(), new MavenProject(), "whatever"), is(onePointTen)); assertThat(Reactor.hasChangedSinceLastRelease(asList(onePointTen, onePointNine), new NeverChanged(), new MavenProject(), "whatever"), is(onePointTen)); } diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/ReleasableModuleTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/ReleasableModuleTest.java index 5f7b10b6..ccd44b2e 100644 --- a/src/test/java/com/github/danielflower/mavenplugins/release/ReleasableModuleTest.java +++ b/src/test/java/com/github/danielflower/mavenplugins/release/ReleasableModuleTest.java @@ -20,18 +20,18 @@ public void getsTheTagFromTheArtifactAndVersion() throws Exception { } @Test - public void aReleaseableModuleCanBeCreatedFromAnUnreleasableOne() { + public void aReleasableModuleCanBeCreatedFromAnUnreleasableOne() { MavenProject project = new MavenProject(); project.setArtifactId("some-arty"); project.setGroupId("some-group"); ReleasableModule first = new ReleasableModule( - project, new VersionName("1.2.3-SNAPSHOT", "1.2.3", 12), "1.2.3.11", "somewhere" + project, new VersionName("1.2.3-SNAPSHOT", "1.2.3", "12"), "1.2.3.11", "somewhere" ); assertThat(first.willBeReleased(), is(false)); ReleasableModule changed = first.createReleasableVersion(); assertThat(changed.getArtifactId(), equalTo("some-arty")); - assertThat(changed.getBuildNumber(), equalTo(12L)); + assertThat(changed.getBuildNumber(), equalTo("12")); assertThat(changed.getGroupId(), equalTo("some-group")); assertThat(changed.getNewVersion(), equalTo("1.2.3.12")); assertThat(changed.getProject(), is(project)); diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/VersionNameTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/VersionNameTest.java new file mode 100644 index 00000000..fb016b72 --- /dev/null +++ b/src/test/java/com/github/danielflower/mavenplugins/release/VersionNameTest.java @@ -0,0 +1,49 @@ +package com.github.danielflower.mavenplugins.release; + +import org.hamcrest.CoreMatchers; +import org.hamcrest.MatcherAssert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +import java.util.Arrays; +import java.util.Collection; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(Parameterized.class) +public class VersionNameTest { + + @Parameter + public String version; + + @Parameter(1) + public String buildNumber; + + @Parameter(2) + public String expectedReleaseVersion; + + @Parameters(name = "{0} {1} -> {2}") + public static Collection data() { + return Arrays.asList( + new String[]{"1.0", "5", "1.0-5"}, + new String[]{"1.0", "", "1.0"} + //new String[]{"1.0", null, "1.0"}, // in theory yes, in practice there's a not-null precondition in the VersionName c'tor + ); + } + + @Test + public void shouldAppendBuildNumberIfNotEmpty() { + // given + VersionName versionName = new VersionName("1.0-SNAPSHOT", version, buildNumber, "-"); + + // when + String releaseVersion = versionName.releaseVersion(); + + // then + assertThat(releaseVersion, is(expectedReleaseVersion)); + } +} diff --git a/src/test/java/com/github/danielflower/mavenplugins/release/VersionNamerTest.java b/src/test/java/com/github/danielflower/mavenplugins/release/VersionNamerTest.java index d4428ae6..0d910e40 100644 --- a/src/test/java/com/github/danielflower/mavenplugins/release/VersionNamerTest.java +++ b/src/test/java/com/github/danielflower/mavenplugins/release/VersionNamerTest.java @@ -1,63 +1,93 @@ package com.github.danielflower.mavenplugins.release; import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; import java.util.ArrayList; -import java.util.List; +import java.util.Arrays; +import java.util.Collection; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.hasItems; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.fail; +@RunWith(Enclosed.class) public class VersionNamerTest { - private final VersionNamer namer = new VersionNamer(); + @RunWith(Parameterized.class) + public static class Name { + @Parameter + public String developmentVersion; - @Test - public void removesTheSnapshotAndSticksTheBuildNumberOnTheEnd() throws Exception { - assertThat(namer.name("1.0-SNAPSHOT", 123L, null).releaseVersion(), is(equalTo("1.0.123"))); - } + @Parameter(1) + public String buildNumber; - @Test - public void ifTheBuildNumberIsNullAndThePreviousBuildNumbersIsEmptyListThenZeroIsUsed() throws Exception { - assertThat(namer.name("1.0-SNAPSHOT", null, new ArrayList()).releaseVersion(), is(equalTo("1.0.0"))); - } + @Parameter(2) + public Collection previousBuildNumbers; - @Test - public void ifTheBuildNumberIsNullButThereIsAPreviousBuildNumbersThenThatValueIsIncremented() throws Exception { - assertThat(namer.name("1.0-SNAPSHOT", null, asList(9L, 10L, 8L)).releaseVersion(), is(equalTo("1.0.11"))); - } + @Parameter(3) + public String delimiter; - @Test - public void throwsIfTheVersionWouldNotBeAValidGitTag() { - assertThat(errorMessageOf("1.0-A : yeah /-SNAPSHOT", 0), - hasItems( - "Sorry, '1.0-A : yeah /.0' is not a valid version.", - "Please see https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html for tag naming rules." - ) - ); - } + @Parameter(4) + public String expectedReleaseVersion; - @Test - public void addsTheBuildWithADash() throws Exception { - assertThat(new VersionNamer("-").name("1.0.0-SNAPSHOT", 123L, null).releaseVersion(), is(equalTo("1.0.0-123"))); - } + @Parameter(5) + public boolean expectException; - @Test - public void getterReturnsDefinedOrDefaultDelimiter() { - assertThat(new VersionNamer("-").getDelimiter(), is("-")); - assertThat(new VersionNamer("@").getDelimiter(), is("@")); - assertThat(new VersionNamer().getDelimiter(), is(".")); + @Parameters + public static Collection data() { + return Arrays.asList( + new Object[]{"1.0-SNAPSHOT", "123", null, null, "1.0.123", false}, + new Object[]{"1.0-SNAPSHOT", null, new ArrayList(), null, "1.0.0", false}, + new Object[]{"1.0-SNAPSHOT", null, asList("9", "10", "8"), null, "1.0.11", false}, + new Object[]{"1.0-SNAPSHOT", null, asList("1", "2", "A", "B"), null, "1.0.3", false}, + new Object[]{"1.0.0-SNAPSHOT", "123", null, "-", "1.0.0-123", false}, + new Object[]{"1.0-A : yeah /-SNAPSHOT", "0", null, null, "1.0-A : yeah /.0", true} + ); + } + + @Test + public void shouldConsiderPreviousBuildNumbers() { + // given + VersionNamer namer; + if (delimiter == null) { + namer = new VersionNamer(); + } else { + namer = new VersionNamer(delimiter); + } + + try { + // when + VersionName name = namer.name(developmentVersion, buildNumber, previousBuildNumbers); + if (expectException) { + fail(String.format("Expected exception for development version '%s' but got none.", developmentVersion)); + } + // then + assertThat(name.releaseVersion(), is(expectedReleaseVersion)); + } catch (ValidationException e) { + assertThat(e.getMessages(), hasSize(3)); + assertThat(e.getMessages(), hasItems( + String.format("Sorry, '%s' is not a valid version.", expectedReleaseVersion), + "Please see https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html for tag naming rules." + )); + } + } } - private List errorMessageOf(String pomVersion, long buildNumber) { - try { - namer.name(pomVersion, buildNumber, null); - throw new AssertionError("Did not throw an error"); - } catch (ValidationException ex) { - return ex.getMessages(); + public static class GetDelimiter { + @Test + public void shouldReturnDefinedDelimiterOrDotPerDefault() { + assertThat(new VersionNamer("-").getDelimiter(), is("-")); + assertThat(new VersionNamer("@").getDelimiter(), is("@")); + assertThat(new VersionNamer().getDelimiter(), is(".")); } } } diff --git a/src/test/java/e2e/NonNumericBuildNumbersTest.java b/src/test/java/e2e/NonNumericBuildNumbersTest.java new file mode 100644 index 00000000..ba594e74 --- /dev/null +++ b/src/test/java/e2e/NonNumericBuildNumbersTest.java @@ -0,0 +1,94 @@ +package e2e; + +import org.apache.maven.shared.invoker.MavenInvocationException; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; +import scaffolding.MvnRunner; +import scaffolding.TestProject; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static scaffolding.ExactCountMatcher.oneOf; + +import static scaffolding.TestProject.differentDelimiterProject; +import static scaffolding.TestProject.emptyBuildNumberInPomProject; +import static scaffolding.TestProject.singleModuleProject; + +/** + * Tests behavior when the build number is not a number. It can be alpha-numeric or an empty string in which case it + * should be omitted in the release version. + */ +@RunWith(Parameterized.class) +public class NonNumericBuildNumbersTest { + @Parameter + public String testCaseName; + + @Parameter(1) + public TestProject testProject; + + @Parameter(2) + public String buildNumber; + + @Parameter(3) + public String expectedReleaseVersion; + + @BeforeClass + public static void installPluginToLocalRepo() { + MvnRunner.installReleasePluginToLocalRepo(); + } + + @Parameters(name = "{0} -> {3}") + public static Collection data() { + return Arrays.asList( + // The projects used here are arbitrary, you just can't use the same project + build number combination twice + new Object[]{"alpha-numeric build number as CLI argument", differentDelimiterProject(), "ABC", "1.0.0-ABC"}, + new Object[]{"empty build number as CLI argument, ''", differentDelimiterProject(), "''", "1.0.0"}, + new Object[]{"empty build number as CLI argument, \"\"", singleModuleProject(), "\"\"", "1.0"}, + // This one is specific because of the in the POM + new Object[]{"empty build number in POM", emptyBuildNumberInPomProject(), null, "1.0.0"} + ); + } + + @Test + public void shouldSupportAlphaNumericOrEmptyBuildNumbers() throws Exception { + // given the test data + List outputLines; + + // when + if (buildNumber == null) { + outputLines = testProject.mvnRelease(); + } else { + outputLines = testProject.mvnRelease(buildNumber); + } + + // then + assertMainClassOutputWithReleaseVersion(outputLines); + assertJarWithVersionInTargetFolder(); + assertArtifactInLocalMavenRepo(); + } + + private void assertMainClassOutputWithReleaseVersion(List outputLines) { + assertThat(outputLines, oneOf(containsString("Hello from version " + expectedReleaseVersion + "!"))); + } + + private void assertArtifactInLocalMavenRepo() throws IOException, MavenInvocationException { + MvnRunner.assertArtifactInLocalRepo("com.github.danielflower.mavenplugins.testprojects", testProject.getName(), expectedReleaseVersion); + } + + private void assertJarWithVersionInTargetFolder() { + String fileName = testProject.getName() + "-" + expectedReleaseVersion + "-package.jar"; + File jarInTargetFolder = new File(testProject.localDir, "target/" + fileName); + assertThat(jarInTargetFolder.exists(), is(true)); + } +} diff --git a/src/test/java/e2e/SingleModuleTest.java b/src/test/java/e2e/SingleModuleTest.java index 21aea334..b0ece7fd 100644 --- a/src/test/java/e2e/SingleModuleTest.java +++ b/src/test/java/e2e/SingleModuleTest.java @@ -54,12 +54,12 @@ public void theBuildNumberIsOptionalAndWillStartAt0AndThenIncrementTakingIntoAcc testProject.mvn("releaser:release"); assertThat(testProject.local, hasTag("single-module-1.0.1")); - AnnotatedTag.create("single-module-1.0.2", "1.0", 2).saveAtHEAD(testProject.local); + AnnotatedTag.create("single-module-1.0.2", "1.0", "2").saveAtHEAD(testProject.local); testProject.mvn("releaser:release"); assertThat(testProject.local, hasTag("single-module-1.0.3")); - AnnotatedTag.create("single-module-1.0.4", "1.0", 4).saveAtHEAD(testProject.origin); - AnnotatedTag.create("unrelated-module-1.0.5", "1.0", 5).saveAtHEAD(testProject.origin); + AnnotatedTag.create("single-module-1.0.4", "1.0", "4").saveAtHEAD(testProject.origin); + AnnotatedTag.create("unrelated-module-1.0.5", "1.0", "5").saveAtHEAD(testProject.origin); testProject.mvn("releaser:release"); assertThat(testProject.local, hasTag("single-module-1.0.5")); @@ -104,8 +104,8 @@ private ObjectId head(Git git) throws IOException { public void originTagsNotConsultedWithoutPull() throws Exception { testProject.mvn("releaser:release"); - AnnotatedTag.create("single-module-1.0.2", "1.0", 2).saveAtHEAD(testProject.local); - AnnotatedTag.create("single-module-1.0.5", "1.0", 5).saveAtHEAD(testProject.origin); + AnnotatedTag.create("single-module-1.0.2", "1.0", "2").saveAtHEAD(testProject.local); + AnnotatedTag.create("single-module-1.0.5", "1.0", "5").saveAtHEAD(testProject.origin); testProject.mvn("-Dpush=false", "-Dpull=false", diff --git a/src/test/java/scaffolding/MvnRunner.java b/src/test/java/scaffolding/MvnRunner.java index 5e9a7f93..21806944 100644 --- a/src/test/java/scaffolding/MvnRunner.java +++ b/src/test/java/scaffolding/MvnRunner.java @@ -1,12 +1,14 @@ package scaffolding; import org.apache.commons.io.filefilter.DirectoryFileFilter; +import org.apache.commons.lang3.StringUtils; import org.apache.maven.shared.invoker.*; import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.io.PrintStream; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Properties; @@ -82,6 +84,8 @@ private List runMavenInternal(File workingDir, String profile, String[] int exitCode; try { + System.out.println(String.format("Running mvn in '%s' with profile(s) '%s' and arguments %s.", + workingDir, StringUtils.defaultString(profile), Arrays.toString(arguments))); InvocationResult result = invoker.execute(request); exitCode = result.getExitCode(); } catch (Exception e) { @@ -93,6 +97,8 @@ private List runMavenInternal(File workingDir, String profile, String[] throw new MavenExecutionException(exitCode, output); } + System.out.println("That produced the following output.\n"); + output.forEach(System.out::println); return output; } diff --git a/src/test/java/scaffolding/ReleasableModuleBuilder.java b/src/test/java/scaffolding/ReleasableModuleBuilder.java index 39471436..de5bb1b3 100644 --- a/src/test/java/scaffolding/ReleasableModuleBuilder.java +++ b/src/test/java/scaffolding/ReleasableModuleBuilder.java @@ -9,12 +9,12 @@ public class ReleasableModuleBuilder { private final VersionNamer versionNamer = new VersionNamer(); MavenProject project = new MavenProject(); - private long buildNumber = 123; + private String buildNumber = "123"; private String equivalentVersion = null; private String relativePathToModule = "."; public ReleasableModuleBuilder withBuildNumber(long buildNumber) { - this.buildNumber = buildNumber; + this.buildNumber = String.valueOf(buildNumber); return this; } diff --git a/src/test/java/scaffolding/TestProject.java b/src/test/java/scaffolding/TestProject.java index 4af74141..e01442bf 100644 --- a/src/test/java/scaffolding/TestProject.java +++ b/src/test/java/scaffolding/TestProject.java @@ -19,28 +19,36 @@ public class TestProject { private static final MvnRunner defaultRunner = new MvnRunner(null); - private static final String PLUGIN_VERSION_FOR_TESTS = "3.2-SNAPSHOT"; + private static final String PLUGIN_VERSION_FOR_TESTS = "3.3-SNAPSHOT"; + private static final String RELEASE_TARGET = "releaser:release"; + private static final String NEXT_TARGET = "releaser:next"; public final File originDir; public final Git origin; public final File localDir; public final Git local; + private final String name; private final AtomicInteger commitCounter = new AtomicInteger(1); private MvnRunner mvnRunner = defaultRunner; - private TestProject(File originDir, Git origin, File localDir, Git local) { + private TestProject(File originDir, Git origin, File localDir, Git local, String name) { this.originDir = originDir; this.origin = origin; this.localDir = localDir; this.local = local; + this.name = name; + } + + public String getName() { + return name; } /** * Runs a mvn command against the local repo and returns the console output. */ - public List mvn(String... arguments) throws IOException { + public List mvn(String... arguments) { return mvnRunner.runMaven(localDir, arguments); } @@ -48,18 +56,20 @@ public void setMvnOpts(String mavenOpts) { mvnRunner.mavenOpts = mavenOpts; } - public List mvnRelease(String buildNumber) throws IOException, InterruptedException { - return mvnRunner.runMaven(localDir, - "-DbuildNumber=" + buildNumber, - "releaser:release"); + public List mvnRelease() { + return mvnRunner.runMaven(localDir, RELEASE_TARGET); + } + + public List mvnRelease(String buildNumber) { + return mvnRunner.runMaven(localDir, "-DbuildNumber=" + buildNumber, RELEASE_TARGET); } - public List mvnRelease(String buildNumber, String...arguments) throws IOException, InterruptedException { - return mvnRun("releaser:release", buildNumber, arguments); + public List mvnRelease(String buildNumber, String...arguments) { + return mvnRun(RELEASE_TARGET, buildNumber, arguments); } - public List mvnReleaserNext(String buildNumber, String...arguments) throws IOException, InterruptedException { - return mvnRun("releaser:next", buildNumber, arguments); + public List mvnReleaserNext(String buildNumber, String...arguments) { + return mvnRun(NEXT_TARGET, buildNumber, arguments); } public TestProject commitRandomFile(String module) throws IOException, GitAPIException { @@ -106,7 +116,7 @@ private static TestProject project(String name) { .setURI(originDir.toURI().toString()) .call(); - return new TestProject(originDir, origin, localDir, local); + return new TestProject(originDir, origin, localDir, local, name); } catch (Exception e) { throw new RuntimeException("Error while creating copies of the test project", e); } @@ -186,6 +196,10 @@ public static TestProject differentDelimiterProject() { return project("different-delimiter"); } + public static TestProject emptyBuildNumberInPomProject() { + return project("empty-build-number-in-pom"); + } + public void setMvnRunner(MvnRunner mvnRunner) { this.mvnRunner = mvnRunner; } diff --git a/test-projects/empty-build-number-in-pom/.gitignore b/test-projects/empty-build-number-in-pom/.gitignore new file mode 100644 index 00000000..e2bcab56 --- /dev/null +++ b/test-projects/empty-build-number-in-pom/.gitignore @@ -0,0 +1,6 @@ +target +.idea/ +*.iml +.classpath +.settings +.project diff --git a/test-projects/empty-build-number-in-pom/assembly-descriptor.xml b/test-projects/empty-build-number-in-pom/assembly-descriptor.xml new file mode 100644 index 00000000..8132b259 --- /dev/null +++ b/test-projects/empty-build-number-in-pom/assembly-descriptor.xml @@ -0,0 +1,18 @@ + + package + + jar + + + false + + + / + true + true + runtime + + + diff --git a/test-projects/empty-build-number-in-pom/pom.xml b/test-projects/empty-build-number-in-pom/pom.xml new file mode 100644 index 00000000..9c646eb9 --- /dev/null +++ b/test-projects/empty-build-number-in-pom/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + com.github.danielflower.mavenplugins.testprojects + empty-build-number-in-pom + 1.0.0-SNAPSHOT + jar + + + UTF-8 + + + + + + + com.github.danielflower.mavenplugins + multi-module-maven-release-plugin + ${current.plugin.version} + + + install + + + "" + + + + + com.google.code.echo-maven-plugin + echo-maven-plugin + 1.0.0 + false + + Hello from version ${project.version}! + + + + + echo + + + + + + + maven-assembly-plugin + 2.5.3 + + + assembly-descriptor.xml + + + + + make-assembly + package + + single + + + + + + + + diff --git a/test-projects/empty-build-number-in-pom/src/main/java/com/github/danielflower/mavenplugins/testproject/singlepom/Main.java b/test-projects/empty-build-number-in-pom/src/main/java/com/github/danielflower/mavenplugins/testproject/singlepom/Main.java new file mode 100644 index 00000000..aab63d46 --- /dev/null +++ b/test-projects/empty-build-number-in-pom/src/main/java/com/github/danielflower/mavenplugins/testproject/singlepom/Main.java @@ -0,0 +1,7 @@ +package com.github.danielflower.mavenplugins.testproject.singlepom; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world"); + } +}