Skip to content
Permalink
Browse files
disabling plugin if not configured properly
  • Loading branch information
chtompki committed Feb 27, 2018
1 parent c176e46 commit 931dc52788e8ae5db850068c64a2f3acfb0b2b03
Showing 4 changed files with 43 additions and 13 deletions.
@@ -25,7 +25,7 @@
</parent>
<artifactId>commons-release-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.1-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
<name>Apache Commons Release Plugin</name>

<description>
@@ -82,23 +82,32 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
/**
* The working directory in <code>target</code> that we use as a sandbox for the plugin.
*/
@Parameter(defaultValue = "${project.build.directory}/commons-release-plugin", alias = "outputDirectory")
@Parameter(defaultValue = "${project.build.directory}/commons-release-plugin",
property = "commons.outputDirectory")
private File workingDirectory;

/**
* The subversion staging url to which we upload all of our staged artifacts.
*/
@Parameter(required = true)
@Parameter(defaultValue = "", property = "commons.distSvnStagingUrl")
private String distSvnStagingUrl;

@Override
public void execute() throws MojoExecutionException {
if ("".equals(distSvnStagingUrl)) {
getLog().warn("commons.distSvnStagingUrl is not set, the commons-release-plugin will not run");
return;
}
getLog().info("Detaching Assemblies");
for (Object attachedArtifact : project.getAttachedArtifacts()) {
if (ARTIFACT_TYPES_TO_DETACH.contains(((Artifact) attachedArtifact).getType())) {
detachedArtifacts.add((Artifact) attachedArtifact);
}
}
if (detachedArtifacts.isEmpty()) {
getLog().info("Current project contains no distributions. Not executing.");
return;
}
for (Artifact artifactToRemove : detachedArtifacts) {
project.getAttachedArtifacts().remove(artifactToRemove);
}
@@ -73,20 +73,21 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
* The main working directory for the plugin, namely <code>target/commons-release-plugin</code>, but
* that assumes that we're using the default maven <code>${project.build.directory}</code>.
*/
@Parameter(defaultValue = "${project.build.directory}/commons-release-plugin", alias = "outputDirectory")
@Parameter(defaultValue = "${project.build.directory}/commons-release-plugin", property = "commons.outputDirectory")
private File workingDirectory;

/**
* The location to which to checkout the dist subversion repository under our working directory, which
* was given above.
*/
@Parameter(defaultValue = "${project.build.directory}/commons-release-plugin/scm", alias = "distCheckoutDirectory")
@Parameter(defaultValue = "${project.build.directory}/commons-release-plugin/scm",
property = "commons.distCheckoutDirectory")
private File distCheckoutDirectory;

/**
* The location of the RELEASE-NOTES.txt file such that multimodule builds can configure it.
*/
@Parameter(defaultValue = "${basedir}/RELEASE-NOTES.txt", alias = "releaseNotesLocation")
@Parameter(defaultValue = "${basedir}/RELEASE-NOTES.txt", property = "commons.releaseNotesLocation")
private File releaseNotesFile;

/**
@@ -103,7 +104,7 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
* <code>scm:svn:https://dist.apache.org/repos/dist/dev/commons/foo</code>. Note. that the prefix to the
* substring <code>https</code> is a requirement.
*/
@Parameter(required = true)
@Parameter(defaultValue = "", property = "commons.distSvnStagingUrl")
private String distSvnStagingUrl;

/**
@@ -120,6 +121,14 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if ("".equals(distSvnStagingUrl)) {
getLog().warn("commons.distSvnStagingUrl is not set, the commons-release-plugin will not run");
return;
}
if (!workingDirectory.exists()) {
getLog().info("Current project contains no distributions. Not executing.");
return;
}
getLog().info("Preparing to stage distributions");
try {
ScmManager scmManager = new BasicScmManager();
@@ -129,9 +138,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {
SvnScmProviderRepository providerRepository = (SvnScmProviderRepository) repository.getProviderRepository();
providerRepository.setUser(username);
providerRepository.setPassword(password);
if (!workingDirectory.exists()) {
SharedFunctions.initDirectory(getLog(), workingDirectory);
}
if (!distCheckoutDirectory.exists()) {
SharedFunctions.initDirectory(getLog(), distCheckoutDirectory);
}
@@ -52,14 +52,24 @@ public class CommonsSiteCompressionMojo extends AbstractMojo {
* The working directory for the plugin which, assuming the maven uses the default
* <code>${project.build.directory}</code>, this becomes <code>target/commons-release-plugin</code>.
*/
@Parameter(defaultValue = "${project.build.directory}/commons-release-plugin", alias = "outputDirectory")
@Parameter(defaultValue = "${project.build.directory}/commons-release-plugin",
property = "commons.outputDirectory")
private File workingDirectory;

/**
*/
@Parameter(defaultValue = "${project.build.directory}/site", alias = "siteOutputDirectory")
@Parameter(defaultValue = "${project.build.directory}/site", property = "commons.siteOutputDirectory")
private File siteDirectory;

/**
* The url of the subversion repository to which we wish the artifacts to be staged. Typicallly
* this would need to be of the form:
* <code>scm:svn:https://dist.apache.org/repos/dist/dev/commons/foo</code>. Note. that the prefix to the
* substring <code>https</code> is a requirement.
*/
@Parameter(defaultValue = "", property = "commons.distSvnStagingUrl")
private String distSvnStagingUrl;

/**
* A variable for the process of creating the site.zip file.
*/
@@ -77,14 +87,19 @@ public class CommonsSiteCompressionMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if ("".equals(distSvnStagingUrl)) {
getLog().warn("commons.distSvnStagingUrl is not set, the commons-release-plugin will not run");
return;
}
if (!siteDirectory.exists()) {
getLog().error("\"mvn site\" was not run before this goal, or a siteDirectory did not exist.");
throw new MojoFailureException(
"\"mvn site\" was not run before this goal, or a siteDirectory did not exist."
);
}
if (!workingDirectory.exists()) {
SharedFunctions.initDirectory(getLog(), workingDirectory);
getLog().info("Current project contains no distributions. Not executing.");
return;
}
try {
filesToCompress = new ArrayList<>();

0 comments on commit 931dc52

Please sign in to comment.