|
20 | 20 | import com.google.common.annotations.VisibleForTesting; |
21 | 21 | import com.google.common.io.Closeables; |
22 | 22 | import com.google.common.io.Files; |
| 23 | + |
23 | 24 | import org.apache.maven.plugin.AbstractMojo; |
24 | 25 | import org.apache.maven.plugin.MojoExecutionException; |
25 | 26 | import org.apache.maven.project.MavenProject; |
|
30 | 31 | import org.eclipse.jgit.storage.file.FileRepositoryBuilder; |
31 | 32 | import org.jetbrains.annotations.NotNull; |
32 | 33 | import org.jetbrains.annotations.Nullable; |
| 34 | + |
33 | 35 | import pl.project13.jgit.DescribeCommand; |
34 | 36 | import pl.project13.jgit.DescribeResult; |
35 | 37 | import pl.project13.maven.git.log.LoggerBridge; |
|
41 | 43 | import java.text.SimpleDateFormat; |
42 | 44 | import java.util.Date; |
43 | 45 | import java.util.List; |
| 46 | +import java.util.Map; |
44 | 47 | import java.util.Properties; |
45 | 48 |
|
46 | 49 | /** |
@@ -379,7 +382,7 @@ void loadGitData(@NotNull Properties properties) throws IOException, MojoExecuti |
379 | 382 |
|
380 | 383 | try { |
381 | 384 | // git.branch |
382 | | - String branch = git.getBranch(); |
| 385 | + String branch = determineBranchName(git); |
383 | 386 | put(properties, BRANCH, branch); |
384 | 387 |
|
385 | 388 | // git.commit.id.describe |
@@ -526,6 +529,21 @@ private boolean directoryExists(@Nullable File fileLocation) { |
526 | 529 | private boolean directoryDoesNotExits(File fileLocation) { |
527 | 530 | return !directoryExists(fileLocation); |
528 | 531 | } |
| 532 | + |
| 533 | + protected String determineBranchName(Repository git) throws IOException { |
| 534 | + String branch = git.getBranch(); |
| 535 | + |
| 536 | + // Special processing if we're in Jenkins/Hudson |
| 537 | + Map<String,String> env = System.getenv(); |
| 538 | + if (env.containsKey("HUDSON_URL") || env.containsKey("JENKINS_URL")) { |
| 539 | + String branchName = env.get("GIT_BRANCH"); |
| 540 | + if (branchName!=null && branchName.length()>0) { |
| 541 | + branch=branchName; |
| 542 | + } |
| 543 | + } |
| 544 | + |
| 545 | + return branch; |
| 546 | + } |
529 | 547 |
|
530 | 548 | // SETTERS FOR TESTS ---------------------------------------------------- |
531 | 549 |
|
|
0 commit comments