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;
}
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);
}
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;
}
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);
}
Aggregations