|
| 1 | +package com.e_gineering.maven.gitflowhelper; |
| 2 | + |
| 3 | +import org.apache.maven.plugin.MojoExecutionException; |
| 4 | +import org.apache.maven.plugin.MojoFailureException; |
| 5 | +import org.apache.maven.plugins.annotations.LifecyclePhase; |
| 6 | +import org.apache.maven.plugins.annotations.Mojo; |
| 7 | +import org.apache.maven.plugins.annotations.Parameter; |
| 8 | + |
| 9 | +/** |
| 10 | + * Set a project property value based upon the current ${env.GIT_BRANCH} resolution. |
| 11 | + */ |
| 12 | +@Mojo(name = "set-property", defaultPhase = LifecyclePhase.VALIDATE) |
| 13 | +public class SetPropertyMojo extends AbstractGitflowBranchMojo { |
| 14 | + |
| 15 | + @Parameter(property = "key", readonly = true, required = true) |
| 16 | + private String key; |
| 17 | + |
| 18 | + @Parameter(property = "masterBranchValue", readonly = true, required = false) |
| 19 | + private String masterBranchValue = null; |
| 20 | + |
| 21 | + @Parameter(property = "releaseBranchValue", readonly = true, required = false) |
| 22 | + private String releaseBranchValue = null; |
| 23 | + |
| 24 | + @Parameter(property = "hotfixBranchValue", readonly = true, required = false) |
| 25 | + private String hotfixBranchValue = null; |
| 26 | + |
| 27 | + @Parameter(property = "developmentBranchValue", readonly = true, required = false) |
| 28 | + private String developmentBranchValue = null; |
| 29 | + |
| 30 | + @Parameter(property = "otherBranchValue", readonly = true, required = false) |
| 31 | + private String otherBranchValue = null; |
| 32 | + |
| 33 | + @Parameter(property = "undefinedBranchValue", readonly = true, required = false) |
| 34 | + private String undefinedBranchValue = null; |
| 35 | + |
| 36 | + @Override |
| 37 | + protected void execute(final GitBranchType type, final String gitBranch, final String branchPattern) throws MojoExecutionException, MojoFailureException { |
| 38 | + String resolvedValue = null; |
| 39 | + switch (type) { |
| 40 | + case MASTER: { |
| 41 | + resolvedValue = resolveExpression(masterBranchValue); |
| 42 | + break; |
| 43 | + } |
| 44 | + case RELEASE: { |
| 45 | + resolvedValue = resolveExpression(releaseBranchValue); |
| 46 | + break; |
| 47 | + } |
| 48 | + case HOTFIX: { |
| 49 | + resolvedValue = resolveExpression(hotfixBranchValue); |
| 50 | + break; |
| 51 | + } |
| 52 | + case DEVELOPMENT: { |
| 53 | + resolvedValue = resolveExpression(developmentBranchValue); |
| 54 | + break; |
| 55 | + } |
| 56 | + case OTHER: { |
| 57 | + resolvedValue = resolveExpression(otherBranchValue); |
| 58 | + break; |
| 59 | + } |
| 60 | + case UNDEFINED: { |
| 61 | + resolvedValue = resolveExpression(undefinedBranchValue); |
| 62 | + break; |
| 63 | + } |
| 64 | + } |
| 65 | + getLog().info("Setting " + key + " = '" + resolvedValue + "'"); |
| 66 | + project.getProperties().put(key, resolvedValue); |
| 67 | + } |
| 68 | +} |
0 commit comments