Skip to content

Commit 10d5362

Browse files
authored
Merge pull request #67 from egineering-llc/revert-65-revert-63-release/1.7.0
Revert "Revert "Release/1.7.0""
2 parents ecc2c9c + 6208560 commit 10d5362

12 files changed

+251
-104
lines changed

README.md

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

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

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
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;
1314
import org.eclipse.aether.RepositorySystemSession;
1415
import org.eclipse.aether.artifact.DefaultArtifact;
1516
import org.eclipse.aether.impl.ArtifactResolver;
17+
import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
1618
import org.eclipse.aether.repository.LocalRepository;
1719
import org.eclipse.aether.repository.RemoteRepository;
20+
import org.eclipse.aether.repository.RepositoryPolicy;
1821
import org.eclipse.aether.resolution.ArtifactRequest;
1922
import org.eclipse.aether.resolution.ArtifactResolutionException;
2023
import org.eclipse.aether.resolution.ArtifactResult;
@@ -28,7 +31,6 @@
2831
import java.io.InputStreamReader;
2932
import java.io.OutputStreamWriter;
3033
import java.io.PrintWriter;
31-
import java.lang.reflect.Field;
3234
import java.nio.charset.Charset;
3335
import java.nio.file.Files;
3436
import java.util.ArrayList;
@@ -55,7 +57,10 @@ public abstract class AbstractGitflowBasedRepositoryMojo extends AbstractGitflow
5557
protected String snapshotDeploymentRepository;
5658

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

6065
@Parameter(defaultValue = "${project.build.directory}", required = true)
6166
protected File buildDirectory;
@@ -126,7 +131,7 @@ protected ArtifactRepository getDeploymentRepository(final String altRepository)
126131
* @throws MojoExecutionException
127132
* @throws MojoFailureException
128133
*/
129-
private RemoteRepository getRepository(final String altRepository) throws MojoExecutionException, MojoFailureException {
134+
protected RemoteRepository getRepository(final String altRepository) throws MojoExecutionException, MojoFailureException {
130135
if (getLog().isDebugEnabled()) {
131136
getLog().debug("Creating remote Aether repository (to resolve remote artifacts) for: " + altRepository);
132137
}
@@ -154,15 +159,14 @@ private RemoteRepository getRepository(final String altRepository) throws MojoEx
154159
}
155160

156161
private String getCoordinates(ArtifactResult result) {
157-
StringBuilder buffer = new StringBuilder( 128 );
158-
buffer.append( result.getArtifact().getGroupId() );
159-
buffer.append( ':' ).append( result.getArtifact().getArtifactId() );
160-
buffer.append( ':' ).append( result.getArtifact().getExtension() );
161-
if ( result.getArtifact().getClassifier().length() > 0 )
162-
{
163-
buffer.append( ':' ).append( result.getArtifact().getClassifier() );
162+
StringBuilder buffer = new StringBuilder(128);
163+
buffer.append(result.getArtifact().getGroupId());
164+
buffer.append(':').append(result.getArtifact().getArtifactId());
165+
buffer.append(':').append(result.getArtifact().getExtension());
166+
if (result.getArtifact().getClassifier().length() > 0) {
167+
buffer.append(':').append(result.getArtifact().getClassifier());
164168
}
165-
buffer.append( ':' ).append( result.getArtifact().getBaseVersion() );
169+
buffer.append(':').append(result.getArtifact().getBaseVersion());
166170
return buffer.toString();
167171
}
168172

@@ -200,47 +204,46 @@ private String getCoordinates(org.apache.maven.artifact.Artifact artifact) {
200204
* group:artifact:type:classifier:version
201205
*/
202206
protected void attachArtifactCatalog() throws MojoExecutionException {
203-
getLog().info("Cataloging Artifacts for promotion & reattachment: " + project.getBuild().getDirectory());
207+
getLog().info("Cataloging Artifacts for promotion & reattachment: " + project.getBuild().getDirectory());
204208

205-
File catalog = new File(buildDirectory, project.getArtifact().getArtifactId() + ".txt");
209+
File catalog = new File(buildDirectory, project.getArtifact().getArtifactId() + ".txt");
206210

207-
PrintWriter writer = null;
211+
PrintWriter writer = null;
208212

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

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

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

246249
/**
@@ -267,35 +270,30 @@ protected void attachExistingArtifacts(final String sourceRepository, final bool
267270
// A place to store our resolved files...
268271
List<ArtifactResult> resolvedArtifacts = new ArrayList<ArtifactResult>();
269272

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

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

285284
getLog().info("Using temporary local repository @ " + tempRepo.getAbsolutePath());
286-
localBaseDir.set(session.getLocalRepositoryManager().getRepository(), tempRepo);
285+
tempSession.setLocalRepositoryManager(localRepositoryManagerFactory.newInstance(tempSession, new LocalRepository(tempRepo)));
287286
} catch (Exception ex) {
288287
getLog().warn("Failed to disable local repository path.", ex);
289288
}
290289
}
291290

292-
293291
List<ArtifactRequest> requiredArtifacts = new ArrayList<ArtifactRequest>();
294292

295293
// Locate our text catalog classifier file. :-)
296294
BufferedReader reader = null;
297295
try {
298-
ArtifactResult catalogResult = artifactResolver.resolveArtifact(session, new ArtifactRequest(new DefaultArtifact(project.getGroupId(), project.getArtifactId(), "catalog", "txt", project.getVersion()), remoteRepositories, null));
296+
ArtifactResult catalogResult = artifactResolver.resolveArtifact(tempSession, new ArtifactRequest(new DefaultArtifact(project.getGroupId(), project.getArtifactId(), "catalog", "txt", project.getVersion()), remoteRepositories, null));
299297
resolvedArtifacts.add(catalogResult);
300298

301299
if (catalogResult.isResolved()) {
@@ -318,14 +316,15 @@ protected void attachExistingArtifacts(final String sourceRepository, final bool
318316
if (reader != null) {
319317
try {
320318
reader.close();
321-
} catch (IOException ioe) {}
319+
} catch (IOException ioe) {
320+
}
322321
}
323322
}
324323

325324

326325
// Resolve the artifacts from the catalog (if there are any)
327326
try {
328-
resolvedArtifacts.addAll(artifactResolver.resolveArtifacts(session, requiredArtifacts));
327+
resolvedArtifacts.addAll(artifactResolver.resolveArtifacts(tempSession, requiredArtifacts));
329328
} catch (ArtifactResolutionException are) {
330329
throw new MojoExecutionException("Failed to resolve the required project files from: " + sourceRepository, are);
331330
}
@@ -356,12 +355,6 @@ protected void attachExistingArtifacts(final String sourceRepository, final bool
356355

357356
// Restore the local repository, again using reflection.
358357
if (disableLocal) {
359-
try {
360-
localBaseDir.set(session.getLocalRepositoryManager().getRepository(), originalBaseDir);
361-
localBaseDir.setAccessible(false);
362-
} catch (Exception ex) {
363-
getLog().warn("Failed to restore original local repository path.", ex);
364-
}
365358
if (tempRepo != null) {
366359
try {
367360
FileUtils.deleteDirectory(tempRepo);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ 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+
3639
@Parameter(defaultValue = "(origin/)?release/(.*)", property = "releaseBranchPattern", required = true)
3740
private String releaseBranchPattern;
3841

@@ -91,6 +94,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
9194
*/
9295
if (gitBranch.matches(masterBranchPattern)) {
9396
logExecute(GitBranchType.MASTER, gitBranch, masterBranchPattern);
97+
} else if (gitBranch.matches(supportBranchPattern)) {
98+
logExecute(GitBranchType.SUPPORT, gitBranch, supportBranchPattern);
9499
} else if (gitBranch.matches(releaseBranchPattern)) {
95100
logExecute(GitBranchType.RELEASE, gitBranch, releaseBranchPattern);
96101
} else if (gitBranch.matches(hotfixBranchPattern)) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ 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: {
19+
case MASTER:
20+
case SUPPORT:
21+
{
2022
getLog().info("Attaching artifacts from release repository...");
2123
attachExistingArtifacts(releaseDeploymentRepository, true);
2224
break;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,18 @@ 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-
// 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())) {
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())) {
3435
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() + "]");
3536
}
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+
}
3643
}
3744
}
3845
} else if (GitBranchType.DEVELOPMENT.equals(type) && !ArtifactUtils.isSnapshot(project.getVersion())) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
*/
88
public enum GitBranchType {
99
MASTER,
10+
SUPPORT,
1011
RELEASE,
1112
HOTFIX,
1213
DEVELOPMENT,
1314
OTHER,
1415
UNDEFINED;
1516

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

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
6565
try {
6666
pluginsToRetain.add(descriptorCreator.findPluginForPrefix(prefix, session));
6767
} catch (NoPluginFoundForPrefixException ex) {
68-
throw new MavenExecutionException("Unable to resolve plugin for prefix: " + prefix, 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);
6970
}
7071
}
7172
}
@@ -128,7 +129,10 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
128129
logger.info("gitflow-helper-maven-plugin: Enabling MasterPromoteExtension. GIT_BRANCH: [" + gitBranch + "] matches masterBranchPattern: [" + masterBranchPattern + "]");
129130

130131
for (MavenProject project : session.getProjects()) {
131-
// Drop all the plugins from the build except for the gitflow-helper-maven-plugin.
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.
132136
project.getBuildPlugins().removeAll(pluginsToDrop.get(project));
133137
}
134138
}

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

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

31+
case SUPPORT:
3132
case MASTER: {
3233
getLog().info("Resolving & Reattaching existing artifacts from stageDeploymentRepository [" + stageDeploymentRepository + "]");
3334

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

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

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

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ public class SetPropertiesMojo extends AbstractGitflowBranchMojo {
3030
@Parameter(property = "masterBranchPropertyFile")
3131
private File masterBranchPropertyFile;
3232

33+
/**
34+
* Properties to be applied if executing against a support branch
35+
*/
36+
@Parameter(property = "supportBranchProperties")
37+
private Properties supportBranchProperties;
38+
39+
/**
40+
* A Property file to load if executing against the support branch
41+
*/
42+
@Parameter(property = "supportBranchPropertyFile")
43+
private File supportBranchPropertyFile;
44+
3345
/**
3446
* Properties to be applied if executing against a release branch
3547
*/
@@ -114,6 +126,11 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
114126
Properties toInject = null;
115127
File toLoad = null;
116128
switch (type) {
129+
case SUPPORT: {
130+
toInject = supportBranchProperties;
131+
toLoad = supportBranchPropertyFile;
132+
break;
133+
}
117134
case MASTER: {
118135
toInject = masterBranchProperties;
119136
toLoad = masterBranchPropertyFile;

0 commit comments

Comments
 (0)