PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/ut/com/atlassian/maven/plugins/jgitflow/manager/ReleaseManagerStartReleaseTest.java

https://bitbucket.org/jbowman/maven-jgitflow-plugin
Java | 424 lines | 319 code | 99 blank | 6 comment | 1 complexity | 26085c019abfc8fe0d8b1a0430bef098 MD5 | raw file
  1. package ut.com.atlassian.maven.plugins.jgitflow.manager;
  2. import java.io.File;
  3. import java.util.List;
  4. import com.atlassian.jgitflow.core.JGitFlow;
  5. import com.atlassian.jgitflow.core.JGitFlowInitCommand;
  6. import com.atlassian.jgitflow.core.exception.DirtyWorkingTreeException;
  7. import com.atlassian.jgitflow.core.util.GitHelper;
  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.UnresolvedSnapshotsException;
  11. import com.atlassian.maven.plugins.jgitflow.helper.ProjectHelper;
  12. import com.atlassian.maven.plugins.jgitflow.manager.FlowReleaseManager;
  13. import org.apache.maven.project.MavenProject;
  14. import org.codehaus.plexus.util.FileUtils;
  15. import org.eclipse.jgit.api.Git;
  16. import org.junit.Test;
  17. import ut.com.atlassian.maven.plugins.jgitflow.testutils.RepoUtil;
  18. import static org.junit.Assert.assertEquals;
  19. import static org.junit.Assert.assertTrue;
  20. /**
  21. * @since version
  22. */
  23. public class ReleaseManagerStartReleaseTest extends AbstractFlowManagerTest
  24. {
  25. @Test(expected = JGitFlowReleaseException.class)
  26. public void uncommittedChangesFails() throws Exception
  27. {
  28. String projectSubdir = "basic-pom";
  29. List<MavenProject> projects = createReactorProjects("rewrite-for-release", projectSubdir);
  30. File projectRoot = projects.get(0).getBasedir();
  31. FlowReleaseManager relman = getReleaseManager();
  32. ReleaseContext ctx = new ReleaseContext(projectRoot);
  33. ctx.setDefaultReleaseVersion("1.0");
  34. ctx.setInteractive(false).setNoTag(true).setPush(false);
  35. try
  36. {
  37. relman.start(ctx, projects);
  38. }
  39. catch (JGitFlowReleaseException e)
  40. {
  41. assertEquals(DirtyWorkingTreeException.class, e.getCause().getClass());
  42. throw e;
  43. }
  44. }
  45. @Test
  46. public void existingSameReleaseIsCheckedOut() throws Exception
  47. {
  48. String projectSubdir = "basic-pom";
  49. List<MavenProject> projects = createReactorProjects("rewrite-for-release", projectSubdir);
  50. File projectRoot = projects.get(0).getBasedir();
  51. JGitFlow flow = JGitFlow.getOrInit(projectRoot);
  52. assertOnDevelop(flow);
  53. initialCommitAll(flow);
  54. flow.git().checkout().setCreateBranch(true).setName(flow.getReleaseBranchPrefix() + "1.0").call();
  55. //go back to develop
  56. flow.git().checkout().setName(flow.getDevelopBranchName()).call();
  57. assertOnDevelop(flow);
  58. assertTrue(GitHelper.localBranchExists(flow.git(), flow.getReleaseBranchPrefix() + "1.0"));
  59. FlowReleaseManager relman = getReleaseManager();
  60. ReleaseContext ctx = new ReleaseContext(projectRoot);
  61. ctx.setInteractive(false).setNoTag(true).setPush(false);
  62. relman.start(ctx, projects);
  63. assertOnRelease(flow, ctx.getDefaultReleaseVersion());
  64. comparePomFiles(projects);
  65. }
  66. @Test(expected = JGitFlowReleaseException.class)
  67. public void existingDifferentReleaseThrows() throws Exception
  68. {
  69. String projectSubdir = "basic-pom";
  70. List<MavenProject> projects = createReactorProjects("rewrite-for-release", projectSubdir);
  71. File projectRoot = projects.get(0).getBasedir();
  72. JGitFlow flow = JGitFlow.getOrInit(projectRoot);
  73. assertOnDevelop(flow);
  74. initialCommitAll(flow);
  75. flow.git().checkout().setCreateBranch(true).setName(flow.getReleaseBranchPrefix() + "0.2").call();
  76. //go back to develop
  77. flow.git().checkout().setName(flow.getDevelopBranchName()).call();
  78. assertOnDevelop(flow);
  79. assertTrue(GitHelper.localBranchExists(flow.git(), flow.getReleaseBranchPrefix() + "0.2"));
  80. FlowReleaseManager relman = getReleaseManager();
  81. ReleaseContext ctx = new ReleaseContext(projectRoot);
  82. ctx.setInteractive(false).setNoTag(true).setPush(false);
  83. relman.start(ctx, projects);
  84. assertOnRelease(flow, ctx.getDefaultReleaseVersion());
  85. comparePomFiles(projects);
  86. }
  87. @Test
  88. public void releaseBasicPom() throws Exception
  89. {
  90. basicReleaseRewriteTest("basic-pom", "1.0");
  91. }
  92. @Test
  93. public void releaseWithInheritedScm() throws Exception
  94. {
  95. basicReleaseRewriteTest("basic-pom-inherited-scm");
  96. }
  97. @Test
  98. public void releaseWithNamespace() throws Exception
  99. {
  100. basicReleaseRewriteTest("basic-pom-namespace");
  101. }
  102. @Test
  103. public void releaseWithTagBase() throws Exception
  104. {
  105. basicReleaseRewriteTest("basic-pom-with-tag-base");
  106. }
  107. @Test(expected = JGitFlowReleaseException.class)
  108. public void releaseWithInternalDifferingSnapshotDeps() throws Exception
  109. {
  110. try
  111. {
  112. basicReleaseRewriteTest("internal-differing-snapshot-dependencies");
  113. }
  114. catch (JGitFlowReleaseException e)
  115. {
  116. assertEquals(UnresolvedSnapshotsException.class, e.getClass());
  117. throw e;
  118. }
  119. }
  120. @Test
  121. public void releaseWithInternalDifferingSnapshotDepsAllow() throws Exception
  122. {
  123. String projectName = "internal-differing-snapshot-dependencies";
  124. List<MavenProject> projects = createReactorProjects("rewrite-for-release", projectName);
  125. File projectRoot = projects.get(0).getBasedir();
  126. ReleaseContext ctx = new ReleaseContext(projectRoot);
  127. ctx.setInteractive(false).setNoTag(true).setPush(false).setAllowSnapshots(true);
  128. basicReleaseRewriteTest(projectName, ctx);
  129. }
  130. @Test(expected = JGitFlowReleaseException.class)
  131. public void releaseWithInternalDifferingSnapshotExtension() throws Exception
  132. {
  133. try
  134. {
  135. basicReleaseRewriteTest("internal-differing-snapshot-extension");
  136. }
  137. catch (JGitFlowReleaseException e)
  138. {
  139. assertEquals(UnresolvedSnapshotsException.class, e.getClass());
  140. throw e;
  141. }
  142. }
  143. @Test
  144. public void releaseWithInternalDifferingSnapshotExtensionAllow() throws Exception
  145. {
  146. String projectName = "internal-differing-snapshot-extension";
  147. List<MavenProject> projects = createReactorProjects("rewrite-for-release", projectName);
  148. File projectRoot = projects.get(0).getBasedir();
  149. ReleaseContext ctx = new ReleaseContext(projectRoot);
  150. ctx.setInteractive(false).setNoTag(true).setPush(false).setAllowSnapshots(true);
  151. basicReleaseRewriteTest(projectName, ctx);
  152. }
  153. @Test(expected = JGitFlowReleaseException.class)
  154. public void releaseWithInternalDifferingSnapshotPlugins() throws Exception
  155. {
  156. try
  157. {
  158. basicReleaseRewriteTest("internal-differing-snapshot-plugins");
  159. }
  160. catch (JGitFlowReleaseException e)
  161. {
  162. assertEquals(UnresolvedSnapshotsException.class, e.getClass());
  163. throw e;
  164. }
  165. }
  166. @Test
  167. public void releaseWithInternalDifferingSnapshotPluginsAllow() throws Exception
  168. {
  169. String projectName = "internal-differing-snapshot-plugins";
  170. List<MavenProject> projects = createReactorProjects("rewrite-for-release", projectName);
  171. File projectRoot = projects.get(0).getBasedir();
  172. ReleaseContext ctx = new ReleaseContext(projectRoot);
  173. ctx.setInteractive(false).setNoTag(true).setPush(false).setAllowSnapshots(true);
  174. basicReleaseRewriteTest(projectName, ctx);
  175. }
  176. @Test(expected = JGitFlowReleaseException.class)
  177. public void releaseWithInternalDifferingSnapshotReportPlugins() throws Exception
  178. {
  179. try
  180. {
  181. basicReleaseRewriteTest("internal-differing-snapshot-report-plugins");
  182. }
  183. catch (JGitFlowReleaseException e)
  184. {
  185. assertEquals(UnresolvedSnapshotsException.class, e.getClass());
  186. throw e;
  187. }
  188. }
  189. @Test
  190. public void releaseWithInternalDifferingSnapshotReportPluginsAllow() throws Exception
  191. {
  192. String projectName = "internal-differing-snapshot-report-plugins";
  193. List<MavenProject> projects = createReactorProjects("rewrite-for-release", projectName);
  194. File projectRoot = projects.get(0).getBasedir();
  195. ReleaseContext ctx = new ReleaseContext(projectRoot);
  196. ctx.setInteractive(false).setNoTag(true).setPush(false).setAllowSnapshots(true);
  197. basicReleaseRewriteTest(projectName, ctx);
  198. }
  199. @Test
  200. public void releaseWithInternalManagedSnapshotDeps() throws Exception
  201. {
  202. basicReleaseRewriteTest("internal-managed-snapshot-dependency");
  203. }
  204. @Test
  205. public void releaseWithInternalManagedSnapshotPlugin() throws Exception
  206. {
  207. basicReleaseRewriteTest("internal-managed-snapshot-plugin");
  208. }
  209. @Test
  210. public void releaseWithInternalSnapshotDeps() throws Exception
  211. {
  212. basicReleaseRewriteTest("internal-snapshot-dependencies");
  213. }
  214. @Test
  215. public void releaseWithInternalSnapshotExtension() throws Exception
  216. {
  217. basicReleaseRewriteTest("internal-snapshot-extension");
  218. }
  219. @Test
  220. public void releaseWithInternalSnapshotPluginDeps() throws Exception
  221. {
  222. basicReleaseRewriteTest("internal-snapshot-plugin-deps");
  223. }
  224. @Test
  225. public void releaseWithInternalSnapshotPlugins() throws Exception
  226. {
  227. basicReleaseRewriteTest("internal-snapshot-plugins");
  228. }
  229. @Test
  230. public void releaseWithInternalSnapshotProfile() throws Exception
  231. {
  232. basicReleaseRewriteTest("internal-snapshot-profile");
  233. }
  234. @Test
  235. public void releaseWithInternalSnapshotReportPlugins() throws Exception
  236. {
  237. basicReleaseRewriteTest("internal-snapshot-report-plugins");
  238. }
  239. @Test
  240. public void releaseWithInterpolatedVersions() throws Exception
  241. {
  242. basicReleaseRewriteTest("interpolated-versions");
  243. }
  244. @Test
  245. public void releaseWithDifferentModuleVersions() throws Exception
  246. {
  247. basicReleaseRewriteTest("modules-with-different-versions");
  248. }
  249. @Test
  250. public void releaseWithDeepMultimodule() throws Exception
  251. {
  252. basicReleaseRewriteTest("multimodule-with-deep-subprojects");
  253. }
  254. @Test
  255. public void releaseWithInheritedVersion() throws Exception
  256. {
  257. basicReleaseRewriteTest("pom-with-inherited-version");
  258. }
  259. @Test
  260. public void releaseWithOverriddenScm() throws Exception
  261. {
  262. basicReleaseRewriteTest("pom-with-overridden-scm");
  263. }
  264. @Test
  265. public void releaseWithParent() throws Exception
  266. {
  267. basicReleaseRewriteTest("pom-with-parent");
  268. }
  269. @Test
  270. public void releaseWithParentAndProperties() throws Exception
  271. {
  272. basicReleaseRewriteTest("pom-with-parent-and-properties");
  273. }
  274. @Test
  275. public void releaseWithFlatParent() throws Exception
  276. {
  277. List<MavenProject> projects = createReactorProjects("rewrite-for-release/pom-with-parent-flat", "root-project");
  278. File projectRoot = projects.get(0).getBasedir();
  279. JGitFlow flow = JGitFlow.getOrInit(projectRoot);
  280. assertOnDevelop(flow);
  281. initialCommitAll(flow);
  282. FlowReleaseManager relman = getReleaseManager();
  283. ReleaseContext ctx = new ReleaseContext(projectRoot);
  284. ctx.setInteractive(false).setNoTag(true).setPush(false);
  285. relman.start(ctx, projects);
  286. assertOnRelease(flow, "1.0");
  287. comparePomFiles(projects);
  288. }
  289. @Test
  290. public void releaseWithPropertyDependencyCoord() throws Exception
  291. {
  292. basicReleaseRewriteTest("pom-with-property-dependency-coordinate");
  293. }
  294. @Test
  295. public void releaseWithReleasedParent() throws Exception
  296. {
  297. basicReleaseRewriteTest("pom-with-released-parent");
  298. }
  299. @Test
  300. public void startReleaseWithMasterOnly() throws Exception
  301. {
  302. ProjectHelper projectHelper = (ProjectHelper) lookup(ProjectHelper.class.getName());
  303. Git git = null;
  304. Git remoteGit = null;
  305. List<MavenProject> remoteProjects = createReactorProjects("remote-git-project", null);
  306. File remoteDir = remoteProjects.get(0).getBasedir();
  307. //make sure we're clean
  308. File remoteGitDir = new File(remoteDir, ".git");
  309. if (remoteGitDir.exists())
  310. {
  311. FileUtils.cleanDirectory(remoteGitDir);
  312. }
  313. remoteGit = RepoUtil.createRepositoryWithMaster(remoteDir);
  314. projectHelper.commitAllChanges(remoteGit, "remote commit");
  315. File localProject = new File(testFileBase, "projects/local/local-git-project");
  316. git = Git.cloneRepository().setDirectory(localProject).setURI("file://" + remoteGit.getRepository().getWorkTree().getPath()).call();
  317. List<MavenProject> projects = createReactorProjects("remote-git-project", "local/local-git-project", null, false);
  318. File projectRoot = projects.get(0).getBasedir();
  319. JGitFlowInitCommand initCommand = new JGitFlowInitCommand();
  320. JGitFlow flow = initCommand.setDirectory(git.getRepository().getWorkTree()).call();
  321. projectHelper.ensureOrigin(projects, flow);
  322. flow.releaseStart("1.0").setFetch(true).call();
  323. assertEquals(flow.getReleaseBranchPrefix() + "1.0", git.getRepository().getBranch());
  324. }
  325. }