Skip to content

Commit

Permalink
Allow build to fail if installation is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jdillon committed Mar 26, 2013
1 parent 6b4b32b commit 0f41e9c
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.sonatype.install4j.maven;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
Expand All @@ -37,6 +38,12 @@ public abstract class Install4jcMojoSupport
@Parameter(property = "install4j.skip", defaultValue = "false")
protected boolean skip;

/**
* Fail if the installation is missing.
*/
@Parameter(property = "install4j.failIfMissing", defaultValue = "false")
protected boolean failIfMissing;

/**
* The location of the install4j installation.
*/
Expand All @@ -56,7 +63,7 @@ protected void doExecute() throws Exception {
AntHelper ant = new AntHelper(this, project);

if (!installDir.exists()) {
log.warn("Invalid install directory; skipping: " + installDir);
maybeFailIfMissing("Invalid install directory; skipping: " + installDir);
return;
}

Expand All @@ -66,7 +73,7 @@ protected void doExecute() throws Exception {
File install4jc = new File(installDir, "bin/install4jc" + (windows ? ".exe" : ""));

if (!install4jc.exists()) {
log.warn("Missing install4j compiler executable: " + install4jc);
maybeFailIfMissing("Missing install4j compiler executable: " + install4jc);
return;
}

Expand All @@ -87,4 +94,14 @@ protected void doExecute() throws Exception {
}

protected abstract void execute(final AntHelper ant, final ExecTask task) throws Exception;

private void maybeFailIfMissing(final String message) throws MojoExecutionException {
if (failIfMissing) {
log.error(message);
throw new MojoExecutionException(message);
}
else {
log.warn(message);
}
}
}

0 comments on commit 0f41e9c

Please sign in to comment.