}
@Override
public void finish(ReleaseContext ctx, List<MavenProject> reactorProjects, MavenSession session) throws JGitFlowReleaseException
{
JGitFlow flow = null;
MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects);
MavenSession currentSession = session;
try
{
flow = JGitFlow.forceInit(ctx.getBaseDir(), ctx.getFlowInitContext());
JGitFlowReporter reporter = flow.getReporter();
writeReportHeader(ctx, reporter);
setupCredentialProviders(ctx, reporter);
String featureLabel = getFeatureFinishName(ctx, flow);
String prefixedBranchName = flow.getFeatureBranchPrefix() + featureLabel;
// make sure we are on specific feature branch
flow.git().checkout().setName(prefixedBranchName).call();
//make sure we're not behind remote
if(GitHelper.remoteBranchExists(flow.git(), prefixedBranchName, reporter))
{
if(GitHelper.localBranchBehindRemote(flow.git(),prefixedBranchName,reporter))
{
reporter.errorText("feature-finish","local branch '" + prefixedBranchName + "' is behind the remote branch");
reporter.flush();
throw new BranchOutOfDateException("local branch '" + prefixedBranchName + "' is behind the remote branch");
}
}
if(GitHelper.remoteBranchExists(flow.git(), flow.getDevelopBranchName(), flow.getReporter()))
{
if(GitHelper.localBranchBehindRemote(flow.git(),flow.getDevelopBranchName(),flow.getReporter()))
{
reporter.errorText("feature-finish","local branch '" + flow.getDevelopBranchName() + "' is behind the remote branch");
reporter.flush();
throw new BranchOutOfDateException("local branch '" + flow.getDevelopBranchName() + "' is behind the remote branch");
}
}
if (ctx.isEnableFeatureVersions())
{
updateFeaturePomsWithNonFeatureVersion(featureLabel, flow, ctx, reactorProjects, session);
//reload the reactor projects
MavenSession featureSession = getSessionForBranch(flow, prefixedBranchName, reactorProjects, session);
List<MavenProject> featureProjects = featureSession.getSortedProjects();
currentSession = featureSession;
rootProject = ReleaseUtil.getRootProject(featureProjects);
}
if (ctx.isPushFeatures())
{
projectHelper.ensureOrigin(ctx.getDefaultOriginUrl(), flow);
}
if (!ctx.isNoBuild())
{
try
{
mavenExecutionHelper.execute(rootProject, ctx, currentSession);
}
catch (MavenExecutorException e)
{
throw new JGitFlowReleaseException("Error building: " + e.getMessage(), e);
}
}
getLogger().info("running jgitflow feature finish...");
flow.featureFinish(featureLabel)
.setKeepBranch(ctx.isKeepBranch())
.setSquash(ctx.isSquash())
.setRebase(ctx.isFeatureRebase())
.setAllowUntracked(ctx.isAllowUntracked())
.setPush(ctx.isPushFeatures())
.setNoMerge(ctx.isNoFeatureMerge())
.setScmMessagePrefix(ctx.getScmCommentPrefix())
.call();
//make sure we're on develop
flow.git().checkout().setName(flow.getDevelopBranchName()).call();
}
catch (JGitFlowException e)
{
throw new JGitFlowReleaseException("Error finish feature: " + e.getMessage(), e);
}
catch (GitAPIException e)
{
throw new JGitFlowReleaseException("Error finish feature: " + e.getMessage(), e);
}
catch (ReactorReloadException e)
{
throw new JGitFlowReleaseException("Error finish feature: " + e.getMessage(), e);
}
catch (IOException e)
{
throw new JGitFlowReleaseException("Error finish feature: " + e.getMessage(), e);
}
finally
{
if (null != flow)
{
flow.getReporter().flush();
}
}
}