}
@Override
public String getReleaseVersion(ReleaseContext ctx, MavenProject rootProject) throws JGitFlowReleaseException
{
Logger log = getLogger();
String defaultVersion = rootProject.getVersion();
if (log.isDebugEnabled())
{
log.debug("calculating release version for " + rootProject.getGroupId() + ":" + rootProject.getArtifactId());
log.debug("defaultVersion is currently: " + defaultVersion);
}
if (StringUtils.isNotBlank(ctx.getDefaultReleaseVersion()))
{
defaultVersion = ctx.getDefaultReleaseVersion();
if (log.isDebugEnabled())
{
log.debug("(ctx change) defaultVersion is currently: " + defaultVersion);
}
}
String suggestedVersion = null;
String releaseVersion = defaultVersion;
if (log.isDebugEnabled())
{
log.debug("releaseVersion is currently: " + releaseVersion);
}
while (null == releaseVersion || ArtifactUtils.isSnapshot(releaseVersion))
{
if (log.isDebugEnabled())
{
log.debug("looping until we find a non-snapshot version...");
}
DefaultVersionInfo info = null;
try
{
info = new DefaultVersionInfo(rootProject.getVersion());
}
catch (VersionParseException e)
{
if (ctx.isInteractive())
{
try
{
info = new DefaultVersionInfo("1.0");
}
catch (VersionParseException e1)
{
throw new JGitFlowReleaseException("error parsing 1.0 version!!!", e1);
}
}
else
{
throw new JGitFlowReleaseException("error parsing release version: " + e.getMessage(), e);
}
}
suggestedVersion = info.getReleaseVersionString();
if (log.isDebugEnabled())
{
log.debug("suggestedVersion: " + suggestedVersion);
}
if (ctx.isInteractive())
{
String message = MessageFormat.format("What is the release version for \"{0}\"? ({1})", rootProject.getName(), ArtifactUtils.versionlessKey(rootProject.getGroupId(), rootProject.getArtifactId()));
try
{
releaseVersion = prompter.promptNotBlank(message, suggestedVersion);
}
catch (PrompterException e)
{
throw new JGitFlowReleaseException("Error reading version from command line " + e.getMessage(), e);
}
}
else
{
releaseVersion = suggestedVersion;
if (log.isDebugEnabled())
{
log.debug("setting release version to suggested version: " + suggestedVersion);
}
}
}