PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jgitflow-maven-plugin/src/main/java/com/atlassian/maven/plugins/jgitflow/extension/command/VerifyReleaseVersionStateAndDepsCommand.java

https://bitbucket.org/lukejackson/jgit-flow
Java | 102 lines | 82 code | 20 blank | 0 comment | 3 complexity | f239c19d4077ad0b1788dbe24998e724 MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.maven.plugins.jgitflow.extension.command;
  2. import java.util.List;
  3. import com.atlassian.jgitflow.core.GitFlowConfiguration;
  4. import com.atlassian.jgitflow.core.JGitFlowReporter;
  5. import com.atlassian.jgitflow.core.command.JGitFlowCommand;
  6. import com.atlassian.jgitflow.core.exception.JGitFlowExtensionException;
  7. import com.atlassian.jgitflow.core.extension.ExtensionCommand;
  8. import com.atlassian.jgitflow.core.extension.ExtensionFailStrategy;
  9. import com.atlassian.jgitflow.core.BranchType;
  10. import com.atlassian.maven.plugins.jgitflow.ReleaseContext;
  11. import com.atlassian.maven.plugins.jgitflow.VersionState;
  12. import com.atlassian.maven.plugins.jgitflow.exception.UnresolvedSnapshotsException;
  13. import com.atlassian.maven.plugins.jgitflow.helper.ProjectHelper;
  14. import com.atlassian.maven.plugins.jgitflow.helper.BranchHelper;
  15. import com.atlassian.maven.plugins.jgitflow.provider.ContextProvider;
  16. import com.atlassian.maven.plugins.jgitflow.provider.ProjectCacheKey;
  17. import com.google.common.base.Joiner;
  18. import org.apache.maven.project.MavenProject;
  19. import org.codehaus.plexus.component.annotations.Component;
  20. import org.codehaus.plexus.component.annotations.Requirement;
  21. import org.eclipse.jgit.api.Git;
  22. @Component(role = VerifyReleaseVersionStateAndDepsCommand.class)
  23. public class VerifyReleaseVersionStateAndDepsCommand implements ExtensionCommand
  24. {
  25. private static final String ls = System.getProperty("line.separator");
  26. @Requirement
  27. private ContextProvider contextProvider;
  28. @Requirement
  29. private ProjectHelper projectHelper;
  30. @Requirement
  31. private BranchHelper branchHelper;
  32. @Override
  33. public void execute(GitFlowConfiguration configuration, Git git, JGitFlowCommand gitFlowCommand, JGitFlowReporter reporter) throws JGitFlowExtensionException
  34. {
  35. try
  36. {
  37. BranchType branchType = branchHelper.getCurrentBranchType();
  38. ProjectCacheKey cacheKey = null;
  39. switch (branchType)
  40. {
  41. case RELEASE:
  42. cacheKey = ProjectCacheKey.RELEASE_BRANCH;
  43. break;
  44. case HOTFIX:
  45. cacheKey = ProjectCacheKey.HOTFIX_BRANCH;
  46. break;
  47. case DEVELOP:
  48. cacheKey = ProjectCacheKey.DEVELOP_BRANCH;
  49. break;
  50. case MASTER:
  51. cacheKey = ProjectCacheKey.MASTER_BRANCH;
  52. break;
  53. case FEATURE:
  54. cacheKey = ProjectCacheKey.FEATURE_BRANCH;
  55. break;
  56. default:
  57. throw new JGitFlowExtensionException("Unsupported branch type '" + branchType.name() + "' while running " + this.getClass().getSimpleName() + " command");
  58. }
  59. ReleaseContext ctx = contextProvider.getContext();
  60. List<MavenProject> branchProjects = branchHelper.getProjectsForCurrentBranch();
  61. projectHelper.checkPomForVersionState(VersionState.RELEASE, branchProjects);
  62. if (!ctx.isAllowSnapshots())
  63. {
  64. List<String> snapshots = projectHelper.checkForNonReactorSnapshots(cacheKey, branchProjects);
  65. if (!snapshots.isEmpty())
  66. {
  67. String details = Joiner.on(ls).join(snapshots);
  68. throw new UnresolvedSnapshotsException("Cannot finish a " + branchType.name().toLowerCase() + " due to snapshot dependencies:" + ls + details);
  69. }
  70. }
  71. }
  72. catch (Exception e)
  73. {
  74. throw new JGitFlowExtensionException("Error verifying version state in poms: " + e.getMessage(), e);
  75. }
  76. }
  77. @Override
  78. public ExtensionFailStrategy failStrategy()
  79. {
  80. return ExtensionFailStrategy.ERROR;
  81. }
  82. }