Skip to content

Commit

Permalink
Merge 629e702 into 8fad8bb
Browse files Browse the repository at this point in the history
  • Loading branch information
bvarner committed Aug 15, 2018
2 parents 8fad8bb + 629e702 commit 0c974e0
Show file tree
Hide file tree
Showing 27 changed files with 1,046 additions and 157 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -3,8 +3,7 @@ language: java
script: mvn verify

jdk:
- openjdk7
- oraclejdk8
- openjdk8

cache:
directories:
Expand All @@ -14,3 +13,6 @@ notifications:
email:
recipients:
- eg.oss@e-gineering.com

after_success:
- mvn jacoco:report coveralls:report
47 changes: 27 additions & 20 deletions README.md
@@ -1,4 +1,4 @@
# gitflow-helper-maven-plugin [![Build Status](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin.svg?branch=master)](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin)
# gitflow-helper-maven-plugin [![Build Status](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin.svg?branch=master)](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin) [![Coverage Status](https://coveralls.io/repos/github/egineering-llc/gitflow-helper-maven-plugin/badge.svg)](https://coveralls.io/github/egineering-llc/gitflow-helper-maven-plugin)

A build extension and plugin that helps Maven play nicely with gitflow projects, CI servers and local development.

Expand Down Expand Up @@ -124,7 +124,6 @@ All of the solutions to these issues are implemented independently in different
<hotfixBranchPropertyFile>foo/bar/emer.props</hotfixBranchPropertyFile>
<releaseBranchPropertyFile>foo/bar/test.props</releaseBranchPropertyFile>
<developmentBranchPropertyFile>foo/bar/dev.props</developmentBranchPropertyFile>
<featureOrBugfixBranchPropertyFile>foo/bar/feat.props</featureOrBugfixBranchPropertyFile>
<otherBranchPropertyFile>foo/bar/ci.props</otherBranchPropertyFile>
<undefinedBranchPropertyFile>foo/bar/local.props</undefinedBranchPropertyFile>
</configuration>
Expand All @@ -144,9 +143,9 @@ One common stumbling block for teams adjusting to gitflow with Maven projects is
In practice, the Maven versions should:

* Be synchronized with release branch and hotfix branch names.
* Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed. (This condition may be disabled by setting `enforceNonSnapshots` = `false`.)
* Always be -SNAPSHOT in the feature and develop branches.
* Be irrelevant if there's no git branch resolvable from your environment.
* Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed.
* Always be -SNAPSHOT in the develop branch.
* Be irrelevant if there's no git branch resolvable from your environment or working in a branch which is not deployed to remote repositories.

The `enforce-versions` goal asserts these semantics when it can resolve the `gitBranchExpression`.

Expand All @@ -166,7 +165,6 @@ The following properties change the behavior of this goal:
| supportBranchPattern | (origin/)?support/(.*) | No | Regex. When matches, signals a support branch (long term master-equivalent for older release) being built. Last subgroup, if present, must be start of the Maven project version. |
| releaseBranchPattern | (origin/)?release/(.*) | No | Regex. When matched, signals a release branch being built. Last subgroup, if present, must match the Maven project version. |
| hotfixBranchPattern | (origin/)?hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Last subgroup, if present, must match the Maven project version. |
| featureOrBugfixBranchPattern | (origin/)?(?:feature&#124;bugfix)/(.*) | Yes | Regex. When matched, signals a feature or bugfix branch is being built. |
| developmentBranchPattern | (origin/)?develop | Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. |


Expand All @@ -185,7 +183,6 @@ plugins in the build process (deploy, site-deploy, etc.) will use the repositori
| Property | Default Value | Description |
| -------- | ------------- | ----------- |
| gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
| deploySnapshotTypeBranches | `false` | When `true`, feature branches will also be deployed to the snapshots repository. |
| releaseDeploymentRepository | n/a | The repository to use for releases. (Builds with a GIT_BRANCH matching `masterBranchPattern` or `supportBranchPattern`) |
| stageDeploymentRepository | n/a | The repository to use for staging. (Builds with a GIT_BRANCH matching `releaseBranchPattern` or `hotfixBranchPattern`) |
| snapshotDeploymentRepository | n/a | The repository to use for snapshots. (Builds matching `developmentBranchPattern`) |
Expand Down Expand Up @@ -339,7 +336,6 @@ The following table describes the git branch expression -> repository used for r
| supportBranchPattern | release |
| releaseBranchPattern | stage |
| hotfixBranchPattern | stage |
| featureOrBugfixBranchPattern | snapshots |
| developmentBranchPattern | snapshots |
| All Others | local |

Expand All @@ -361,15 +357,26 @@ it's building. The attach-deploy will 'clean' the maven project, then download t
that the first build deployed into. Once they're attached to the project, the `jboss-as:deploy-only` goal will deliver
the artifacts built by the first job into a jboss application server.


# Resolving the Git branch name
As stated before, the plugin determines what to do by resolving the Git branch name.

* The first try is a `git symbolic-ref HEAD` to check the local branch name. If it's found, that's the branch name that's used.
* If the `symbolic-ref` fails then it's probably due to a detached HEAD. This typically happens on Jenkins, when it simply checks out the commit hash that was just pushed.
Or, it's because of a developer doing a `git checkout origin/feature/x`, e.g. when doing a code review and no local branch is required.
In such a case:
* The plugin will first resolve the HEAD to a commit using `git rev-parse HEAD`.
* Next, it will do a `git show-ref` to check which (local/remote) branches point to the commit.
* If it can resolve the commit to a single branch type (e.g. develop or master) then that's the branch name that's used.
* If all of the above fails, `${env.GIT_BRANCH}` is tried.
# Additional Notes
## How Git branch name resolution works
1. If the `<scm>` sections of the pom points to a git repository, `git symbolic-ref HEAD` to is used to check the local branch name.
2. If the `symbolic-ref` fails then it's likely due to a detached HEAD.
This is typical of CI servers like Jenkins, where the commit hash that was just pushed is pulled.
This can also be done as a consequene of attempting to rebuild from a tag, without branching, or in some
workflows where code reviews are done without branches.

In the case of a detached HEAD the plugin will:
* Resolve the HEAD to a commit using `git rev-parse HEAD`.
* `git show-ref` to resolve which (local/remote) branches point to the commit.
* If the detached HEAD commit resolves to a single branch type, it uses that branch name.
3. If the first two methods fail, the plugin attempts to resolve `${env.GIT_BRANCH}`.

## Building with IntelliJ IDEA notes
### To Debug Tests:
Configure the Maven commandline to include
`-DforkMode=never` You will likely get warnings when you run maven with this argument.

### To inspect code-coverage results from Integration Tests:
* Select the **Analyze** -> **Show Coverage Data** menu.
* In the dialog that appears, click the **+** in the upper left corner to `Add (Insert)`, and browse to `target/jacoco.exec`.
* Selecting that file will show coverage data in the code editor.
140 changes: 128 additions & 12 deletions pom.xml
Expand Up @@ -52,6 +52,8 @@
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<it.repository.basedir>${project.build.directory}/it-repositories</it.repository.basedir>
<version.gitflow.plugin>${project.version}</version.gitflow.plugin>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -115,12 +117,6 @@
<artifactId>aether-util</artifactId>
<version>0.9.0.M2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -140,12 +136,6 @@
<goal>descriptor</goal>
</goals>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -179,6 +169,132 @@
</build>

<profiles>
<profile>
<id>testing</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<!-- Jacoco -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- Jacoco Is configured to munge the results of the normal unit tests
and integration tests into the same output file.
This gives us a 'global view' of all tested code paths.
-->
<execution>
<id>pre-integration-test</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
</configuration>
</execution>
</executions>
</plugin>

<!-- Enable surefire so we do integration testing only -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<systemProperties>
<argLine>${argLine}</argLine>
</systemProperties>
<forkCount>1</forkCount>
</configuration>
</plugin>

<!-- Enable failsafe for integration testing -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<configuration>
<systemProperties>
<maven.repo.local>${it.repository.basedir}/local</maven.repo.local>
<project.version>${project.version}</project.version>
<argLine>${argLine}</argLine>
</systemProperties>
<forkCount>1</forkCount>
</configuration>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- Copy the packaged artifact to the local repository used by the integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<configuration>
<localRepositoryPath>${it.repository.basedir}/local</localRepositoryPath>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<pomFile>${pom.basedir}/pom.xml</pomFile>
<file>${project.build.directory}${file.separator}${project.build.finalName}.jar</file>
</configuration>
<phase>pre-integration-test</phase>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- Coveralls Reporting -->
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-verifier</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>

<profile>
<id>eg.oss</id>
<activation>
Expand Down
Expand Up @@ -25,7 +25,15 @@
import org.eclipse.aether.util.repository.AuthenticationBuilder;

import javax.annotation.Nullable;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
Expand Down
@@ -1,6 +1,5 @@
package com.e_gineering.maven.gitflowhelper;

import com.e_gineering.maven.gitflowhelper.properties.ExpansionBuffer;
import com.e_gineering.maven.gitflowhelper.properties.PropertyResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -42,18 +41,16 @@ public abstract class AbstractGitflowBranchMojo extends AbstractMojo {
@Parameter(defaultValue = "(origin/)?develop", property = "developmentBranchPattern", required = true)
private String developmentBranchPattern;

@Parameter(defaultValue = "(origin/)?(?:feature|bugfix)/(.*)", property = "featureOrBugfixBranchPattern", required = true)
private String featureOrBugfixBranchPattern;

// An expression that resolves to the git branch at run-time.
// @Parameter tag causes property resolution to fail for patterns containing ${env.}.
// The default value _must_ be provided programmaticially at run-time.
@Parameter(property = "gitBranchExpression", required = false)
private String gitBranchExpression;

@Parameter(defaultValue = "false", property = "deploySnapshotTypeBranches")
boolean deploySnapshotTypeBranches;

/**
* If this is "equals" then exact version matching to branch name matching is preformed.
* Otherwise, this is treated as a "startsWith".
*/
@Parameter(defaultValue = "equals", property = "releaseBranchMatchType", required = true)
String releaseBranchMatchType;

Expand Down Expand Up @@ -88,7 +85,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// Validate the match type.
checkReleaseBranchMatchTypeParam();

ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, project, getLog(), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern, featureOrBugfixBranchPattern);
ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, project, getLog(), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern);
GitBranchInfo branchInfo = scmUtils.resolveBranchInfo(gitBranchExpression);

getLog().debug("Building for: " + branchInfo);
Expand Down
Expand Up @@ -29,7 +29,6 @@ protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionEx
attachExistingArtifacts(stageDeploymentRepository, true);
break;
}
case FEATURE_OR_BUGFIX_BRANCH:
case DEVELOPMENT: {
getLog().info("Attaching artifacts from snapshot repository...");
attachExistingArtifacts(snapshotDeploymentRepository, true);
Expand Down

0 comments on commit 0c974e0

Please sign in to comment.