Search in sources :

Example 81 with MojoExecutionException

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) UnicodeBomInputStream(com.googlecode.jslint4java.UnicodeBomInputStream) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 82 with MojoExecutionException

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 + "] ");
    }
}
Also used : GrailsPluginProject(org.grails.maven.plugin.tools.GrailsPluginProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 83 with MojoExecutionException

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();
    }
}
Also used : DefaultGrailsRuntime(org.grails.maven.plugin.tools.DefaultGrailsRuntime) File(java.io.File) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ForkedGrailsRuntime(org.grails.maven.plugin.tools.ForkedGrailsRuntime)

Example 84 with MojoExecutionException

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;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 85 with MojoExecutionException

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
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)586 IOException (java.io.IOException)322 File (java.io.File)261 MojoFailureException (org.apache.maven.plugin.MojoFailureException)138 Artifact (org.apache.maven.artifact.Artifact)86 ArrayList (java.util.ArrayList)70 FileInputStream (java.io.FileInputStream)56 HashMap (java.util.HashMap)47 MavenProject (org.apache.maven.project.MavenProject)37 MalformedURLException (java.net.MalformedURLException)34 Map (java.util.Map)34 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)32 Properties (java.util.Properties)30 FileOutputStream (java.io.FileOutputStream)28 FileWriter (java.io.FileWriter)28 List (java.util.List)25 URL (java.net.URL)22 InputStream (java.io.InputStream)21 LinkedHashSet (java.util.LinkedHashSet)21 FileNotFoundException (java.io.FileNotFoundException)20