All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.danielflower.mavenplugins.release.BaseMojo Maven / Gradle / Ivy

Go to download

A maven release plugin built for multi-maven-module git repositories allowing continuous deployment

There is a newer version: 3.6.4
Show newest version
package com.github.danielflower.mavenplugins.release;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.eclipse.jgit.transport.JschConfigSessionFactory;

import java.util.List;

import static java.lang.String.format;

/**
 * @author Roland Hauser [email protected]
 *
 */
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 projects;

	/**
	 * 

* 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". *

*

* By default, the plugin will automatically find a suitable build number. * It will start at version 0 and increment this with each release. *

*

* This can be specified using a command line parameter ("-DbuildNumber=2") * or in this plugin's configuration. *

*/ @Parameter(property = "buildNumber") protected Long buildNumber; /** * 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 modulesToRelease; /** * A module to force release on, even if no changes has been detected. */ @Parameter(alias = "forceRelease", property = "forceRelease") protected List modulesToForceRelease; @Parameter(property = "disableSshAgent") private boolean disableSshAgent; @Parameter(defaultValue = "${settings}", readonly = true, required = true) private Settings settings; /** * If set, the identityFile and passphrase will be read from the Maven * settings file. */ @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. */ @Parameter(property = "privateKey") private String privateKey; /** * Specifies the passphrase to be used with the identityFile specified. */ @Parameter(property = "passphrase") private String passphrase; final void setSettings(final Settings settings) { this.settings = settings; } final void setServerId(final String serverId) { this.serverId = serverId; } final void setKnownHosts(final String knownHosts) { this.knownHosts = knownHosts; } final void setPrivateKey(final String privateKey) { this.privateKey = privateKey; } final void setPassphrase(final String passphrase) { this.passphrase = passphrase; } final void disableSshAgent() { disableSshAgent = true; } 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 linesToLog) throws MojoExecutionException { log.error(""); log.error(""); log.error(""); log.error("************************************"); log.error("Could not execute the release plugin"); log.error("************************************"); log.error(""); log.error(""); for (String line : linesToLog) { log.error(line); } log.error(""); log.error(""); throw new MojoExecutionException(terseMessage); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy