Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<groupId>com.github.danielflower.mavenplugins</groupId>
<artifactId>multi-module-maven-release-plugin</artifactId>
<version>3.6-SNAPSHOT</version> <!-- When changing also update scaffolding.TestProject.PLUGIN_VERSION_FOR_TESTS and add to src/site/markdown/changelog.md -->
<version>3.7-SNAPSHOT</version> <!-- When changing also update scaffolding.TestProject.PLUGIN_VERSION_FOR_TESTS and add to src/site/markdown/changelog.md -->

<name>The Multi Module Maven Release Plugin</name>
<description>A maven release plugin built for multi-maven-module git repositories allowing continuous deployment
</description>
Expand Down
229 changes: 124 additions & 105 deletions src/main/java/com/github/danielflower/mavenplugins/release/BaseMojo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.github.danielflower.mavenplugins.release;

import static java.lang.String.format;

import java.util.List;
import java.util.Set;

import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver;
Expand All @@ -16,41 +21,38 @@
import org.eclipse.jgit.transport.JschConfigSessionFactory;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;

import java.util.List;

import static java.lang.String.format;

/**
* @author Roland Hauser sourcepond@gmail.com
*
*/
public abstract class BaseMojo extends AbstractMojo {
/**
* The Maven Project.
*/
@Parameter(property = "project", required = true, readonly = true, defaultValue = "${project}")
protected MavenProject project;

@Parameter(property = "projects", required = true, readonly = true, defaultValue = "${reactorProjects}")
protected List<MavenProject> projects;

/**
* <p>
* The build number to use in the release version. Given a snapshot version
* of "1.0-SNAPSHOT" and a buildNumber value of "2", the actual released
* version will be "1.0.2".
* </p>
* <p>
* By default, the plugin will automatically find a suitable build number.
* It will start at version 0 and increment this with each release.
* </p>
* <p>
* This can be specified using a command line parameter ("-DbuildNumber=2")
* or in this plugin's configuration.
* </p>
*/
@Parameter(property = "buildNumber")
protected Long buildNumber;

/**
* The Maven Project.
*/
@Parameter(property = "project", required = true, readonly = true, defaultValue = "${project}")
protected MavenProject project;

@Parameter(property = "projects", required = true, readonly = true, defaultValue = "${reactorProjects}")
protected List<MavenProject> projects;

/**
* <p>
* The build number to use in the release version. Given a snapshot version
* of "1.0-SNAPSHOT" and a buildNumber value of "2", the actual released
* version will be "1.0.2".
* </p>
* <p>
* By default, the plugin will automatically find a suitable build number.
* It will start at version 0 and increment this with each release.
* </p>
* <p>
* This can be specified using a command line parameter ("-DbuildNumber=2")
* or in this plugin's configuration.
* </p>
*/
@Parameter(property = "buildNumber")
protected Long buildNumber;


/**
Expand All @@ -61,20 +63,20 @@ public abstract class BaseMojo extends AbstractMojo {
@Parameter(property = "versionNamer")
protected VersionNamer versionNamer = new VersionNamer(".");

/**
* The modules to release, or no value to to release the project from the
* root pom, which is the default. The selected module plus any other
* modules it needs will be built and released also. When run from the
* command line, this can be a comma-separated list of module names.
*/
@Parameter(alias = "modulesToRelease", property = "modulesToRelease")
protected List<String> modulesToRelease;

/**
* A module to force release on, even if no changes has been detected.
*/
@Parameter(alias = "forceRelease", property = "forceRelease")
protected List<String> modulesToForceRelease;
/**
* The modules to release, or no value to to release the project from the
* root pom, which is the default. The selected module plus any other
* modules it needs will be built and released also. When run from the
* command line, this can be a comma-separated list of module names.
*/
@Parameter(alias = "modulesToRelease", property = "modulesToRelease")
protected List<String> modulesToRelease;

/**
* A module to force release on, even if no changes has been detected.
*/
@Parameter(alias = "forceRelease", property = "forceRelease")
protected List<String> modulesToForceRelease;

/**
* Determines the action to take when no module changes are detected. Possible values:
Expand Down Expand Up @@ -108,40 +110,40 @@ public abstract class BaseMojo extends AbstractMojo {
@Parameter(property = "localRepository", required = true, readonly = true, defaultValue = "${localRepository}")
protected ArtifactRepository localRepository;

@Parameter(property = "disableSshAgent")
private boolean disableSshAgent;
@Parameter(property = "disableSshAgent")
private boolean disableSshAgent;

@Parameter(defaultValue = "${settings}", readonly = true, required = true)
private Settings settings;
@Parameter(defaultValue = "${settings}", readonly = true, required = true)
private Settings settings;

/**
* <p>If set, the identityFile and passphrase will be read from the Maven settings file.</p>
/**
* <p>If set, the identityFile and passphrase will be read from the Maven settings file.</p>
* <p>See <a href="https://maven.apache.org/guides/mini/guide-deployment-security-settings.html">https://maven.apache.org/guides/mini/guide-deployment-security-settings.html</a>
* for more information on configuring servers in Maven.</p>
*/
@Parameter(property = "serverId")
private String serverId;

/**
* If set, this file will be used to specify the known_hosts. This will
* override any default value.
*/
@Parameter(property = "knownHosts")
private String knownHosts;

/**
* Specifies the private key to be used for SSH URLs. By default it will use <code>~/.ssh/id_rsa</code>
*/
@Parameter(property = "privateKey")
private String privateKey;

/**
* <p>Specifies the passphrase to be used with the identityFile specified for SSH where the private key requires a pass phrase.</p>
*/
@Parameter(property = "serverId")
private String serverId;

/**
* If set, this file will be used to specify the known_hosts. This will
* override any default value.
*/
@Parameter(property = "knownHosts")
private String knownHosts;

/**
* Specifies the private key to be used for SSH URLs. By default it will use <code>~/.ssh/id_rsa</code>
*/
@Parameter(property = "privateKey")
private String privateKey;

/**
* <p>Specifies the passphrase to be used with the identityFile specified for SSH where the private key requires a pass phrase.</p>
* <p>To avoid specifying a passphrase in your pom, you could instead specify a <code>server</code> in your
* maven settings file and then set the <code>serverId</code> property.</p>
*/
@Parameter(property = "passphrase")
private String passphrase;
*/
@Parameter(property = "passphrase")
private String passphrase;

/**
* Fetch tags from remote repository to determine the next build number. If
Expand All @@ -161,35 +163,52 @@ public abstract class BaseMojo extends AbstractMojo {
@Parameter(property = "arguments")
public String arguments;

/**
* <p>List of relative file system paths to ignore when detecting changes in the project(s).</p>
* <p>The primary purpose is to skip creating new releases if only "infrastructure" files such as
* <code>.gitignore</code>, <code>.editorconfig</code> and the like changed. Very basic wild cards are supported as
* follows:
* <ul>
* <li><code>foo.txt</code> - matches <code>foo.txt</code> in the root of the top-level project</li>
* <li><code>bar/foo.txt</code> - matches <code>foo.txt</code> in the root of the <code>bar</code> directory</li>
* <li><code>bar</code> - matches the <code>foo</code> directory and ignores everything below</li>
* <li><code>**.txt</code> - matches all paths ending in <code>.txt</code> (suffix match)</li>
* <li><code>**.editorconfig</code> - matches all <code>.editorconfig</code> files in all (sub)directories; a special case of suffix matching</li>
* <ul/>
* <p/>
*/
@Parameter(property = "ignoredPaths")
Set<String> ignoredPaths;

final void setSettings(final Settings settings) {
this.settings = settings;
}
this.settings = settings;
}

final Settings getSettings() {
return settings;
}

final void setServerId(final String serverId) {
this.serverId = serverId;
}
final void setServerId(final String serverId) {
this.serverId = serverId;
}

final void setKnownHosts(final String knownHosts) {
this.knownHosts = knownHosts;
}
final void setKnownHosts(final String knownHosts) {
this.knownHosts = knownHosts;
}

final void setPrivateKey(final String privateKey) {
this.privateKey = privateKey;
}
final void setPrivateKey(final String privateKey) {
this.privateKey = privateKey;
}

final void setPassphrase(final String passphrase) {
this.passphrase = passphrase;
}
final void setPassphrase(final String passphrase) {
this.passphrase = passphrase;
}

final void disableSshAgent() {
disableSshAgent = true;
}
final void disableSshAgent() {
disableSshAgent = true;
}

protected CredentialsProvider getCredentialsProvider(final Log log) throws ValidationException {
protected CredentialsProvider getCredentialsProvider(final Log log) throws ValidationException {
if (serverId != null) {
Server server = settings.getServer(serverId);
if (server == null) {
Expand All @@ -204,21 +223,21 @@ protected CredentialsProvider getCredentialsProvider(final Log log) throws Valid
return null;
}

protected final void configureJsch(final Log log) {
if (!disableSshAgent) {
if (serverId != null) {
final Server server = settings.getServer(serverId);
if (server != null) {
privateKey = privateKey == null ? server.getPrivateKey() : privateKey;
passphrase = passphrase == null ? server.getPassphrase() : passphrase;
} else {
log.warn(format("No server configuration in Maven settings found with id %s", serverId));
}
}

JschConfigSessionFactory.setInstance(new SshAgentSessionFactory(log, knownHosts, privateKey, passphrase));
}
}
protected final void configureJsch(final Log log) {
if (!disableSshAgent) {
if (serverId != null) {
final Server server = settings.getServer(serverId);
if (server != null) {
privateKey = privateKey == null ? server.getPrivateKey() : privateKey;
passphrase = passphrase == null ? server.getPassphrase() : passphrase;
} else {
log.warn(format("No server configuration in Maven settings found with id %s", serverId));
}
}

JschConfigSessionFactory.setInstance(new SshAgentSessionFactory(log, knownHosts, privateKey, passphrase));
}
}

static void printBigErrorMessageAndThrow(Log log, String terseMessage, List<String> linesToLog) throws MojoExecutionException {
log.error("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.credentialsProvider(getCredentialsProvider(log))
.buildFromCurrentDir();
ResolverWrapper resolverWrapper = new ResolverWrapper(factory, artifactResolver, remoteRepositories, localRepository);
Reactor reactor = Reactor.fromProjects(log, repo, project, projects, buildNumber, modulesToForceRelease, noChangesAction, resolverWrapper, versionNamer);
Reactor reactor = Reactor.fromProjects(log, repo, project, projects, buildNumber, modulesToForceRelease, noChangesAction, resolverWrapper, versionNamer, ignoredPaths);
if (reactor == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import static com.github.danielflower.mavenplugins.release.MavenVersionResolver.resolveVersionsDefinedThroughProperties;

Expand All @@ -28,8 +29,8 @@ public List<ReleasableModule> getModulesInBuildOrder() {
return modulesInBuildOrder;
}

public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject rootProject, List<MavenProject> projects, Long buildNumber, List<String> modulesToForceRelease, NoChangesAction actionWhenNoChangesDetected, ResolverWrapper resolverWrapper, VersionNamer versionNamer) throws ValidationException, GitAPIException, MojoExecutionException {
DiffDetector detector = new TreeWalkingDiffDetector(gitRepo.git.getRepository());
public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject rootProject, List<MavenProject> projects, Long buildNumber, List<String> modulesToForceRelease, NoChangesAction actionWhenNoChangesDetected, ResolverWrapper resolverWrapper, VersionNamer versionNamer, Set<String> ignoredPaths) throws ValidationException, GitAPIException, MojoExecutionException {
DiffDetector detector = new TreeWalkingDiffDetector(gitRepo.git.getRepository(), ignoredPaths);
List<ReleasableModule> modules = new ArrayList<ReleasableModule>();

resolveVersionsDefinedThroughProperties(projects);
Expand Down Expand Up @@ -121,7 +122,7 @@ public static Reactor fromProjects(Log log, LocalGitRepo gitRepo, MavenProject r
throw new MojoExecutionException("No module changes have been detected");
default:
log.warn("No changes have been detected in any modules so will re-release them all");
List<ReleasableModule> newList = new ArrayList<ReleasableModule>();
List<ReleasableModule> newList = new ArrayList<>();
for (ReleasableModule module : modules) {
newList.add(module.createReleasableVersion());
}
Expand Down
Loading