Search in sources :

Example 51 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class AbstractCheckDocumentationMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    setupProxy();
    if (output != null) {
        getLog().info("Writing documentation check results to: " + output);
    }
    Map<MavenProject, DocumentationReporter> reporters = new LinkedHashMap<MavenProject, DocumentationReporter>();
    boolean hasErrors = false;
    for (MavenProject project : reactorProjects) {
        if (approveProjectPackaging(project.getPackaging())) {
            getLog().info("Checking project: " + project.getName());
            DocumentationReporter reporter = new DocumentationReporter();
            checkProject(project, reporter);
            if (!hasErrors && reporter.hasErrors()) {
                hasErrors = true;
            }
            reporters.put(project, reporter);
        } else {
            getLog().info("Skipping unsupported project: " + project.getName());
        }
    }
    String messages;
    messages = buildErrorMessages(reporters);
    if (!hasErrors) {
        messages += "No documentation errors were found.";
    }
    try {
        writeMessages(messages, hasErrors);
    } catch (IOException e) {
        throw new MojoExecutionException("Error writing results to output file: " + output);
    }
    if (hasErrors) {
        String logLocation;
        if (output == null) {
            logLocation = "Please see the console output above for more information.";
        } else {
            logLocation = "Please see \'" + output + "\' for more information.";
        }
        throw new MojoFailureException("Documentation problems were found. " + logLocation);
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DocumentationReporter(org.apache.maven.plugin.docck.reports.DocumentationReporter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 52 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class AbstractEarModule method resolveArtifact.

/** {@inheritDoc} */
public void resolveArtifact(Set<Artifact> artifacts) throws EarPluginException, MojoFailureException {
    // If the artifact is already set no need to resolve it
    if (artifact == null) {
        // Make sure that at least the groupId and the artifactId are specified
        if (groupId == null || artifactId == null) {
            throw new MojoFailureException("Could not resolve artifact[" + groupId + ":" + artifactId + ":" + getType() + "]");
        }
        final ArtifactRepository ar = earExecutionContext.getArtifactRepository();
        artifact = ar.getUniqueArtifact(groupId, artifactId, getType(), classifier);
        // Artifact has not been found
        if (artifact == null) {
            Set<Artifact> candidates = ar.getArtifacts(groupId, artifactId, getType());
            if (candidates.size() > 1) {
                throw new MojoFailureException("Artifact[" + this + "] has " + candidates.size() + " candidates, please provide a classifier.");
            } else {
                throw new MojoFailureException("Artifact[" + this + "] is not a dependency of the project.");
            }
        }
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactRepository(org.apache.maven.plugins.ear.util.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact)

Example 53 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class ApplyMojo method findPatchesToApply.

private Map findPatchesToApply(List foundPatchFiles, File patchSourceDir) throws MojoFailureException {
    Map patchesApplied = new LinkedHashMap();
    if (naturalOrderProcessing) {
        patches = new ArrayList(foundPatchFiles);
        Collections.sort(patches);
    }
    String alreadyAppliedPatches = "";
    try {
        if (optimizations && patchTrackingFile.exists()) {
            alreadyAppliedPatches = FileUtils.fileRead(patchTrackingFile);
        }
    } catch (IOException ioe) {
        throw new MojoFailureException("unable to read patch tracking file: " + ioe.getMessage());
    }
    for (Object patche : patches) {
        String patch = (String) patche;
        if (!alreadyAppliedPatches.contains(patch)) {
            File patchFile = new File(patchSourceDir, patch);
            getLog().debug("Looking for patch: " + patch + " in: " + patchFile);
            if (!patchFile.exists()) {
                if (strictPatching) {
                    throw new MojoFailureException(this, "Patch operation cannot proceed.", "Cannot find specified patch: \'" + patch + "\' in patch-source directory: \'" + patchSourceDir + "\'.\n\nEither fix this error, " + "or relax strictPatching.");
                } else {
                    getLog().info("Skipping patch: " + patch + " listed in the parameter \"patches\"; " + "it is missing.");
                }
            } else {
                foundPatchFiles.remove(patch);
                patchesApplied.put(patch, createPatchCommand(patchFile));
            }
        }
    }
    return patchesApplied;
}
Also used : ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

Example 54 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class JModCreateMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    failIfParametersAreNotInTheirValidValueRanges();
    String jModExecutable;
    try {
        jModExecutable = getJModExecutable();
    } catch (IOException e) {
        throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e);
    }
    getLog().info("Toolchain in maven-jmod-plugin: jmod [ " + jModExecutable + " ]");
    // We need to put the resulting x.jmod files into jmods folder.
    // Check why?
    File modsFolder = new File(outputDirectory, "jmods");
    File resultingJModFile = new File(modsFolder, moduleName + ".jmod");
    deleteOutputIfAlreadyExists(resultingJModFile);
    // create the jmods folder...
    modsFolder.mkdirs();
    Commandline cmd = createJModCreateCommandLine(resultingJModFile);
    cmd.setExecutable(jModExecutable);
    executeCommand(cmd, outputDirectory);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) File(java.io.File)

Example 55 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException in project maven-plugins by apache.

the class JModHashMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    String jModExecutable;
    try {
        jModExecutable = getJModExecutable();
    } catch (IOException e) {
        throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e);
    }
    Commandline cmd = createJModHashCommandLine();
    cmd.setExecutable(jModExecutable);
// executeCommand( cmd, outputDirectory );
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException)

Aggregations

MojoFailureException (org.apache.maven.plugin.MojoFailureException)157 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)94 File (java.io.File)93 IOException (java.io.IOException)91 ArrayList (java.util.ArrayList)50 TreeSet (java.util.TreeSet)33 FileInputStream (java.io.FileInputStream)32 FileOutputStream (java.io.FileOutputStream)21 List (java.util.List)21 Map (java.util.Map)21 MavenProject (org.apache.maven.project.MavenProject)18 Set (java.util.Set)15 MalformedURLException (java.net.MalformedURLException)14 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)13 InputStream (java.io.InputStream)12 URLClassLoader (java.net.URLClassLoader)12 Matcher (java.util.regex.Matcher)12 Artifact (org.apache.maven.artifact.Artifact)12 AbstractMojo (org.apache.maven.plugin.AbstractMojo)12