Example usage for org.apache.maven.reporting MavenReportException MavenReportException

List of usage examples for org.apache.maven.reporting MavenReportException MavenReportException

Introduction

In this page you can find the example usage for org.apache.maven.reporting MavenReportException MavenReportException.

Prototype

public MavenReportException(String msg, Exception e) 

Source Link

Usage

From source file:br.com.anteros.restdoc.maven.plugin.AnterosRestDocMojo.java

License:Apache License

/**
 * Resolve dependency sources so they can be included directly in the
 * javadoc process. To customize this, override
 * {@link AbstractJavadocMojo#configureDependencySourceResolution(SourceResolverConfig)}.
 *///from  w  ww. j a v a 2 s . c  om
protected final List<String> getDependencySourcePaths() throws MavenReportException {
    try {
        if (sourceDependencyCacheDir.exists()) {
            FileUtils.forceDelete(sourceDependencyCacheDir);
            sourceDependencyCacheDir.mkdirs();
        }
    } catch (IOException e) {
        throw new MavenReportException(
                "Failed to delete cache directory: " + sourceDependencyCacheDir + "\nReason: " + e.getMessage(),
                e);
    }

    final SourceResolverConfig config = getDependencySourceResolverConfig();

    final AndArtifactFilter andFilter = new AndArtifactFilter();

    final List<String> dependencyIncludes = dependencySourceIncludes;
    final List<String> dependencyExcludes = dependencySourceExcludes;

    if (!includeTransitiveDependencySources || isNotEmpty(dependencyIncludes)
            || isNotEmpty(dependencyExcludes)) {
        if (!includeTransitiveDependencySources) {
            andFilter.add(createDependencyArtifactFilter());
        }

        if (isNotEmpty(dependencyIncludes)) {
            andFilter.add(new PatternIncludesArtifactFilter(dependencyIncludes, false));
        }

        if (isNotEmpty(dependencyExcludes)) {
            andFilter.add(new PatternExcludesArtifactFilter(dependencyExcludes, false));
        }

        config.withFilter(andFilter);
    }

    try {
        return ResourceResolver.resolveDependencySourcePaths(config);
    } catch (final ArtifactResolutionException e) {
        throw new MavenReportException(
                "Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
    } catch (final ArtifactNotFoundException e) {
        throw new MavenReportException(
                "Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
    }
}

From source file:com.adobe.ac.cpd.maven.FlexCpdMojo.java

License:Apache License

@Override
protected void executeReport(final Locale locale) throws MavenReportException {
    new LoggerUtils().loadConfiguration();

    final CPD cpd = new CPD(minimumTokenCount, new FlexLanguage());

    try {/* w ww.  j  ava  2s . c om*/
        final Map<String, IFlexFile> files = FileUtils.computeFilesList(sourceDirectory, null, "", null);

        for (final Entry<String, IFlexFile> fileEntry : files.entrySet()) {
            cpd.add(new File(fileEntry.getValue().getFilePath())); // NOPMD
        }

        cpd.go();

        report(cpd);
    } catch (final PMDException e) {
        throw new MavenReportException("", e);
    } catch (final IOException e) {
        throw new MavenReportException("", e);
    } catch (final ReportException e) {
        throw new MavenReportException("", e);
    }
}

From source file:com.adobe.ac.maven.ncss.NcssReportMojo.java

License:Apache License

/**
 * Load the xml file generated by javancss.
 * It first tries to load it as is.//from  w w w  . j ava  2s .co  m
 * If this fails it tries to load it with the forceEncoding parameter which defaults to the system property "file.encoding".
 * If this latter fails, it throws a MavenReportException.
 */
private Document loadDocument(final File file) throws MavenReportException {
    try {
        return loadDocument(file, null);
    } catch (DocumentException ignored) {
        if (forceEncoding == null) {
            forceEncoding = System.getProperty("file.encoding");
        }
        getLog().debug("Loading document without specifying encoding failed, trying with forceEncoding = ["
                + forceEncoding + "]");
        try {
            return loadDocument(file, forceEncoding);
        } catch (DocumentException de) {

            throw new MavenReportException(de.getMessage(), de);
        }
    }
}

From source file:com.adobe.ac.pmd.maven.AbstractFlexPmdMojo.java

License:Apache License

@Override
protected final void executeReport(final Locale locale) throws MavenReportException {
    new LoggerUtils().loadConfiguration();
    getLog().info("FlexPmdMojo starts");
    getLog().info("   failOnError     " + failOnError);
    getLog().info("   ruleSet         " + ruleSet);
    getLog().info("   sourceDirectory " + sourceDirectory);
    getLog().info("   ruleSetURL      " + url);
    try {/*from   w  w w .  j  a v  a2 s.  c  om*/
        final AbstractFlexPmdEngine engine = new FlexPmdXmlEngine(new FlexPmdParameters(excludePackage,
                failOnError, failOnRuleViolation, outputDirectory, getRuleSet(), sourceDirectory));
        final FlexPmdViolations violations = new FlexPmdViolations();
        engine.executeReport(violations);

        onXmlReportExecuted(violations, locale);
    } catch (final Exception e) {
        throw new MavenReportException("A system exception has been thrown", e);
    }
}

From source file:com.adobe.ac.pmd.maven.FlexPmdReportMojo.java

License:Apache License

@Override
protected void onXmlReportExecuted(final FlexPmdViolations violations, final Locale locale)
        throws MavenReportException {
    super.onXmlReportExecuted(violations, locale);

    final FlexPmdParameters parameters = new FlexPmdParameters(getExcludePackage(), getOutputDirectoryFile(),
            getRuleSet(), getSourceDirectory());
    final FlexPmdHtmlEngine flexPmdHtmlEngine = new FlexPmdHtmlEngine(getSink(), getBundle(locale), aggregate,
            getProject(), parameters);//from w w w.ja va  2  s.  co m

    try {
        flexPmdHtmlEngine.executeReport(violations);
    } catch (final PMDException e) {
        throw new MavenReportException("An exception has been thrown while executing the HTML report", e);
    }
}

From source file:com.adobe.ac.pmd.metrics.maven.FlexMetricsReportMojo.java

License:Apache License

/**
 * @see org.apache.maven.reporting.MavenReport#execute(java.util.Locale)
 *//*from w ww .  ja  v  a  2s  . com*/
@Override
public void executeReport(final Locale locale) throws MavenReportException {
    new LoggerUtils().loadConfiguration();
    if (sourceDirectory != null) {
        if (sourceDirectory.exists()) {
            try {
                generateSingleReport();
            } catch (final DocumentException e) {
                throw new MavenReportException(e.getMessage(), e);
            } catch (final IOException e) {
                throw new MavenReportException(e.getMessage(), e);
            }
        } else {
            getLog().error("The source directory is not found " + sourceDirectory.getAbsolutePath());
        }
    } else {
        generateAggregateReport(locale);
    }
}

From source file:com.adobe.ac.pmd.metrics.maven.FlexMetricsReportMojo.java

License:Apache License

/**
 * Load the xml file generated by javancss. It first tries to load it as is.
 * If this fails it tries to load it with the forceEncoding parameter which
 * defaults to the system property "file.encoding". If this latter fails, it
 * throws a MavenReportException./*from ww  w  .  j  a va2s . com*/
 */
private Document loadDocument(final File file) throws MavenReportException {
    try {
        return loadDocument(file, null);
    } catch (final DocumentException ignored) {
        try {
            return loadDocument(file, System.getProperty("file.encoding"));
        } catch (final DocumentException de) {
            throw new MavenReportException(de.getMessage(), de);
        }
    }
}

From source file:com.atlassian.maven.plugin.clover.CloverReportMojo.java

License:Apache License

/**
 * @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
 *///from   w w  w.  j a  v a  2 s .  c  om
public void executeReport(final Locale locale) throws MavenReportException {
    if (!canGenerateReport()) {
        getLog().info("No report being generated for this module.");
    }

    // only run the report once, on the very last project.
    final MavenProject lastProject = getReactorProjects().get(getReactorProjects().size() - 1);
    final MavenProject thisProject = getProject();
    if (isSingleCloverDatabase() && !thisProject.equals(lastProject)) {
        getLog().info("Skipping report generation until the final project in the reactor.");
        return;
    }

    // Register the Clover license
    try {
        AbstractCloverMojo.registerLicenseFile(this.project, this.resourceManager, this.licenseLocation,
                getLog(), this.getClass().getClassLoader(), this.license);
    } catch (MojoExecutionException e) {
        throw new MavenReportException("Failed to locate Clover license", e);
    }

    // Ensure the output directory exists
    this.outputDirectory.mkdirs();

    if (reportDescriptor == null) {
        reportDescriptor = resolveCloverDescriptor();
    } else if (!reportDescriptor.exists()) { // try finding this as a resource
        try {
            reportDescriptor = AbstractCloverMojo.getResourceAsFile(project, resourceManager,
                    reportDescriptor.getPath(), getLog(), this.getClass().getClassLoader());
        } catch (MojoExecutionException e) {
            throw new MavenReportException("Could not resolve report descriptor: " + reportDescriptor.getPath(),
                    e);
        }
    }

    getLog().info("Using Clover report descriptor: " + reportDescriptor.getAbsolutePath());

    if (title != null && title.startsWith("Unnamed")) { // no project.name on the project
        title = project.getArtifactId() + " " + project.getVersion();
    }

    File singleModuleCloverDatabase = new File(resolveCloverDatabase());
    if (singleModuleCloverDatabase.exists()) {
        createAllReportTypes(resolveCloverDatabase(), title);
    }

    File mergedCloverDatabase = new File(this.cloverMergeDatabase);
    if (mergedCloverDatabase.exists()) {
        createAllReportTypes(this.cloverMergeDatabase, title + " (Aggregated)");
    }
}

From source file:com.atlassian.maven.plugin.clover.CloverReportMojo.java

License:Apache License

/**
 * The logic here is taken from AbstractSiteRenderingMojo#resolveSiteDescriptor in the maven-site-plugin.
 * See also: http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook
 *
 * @return the clover report configuration file to use
 * @throws MavenReportException if at least the default file can't be resolved
 *//*  w ww .j a v  a 2  s  . c  o  m*/
protected File resolveCloverDescriptor() throws MavenReportException {

    if (resolveReportDescriptor) {
        getLog().info("Attempting to resolve the clover-report configuration as an xml artifact.");
        Artifact artifact = artifactFactory.createArtifactWithClassifier(project.getGroupId(),
                project.getArtifactId(), project.getVersion(), "xml", "clover-report");

        try {
            artifactResolver.resolve(artifact, repositories, localRepository);
            return artifact.getFile();
        } catch (ArtifactResolutionException e) {
            getLog().warn(e.getMessage(), e);
        } catch (ArtifactNotFoundException e) {
            getLog().warn(e.getMessage(), e);
        }
    }
    try {
        getLog().info("Using /default-clover-report descriptor.");
        final File file = AbstractCloverMojo.getResourceAsFile(project, resourceManager,
                "/default-clover-report.xml", getLog(), this.getClass().getClassLoader());
        file.deleteOnExit();
        return file;

    } catch (Exception e) {
        throw new MavenReportException("Could not resolve default-clover-report.xml. "
                + "Please try specifying this via the maven.clover.reportDescriptor property.", e);
    }
}

From source file:com.github.jrh3k5.plugin.maven.l10n.mojo.report.TranslationKeyVerifier.java

License:Apache License

@Override
protected void executeReport(Locale locale) throws MavenReportException {
    ClassLoader classLoader;/*w w w. j a  v  a 2  s .  c om*/
    try {
        classLoader = ClassLoaderUtils.getClassLoader(getProject());
    } catch (IOException e) {
        throw new MavenReportException("Failed to load project classloader.", e);
    }

    AuthoritativeMessagesProperties authoritativeProperties;
    Collection<TranslatedMessagesProperties> translatedProperties;
    try {
        authoritativeProperties = new AuthoritativeMessagesProperties.Parser().parse(messagesFile);
    } catch (IOException e) {
        throw new MavenReportException(
                String.format("Failed to parse authoritative messages file: %s", messagesFile), e);
    }

    try {
        final List<File> translationFiles = FileUtils.getFiles(getProject().getBasedir(),
                translatedMessagesPattern, null);
        // Don't consider the authoritative resource, if found, to be a "translation"
        translationFiles.remove(messagesFile);
        translatedProperties = new TranslatedMessagesProperties.Parser().parse(authoritativeProperties,
                translationFiles);
    } catch (IOException e) {
        throw new MavenReportException(String.format(
                "Failed to parse translated messages files for pattern: %s", translatedMessagesPattern), e);
    }

    ClassinessAnalysisResults analysisResults;
    try {
        analysisResults = TranslationKeyAnalysisUtils.getInstance(getLog()).analyzeClassiness(classLoader,
                authoritativeProperties);
    } catch (IOException e) {
        throw new MavenReportException(String.format("Failed to verify %s", messagesFile), e);
    }

    Collection<String> translationClassKeys;
    try {
        translationClassKeys = TranslationClassUtils.getTranslationKeys(keyClasses, classLoader);
    } catch (ClassNotFoundException e) {
        throw new MavenReportException("Failed to translate key classes: " + keyClasses, e);
    }
    translationClassKeys.removeAll(authoritativeProperties.getTranslationKeys());

    new ReportRenderer(this, locale, getSink(), authoritativeProperties, analysisResults, translatedProperties,
            translationClassKeys).render();
}