Skip to content

Commit 72c234c

Browse files
authored
Merge pull request #90 from egineering-llc/feature/integration-tests
Feature/integration tests
2 parents 8fad8bb + d8d94ce commit 72c234c

27 files changed

+1118
-157
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ language: java
33
script: mvn verify
44

55
jdk:
6-
- openjdk7
7-
- oraclejdk8
6+
- openjdk8
87

98
cache:
109
directories:
@@ -14,3 +13,6 @@ notifications:
1413
email:
1514
recipients:
1615
16+
17+
after_success:
18+
- mvn jacoco:report coveralls:report

README.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 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)
1+
# 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)
22

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

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

146145
* Be synchronized with release branch and hotfix branch names.
147-
* 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`.)
148-
* Always be -SNAPSHOT in the feature and develop branches.
149-
* Be irrelevant if there's no git branch resolvable from your environment.
146+
* Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed.
147+
* Always be -SNAPSHOT in the develop branch.
148+
* Be irrelevant if there's no git branch resolvable from your environment or working in a branch which is not deployed to remote repositories.
150149

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

@@ -166,7 +165,6 @@ The following properties change the behavior of this goal:
166165
| 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. |
167166
| releaseBranchPattern | (origin/)?release/(.*) | No | Regex. When matched, signals a release branch being built. Last subgroup, if present, must match the Maven project version. |
168167
| hotfixBranchPattern | (origin/)?hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Last subgroup, if present, must match the Maven project version. |
169-
| featureOrBugfixBranchPattern | (origin/)?(?:feature&#124;bugfix)/(.*) | Yes | Regex. When matched, signals a feature or bugfix branch is being built. |
170168
| developmentBranchPattern | (origin/)?develop | Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. |
171169

172170

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

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

364-
365-
# Resolving the Git branch name
366-
As stated before, the plugin determines what to do by resolving the Git branch name.
367-
368-
* 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.
369-
* 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.
370-
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.
371-
In such a case:
372-
* The plugin will first resolve the HEAD to a commit using `git rev-parse HEAD`.
373-
* Next, it will do a `git show-ref` to check which (local/remote) branches point to the commit.
374-
* 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.
375-
* If all of the above fails, `${env.GIT_BRANCH}` is tried.
360+
# Additional Notes
361+
## How Git branch name resolution works
362+
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.
363+
2. If the `symbolic-ref` fails then it's likely due to a detached HEAD.
364+
This is typical of CI servers like Jenkins, where the commit hash that was just pushed is pulled.
365+
This can also be done as a consequene of attempting to rebuild from a tag, without branching, or in some
366+
workflows where code reviews are done without branches.
367+
368+
In the case of a detached HEAD the plugin will:
369+
* Resolve the HEAD to a commit using `git rev-parse HEAD`.
370+
* `git show-ref` to resolve which (local/remote) branches point to the commit.
371+
* If the detached HEAD commit resolves to a single branch type, it uses that branch name.
372+
3. If the first two methods fail, the plugin attempts to resolve `${env.GIT_BRANCH}`.
373+
374+
## Building with IntelliJ IDEA notes
375+
### To Debug Tests:
376+
Configure the Maven commandline to include
377+
`-DforkMode=never` You will likely get warnings when you run maven without this argument.
378+
379+
### To inspect code-coverage results from Integration Tests:
380+
* Select the **Analyze** -> **Show Coverage Data** menu.
381+
* In the dialog that appears, click the **+** in the upper left corner to `Add (Insert)`, and browse to `target/jacoco.exec`.
382+
* Selecting that file will show coverage data in the code editor.

pom.xml

Lines changed: 128 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
<maven.compiler.source>1.7</maven.compiler.source>
5353
<maven.compiler.target>1.7</maven.compiler.target>
5454
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
55+
<it.repository.basedir>${project.build.directory}/it-repositories</it.repository.basedir>
56+
<version.gitflow.plugin>${project.version}</version.gitflow.plugin>
5557
</properties>
5658

5759
<distributionManagement>
@@ -115,12 +117,6 @@
115117
<artifactId>aether-util</artifactId>
116118
<version>0.9.0.M2</version>
117119
</dependency>
118-
<dependency>
119-
<groupId>junit</groupId>
120-
<artifactId>junit</artifactId>
121-
<version>4.8.2</version>
122-
<scope>test</scope>
123-
</dependency>
124120
</dependencies>
125121

126122
<build>
@@ -140,12 +136,6 @@
140136
<goal>descriptor</goal>
141137
</goals>
142138
</execution>
143-
<execution>
144-
<id>help-goal</id>
145-
<goals>
146-
<goal>helpmojo</goal>
147-
</goals>
148-
</execution>
149139
</executions>
150140
</plugin>
151141
<plugin>
@@ -179,6 +169,132 @@
179169
</build>
180170

181171
<profiles>
172+
<profile>
173+
<id>testing</id>
174+
<activation>
175+
<activeByDefault>true</activeByDefault>
176+
</activation>
177+
<build>
178+
<testResources>
179+
<testResource>
180+
<directory>src/test/java</directory>
181+
</testResource>
182+
<testResource>
183+
<directory>src/test/resources</directory>
184+
<filtering>true</filtering>
185+
</testResource>
186+
</testResources>
187+
<plugins>
188+
<!-- Jacoco -->
189+
<plugin>
190+
<groupId>org.jacoco</groupId>
191+
<artifactId>jacoco-maven-plugin</artifactId>
192+
<version>0.8.1</version>
193+
<executions>
194+
<execution>
195+
<id>default-prepare-agent</id>
196+
<goals>
197+
<goal>prepare-agent</goal>
198+
</goals>
199+
</execution>
200+
<!-- Jacoco Is configured to munge the results of the normal unit tests
201+
and integration tests into the same output file.
202+
This gives us a 'global view' of all tested code paths.
203+
-->
204+
<execution>
205+
<id>pre-integration-test</id>
206+
<goals>
207+
<goal>prepare-agent-integration</goal>
208+
</goals>
209+
<configuration>
210+
<destFile>${project.build.directory}/jacoco.exec</destFile>
211+
</configuration>
212+
</execution>
213+
</executions>
214+
</plugin>
215+
216+
<!-- Enable surefire so we do integration testing only -->
217+
<plugin>
218+
<groupId>org.apache.maven.plugins</groupId>
219+
<artifactId>maven-surefire-plugin</artifactId>
220+
<version>2.22.0</version>
221+
<configuration>
222+
<systemProperties>
223+
<argLine>${argLine}</argLine>
224+
</systemProperties>
225+
<forkCount>1</forkCount>
226+
</configuration>
227+
</plugin>
228+
229+
<!-- Enable failsafe for integration testing -->
230+
<plugin>
231+
<groupId>org.apache.maven.plugins</groupId>
232+
<artifactId>maven-failsafe-plugin</artifactId>
233+
<version>2.22.0</version>
234+
<executions>
235+
<execution>
236+
<configuration>
237+
<systemProperties>
238+
<maven.repo.local>${it.repository.basedir}/local</maven.repo.local>
239+
<project.version>${project.version}</project.version>
240+
<argLine>${argLine}</argLine>
241+
</systemProperties>
242+
<forkCount>1</forkCount>
243+
</configuration>
244+
<goals>
245+
<goal>integration-test</goal>
246+
<goal>verify</goal>
247+
</goals>
248+
</execution>
249+
</executions>
250+
</plugin>
251+
252+
<!-- Copy the packaged artifact to the local repository used by the integration tests -->
253+
<plugin>
254+
<groupId>org.apache.maven.plugins</groupId>
255+
<artifactId>maven-install-plugin</artifactId>
256+
<version>2.5.2</version>
257+
<executions>
258+
<execution>
259+
<configuration>
260+
<localRepositoryPath>${it.repository.basedir}/local</localRepositoryPath>
261+
<groupId>${project.groupId}</groupId>
262+
<artifactId>${project.artifactId}</artifactId>
263+
<version>${project.version}</version>
264+
<pomFile>${pom.basedir}/pom.xml</pomFile>
265+
<file>${project.build.directory}${file.separator}${project.build.finalName}.jar</file>
266+
</configuration>
267+
<phase>pre-integration-test</phase>
268+
<goals>
269+
<goal>install-file</goal>
270+
</goals>
271+
</execution>
272+
</executions>
273+
</plugin>
274+
275+
<!-- Coveralls Reporting -->
276+
<plugin>
277+
<groupId>org.eluder.coveralls</groupId>
278+
<artifactId>coveralls-maven-plugin</artifactId>
279+
<version>4.3.0</version>
280+
</plugin>
281+
</plugins>
282+
</build>
283+
<dependencies>
284+
<dependency>
285+
<groupId>org.apache.maven.shared</groupId>
286+
<artifactId>maven-verifier</artifactId>
287+
<version>1.6</version>
288+
</dependency>
289+
<dependency>
290+
<groupId>junit</groupId>
291+
<artifactId>junit</artifactId>
292+
<version>4.8.2</version>
293+
<scope>test</scope>
294+
</dependency>
295+
</dependencies>
296+
</profile>
297+
182298
<profile>
183299
<id>eg.oss</id>
184300
<activation>

src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@
2525
import org.eclipse.aether.util.repository.AuthenticationBuilder;
2626

2727
import javax.annotation.Nullable;
28-
import java.io.*;
28+
import java.io.BufferedReader;
29+
import java.io.File;
30+
import java.io.FileInputStream;
31+
import java.io.FileNotFoundException;
32+
import java.io.FileOutputStream;
33+
import java.io.IOException;
34+
import java.io.InputStreamReader;
35+
import java.io.OutputStreamWriter;
36+
import java.io.PrintWriter;
2937
import java.nio.file.Files;
3038
import java.util.ArrayList;
3139
import java.util.Collections;

src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBranchMojo.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.e_gineering.maven.gitflowhelper;
22

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

45-
@Parameter(defaultValue = "(origin/)?(?:feature|bugfix)/(.*)", property = "featureOrBugfixBranchPattern", required = true)
46-
private String featureOrBugfixBranchPattern;
47-
4844
// An expression that resolves to the git branch at run-time.
4945
// @Parameter tag causes property resolution to fail for patterns containing ${env.}.
5046
// The default value _must_ be provided programmaticially at run-time.
5147
@Parameter(property = "gitBranchExpression", required = false)
5248
private String gitBranchExpression;
5349

54-
@Parameter(defaultValue = "false", property = "deploySnapshotTypeBranches")
55-
boolean deploySnapshotTypeBranches;
56-
50+
/**
51+
* If this is "equals" then exact version matching to branch name matching is preformed.
52+
* Otherwise, this is treated as a "startsWith".
53+
*/
5754
@Parameter(defaultValue = "equals", property = "releaseBranchMatchType", required = true)
5855
String releaseBranchMatchType;
5956

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

91-
ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, project, getLog(), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern, featureOrBugfixBranchPattern);
88+
ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, project, getLog(), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern);
9289
GitBranchInfo branchInfo = scmUtils.resolveBranchInfo(gitBranchExpression);
9390

9491
getLog().debug("Building for: " + branchInfo);

src/main/java/com/e_gineering/maven/gitflowhelper/AttachDeployedArtifactsMojo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionEx
2929
attachExistingArtifacts(stageDeploymentRepository, true);
3030
break;
3131
}
32-
case FEATURE_OR_BUGFIX_BRANCH:
3332
case DEVELOPMENT: {
3433
getLog().info("Attaching artifacts from snapshot repository...");
3534
attachExistingArtifacts(snapshotDeploymentRepository, true);

0 commit comments

Comments
 (0)