/src/main/java/com/atlassian/maven/plugins/jgitflow/manager/AbstractFlowReleaseManager.java

https://bitbucket.org/ronsmits/maven-jgitflow-plugin · Java · 611 lines · 527 code · 79 blank · 5 comment · 40 complexity · e144191c1858b8ecef4f672cd594cbd7 MD5 · raw file

  1. package com.atlassian.maven.plugins.jgitflow.manager;
  2. import java.io.IOException;
  3. import java.security.SecureRandom;
  4. import java.util.List;
  5. import java.util.Map;
  6. import com.atlassian.jgitflow.core.JGitFlow;
  7. import com.atlassian.maven.plugins.jgitflow.MavenJGitFlowConfiguration;
  8. import com.atlassian.maven.plugins.jgitflow.ReleaseContext;
  9. import com.atlassian.maven.plugins.jgitflow.exception.JGitFlowReleaseException;
  10. import com.atlassian.maven.plugins.jgitflow.exception.ProjectRewriteException;
  11. import com.atlassian.maven.plugins.jgitflow.exception.ReactorReloadException;
  12. import com.atlassian.maven.plugins.jgitflow.helper.MavenExecutionHelper;
  13. import com.atlassian.maven.plugins.jgitflow.helper.ProjectHelper;
  14. import com.atlassian.maven.plugins.jgitflow.rewrite.MavenProjectRewriter;
  15. import com.atlassian.maven.plugins.jgitflow.rewrite.ProjectChangeset;
  16. import com.google.common.base.Function;
  17. import com.google.common.collect.Maps;
  18. import org.apache.commons.lang.StringUtils;
  19. import org.apache.maven.artifact.ArtifactUtils;
  20. import org.apache.maven.execution.MavenSession;
  21. import org.apache.maven.project.MavenProject;
  22. import org.apache.maven.shared.release.util.ReleaseUtil;
  23. import org.codehaus.plexus.logging.AbstractLogEnabled;
  24. import org.codehaus.plexus.logging.Logger;
  25. import org.eclipse.jgit.api.errors.GitAPIException;
  26. import static com.atlassian.maven.plugins.jgitflow.rewrite.ArtifactReleaseVersionChange.artifactReleaseVersionChange;
  27. import static com.atlassian.maven.plugins.jgitflow.rewrite.ParentReleaseVersionChange.parentReleaseVersionChange;
  28. import static com.atlassian.maven.plugins.jgitflow.rewrite.ProjectReleaseVersionChange.projectReleaseVersionChange;
  29. import static com.atlassian.maven.plugins.jgitflow.rewrite.ScmDefaultHeadTagChange.scmDefaultHeadTagChange;
  30. import static com.atlassian.maven.plugins.jgitflow.rewrite.ScmDefaultTagChange.scmDefaultTagChange;
  31. /**
  32. * @since version
  33. */
  34. public abstract class AbstractFlowReleaseManager extends AbstractLogEnabled implements FlowReleaseManager
  35. {
  36. protected static final String ls = System.getProperty("line.separator");
  37. private static final SecureRandom random = new SecureRandom();
  38. protected ProjectHelper projectHelper;
  39. protected MavenProjectRewriter projectRewriter;
  40. protected MavenExecutionHelper mavenExecutionHelper;
  41. protected MavenJGitFlowConfigManager configManager;
  42. protected String getReleaseLabel(String key, ReleaseContext ctx, List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  43. {
  44. Map<String, String> releaseVersions = projectHelper.getReleaseVersions(key, reactorProjects, ctx);
  45. MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects);
  46. String rootProjectId = ArtifactUtils.versionlessKey(rootProject.getGroupId(), rootProject.getArtifactId());
  47. return releaseVersions.get(rootProjectId);
  48. }
  49. protected String getHotfixLabel(String key, ReleaseContext ctx, List<MavenProject> reactorProjects, MavenJGitFlowConfiguration config) throws JGitFlowReleaseException
  50. {
  51. Map<String, String> hotfixVersions = projectHelper.getHotfixVersions(key, reactorProjects, ctx, config.getLastReleaseVersions());
  52. MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects);
  53. String rootProjectId = ArtifactUtils.versionlessKey(rootProject.getGroupId(), rootProject.getArtifactId());
  54. return hotfixVersions.get(rootProjectId);
  55. }
  56. protected String getDevelopmentLabel(String key, ReleaseContext ctx, List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  57. {
  58. Map<String, String> developmentVersions = projectHelper.getDevelopmentVersions(key, reactorProjects, ctx);
  59. MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects);
  60. String rootProjectId = ArtifactUtils.versionlessKey(rootProject.getGroupId(), rootProject.getArtifactId());
  61. return developmentVersions.get(rootProjectId);
  62. }
  63. protected String getFeatureStartName(ReleaseContext ctx, JGitFlow flow) throws JGitFlowReleaseException
  64. {
  65. return projectHelper.getFeatureStartName(ctx, flow);
  66. }
  67. protected String getFeatureFinishName(ReleaseContext ctx, JGitFlow flow) throws JGitFlowReleaseException
  68. {
  69. return projectHelper.getFeatureFinishName(ctx, flow);
  70. }
  71. protected void updatePomsWithReleaseVersion(String key, ReleaseContext ctx, List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  72. {
  73. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  74. Map<String, String> releaseVersions = projectHelper.getReleaseVersions(key, reactorProjects, ctx);
  75. getLogger().info("updating poms for all projects...");
  76. if(!getLogger().isDebugEnabled())
  77. {
  78. getLogger().info("turn on debug logging with -X to see exact changes");
  79. }
  80. for (MavenProject project : reactorProjects)
  81. {
  82. ProjectChangeset changes = new ProjectChangeset()
  83. .with(parentReleaseVersionChange(originalVersions, releaseVersions))
  84. .with(projectReleaseVersionChange(releaseVersions))
  85. .with(artifactReleaseVersionChange(originalVersions, releaseVersions, ctx.isUpdateDependencies()))
  86. .with(scmDefaultTagChange(releaseVersions));
  87. try
  88. {
  89. getLogger().info("updating pom for " + project.getName() + "...");
  90. projectRewriter.applyChanges(project, changes);
  91. logChanges(changes);
  92. }
  93. catch (ProjectRewriteException e)
  94. {
  95. throw new JGitFlowReleaseException("Error updating poms with release versions", e);
  96. }
  97. }
  98. }
  99. protected void updatePomsWithReleaseVersion(String key, final String releaseLabel, ReleaseContext ctx, List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  100. {
  101. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  102. Map<String, String> releaseSnapshotVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  103. final String releaseSuffix = (StringUtils.isBlank(ctx.getReleaseBranchVersionSuffix())) ? "" : "-" + ctx.getReleaseBranchVersionSuffix();
  104. Map<String, String> releaseVersions = Maps.transformValues(releaseSnapshotVersions,new Function<String, String>() {
  105. @Override
  106. public String apply(String input)
  107. {
  108. if(input.equalsIgnoreCase(releaseLabel + releaseSuffix + "-SNAPSHOT"))
  109. {
  110. return StringUtils.substringBeforeLast(input,releaseSuffix + "-SNAPSHOT");
  111. }
  112. else
  113. {
  114. return input;
  115. }
  116. }
  117. });
  118. getLogger().info("updating poms for all projects...");
  119. if(!getLogger().isDebugEnabled())
  120. {
  121. getLogger().info("turn on debug logging with -X to see exact changes");
  122. }
  123. for (MavenProject project : reactorProjects)
  124. {
  125. ProjectChangeset changes = new ProjectChangeset()
  126. .with(parentReleaseVersionChange(originalVersions, releaseVersions))
  127. .with(projectReleaseVersionChange(releaseVersions))
  128. .with(artifactReleaseVersionChange(originalVersions, releaseVersions, ctx.isUpdateDependencies()))
  129. .with(scmDefaultTagChange(releaseVersions));
  130. try
  131. {
  132. getLogger().info("updating pom for " + project.getName() + "...");
  133. projectRewriter.applyChanges(project, changes);
  134. logChanges(changes);
  135. }
  136. catch (ProjectRewriteException e)
  137. {
  138. throw new JGitFlowReleaseException("Error updating poms with release versions", e);
  139. }
  140. }
  141. }
  142. protected void updatePomsWithReleaseSnapshotVersion(String key, final String releaseLabel, ReleaseContext ctx, List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  143. {
  144. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  145. Map<String, String> releaseVersions = projectHelper.getReleaseVersions(key, reactorProjects, ctx);
  146. final String releaseSuffix = (StringUtils.isBlank(ctx.getReleaseBranchVersionSuffix())) ? "" : "-" + ctx.getReleaseBranchVersionSuffix();
  147. Map<String, String> releaseSnapshotVersions = Maps.transformValues(releaseVersions,new Function<String, String>() {
  148. @Override
  149. public String apply(String input)
  150. {
  151. if(input.equalsIgnoreCase(releaseLabel))
  152. {
  153. return input + releaseSuffix + "-SNAPSHOT";
  154. }
  155. else
  156. {
  157. return input;
  158. }
  159. }
  160. });
  161. getLogger().info("updating poms for all projects...");
  162. if(!getLogger().isDebugEnabled())
  163. {
  164. getLogger().info("turn on debug logging with -X to see exact changes");
  165. }
  166. for (MavenProject project : reactorProjects)
  167. {
  168. ProjectChangeset changes = new ProjectChangeset()
  169. .with(parentReleaseVersionChange(originalVersions, releaseSnapshotVersions))
  170. .with(projectReleaseVersionChange(releaseSnapshotVersions))
  171. .with(artifactReleaseVersionChange(originalVersions, releaseSnapshotVersions, ctx.isUpdateDependencies()))
  172. .with(scmDefaultHeadTagChange(releaseSnapshotVersions));
  173. try
  174. {
  175. getLogger().info("updating pom for " + project.getName() + "...");
  176. projectRewriter.applyChanges(project, changes);
  177. logChanges(changes);
  178. }
  179. catch (ProjectRewriteException e)
  180. {
  181. throw new JGitFlowReleaseException("Error updating poms with release versions", e);
  182. }
  183. }
  184. }
  185. protected void updatePomsWithFeatureVersion(String key, final String featureVersion, ReleaseContext ctx, List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  186. {
  187. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  188. Map<String, String> featureVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  189. Map<String, String> featureSuffixedVersions = Maps.transformValues(featureVersions,new Function<String, String>() {
  190. @Override
  191. public String apply(String input)
  192. {
  193. if(input.endsWith("-SNAPSHOT"))
  194. {
  195. return StringUtils.substringBeforeLast(input,"-SNAPSHOT") + "-" + featureVersion + "-SNAPSHOT";
  196. }
  197. else
  198. {
  199. return input;
  200. }
  201. }
  202. });
  203. getLogger().info("updating poms for all projects...");
  204. if(!getLogger().isDebugEnabled())
  205. {
  206. getLogger().info("turn on debug logging with -X to see exact changes");
  207. }
  208. for (MavenProject project : reactorProjects)
  209. {
  210. ProjectChangeset changes = new ProjectChangeset()
  211. .with(parentReleaseVersionChange(originalVersions, featureSuffixedVersions))
  212. .with(projectReleaseVersionChange(featureSuffixedVersions))
  213. .with(artifactReleaseVersionChange(originalVersions, featureSuffixedVersions, ctx.isUpdateDependencies()))
  214. .with(scmDefaultHeadTagChange(featureSuffixedVersions));
  215. try
  216. {
  217. getLogger().info("updating pom for " + project.getName() + "...");
  218. projectRewriter.applyChanges(project, changes);
  219. logChanges(changes);
  220. }
  221. catch (ProjectRewriteException e)
  222. {
  223. throw new JGitFlowReleaseException("Error updating poms with feature versions", e);
  224. }
  225. }
  226. }
  227. protected void updatePomsWithNonFeatureVersion(String key, final String featureVersion, ReleaseContext ctx, List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  228. {
  229. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  230. Map<String, String> featureSuffixedVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  231. final String featureSuffix = "-" + featureVersion + "-SNAPSHOT";
  232. Map<String, String> featureVersions = Maps.transformValues(featureSuffixedVersions,new Function<String, String>() {
  233. @Override
  234. public String apply(String input)
  235. {
  236. if(input.endsWith(featureSuffix))
  237. {
  238. return StringUtils.substringBeforeLast(input,featureSuffix) + "-SNAPSHOT";
  239. }
  240. else
  241. {
  242. return input;
  243. }
  244. }
  245. });
  246. getLogger().info("updating poms for all projects...");
  247. if(!getLogger().isDebugEnabled())
  248. {
  249. getLogger().info("turn on debug logging with -X to see exact changes");
  250. }
  251. for (MavenProject project : reactorProjects)
  252. {
  253. ProjectChangeset changes = new ProjectChangeset()
  254. .with(parentReleaseVersionChange(originalVersions, featureVersions))
  255. .with(projectReleaseVersionChange(featureVersions))
  256. .with(artifactReleaseVersionChange(originalVersions, featureVersions, ctx.isUpdateDependencies()))
  257. .with(scmDefaultTagChange(featureVersions));
  258. try
  259. {
  260. getLogger().info("updating pom for " + project.getName() + "...");
  261. projectRewriter.applyChanges(project, changes);
  262. logChanges(changes);
  263. }
  264. catch (ProjectRewriteException e)
  265. {
  266. throw new JGitFlowReleaseException("Error updating poms with non-feature versions", e);
  267. }
  268. }
  269. }
  270. protected void updatePomsWithVersionCopy(ReleaseContext ctx, List<MavenProject> projectsToUpdate, List<MavenProject> projectsWithVersions) throws JGitFlowReleaseException
  271. {
  272. Map<String, String> originalVersions = projectHelper.getOriginalVersions(randomName("copy"), projectsToUpdate);
  273. Map<String, String> releaseVersions = projectHelper.getOriginalVersions(randomName("copy"), projectsWithVersions);
  274. getLogger().info("updating poms for all projects...");
  275. if(!getLogger().isDebugEnabled())
  276. {
  277. getLogger().info("turn on debug logging with -X to see exact changes");
  278. }
  279. for (MavenProject project : projectsToUpdate)
  280. {
  281. ProjectChangeset changes = new ProjectChangeset()
  282. .with(parentReleaseVersionChange(originalVersions, releaseVersions))
  283. .with(projectReleaseVersionChange(releaseVersions))
  284. .with(artifactReleaseVersionChange(originalVersions, releaseVersions, ctx.isUpdateDependencies()))
  285. .with(scmDefaultTagChange(releaseVersions));
  286. try
  287. {
  288. getLogger().info("updating pom for " + project.getName() + "...");
  289. projectRewriter.applyChanges(project, changes);
  290. logChanges(changes);
  291. }
  292. catch (ProjectRewriteException e)
  293. {
  294. throw new JGitFlowReleaseException("Error updating poms with release versions", e);
  295. }
  296. }
  297. }
  298. protected void updatePomsWithPreviousVersions(String key, ReleaseContext ctx, List<MavenProject> reactorProjects, MavenJGitFlowConfiguration config) throws JGitFlowReleaseException
  299. {
  300. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  301. Map<String, String> preHotfixVersions = config.getPreHotfixVersions();
  302. if(null == preHotfixVersions || preHotfixVersions.isEmpty())
  303. {
  304. //uh, not sure what to do here other than set to next develop version
  305. updatePomsWithDevelopmentVersion(key, ctx,reactorProjects);
  306. return;
  307. }
  308. getLogger().info("updating poms for all projects...");
  309. if(!getLogger().isDebugEnabled())
  310. {
  311. getLogger().info("turn on debug logging with -X to see exact changes");
  312. }
  313. for (MavenProject project : reactorProjects)
  314. {
  315. ProjectChangeset changes = new ProjectChangeset()
  316. .with(parentReleaseVersionChange(originalVersions, preHotfixVersions))
  317. .with(projectReleaseVersionChange(preHotfixVersions))
  318. .with(artifactReleaseVersionChange(originalVersions, preHotfixVersions, ctx.isUpdateDependencies()))
  319. .with(scmDefaultTagChange(preHotfixVersions));
  320. try
  321. {
  322. getLogger().info("updating pom for " + project.getName() + "...");
  323. projectRewriter.applyChanges(project, changes);
  324. logChanges(changes);
  325. }
  326. catch (ProjectRewriteException e)
  327. {
  328. throw new JGitFlowReleaseException("Error updating poms with development versions", e);
  329. }
  330. }
  331. }
  332. protected void updatePomsWithHotfixVersion(String key, ReleaseContext ctx, List<MavenProject> reactorProjects, MavenJGitFlowConfiguration config) throws JGitFlowReleaseException
  333. {
  334. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  335. Map<String, String> hotfixVersions = projectHelper.getHotfixVersions(key, reactorProjects, ctx, config.getLastReleaseVersions());
  336. getLogger().info("updating poms for all projects...");
  337. if(!getLogger().isDebugEnabled())
  338. {
  339. getLogger().info("turn on debug logging with -X to see exact changes");
  340. }
  341. for (MavenProject project : reactorProjects)
  342. {
  343. ProjectChangeset changes = new ProjectChangeset()
  344. .with(parentReleaseVersionChange(originalVersions, hotfixVersions))
  345. .with(projectReleaseVersionChange(hotfixVersions))
  346. .with(artifactReleaseVersionChange(originalVersions, hotfixVersions, ctx.isUpdateDependencies()))
  347. .with(scmDefaultTagChange(hotfixVersions));
  348. try
  349. {
  350. getLogger().info("updating pom for " + project.getName() + "...");
  351. projectRewriter.applyChanges(project, changes);
  352. logChanges(changes);
  353. }
  354. catch (ProjectRewriteException e)
  355. {
  356. throw new JGitFlowReleaseException("Error updating poms with hotfix versions", e);
  357. }
  358. }
  359. }
  360. protected void updatePomsWithHotfixVersion(String key, final String hotfixLabel, ReleaseContext ctx, List<MavenProject> reactorProjects, MavenJGitFlowConfiguration config) throws JGitFlowReleaseException
  361. {
  362. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  363. Map<String, String> hotfixSnapshotVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  364. Map<String, String> hotfixVersions = Maps.transformValues(hotfixSnapshotVersions,new Function<String, String>() {
  365. @Override
  366. public String apply(String input)
  367. {
  368. if(input.equalsIgnoreCase(hotfixLabel + "-SNAPSHOT"))
  369. {
  370. return StringUtils.substringBeforeLast(input,"-SNAPSHOT");
  371. }
  372. else
  373. {
  374. return input;
  375. }
  376. }
  377. });
  378. getLogger().info("updating poms for all projects...");
  379. if(!getLogger().isDebugEnabled())
  380. {
  381. getLogger().info("turn on debug logging with -X to see exact changes");
  382. }
  383. for (MavenProject project : reactorProjects)
  384. {
  385. ProjectChangeset changes = new ProjectChangeset()
  386. .with(parentReleaseVersionChange(originalVersions, hotfixVersions))
  387. .with(projectReleaseVersionChange(hotfixVersions))
  388. .with(artifactReleaseVersionChange(originalVersions, hotfixVersions, ctx.isUpdateDependencies()))
  389. .with(scmDefaultTagChange(hotfixVersions));
  390. try
  391. {
  392. getLogger().info("updating pom for " + project.getName() + "...");
  393. projectRewriter.applyChanges(project, changes);
  394. logChanges(changes);
  395. }
  396. catch (ProjectRewriteException e)
  397. {
  398. throw new JGitFlowReleaseException("Error updating poms with hotfix versions", e);
  399. }
  400. }
  401. }
  402. protected void updatePomsWithHotfixSnapshotVersion(String key, final String hotfixLabel, ReleaseContext ctx, List<MavenProject> reactorProjects, MavenJGitFlowConfiguration config) throws JGitFlowReleaseException
  403. {
  404. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  405. Map<String, String> hotfixVersions = projectHelper.getHotfixVersions(key, reactorProjects, ctx,config.getLastReleaseVersions());
  406. Map<String, String> hotfixSnapshotVersions = Maps.transformValues(hotfixVersions,new Function<String, String>() {
  407. @Override
  408. public String apply(String input)
  409. {
  410. if(input.equalsIgnoreCase(hotfixLabel))
  411. {
  412. return input + "-SNAPSHOT";
  413. }
  414. else
  415. {
  416. return input;
  417. }
  418. }
  419. });
  420. getLogger().info("updating poms for all projects...");
  421. if(!getLogger().isDebugEnabled())
  422. {
  423. getLogger().info("turn on debug logging with -X to see exact changes");
  424. }
  425. for (MavenProject project : reactorProjects)
  426. {
  427. ProjectChangeset changes = new ProjectChangeset()
  428. .with(parentReleaseVersionChange(originalVersions, hotfixSnapshotVersions))
  429. .with(projectReleaseVersionChange(hotfixSnapshotVersions))
  430. .with(artifactReleaseVersionChange(originalVersions, hotfixSnapshotVersions, ctx.isUpdateDependencies()))
  431. .with(scmDefaultHeadTagChange(hotfixSnapshotVersions));
  432. try
  433. {
  434. getLogger().info("updating pom for " + project.getName() + "...");
  435. projectRewriter.applyChanges(project, changes);
  436. logChanges(changes);
  437. }
  438. catch (ProjectRewriteException e)
  439. {
  440. throw new JGitFlowReleaseException("Error updating poms with release versions", e);
  441. }
  442. }
  443. }
  444. protected void updatePomsWithDevelopmentVersion(String key, ReleaseContext ctx, List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  445. {
  446. Map<String, String> originalVersions = projectHelper.getOriginalVersions(key, reactorProjects);
  447. Map<String, String> developmentVersions = projectHelper.getDevelopmentVersions(key, reactorProjects, ctx);
  448. getLogger().info("updating poms for all projects...");
  449. if(!getLogger().isDebugEnabled())
  450. {
  451. getLogger().info("turn on debug logging with -X to see exact changes");
  452. }
  453. for (MavenProject project : reactorProjects)
  454. {
  455. ProjectChangeset changes = new ProjectChangeset()
  456. .with(parentReleaseVersionChange(originalVersions, developmentVersions))
  457. .with(projectReleaseVersionChange(developmentVersions))
  458. .with(artifactReleaseVersionChange(originalVersions, developmentVersions, ctx.isUpdateDependencies()))
  459. .with(scmDefaultHeadTagChange(developmentVersions));
  460. try
  461. {
  462. getLogger().info("updating pom for " + project.getName() + "...");
  463. projectRewriter.applyChanges(project, changes);
  464. logChanges(changes);
  465. }
  466. catch (ProjectRewriteException e)
  467. {
  468. throw new JGitFlowReleaseException("Error updating poms with development versions", e);
  469. }
  470. }
  471. }
  472. protected void checkPomForSnapshot(List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  473. {
  474. getLogger().info("Checking for SNAPSHOT version in projects...");
  475. boolean hasSnapshotProject = false;
  476. for (MavenProject project : reactorProjects)
  477. {
  478. if (ArtifactUtils.isSnapshot(project.getVersion()))
  479. {
  480. hasSnapshotProject = true;
  481. break;
  482. }
  483. }
  484. if (!hasSnapshotProject)
  485. {
  486. throw new JGitFlowReleaseException("Unable to find SNAPSHOT version in reactor projects!");
  487. }
  488. }
  489. protected void checkPomForRelease(List<MavenProject> reactorProjects) throws JGitFlowReleaseException
  490. {
  491. getLogger().info("Checking for release version in projects...");
  492. boolean hasSnapshotProject = false;
  493. for (MavenProject project : reactorProjects)
  494. {
  495. if (ArtifactUtils.isSnapshot(project.getVersion()))
  496. {
  497. hasSnapshotProject = true;
  498. break;
  499. }
  500. }
  501. if (hasSnapshotProject)
  502. {
  503. throw new JGitFlowReleaseException("Some reactor projects contain SNAPSHOT versions!");
  504. }
  505. }
  506. protected void logChanges(ProjectChangeset changes)
  507. {
  508. if(getLogger().isDebugEnabled())
  509. {
  510. for (String desc : changes.getChangeDescriptionsOrSummaries())
  511. {
  512. getLogger().debug(" " + desc);
  513. }
  514. }
  515. }
  516. protected MavenSession getSessionForBranch(JGitFlow flow, String branchName, List<MavenProject> originalProjects, MavenSession oldSession) throws GitAPIException, ReactorReloadException, IOException
  517. {
  518. String originalBranch = flow.git().getRepository().getBranch();
  519. flow.git().checkout().setName(branchName).call();
  520. //reload the reactor projects
  521. MavenProject rootProject = ReleaseUtil.getRootProject(originalProjects);
  522. MavenSession newSession = mavenExecutionHelper.reloadReactor(rootProject,oldSession);
  523. flow.git().checkout().setName(originalBranch).call();
  524. return newSession;
  525. }
  526. protected String randomName(String base)
  527. {
  528. long n = random.nextLong();
  529. n = (n == Long.MIN_VALUE) ? 0 : Math.abs(n);
  530. return base + Long.toString(n);
  531. }
  532. }