use of org.apache.maven.plugin.MojoExecutionException in project jslint4java by happygiraffe.
the class JSLintMojo method lintFile.
private JSLintResult lintFile(JSLint jsLint, File file) throws MojoExecutionException {
getLog().debug("lint " + file);
BufferedReader reader = null;
try {
UnicodeBomInputStream stream = new UnicodeBomInputStream(new FileInputStream(file));
stream.skipBOM();
reader = new BufferedReader(new InputStreamReader(stream, getEncoding()));
return jsLint.lint(file.toString(), reader);
} catch (FileNotFoundException e) {
throw new MojoExecutionException("file not found: " + file, e);
} catch (UnsupportedEncodingException e) {
// Can never happen.
throw new MojoExecutionException("unsupported character encoding UTF-8", e);
} catch (IOException e) {
throw new MojoExecutionException("problem whilst linting " + file, e);
} finally {
Closeables.closeQuietly(reader);
}
}
use of org.apache.maven.plugin.MojoExecutionException in project grails-maven by grails.
the class MvnPluginValidateMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
try {
getGrailsServices().readProjectDescriptor();
} catch (final MojoExecutionException e) {
getLog().info("No Grails project found - skipping validation.");
return;
}
final GrailsPluginProject grailsProject = getGrailsServices().readGrailsPluginProject();
final String pluginName = grailsProject.getPluginName();
if (!artifactId.equals(pluginName) && !artifactId.equals(PLUGIN_PREFIX + pluginName)) {
throw new MojoFailureException("The plugin name in the pom.xml [" + artifactId + "]" + " is not the expected '" + pluginName + "' or '" + PLUGIN_PREFIX + pluginName + "'. " + "Please correct the pom.xml or the plugin " + "descriptor.");
}
final String pomVersion = version.trim();
final String grailsVersion = grailsProject.getVersion();
if (!grailsVersion.equals(pomVersion)) {
throw new MojoFailureException("The version specified in the plugin descriptor " + "[" + grailsVersion + "] is different from the version in the pom.xml [" + pomVersion + "] ");
}
}
use of org.apache.maven.plugin.MojoExecutionException in project grails-maven by grails.
the class AbstractGrailsMojo method runGrails.
/**
* Executes the requested Grails target. The "targetName" must match a known
* Grails script provided by grails-scripts.
*
* @param targetName The name of the Grails target to execute.
* @param args String of arguments to be passed to the executed Grails target.
* @throws MojoExecutionException if an error occurs while attempting to execute the target.
*/
protected void runGrails(final String targetName, String args) throws MojoExecutionException {
configureMavenProxy();
handleVersionSync();
if (fork) {
ForkedGrailsRuntime fgr = new ForkedGrailsRuntime(createExecutionContext(targetName, args));
if (activateAgent) {
File springLoadedJar = resolveArtifact("org.springframework:springloaded:" + SPRING_LOADED_VERSION);
if (springLoadedJar != null) {
fgr.setReloadingAgent(springLoadedJar);
} else {
getLog().warn("Grails Reloading: org.springframework:springloaded:" + SPRING_LOADED_VERSION + " not found");
getLog().error("Grails Reloading: not enabled");
}
}
fgr.setDebug(forkDebug);
fgr.setMaxMemory(forkMaxMemory);
fgr.setMaxPerm(forkPermGen);
fgr.setMinMemory(forkMinMemory);
try {
fgr.run();
} catch (Exception e) {
throw new RuntimeException("Error forking vm: ", e);
}
} else {
DefaultGrailsRuntime dgr = new DefaultGrailsRuntime(createExecutionContext(targetName, args));
dgr.run();
}
}
use of org.apache.maven.plugin.MojoExecutionException in project grails-maven by grails.
the class AbstractGrailsMojo method resolveArtifact.
protected File resolveArtifact(String artifactId) throws MojoExecutionException {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(new DefaultArtifact(artifactId));
request.setRepositories(remoteRepos);
getLog().debug("Resolving artifact " + artifactId + " from " + remoteRepos);
ArtifactResult result;
File file;
try {
result = repoSystem.resolveArtifact(repoSession, request);
file = result.getArtifact().getFile();
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
getLog().debug("Resolved artifact " + artifactId + " to " + file + " from " + result.getRepository());
return file;
}
use of org.apache.maven.plugin.MojoExecutionException in project grails-maven by grails.
the class AbstractGrailsMojo method handleVersionSync.
private void handleVersionSync() throws MojoExecutionException {
// Search for all Grails plugin dependencies and install
// any that haven't already been installed.
final Properties metadata = new Properties();
File metadataFile = new File(getBasedir(), "application.properties");
FileReader reader = null;
FileWriter writer = null;
try {
boolean created = true;
if (!metadataFile.exists()) {
created = metadataFile.createNewFile();
}
if (created) {
reader = new FileReader(metadataFile);
metadata.load(reader);
boolean metadataModified = syncVersions(metadata);
if (metadataModified) {
writer = new FileWriter(metadataFile);
metadata.store(writer, "Grails Metadata file");
}
}
} catch (IOException e) {
throw new MojoExecutionException("Failed to sync application version with Maven plugin defined version");
} finally {
try {
if (reader != null)
reader.close();
if (writer != null)
writer.close();
} catch (IOException e) {
// ignore
}
}
}
Aggregations