PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/lukejackson/jgit-flow
Java | 85 lines | 65 code | 19 blank | 1 comment | 1 complexity | 1519a57de7b178761612f8931e8c9c8c 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.JGitFlow;
  5. import com.atlassian.jgitflow.core.JGitFlowReporter;
  6. import com.atlassian.jgitflow.core.command.JGitFlowCommand;
  7. import com.atlassian.jgitflow.core.exception.JGitFlowExtensionException;
  8. import com.atlassian.jgitflow.core.extension.ExtensionCommand;
  9. import com.atlassian.jgitflow.core.extension.ExtensionFailStrategy;
  10. import com.atlassian.maven.plugins.jgitflow.ReleaseContext;
  11. import com.atlassian.maven.plugins.jgitflow.helper.BranchHelper;
  12. import com.atlassian.maven.plugins.jgitflow.helper.PomUpdater;
  13. import com.atlassian.maven.plugins.jgitflow.helper.ProjectHelper;
  14. import com.atlassian.maven.plugins.jgitflow.provider.ContextProvider;
  15. import com.atlassian.maven.plugins.jgitflow.provider.JGitFlowProvider;
  16. import com.atlassian.maven.plugins.jgitflow.provider.ProjectCacheKey;
  17. import com.atlassian.maven.plugins.jgitflow.util.NamingUtil;
  18. import org.apache.commons.lang.StringUtils;
  19. import org.apache.maven.project.MavenProject;
  20. import org.codehaus.plexus.component.annotations.Component;
  21. import org.codehaus.plexus.component.annotations.Requirement;
  22. import org.eclipse.jgit.api.Git;
  23. @Component(role = UpdateFeaturePomsWithSnapshotsCommand.class)
  24. public class UpdateFeaturePomsWithSnapshotsCommand implements ExtensionCommand
  25. {
  26. @Requirement
  27. private ContextProvider contextProvider;
  28. @Requirement
  29. private JGitFlowProvider jGitFlowProvider;
  30. @Requirement
  31. private PomUpdater pomUpdater;
  32. @Requirement
  33. private ProjectHelper projectHelper;
  34. @Requirement
  35. private BranchHelper branchHelper;
  36. @Override
  37. public void execute(GitFlowConfiguration configuration, Git git, JGitFlowCommand gitFlowCommand, JGitFlowReporter reporter) throws JGitFlowExtensionException
  38. {
  39. String unprefixedBranchName = "";
  40. try
  41. {
  42. ReleaseContext ctx = contextProvider.getContext();
  43. if(!ctx.isEnableFeatureVersions())
  44. {
  45. return;
  46. }
  47. JGitFlow flow = jGitFlowProvider.gitFlow();
  48. unprefixedBranchName = branchHelper.getUnprefixedCurrentBranchName();
  49. //reload the reactor projects for release
  50. List<MavenProject> branchProjects = branchHelper.getProjectsForCurrentBranch();
  51. String featureVersion = NamingUtil.camelCaseOrSpaceToDashed(unprefixedBranchName);
  52. featureVersion = StringUtils.replace(featureVersion, "-", "_");
  53. pomUpdater.addFeatureVersionToSnapshotVersions(ProjectCacheKey.FEATURE_START_LABEL, featureVersion, branchProjects);
  54. projectHelper.commitAllPoms(flow.git(), branchProjects, ctx.getScmCommentPrefix() + "updating poms for " + featureVersion + " version" + ctx.getScmCommentSuffix());
  55. }
  56. catch (Exception e)
  57. {
  58. throw new JGitFlowExtensionException("Error updating poms with feature versions for branch '" + unprefixedBranchName + "'");
  59. }
  60. }
  61. @Override
  62. public ExtensionFailStrategy failStrategy()
  63. {
  64. return ExtensionFailStrategy.ERROR;
  65. }
  66. }