Search in sources :

Example 31 with MojoExecutionException

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

the class PdfMojo method generateMavenReport.

/**
     * Generate the given Maven report only if it is not an external report and the report could be generated.
     *
     * @param mojoDescriptor not null, to catch linkage error
     * @param report could be null
     * @param locale not null
     * @throws IOException if any
     * @throws MojoExecutionException if any
     * @see #isValidGeneratedReport(MojoDescriptor, File, String)
     * @since 1.1
     */
private void generateMavenReport(MavenReport report, Artifact pluginArtifact, Locale locale) throws IOException, MojoExecutionException {
    if (report == null) {
        return;
    }
    String localReportName = report.getName(locale);
    if (!report.canGenerateReport()) {
        getLog().info("Skipped \"" + localReportName + "\" report.");
        getLog().debug("canGenerateReport() was false.");
        return;
    }
    if (report.isExternalReport()) {
        getLog().info("Skipped external \"" + localReportName + "\" report.");
        getLog().debug("isExternalReport() was false.");
        return;
    }
    for (final MavenReport generatedReport : getGeneratedMavenReports(locale)) {
        if (report.getName(locale).equals(generatedReport.getName(locale))) {
            if (getLog().isDebugEnabled()) {
                getLog().debug(report.getName(locale) + " was already generated.");
            }
            return;
        }
    }
    File outDir = new File(getGeneratedSiteDirectoryTmp(), "xdoc");
    if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
        outDir = new File(new File(getGeneratedSiteDirectoryTmp(), locale.getLanguage()), "xdoc");
    }
    outDir.mkdirs();
    File generatedReport = new File(outDir, report.getOutputName() + ".xml");
    String excludes = getDefaultExcludesWithLocales(getAvailableLocales(), getDefaultLocale());
    List<String> files = FileUtils.getFileNames(siteDirectory, "*/" + report.getOutputName() + ".*", excludes, false);
    if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
        files = FileUtils.getFileNames(new File(siteDirectory, locale.getLanguage()), "*/" + report.getOutputName() + ".*", excludes, false);
    }
    if (files.size() != 0) {
        String displayLanguage = locale.getDisplayLanguage(Locale.ENGLISH);
        if (getLog().isInfoEnabled()) {
            getLog().info("Skipped \"" + report.getName(locale) + "\" report, file \"" + report.getOutputName() + "\" already exists for the " + displayLanguage + " version.");
        }
        return;
    }
    if (getLog().isInfoEnabled()) {
        getLog().info("Generating \"" + localReportName + "\" report.");
    }
    StringWriter sw = new StringWriter();
    PdfSink sink = null;
    try {
        sink = new PdfSink(sw);
        org.codehaus.doxia.sink.Sink proxy = (org.codehaus.doxia.sink.Sink) Proxy.newProxyInstance(org.codehaus.doxia.sink.Sink.class.getClassLoader(), new Class[] { org.codehaus.doxia.sink.Sink.class }, new SinkDelegate(sink));
        report.generate(proxy, locale);
    } catch (MavenReportException e) {
        throw new MojoExecutionException("MavenReportException: " + e.getMessage(), e);
    } finally {
        if (sink != null) {
            sink.close();
        }
    }
    writeGeneratedReport(sw.toString(), generatedReport);
    if (isValidGeneratedReport(pluginArtifact, generatedReport, localReportName)) {
        getGeneratedMavenReports(locale).add(report);
    }
}
Also used : MavenReport(org.apache.maven.reporting.MavenReport) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) StringWriter(java.io.StringWriter) Sink(org.apache.maven.doxia.sink.Sink) IndexingSink(org.apache.maven.doxia.index.IndexingSink) XdocSink(org.apache.maven.doxia.module.xdoc.XdocSink) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 32 with MojoExecutionException

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

the class PdfMojo method getMavenReport.

/**
     * @param mojoDescriptor not null
     * @return the MavenReport instance for the given mojoDescriptor.
     * @throws MojoExecutionException if any
     * @since 1.1
     */
private MavenReport getMavenReport(MojoDescriptor mojoDescriptor) throws MojoExecutionException {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader());
        MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
        return pluginManager.getReport(project, mojoExecution, session);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("ArtifactNotFoundException: " + e.getMessage(), e);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("ArtifactResolutionException: " + e.getMessage(), e);
    } catch (PluginConfigurationException e) {
        throw new MojoExecutionException("PluginConfigurationException: " + e.getMessage(), e);
    } catch (PluginManagerException e) {
        throw new MojoExecutionException("PluginManagerException: " + e.getMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoExecution(org.apache.maven.plugin.MojoExecution) PluginConfigurationException(org.apache.maven.plugin.PluginConfigurationException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) PluginManagerException(org.apache.maven.plugin.PluginManagerException)

Example 33 with MojoExecutionException

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

the class JavadocReportTest method testHeaderFooter.

/**
     * Test newline in the header/footer parameter
     *
     * @throws Exception if any
     */
public void testHeaderFooter() throws Exception {
    File testPom = new File(unit, "header-footer-test/header-footer-test-plugin-config.xml");
    JavadocReport mojo = lookupMojo(testPom);
    try {
        mojo.execute();
    } catch (MojoExecutionException e) {
        assertTrue("Doesnt handle correctly newline for header or footer parameter", false);
    }
    assertTrue(true);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File)

Example 34 with MojoExecutionException

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

the class JavadocReportTest method testValidateOptions.

/**
     * Method to test error or conflict in Javadoc options and in standard doclet options.
     *
     * @throws Exception if any
     */
public void testValidateOptions() throws Exception {
    // encoding
    File testPom = new File(unit, "validate-options-test/wrong-encoding-test-plugin-config.xml");
    JavadocReport mojo = lookupMojo(testPom);
    try {
        mojo.execute();
        assertTrue("No wrong encoding catch", false);
    } catch (MojoExecutionException e) {
        assertTrue("No wrong encoding catch", e.getMessage().contains("Unsupported option <encoding/>"));
    }
    testPom = new File(unit, "validate-options-test/wrong-docencoding-test-plugin-config.xml");
    mojo = lookupMojo(testPom);
    try {
        mojo.execute();
        assertTrue("No wrong docencoding catch", false);
    } catch (MojoExecutionException e) {
        assertTrue("No wrong docencoding catch", e.getMessage().contains("Unsupported option <docencoding/>"));
    }
    testPom = new File(unit, "validate-options-test/wrong-charset-test-plugin-config.xml");
    mojo = lookupMojo(testPom);
    try {
        mojo.execute();
        assertTrue("No wrong charset catch", false);
    } catch (MojoExecutionException e) {
        assertTrue("No wrong charset catch", e.getMessage().contains("Unsupported option <charset/>"));
    }
    // locale
    testPom = new File(unit, "validate-options-test/wrong-locale-test-plugin-config.xml");
    mojo = lookupMojo(testPom);
    try {
        mojo.execute();
        assertTrue("No wrong locale catch", false);
    } catch (MojoExecutionException e) {
        assertTrue("No wrong locale catch", e.getMessage().contains("Unsupported option <locale/>"));
    }
    testPom = new File(unit, "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml");
    mojo = lookupMojo(testPom);
    mojo.execute();
    assertTrue("No wrong locale catch", true);
    // conflict options
    testPom = new File(unit, "validate-options-test/conflict-options-test-plugin-config.xml");
    mojo = lookupMojo(testPom);
    try {
        mojo.execute();
        assertTrue("No conflict catch", false);
    } catch (MojoExecutionException e) {
        assertTrue("No conflict catch", e.getMessage().contains("Option <nohelp/> conflicts with <helpfile/>"));
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File)

Example 35 with MojoExecutionException

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

the class AbstractFixJavadocMojo method preCheck.

/**
     * @return <code>true</code> if the user wants to proceed, <code>false</code> otherwise.
     * @throws MojoExecutionException if any
     */
private boolean preCheck() throws MojoExecutionException {
    if (force) {
        return true;
    }
    if (outputDirectory != null && !outputDirectory.getAbsolutePath().equals(getProjectSourceDirectory().getAbsolutePath())) {
        return true;
    }
    if (!settings.isInteractiveMode()) {
        getLog().error("Maven is not attempt to interact with the user for input. " + "Verify the <interactiveMode/> configuration in your settings.");
        return false;
    }
    getLog().warn("");
    getLog().warn("    WARRANTY DISCLAIMER");
    getLog().warn("");
    getLog().warn("All warranties with regard to this Maven goal are disclaimed!");
    getLog().warn("The changes will be done directly in the source code.");
    getLog().warn("The Maven Team strongly recommends the use of a SCM software BEFORE executing this goal.");
    getLog().warn("");
    while (true) {
        getLog().info("Are you sure to proceed? [Y]es [N]o");
        try {
            String userExpression = inputHandler.readLine();
            if (userExpression == null || JavadocUtil.equalsIgnoreCase(userExpression, "Y", "Yes")) {
                getLog().info("OK, let's proceed...");
                break;
            }
            if (JavadocUtil.equalsIgnoreCase(userExpression, "N", "No")) {
                getLog().info("No changes in your sources occur.");
                return false;
            }
        } catch (IOException e) {
            throw new MojoExecutionException("Unable to read from standard input.", e);
        }
    }
    return true;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1221 IOException (java.io.IOException)656 File (java.io.File)572 MojoFailureException (org.apache.maven.plugin.MojoFailureException)275 Artifact (org.apache.maven.artifact.Artifact)162 ArrayList (java.util.ArrayList)151 FileInputStream (java.io.FileInputStream)77 MavenProject (org.apache.maven.project.MavenProject)76 HashMap (java.util.HashMap)68 Properties (java.util.Properties)63 FileOutputStream (java.io.FileOutputStream)61 Map (java.util.Map)60 URL (java.net.URL)59 MalformedURLException (java.net.MalformedURLException)57 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)52 FileWriter (java.io.FileWriter)50 List (java.util.List)49 URLClassLoader (java.net.URLClassLoader)45 LinkedHashSet (java.util.LinkedHashSet)40 InputStream (java.io.InputStream)38