-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Issue with the next development version logic.
The next development version is computed by increment of one, for either the buildNumber when present or the patch version even when those one are set to zero. The current logic does not allow us to use the patch version for hotfixes only. For example, given a current development version 6.144.0-SNAPSHOT, if the logic is to increment the patch version, at release time, the plugin will propose 6.144.1-SNAPSHOT but I need 6.145.0-SNAPSHOT and I will have to manually update the next development version manually and that at every single release. Now, if we change the logic to increment only when it is not zero, I only need to change the next development version when a major change is required, the rest of the time the desired version part will be incremented automatically. The new logic would propose by default, given a strategy: release version ==> next development version : UNKNOWN : 6.0.0 ==> 6.0.1-SNAPSHOT UNKNOWN : 6.1.0 ==> 6.1.1-SNAPSHOT UNKNOWN : 6.0.1 ==> 6.0.2-SNAPSHOT UNKNOWN : 6.1.0-0 ==> 6.1.1-SNAPSHOT UNKNOWN : 6.1.0-22 ==> 6.1.0-23-SNAPSHOT UNKNOWN : 6.1 ==> 6.1.1-SNAPSHOT UNKNOWN : 6 ==> 6.0.1-SNAPSHOT DEFAULT : 6.0.0 ==> 6.0.1-SNAPSHOT DEFAULT : 6.1.0 ==> 6.1.1-SNAPSHOT DEFAULT : 6.0.1 ==> 6.0.2-SNAPSHOT DEFAULT : 6.1.0-0 ==> 6.1.1-SNAPSHOT DEFAULT : 6.1.0-22 ==> 6.1.0-23-SNAPSHOT DEFAULT : 6.1 ==> 6.1.1-SNAPSHOT DEFAULT : 6 ==> 6.0.1-SNAPSHOT IGNORE_ZEROS : 6.0.0 ==> 7.0.0-SNAPSHOT IGNORE_ZEROS : 6.1.0 ==> 6.2.0-SNAPSHOT IGNORE_ZEROS : 6.0.1 ==> 6.0.2-SNAPSHOT IGNORE_ZEROS : 6.1.0-0 ==> 6.2.0-SNAPSHOT IGNORE_ZEROS : 6.1.0-22 ==> 6.1.0-23-SNAPSHOT IGNORE_ZEROS : 6.1 ==> 6.2.0-SNAPSHOT IGNORE_ZEROS : 6 ==> 7.0.0-SNAPSHOT Everything works almost as before except for when the lowest version part is zero.
- Loading branch information
Showing
7 changed files
with
188 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
server/src/main/java/org/jfrog/teamcity/server/project/strategy/NextDevelopmentVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.jfrog.teamcity.server.project.strategy; | ||
|
||
import org.codehaus.mojo.buildhelper.versioning.VersionInformation; | ||
import org.jfrog.teamcity.common.ConstantValues; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.ListIterator; | ||
|
||
public class NextDevelopmentVersion { | ||
private final static String PREFIX = ConstantValues.PLUGIN_PREFIX + "releaseManagement."; | ||
public final static String PARAMETER_NAME = PREFIX + "nextDevelopmentVersionStrategy"; | ||
|
||
public enum StrategyEnum implements NextDevelopmentVersionStrategy { | ||
DEFAULT(), | ||
IGNORE_ZEROS(); | ||
|
||
public List<Integer> apply(String releaseVersion) { | ||
final VersionInformation versionInformation = new VersionInformation(releaseVersion); | ||
final List<Integer> versionParts = new ArrayList<Integer>(); | ||
|
||
versionParts.add(versionInformation.getBuildNumber()); | ||
versionParts.add(versionInformation.getPatch()); | ||
versionParts.add(versionInformation.getMinor()); | ||
versionParts.add(versionInformation.getMajor()); | ||
|
||
ListIterator<Integer> listIterator = versionParts.listIterator(); | ||
boolean done = false; | ||
|
||
while (!done && listIterator.hasNext()) { | ||
switch (this) { | ||
|
||
case IGNORE_ZEROS: | ||
done = applyIgnoreZero(listIterator); | ||
break; | ||
|
||
case DEFAULT: | ||
default: | ||
done = applyDefault(listIterator); | ||
break; | ||
} | ||
} | ||
|
||
return versionParts; | ||
} | ||
} | ||
|
||
private static boolean applyDefault(ListIterator<Integer> i) { | ||
int versionPart = i.next(); | ||
boolean done = false; | ||
|
||
if (i.previousIndex() + versionPart > 0) { | ||
i.set(versionPart + 1); | ||
done = true; | ||
} | ||
|
||
return done; | ||
} | ||
|
||
private static boolean applyIgnoreZero(ListIterator<Integer> i) { | ||
int versionPart = i.next(); | ||
boolean done = false; | ||
|
||
if (versionPart > 0) { | ||
i.set(versionPart + 1); | ||
done = true; | ||
} | ||
|
||
return done; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../main/java/org/jfrog/teamcity/server/project/strategy/NextDevelopmentVersionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.jfrog.teamcity.server.project.strategy; | ||
|
||
import java.util.List; | ||
|
||
public interface NextDevelopmentVersionStrategy { | ||
List<Integer> apply(String releaseVersion); | ||
} |
63 changes: 63 additions & 0 deletions
63
server/src/test/java/org/jfrog/teamcity/server/project/ReleaseManagementConfigModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.jfrog.teamcity.server.project; | ||
|
||
import org.jfrog.teamcity.server.project.strategy.NextDevelopmentVersion.StrategyEnum; | ||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.jfrog.teamcity.server.project.strategy.NextDevelopmentVersion.StrategyEnum.DEFAULT; | ||
import static org.jfrog.teamcity.server.project.strategy.NextDevelopmentVersion.StrategyEnum.IGNORE_ZEROS; | ||
|
||
public class ReleaseManagementConfigModelTest { | ||
private final static StrategyEnum UNKNOWN = null; | ||
|
||
private ReleaseManagementConfigModel instance = new ReleaseManagementConfigModel() { | ||
@Override | ||
public String getDefaultTagUrl() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getDefaultReleaseBranch() { | ||
return null; | ||
} | ||
}; | ||
|
||
@DataProvider(name = "data-provider") | ||
public Object[][] dataProviderMethod() { | ||
return new Object[][]{ | ||
{UNKNOWN, "6.0.0", "6.0.1-SNAPSHOT"}, | ||
{UNKNOWN, "6.1.0", "6.1.1-SNAPSHOT"}, | ||
{UNKNOWN, "6.0.1", "6.0.2-SNAPSHOT"}, | ||
{UNKNOWN, "6.1.0-0", "6.1.1-SNAPSHOT"}, | ||
{UNKNOWN, "6.1.0-22", "6.1.0-23-SNAPSHOT"}, | ||
{UNKNOWN, "6.1", "6.1.1-SNAPSHOT"}, | ||
{UNKNOWN, "6", "6.0.1-SNAPSHOT"}, | ||
|
||
{DEFAULT, "6.0.0", "6.0.1-SNAPSHOT"}, | ||
{DEFAULT, "6.1.0", "6.1.1-SNAPSHOT"}, | ||
{DEFAULT, "6.0.1", "6.0.2-SNAPSHOT"}, | ||
{DEFAULT, "6.1.0-0", "6.1.1-SNAPSHOT"}, | ||
{DEFAULT, "6.1.0-22", "6.1.0-23-SNAPSHOT"}, | ||
{DEFAULT, "6.1", "6.1.1-SNAPSHOT"}, | ||
{DEFAULT, "6", "6.0.1-SNAPSHOT"}, | ||
|
||
{IGNORE_ZEROS, "6.0.0", "7.0.0-SNAPSHOT"}, | ||
{IGNORE_ZEROS, "6.1.0", "6.2.0-SNAPSHOT"}, | ||
{IGNORE_ZEROS, "6.0.1", "6.0.2-SNAPSHOT"}, | ||
{IGNORE_ZEROS, "6.1.0-0", "6.2.0-SNAPSHOT"}, | ||
{IGNORE_ZEROS, "6.1.0-22", "6.1.0-23-SNAPSHOT"}, | ||
{IGNORE_ZEROS, "6.1", "6.2.0-SNAPSHOT"}, | ||
{IGNORE_ZEROS, "6", "7.0.0-SNAPSHOT"}}; | ||
} | ||
|
||
@Test(dataProvider = "data-provider") | ||
public void testGetNextDevelopmentVersion(StrategyEnum strategy, String releaseVersion, String expected) { | ||
instance.setNextDevelopmentVersionStrategy(strategy); | ||
instance.setCurrentVersion(releaseVersion); | ||
|
||
final String current = instance.getNextDevelopmentVersion(); | ||
|
||
Assert.assertEquals(current, expected); | ||
} | ||
} |