Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/other branch reversioning extension #126

Merged
merged 19 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7c65a36
feat: Initial work on an extension to set version info for other depl…
bvarner Dec 23, 2019
d25c854
Updated readme documention on debugging.
bvarner Dec 23, 2019
815d102
* Adjust build final names, incase they include the version.
bvarner Dec 23, 2019
7cd44ec
feat: Massaging of version information within reactor POMs.
bvarner Dec 26, 2019
5aedf12
Import cleanup. and odds and ends
bvarner Jan 3, 2020
877f841
Test cases are all adjusted, and they found some thing.
bvarner Jan 3, 2020
c60b5c2
Added support for dealing with partial multi-module builds in the Oth…
glimmerveen Aug 15, 2020
959b269
Copied the mirrors, remote repositories and plugin artifact repositor…
glimmerveen Sep 17, 2020
264c0b4
Propagate servers & proxies from session to nested maven execution as…
glimmerveen Sep 24, 2020
2cb2c77
fix an issue wherein certain plugin execution orders could lead to th…
Oct 2, 2020
a79b41e
add unit test to cover branch renaming
Oct 5, 2020
9d1c277
Merge branch 'feature/fix-repeated-other-branch-renaming' of github.c…
glimmerveen Oct 7, 2020
2ee35eb
Bump junit from 4.8.2 to 4.13.1
dependabot[bot] Oct 13, 2020
c2db550
Restore Session in LegacySupport *after* running the additional Maven…
glimmerveen Nov 23, 2020
b30df68
Changed approach on how to construct the MavenExecutionRequest for th…
glimmerveen Nov 26, 2020
9889c7f
Merge pull request #122 from rdefreitas/feature/fix-repeated-other-br…
bvarner Jan 14, 2021
13fcbaf
Merge pull request #120 from glimmerveen/feature/partial-multi-module…
bvarner Jan 14, 2021
3a09f95
Merge pull request #123 from egineering-llc/dependabot/maven/junit-ju…
bvarner Jan 14, 2021
1261c44
Merge branch 'master' into feature/other-branch-reversioning-extension
bvarner Jan 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,16 @@ the artifacts built by the first job into a jboss application server.

## To Debug the plugin (replicating a test-case but without being run from jUnit)
You can 'bootstrap' the plugin into your local repository and get the test project stubbed by running:
`mvn -Dmaven.test.skip=true install`

Then, change directories:
`cd target/test-classes/project-stub`

From there, you'll need to supply the required environment variables or commandline arguments to `mvnDebug`:
```
mvn process-test-classes
mvn -Dmaven.test.skip=true install
cd target/test-classes/project-stub`
export GIT_BRANCH=origin/feature/mybranch-foo-bar
mvnDebug -Dstub.project.version=5.0.0-SNAPSHOT -DotherBranchDeploy=semver -DallowGitflowPluginSnapshot=true deploy
mvnDebug -Dstub.project.version=5.0.0-SNAPSHOT -DallowGitflowPluginSnapshot=true deploy
```
This will get the test classes into the target directory and install the plugin into your local repository.
Then you move to the proper stub directory, supply the environment variables and arguments to `mvnDebug`.

You can then connect a remote debugger and step through the plugin code.

## Building with IntelliJ IDEA notes
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package com.e_gineering.maven.gitflowhelper;

import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.manager.ScmManager;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;

import java.io.IOException;
import java.util.Properties;

public abstract class AbstractBranchDetectingExtension extends AbstractMavenLifecycleParticipant {
@Requirement
MojoDescriptorCreator descriptorCreator;

@Requirement
Logger logger;

@Requirement
ScmManager scmManager;

boolean pluginFound = false;
String masterBranchPattern;
String supportBranchPattern;
String releaseBranchPattern;
String hotfixBranchPattern;
String developmentBranchPattern;
String featureOrBugfixBranchPattern;
String otherDeployBranchPattern;
String otherBranchVersionDelimiter;
GitBranchInfo branchInfo;
Properties systemEnvVars;

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
try {
systemEnvVars = CommandLineUtils.getSystemEnvVars();
} catch (IOException ioe) {
throw new MavenExecutionException("Unable to read System Envirionment Variables: ", ioe);
}

// Look for a configured gitflow-helper-maven-plugin,
// To determine what the gitBranchExpression and branch patterns are...
String gitBranchExpression = null;

pluginFound = false;
for (MavenProject project : session.getProjects()) {
for (Plugin plugin : project.getModel().getBuild().getPlugins()) {
// Don't drop our plugin. Read it's config
if (plugin.getKey().equals("com.e-gineering:gitflow-helper-maven-plugin")) {
pluginFound = true;

logger.debug("gitflow-helper-maven-plugin found in project: [" + project.getName() + "]");

if (masterBranchPattern == null) {
masterBranchPattern = extractPluginConfigValue("masterBranchPattern", plugin);
}

if (supportBranchPattern == null) {
supportBranchPattern = extractPluginConfigValue("supportBranchPattern", plugin);
}

if (releaseBranchPattern == null) {
releaseBranchPattern = extractPluginConfigValue("releaseBranchPattern", plugin);
}

if (hotfixBranchPattern == null) {
hotfixBranchPattern = extractPluginConfigValue("hotfixBranchPattern", plugin);
}

if (developmentBranchPattern == null) {
developmentBranchPattern = extractPluginConfigValue("developmentBranchPattern", plugin);
}

if (featureOrBugfixBranchPattern == null) {
featureOrBugfixBranchPattern = extractPluginConfigValue("featureOrBugfixBranchPattern", plugin);
}

if (otherDeployBranchPattern == null) {
otherDeployBranchPattern = extractPluginConfigValue("otherDeployBranchPattern", plugin);
}

if (otherBranchVersionDelimiter == null) {
otherBranchVersionDelimiter = extractPluginConfigValue("otherBranchVersionDelimiter", plugin);
}

if (gitBranchExpression == null) {
gitBranchExpression = extractPluginConfigValue("gitBranchExpression", plugin);
}
}
}
}

// Any missing configuration options need to be defaulted.
if (pluginFound) {
if (masterBranchPattern == null) {
logger.debug("Using default master branch Pattern.");
masterBranchPattern = "(origin/)?master";
}
logger.debug("Master Branch Pattern: " + masterBranchPattern);

if (supportBranchPattern == null) {
logger.debug("Using default support branch Pattern.");
supportBranchPattern = "(origin/)?support/(.*)";
}
logger.debug("Support Branch Pattern: " + supportBranchPattern);

if (releaseBranchPattern == null) {
logger.debug("Using default release branch Pattern.");
releaseBranchPattern = "(origin/)?release/(.*)";
}
logger.debug("Release Branch Pattern: " + releaseBranchPattern);

if (hotfixBranchPattern == null) {
logger.debug("Using default hotfix branch Pattern.");
hotfixBranchPattern = "(origin/)?hotfix/(.*)";
}
logger.debug("Hotfix Branch Pattern: " + hotfixBranchPattern);

if (developmentBranchPattern == null) {
logger.debug("Using default development Pattern.");
developmentBranchPattern = "(origin/)?develop";
}
logger.debug("Development Branch Pattern: " + developmentBranchPattern);

if (featureOrBugfixBranchPattern == null) {
logger.debug("Using default feature or bugfix Pattern.");
featureOrBugfixBranchPattern = "(origin/)?(?:feature|bugfix)/(.*)";
}
logger.debug("Feature or Bugfix Branch Pattern: " + featureOrBugfixBranchPattern);

if (otherDeployBranchPattern == null) {
logger.debug("Using default other deployment branch Pattern.");
otherDeployBranchPattern = "";
}
logger.debug("Other Branch Deployment Pattern: " + otherDeployBranchPattern);

if (otherBranchVersionDelimiter == null) {
logger.debug("Using default otherBranchVersionDelimiter.");
otherBranchVersionDelimiter = "+";
}

ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, session.getTopLevelProject(), new PlexusLoggerToMavenLog(logger), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern);
branchInfo = scmUtils.resolveBranchInfo(gitBranchExpression);
} else {
logger.debug("Unable to configure gitflow-helper-maven-plugin lifecycle extensions. No Plugin configuration found.");
}
}

private String extractPluginConfigValue(String parameter, Plugin plugin) {
String value = extractConfigValue(parameter, plugin.getConfiguration());
for (int i = 0; i < plugin.getExecutions().size() && value == null; i++) {
value = extractConfigValue(parameter, plugin.getExecutions().get(i).getConfiguration());
}
return value;
}

private String extractConfigValue(String parameter, Object configuration) {
try {
return ((Xpp3Dom) configuration).getChild(parameter).getValue();
} catch (Exception ignored) {
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.bridge.MavenRepositorySystem;
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.shared.utils.StringUtils;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
Expand All @@ -38,7 +34,6 @@
import java.io.PrintWriter;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -75,7 +70,7 @@ private static PrintWriter newPrintWriter(File catalog) throws FileNotFoundExcep
RepositorySystemSession repositorySystemSession;

@Parameter(defaultValue = "${project.build.directory}", required = true)
private File buildDirectory;
File buildDirectory;

@Component
private RepositorySystem repositorySystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.e_gineering.maven.gitflowhelper;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Execute;
Expand Down
Loading