Skip to content

Commit b79e295

Browse files
authored
Merge branch 'master' into release/1.7.0
2 parents ad3b498 + a4baaf3 commit b79e295

13 files changed

+105
-252
lines changed

README.md

Lines changed: 32 additions & 54 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<groupId>com.e-gineering</groupId>
1010
<artifactId>gitflow-helper-maven-plugin</artifactId>
1111

12-
<version>1.7.0</version>
12+
<version>1.6.0</version>
1313
<packaging>maven-plugin</packaging>
1414

1515
<name>gitflow-helper-maven-plugin</name>

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

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@
1010
import org.apache.maven.plugins.annotations.Parameter;
1111
import org.apache.maven.project.MavenProjectHelper;
1212
import org.codehaus.plexus.util.FileUtils;
13-
import org.eclipse.aether.DefaultRepositorySystemSession;
1413
import org.eclipse.aether.RepositorySystemSession;
1514
import org.eclipse.aether.artifact.DefaultArtifact;
1615
import org.eclipse.aether.impl.ArtifactResolver;
17-
import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
1816
import org.eclipse.aether.repository.LocalRepository;
1917
import org.eclipse.aether.repository.RemoteRepository;
20-
import org.eclipse.aether.repository.RepositoryPolicy;
2118
import org.eclipse.aether.resolution.ArtifactRequest;
2219
import org.eclipse.aether.resolution.ArtifactResolutionException;
2320
import org.eclipse.aether.resolution.ArtifactResult;
@@ -31,6 +28,7 @@
3128
import java.io.InputStreamReader;
3229
import java.io.OutputStreamWriter;
3330
import java.io.PrintWriter;
31+
import java.lang.reflect.Field;
3432
import java.nio.charset.Charset;
3533
import java.nio.file.Files;
3634
import java.util.ArrayList;
@@ -57,10 +55,7 @@ public abstract class AbstractGitflowBasedRepositoryMojo extends AbstractGitflow
5755
protected String snapshotDeploymentRepository;
5856

5957
@Parameter(defaultValue = "${repositorySystemSession}", required = true)
60-
protected RepositorySystemSession session;
61-
62-
@Component
63-
protected EnhancedLocalRepositoryManagerFactory localRepositoryManagerFactory;
58+
private RepositorySystemSession session;
6459

6560
@Parameter(defaultValue = "${project.build.directory}", required = true)
6661
protected File buildDirectory;
@@ -130,7 +125,7 @@ protected ArtifactRepository getDeploymentRepository(final String altRepository)
130125
* @throws MojoExecutionException
131126
* @throws MojoFailureException
132127
*/
133-
protected RemoteRepository getRepository(final String altRepository) throws MojoExecutionException, MojoFailureException {
128+
private RemoteRepository getRepository(final String altRepository) throws MojoExecutionException, MojoFailureException {
134129
if (getLog().isDebugEnabled()) {
135130
getLog().debug("Creating remote Aether repository (to resolve remote artifacts) for: " + altRepository);
136131
}
@@ -158,14 +153,15 @@ protected RemoteRepository getRepository(final String altRepository) throws Mojo
158153
}
159154

160155
private String getCoordinates(ArtifactResult result) {
161-
StringBuilder buffer = new StringBuilder(128);
162-
buffer.append(result.getArtifact().getGroupId());
163-
buffer.append(':').append(result.getArtifact().getArtifactId());
164-
buffer.append(':').append(result.getArtifact().getExtension());
165-
if (result.getArtifact().getClassifier().length() > 0) {
166-
buffer.append(':').append(result.getArtifact().getClassifier());
156+
StringBuilder buffer = new StringBuilder( 128 );
157+
buffer.append( result.getArtifact().getGroupId() );
158+
buffer.append( ':' ).append( result.getArtifact().getArtifactId() );
159+
buffer.append( ':' ).append( result.getArtifact().getExtension() );
160+
if ( result.getArtifact().getClassifier().length() > 0 )
161+
{
162+
buffer.append( ':' ).append( result.getArtifact().getClassifier() );
167163
}
168-
buffer.append(':').append(result.getArtifact().getBaseVersion());
164+
buffer.append( ':' ).append( result.getArtifact().getBaseVersion() );
169165
return buffer.toString();
170166
}
171167

@@ -203,46 +199,47 @@ private String getCoordinates(org.apache.maven.artifact.Artifact artifact) {
203199
* group:artifact:type:classifier:version
204200
*/
205201
protected void attachArtifactCatalog() throws MojoExecutionException {
206-
getLog().info("Cataloging Artifacts for promotion & reattachment: " + project.getBuild().getDirectory());
202+
getLog().info("Cataloging Artifacts for promotion & reattachment: " + project.getBuild().getDirectory());
207203

208-
File catalog = new File(buildDirectory, project.getArtifact().getArtifactId() + ".txt");
204+
File catalog = new File(buildDirectory, project.getArtifact().getArtifactId() + ".txt");
209205

210-
PrintWriter writer = null;
206+
PrintWriter writer = null;
211207

212-
try {
213-
catalog.delete();
214-
buildDirectory.mkdirs();
215-
writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(catalog), Charset.forName("UTF-8")));
216-
217-
if (project.getArtifact() != null && project.getArtifact().getFile() != null &&
218-
project.getArtifact().getFile().exists() && !project.getArtifact().getFile().isDirectory()) {
219-
String coords = getCoordinates(project.getArtifact());
220-
if (!coords.isEmpty()) {
221-
getLog().info("Cataloging: " + coords);
222-
writer.println(coords);
208+
try {
209+
catalog.delete();
210+
buildDirectory.mkdirs();
211+
writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(catalog), Charset.forName("UTF-8")));
212+
213+
if (project.getArtifact() != null && project.getArtifact().getFile() != null &&
214+
project.getArtifact().getFile().exists() && !project.getArtifact().getFile().isDirectory())
215+
{
216+
String coords = getCoordinates(project.getArtifact());
217+
if (!coords.isEmpty()){
218+
getLog().info("Cataloging: " + coords);
219+
writer.println(coords);
220+
}
221+
} else {
222+
getLog().info("No primary artifact to catalog, cataloging attached artifacts instead.");
223223
}
224-
} else {
225-
getLog().info("No primary artifact to catalog, cataloging attached artifacts instead.");
226-
}
227224

228-
// Iterate the attached artifacts.
229-
for (org.apache.maven.artifact.Artifact artifact : project.getAttachedArtifacts()) {
230-
String coords = getCoordinates(artifact);
231-
if (!coords.isEmpty()) {
232-
getLog().info("Cataloging: " + coords);
233-
writer.println(coords);
225+
// Iterate the attached artifacts.
226+
for (org.apache.maven.artifact.Artifact artifact : project.getAttachedArtifacts()) {
227+
String coords = getCoordinates(artifact);
228+
if (!coords.isEmpty()) {
229+
getLog().info("Cataloging: " + coords);
230+
writer.println(coords);
231+
}
234232
}
235-
}
236233

237-
getLog().info("Attaching catalog artifact: " + catalog);
238-
projectHelper.attachArtifact(project, "txt", "catalog", catalog);
239-
} catch (IOException ioe) {
240-
throw new MojoExecutionException("Failed to create catalog of artifacts", ioe);
241-
} finally {
242-
if (writer != null) {
243-
writer.close();
234+
getLog().info("Attaching catalog artifact: " + catalog);
235+
projectHelper.attachArtifact(project, "txt", "catalog", catalog);
236+
} catch (IOException ioe) {
237+
throw new MojoExecutionException("Failed to create catalog of artifacts", ioe);
238+
} finally {
239+
if (writer != null) {
240+
writer.close();
241+
}
244242
}
245-
}
246243
}
247244

248245
/**
@@ -269,30 +266,35 @@ protected void attachExistingArtifacts(final String sourceRepository, final bool
269266
// A place to store our resolved files...
270267
List<ArtifactResult> resolvedArtifacts = new ArrayList<ArtifactResult>();
271268

269+
// Keep track of the original base directory.
270+
Field localBaseDir = null;
271+
File originalBaseDir = session.getLocalRepositoryManager().getRepository().getBasedir();
272272

273-
// Use a custom repository session, setup to force a few behaviors we like.
274-
DefaultRepositorySystemSession tempSession = new DefaultRepositorySystemSession(session);
275-
tempSession.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
276-
273+
// Disable the local repository - using a bit of reflection that I wish we didn't need to use.
277274
File tempRepo = null;
278275
if (disableLocal) {
279-
getLog().info("Disabling local repository @ " + tempSession.getLocalRepository().getBasedir());
276+
getLog().info("Disabling local repository @ " + session.getLocalRepository().getBasedir());
280277
try {
278+
localBaseDir = LocalRepository.class.getDeclaredField("basedir");
279+
localBaseDir.setAccessible(true);
280+
281+
// Generate a new temp directory.
281282
tempRepo = Files.createTempDirectory("gitflow-helper-maven-plugin-repo").toFile();
282283

283284
getLog().info("Using temporary local repository @ " + tempRepo.getAbsolutePath());
284-
tempSession.setLocalRepositoryManager(localRepositoryManagerFactory.newInstance(tempSession, new LocalRepository(tempRepo)));
285+
localBaseDir.set(session.getLocalRepositoryManager().getRepository(), tempRepo);
285286
} catch (Exception ex) {
286287
getLog().warn("Failed to disable local repository path.", ex);
287288
}
288289
}
289290

291+
290292
List<ArtifactRequest> requiredArtifacts = new ArrayList<ArtifactRequest>();
291293

292294
// Locate our text catalog classifier file. :-)
293295
BufferedReader reader = null;
294296
try {
295-
ArtifactResult catalogResult = artifactResolver.resolveArtifact(tempSession, new ArtifactRequest(new DefaultArtifact(project.getGroupId(), project.getArtifactId(), "catalog", "txt", project.getVersion()), remoteRepositories, null));
297+
ArtifactResult catalogResult = artifactResolver.resolveArtifact(session, new ArtifactRequest(new DefaultArtifact(project.getGroupId(), project.getArtifactId(), "catalog", "txt", project.getVersion()), remoteRepositories, null));
296298
resolvedArtifacts.add(catalogResult);
297299

298300
if (catalogResult.isResolved()) {
@@ -315,15 +317,14 @@ protected void attachExistingArtifacts(final String sourceRepository, final bool
315317
if (reader != null) {
316318
try {
317319
reader.close();
318-
} catch (IOException ioe) {
319-
}
320+
} catch (IOException ioe) {}
320321
}
321322
}
322323

323324

324325
// Resolve the artifacts from the catalog (if there are any)
325326
try {
326-
resolvedArtifacts.addAll(artifactResolver.resolveArtifacts(tempSession, requiredArtifacts));
327+
resolvedArtifacts.addAll(artifactResolver.resolveArtifacts(session, requiredArtifacts));
327328
} catch (ArtifactResolutionException are) {
328329
throw new MojoExecutionException("Failed to resolve the required project files from: " + sourceRepository, are);
329330
}
@@ -354,6 +355,12 @@ protected void attachExistingArtifacts(final String sourceRepository, final bool
354355

355356
// Restore the local repository, again using reflection.
356357
if (disableLocal) {
358+
try {
359+
localBaseDir.set(session.getLocalRepositoryManager().getRepository(), originalBaseDir);
360+
localBaseDir.setAccessible(false);
361+
} catch (Exception ex) {
362+
getLog().warn("Failed to restore original local repository path.", ex);
363+
}
357364
if (tempRepo != null) {
358365
try {
359366
FileUtils.deleteDirectory(tempRepo);

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ public abstract class AbstractGitflowBranchMojo extends AbstractMojo {
3333
@Parameter(defaultValue = "(origin/)?master", property = "masterBranchPattern", required = true)
3434
private String masterBranchPattern;
3535

36-
@Parameter(defaultValue = "(origin/)?support/(.*)", property = "supportBranchPattern", required = true)
37-
private String supportBranchPattern;
38-
3936
@Parameter(defaultValue = "(origin/)?release/(.*)", property = "releaseBranchPattern", required = true)
4037
private String releaseBranchPattern;
4138

@@ -94,8 +91,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
9491
*/
9592
if (gitBranch.matches(masterBranchPattern)) {
9693
logExecute(GitBranchType.MASTER, gitBranch, masterBranchPattern);
97-
} else if (gitBranch.matches(supportBranchPattern)) {
98-
logExecute(GitBranchType.SUPPORT, gitBranch, supportBranchPattern);
9994
} else if (gitBranch.matches(releaseBranchPattern)) {
10095
logExecute(GitBranchType.RELEASE, gitBranch, releaseBranchPattern);
10196
} else if (gitBranch.matches(hotfixBranchPattern)) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public class AttachDeployedArtifactsMojo extends AbstractGitflowBasedRepositoryM
1616
@Override
1717
protected void execute(GitBranchType type, String gitBranch, String branchPattern) throws MojoExecutionException, MojoFailureException {
1818
switch (type) {
19-
case MASTER:
20-
case SUPPORT:
21-
{
19+
case MASTER: {
2220
getLog().info("Attaching artifacts from release repository...");
2321
attachExistingArtifacts(releaseDeploymentRepository, true);
2422
break;

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,11 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
2828
throw new MojoFailureException("The current git branch: [" + gitBranch + "] is defined as a release branch. The maven project version: [" + project.getVersion() + "] is currently a snapshot version.");
2929
}
3030

31-
// Non-master version branches require a pom version match of some kind to the branch subgroups.
32-
if (gitMatcher.groupCount() > 0) {
33-
// HOTFIX and RELEASE branches require an exact match to the last subgroup.
34-
if ((GitBranchType.RELEASE.equals(type) || GitBranchType.HOTFIX.equals(type)) && !gitMatcher.group(gitMatcher.groupCount()).trim().equals(project.getVersion().trim())) {
31+
// Expect the last group on non-master branches to match (exactly) the current projectVersion. (only release / hotfix branches)
32+
if (gitMatcher.groupCount() > 0 && !GitBranchType.MASTER.equals(type)) {
33+
if (!gitMatcher.group(gitMatcher.groupCount()).trim().equals(project.getVersion().trim())) {
3534
throw new MojoFailureException("The current git branch: [" + gitBranch + "] expected the maven project version to be: [" + gitMatcher.group(gitMatcher.groupCount()).trim() + "], but the maven project version is: [" + project.getVersion() + "]");
3635
}
37-
38-
// SUPPORT branches require a 'starts with' match of the maven project version to the subgroup.
39-
// ex: /origin/support/3.1 must have a maven version that starts with "3.1", ala: "3.1.2"
40-
if (GitBranchType.SUPPORT.equals(type) && !project.getVersion().startsWith(gitMatcher.group(gitMatcher.groupCount()).trim())) {
41-
throw new MojoFailureException("The current git branch: [" + gitBranch + "] expected the maven project version to start with: [" + gitMatcher.group(gitMatcher.groupCount()).trim() + "], but the maven project version is: [" + project.getVersion() + "]");
42-
}
4336
}
4437
}
4538
} else if (GitBranchType.DEVELOPMENT.equals(type) && !ArtifactUtils.isSnapshot(project.getVersion())) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
*/
88
public enum GitBranchType {
99
MASTER,
10-
SUPPORT,
1110
RELEASE,
1211
HOTFIX,
1312
DEVELOPMENT,
1413
OTHER,
1514
UNDEFINED;
1615

17-
static final EnumSet<GitBranchType> VERSIONED_TYPES = EnumSet.of(GitBranchType.MASTER, GitBranchType.SUPPORT, GitBranchType.RELEASE, GitBranchType.HOTFIX);
16+
static final EnumSet<GitBranchType> VERSIONED_TYPES = EnumSet.of(GitBranchType.MASTER, GitBranchType.RELEASE, GitBranchType.HOTFIX);
1817
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
6565
try {
6666
pluginsToRetain.add(descriptorCreator.findPluginForPrefix(prefix, session));
6767
} catch (NoPluginFoundForPrefixException ex) {
68-
logger.warn("gitflow-helper-maven-plugin: Unable to resolve project plugin for prefix: " + prefix + " for goal: " + goal);
69-
// throw new MavenExecutionException("Unable to resolve plugin for prefix: " + prefix, ex);
68+
throw new MavenExecutionException("Unable to resolve plugin for prefix: " + prefix, ex);
7069
}
7170
}
7271
}
@@ -129,10 +128,7 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
129128
logger.info("gitflow-helper-maven-plugin: Enabling MasterPromoteExtension. GIT_BRANCH: [" + gitBranch + "] matches masterBranchPattern: [" + masterBranchPattern + "]");
130129

131130
for (MavenProject project : session.getProjects()) {
132-
// Drop all the plugins from the build except for the gitflow-helper-maven-plugin, or plugins we
133-
// invoked goals for which could be mapped back to plugins in our project build.
134-
// Goals invoked from the commandline which cannot be mapped back to our project, will get warnings, but should still execute.
135-
// If someone is on 'master' and starts executing goals, we need to allow them to do that.
131+
// Drop all the plugins from the build except for the gitflow-helper-maven-plugin.
136132
project.getBuildPlugins().removeAll(pluginsToDrop.get(project));
137133
}
138134
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
2828
break;
2929
}
3030

31-
case SUPPORT:
3231
case MASTER: {
3332
getLog().info("Resolving & Reattaching existing artifacts from stageDeploymentRepository [" + stageDeploymentRepository + "]");
3433

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
1818
}
1919

2020
switch (type) {
21-
case SUPPORT:
2221
case MASTER: {
2322
getLog().info("Setting release artifact repository to: [" + releaseDeploymentRepository + "]");
2423
project.setSnapshotArtifactRepository(null);

0 commit comments

Comments
 (0)