Search in sources :

Example 1 with ProjectDependencyAnalysis

use of org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis in project maven-dependency-plugin by apache.

the class AbstractAnalyzeMojo method checkDependencies.

// private methods --------------------------------------------------------
private boolean checkDependencies() throws MojoExecutionException {
    ProjectDependencyAnalysis analysis;
    try {
        analysis = createProjectDependencyAnalyzer().analyze(project);
        if (usedDependencies != null) {
            analysis = analysis.forceDeclaredDependenciesUsage(usedDependencies);
        }
    } catch (ProjectDependencyAnalyzerException exception) {
        throw new MojoExecutionException("Cannot analyze dependencies", exception);
    }
    if (ignoreNonCompile) {
        analysis = analysis.ignoreNonCompile();
    }
    Set<Artifact> usedDeclared = new LinkedHashSet<Artifact>(analysis.getUsedDeclaredArtifacts());
    Set<Artifact> usedUndeclared = new LinkedHashSet<Artifact>(analysis.getUsedUndeclaredArtifacts());
    Set<Artifact> unusedDeclared = new LinkedHashSet<Artifact>(analysis.getUnusedDeclaredArtifacts());
    Set<Artifact> ignoredUsedUndeclared = new LinkedHashSet<Artifact>();
    Set<Artifact> ignoredUnusedDeclared = new LinkedHashSet<Artifact>();
    ignoredUsedUndeclared.addAll(filterDependencies(usedUndeclared, ignoredDependencies));
    ignoredUsedUndeclared.addAll(filterDependencies(usedUndeclared, ignoredUsedUndeclaredDependencies));
    ignoredUnusedDeclared.addAll(filterDependencies(unusedDeclared, ignoredDependencies));
    ignoredUnusedDeclared.addAll(filterDependencies(unusedDeclared, ignoredUnusedDeclaredDependencies));
    boolean reported = false;
    boolean warning = false;
    if (verbose && !usedDeclared.isEmpty()) {
        getLog().info("Used declared dependencies found:");
        logArtifacts(analysis.getUsedDeclaredArtifacts(), false);
        reported = true;
    }
    if (!usedUndeclared.isEmpty()) {
        getLog().warn("Used undeclared dependencies found:");
        logArtifacts(usedUndeclared, true);
        reported = true;
        warning = true;
    }
    if (!unusedDeclared.isEmpty()) {
        getLog().warn("Unused declared dependencies found:");
        logArtifacts(unusedDeclared, true);
        reported = true;
        warning = true;
    }
    if (verbose && !ignoredUsedUndeclared.isEmpty()) {
        getLog().info("Ignored used undeclared dependencies:");
        logArtifacts(ignoredUsedUndeclared, false);
        reported = true;
    }
    if (verbose && !ignoredUnusedDeclared.isEmpty()) {
        getLog().info("Ignored unused declared dependencies:");
        logArtifacts(ignoredUnusedDeclared, false);
        reported = true;
    }
    if (outputXML) {
        writeDependencyXML(usedUndeclared);
    }
    if (scriptableOutput) {
        writeScriptableOutput(usedUndeclared);
    }
    if (!reported) {
        getLog().info("No dependency problems found");
    }
    return warning;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProjectDependencyAnalysis(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis) ProjectDependencyAnalyzerException(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with ProjectDependencyAnalysis

use of org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis in project maven-dependency-plugin by apache.

the class AnalyzeReportMojo method executeReport.

// Mojo methods -----------------------------------------------------------
/*
     * @see org.apache.maven.plugin.Mojo#execute()
     */
@Override
public void executeReport(Locale locale) throws MavenReportException {
    if (skip) {
        getLog().info("Skipping plugin execution");
        return;
    }
    // Step 0: Checking pom availability
    if ("pom".equals(project.getPackaging())) {
        getLog().info("Skipping pom project");
        return;
    }
    if (outputDirectory == null || !outputDirectory.exists()) {
        getLog().info("Skipping project with no Target directory");
        return;
    }
    // Step 1: Analyze the project
    ProjectDependencyAnalysis analysis;
    try {
        analysis = analyzer.analyze(project);
        if (usedDependencies != null) {
            analysis = analysis.forceDeclaredDependenciesUsage(usedDependencies);
        }
    } catch (ProjectDependencyAnalyzerException exception) {
        throw new MavenReportException("Cannot analyze dependencies", exception);
    }
    // remove everything that's not in the compile scope
    if (ignoreNonCompile) {
        analysis = analysis.ignoreNonCompile();
    }
    // Step 2: Create sink and bundle
    Sink sink = getSink();
    ResourceBundle bundle = getBundle(locale);
    // Step 3: Generate the report
    AnalyzeReportView analyzethis = new AnalyzeReportView();
    analyzethis.generateReport(analysis, sink, bundle);
}
Also used : ProjectDependencyAnalysis(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis) ProjectDependencyAnalyzerException(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException) Sink(org.apache.maven.doxia.sink.Sink) ResourceBundle(java.util.ResourceBundle) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 3 with ProjectDependencyAnalysis

use of org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis in project maven-plugins by apache.

the class AbstractAnalyzeMojo method checkDependencies.

// private methods --------------------------------------------------------
private boolean checkDependencies() throws MojoExecutionException {
    ProjectDependencyAnalysis analysis;
    try {
        analysis = createProjectDependencyAnalyzer().analyze(project);
        if (usedDependencies != null) {
            analysis = analysis.forceDeclaredDependenciesUsage(usedDependencies);
        }
    } catch (ProjectDependencyAnalyzerException exception) {
        throw new MojoExecutionException("Cannot analyze dependencies", exception);
    }
    if (ignoreNonCompile) {
        analysis = analysis.ignoreNonCompile();
    }
    Set<Artifact> usedDeclared = new LinkedHashSet<Artifact>(analysis.getUsedDeclaredArtifacts());
    Set<Artifact> usedUndeclared = new LinkedHashSet<Artifact>(analysis.getUsedUndeclaredArtifacts());
    Set<Artifact> unusedDeclared = new LinkedHashSet<Artifact>(analysis.getUnusedDeclaredArtifacts());
    Set<Artifact> ignoredUsedUndeclared = new LinkedHashSet<Artifact>();
    Set<Artifact> ignoredUnusedDeclared = new LinkedHashSet<Artifact>();
    ignoredUsedUndeclared.addAll(filterDependencies(usedUndeclared, ignoredDependencies));
    ignoredUsedUndeclared.addAll(filterDependencies(usedUndeclared, ignoredUsedUndeclaredDependencies));
    ignoredUnusedDeclared.addAll(filterDependencies(unusedDeclared, ignoredDependencies));
    ignoredUnusedDeclared.addAll(filterDependencies(unusedDeclared, ignoredUnusedDeclaredDependencies));
    boolean reported = false;
    boolean warning = false;
    if (verbose && !usedDeclared.isEmpty()) {
        getLog().info("Used declared dependencies found:");
        logArtifacts(analysis.getUsedDeclaredArtifacts(), false);
        reported = true;
    }
    if (!usedUndeclared.isEmpty()) {
        getLog().warn("Used undeclared dependencies found:");
        logArtifacts(usedUndeclared, true);
        reported = true;
        warning = true;
    }
    if (!unusedDeclared.isEmpty()) {
        getLog().warn("Unused declared dependencies found:");
        logArtifacts(unusedDeclared, true);
        reported = true;
        warning = true;
    }
    if (verbose && !ignoredUsedUndeclared.isEmpty()) {
        getLog().info("Ignored used undeclared dependencies:");
        logArtifacts(ignoredUsedUndeclared, false);
        reported = true;
    }
    if (verbose && !ignoredUnusedDeclared.isEmpty()) {
        getLog().info("Ignored unused declared dependencies:");
        logArtifacts(ignoredUnusedDeclared, false);
        reported = true;
    }
    if (outputXML) {
        writeDependencyXML(usedUndeclared);
    }
    if (scriptableOutput) {
        writeScriptableOutput(usedUndeclared);
    }
    if (!reported) {
        getLog().info("No dependency problems found");
    }
    return warning;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProjectDependencyAnalysis(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis) ProjectDependencyAnalyzerException(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with ProjectDependencyAnalysis

use of org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis in project maven-plugins by apache.

the class AnalyzeReportMojo method executeReport.

// Mojo methods -----------------------------------------------------------
/*
     * @see org.apache.maven.plugin.Mojo#execute()
     */
@Override
public void executeReport(Locale locale) throws MavenReportException {
    if (skip) {
        getLog().info("Skipping plugin execution");
        return;
    }
    // Step 0: Checking pom availability
    if ("pom".equals(project.getPackaging())) {
        getLog().info("Skipping pom project");
        return;
    }
    if (outputDirectory == null || !outputDirectory.exists()) {
        getLog().info("Skipping project with no Target directory");
        return;
    }
    // Step 1: Analyze the project
    ProjectDependencyAnalysis analysis;
    try {
        analysis = analyzer.analyze(project);
        if (usedDependencies != null) {
            analysis = analysis.forceDeclaredDependenciesUsage(usedDependencies);
        }
    } catch (ProjectDependencyAnalyzerException exception) {
        throw new MavenReportException("Cannot analyze dependencies", exception);
    }
    // remove everything that's not in the compile scope
    if (ignoreNonCompile) {
        analysis = analysis.ignoreNonCompile();
    }
    // Step 2: Create sink and bundle
    Sink sink = getSink();
    ResourceBundle bundle = getBundle(locale);
    // Step 3: Generate the report
    AnalyzeReportView analyzethis = new AnalyzeReportView();
    analyzethis.generateReport(analysis, sink, bundle);
}
Also used : ProjectDependencyAnalysis(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis) ProjectDependencyAnalyzerException(org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException) Sink(org.apache.maven.doxia.sink.Sink) ResourceBundle(java.util.ResourceBundle) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

ProjectDependencyAnalysis (org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis)4 ProjectDependencyAnalyzerException (org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException)4 LinkedHashSet (java.util.LinkedHashSet)2 ResourceBundle (java.util.ResourceBundle)2 Artifact (org.apache.maven.artifact.Artifact)2 Sink (org.apache.maven.doxia.sink.Sink)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2