Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ under the License.
</dependency>

<!-- reporting -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
<version>1.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
Expand Down Expand Up @@ -193,6 +203,17 @@ under the License.
<artifactId>plexus-io</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-i18n</artifactId>
<version>1.0-beta-10</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- shared -->
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions src/it/projects/analyze-report/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

invoker.goals = site
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:analyze-report
42 changes: 0 additions & 42 deletions src/it/projects/analyze-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,46 +53,4 @@
<version>2.0.6</version>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>@project.version@</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.10.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>

<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.2.1</version>
<reportSets>
<reportSet>
<reports>
<report>index</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<report>analyze-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

invoker.goals = clean ${project.groupId}:${project.artifactId}:${project.version}:analyze-report
invoker.maven.version = 3.0+
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:analyze-report
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
package org.apache.maven.plugins.dependency.analyze;

import java.util.Locale;
import java.util.ResourceBundle;

import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -33,6 +31,7 @@
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException;
import org.codehaus.plexus.i18n.I18N;

/**
* Analyzes the dependencies of this project and produces a report that summarizes which are: used and declared; used
Expand Down Expand Up @@ -76,6 +75,12 @@ public class AnalyzeReportMojo extends AbstractMavenReport {
@Parameter(property = "mdep.analyze.skip", defaultValue = "false")
private boolean skip;

/**
* Internationalization component
*/
@Component
private I18N i18n;

// Mojo methods -----------------------------------------------------------

/*
Expand All @@ -100,13 +105,9 @@ public void executeReport(Locale locale) throws MavenReportException {
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);
AnalyzeReportRenderer r = new AnalyzeReportRenderer(getSink(), i18n, locale, analysis);
r.render();
}

// MavenReport methods ----------------------------------------------------
Expand All @@ -127,38 +128,30 @@ public boolean canGenerateReport() {
return true;
}

/*
* @see org.apache.maven.reporting.AbstractMavenReport#getOutputName()
*/
/** {@inheritDoc} */
@Override
public String getOutputName() {
return "dependency-analysis";
}

/*
* @see org.apache.maven.reporting.AbstractMavenReport#getName(java.util.Locale)
*/
@Override
/** {@inheritDoc} */
public String getName(Locale locale) {
return getBundle(locale).getString("analyze.report.name");
return getI18nString(locale, "name");
}

/*
* @see org.apache.maven.reporting.AbstractMavenReport#getDescription(java.util.Locale)
*/
@Override
/** {@inheritDoc} */
public String getDescription(Locale locale) {
return getBundle(locale).getString("analyze.report.description");
return getI18nString(locale, "description");
}

// protected methods ------------------------------------------------------

/**
* @param locale the current locale
* @return The resource bundle {@link ResourceBundle}
* @param locale The locale
* @param key The key to search for
* @return The text appropriate for the locale.
*/
protected ResourceBundle getBundle(Locale locale) {
return ResourceBundle.getBundle(
"analyze-report", locale, this.getClass().getClassLoader());
protected String getI18nString(Locale locale, String key) {
return i18n.getString("analyze-report", locale, "report.analyze." + key);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.plugins.dependency.analyze;

import java.util.Collection;
import java.util.Locale;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis;
import org.codehaus.plexus.i18n.I18N;

/**
* This is the view part of the analyze-report mojo. It generates the HTML report for the project website. The HTML
* output is same as the CLI output.
*/
public class AnalyzeReportRenderer extends AbstractMavenReportRenderer {
private final I18N i18n;

private final Locale locale;

private final ProjectDependencyAnalysis analysis;

public AnalyzeReportRenderer(Sink sink, I18N i18n, Locale locale, ProjectDependencyAnalysis analysis) {
super(sink);
this.i18n = i18n;
this.locale = locale;
this.analysis = analysis;
}

@Override
public String getTitle() {
return getI18nString("title");
}

/**
* @param key The key.
* @return The translated string.
*/
private String getI18nString(String key) {
return i18n.getString("analyze-report", locale, "report.analyze." + key);
}

protected void renderBody() {
startSection(getTitle());

boolean reported = false;

// Generate Used Declared dependencies:
if (!analysis.getUsedDeclaredArtifacts().isEmpty()) {
startSection(getI18nString("UsedDeclaredDependencies"));
renderDependenciesTable(sink, analysis.getUsedDeclaredArtifacts());
endSection();
reported = true;
}

// Generate Used Undeclared dependencies:

if (!analysis.getUsedUndeclaredArtifacts().isEmpty()) {
startSection(getI18nString("UsedUndeclaredDependencies"));
renderDependenciesTable(sink, analysis.getUsedUndeclaredArtifacts());
endSection();
reported = true;
}

// Generate Unused declared dependencies:
if (!analysis.getUnusedDeclaredArtifacts().isEmpty()) {
startSection(getI18nString("UnusedDeclaredDependencies"));
renderDependenciesTable(sink, analysis.getUnusedDeclaredArtifacts());
endSection();
reported = true;
}

// Generate Non-Test Scoped Test Dependencies:
if (!analysis.getTestArtifactsWithNonTestScope().isEmpty()) {
startSection(getI18nString("CompileScopeTestOnlyDependencies"));
renderDependenciesTable(sink, analysis.getTestArtifactsWithNonTestScope());
endSection();
reported = true;
}

if (!reported) {
text(getI18nString("noDependencyProblems"));
}

endSection();
}

private void renderDependenciesTable(Sink sink, Collection<Artifact> artifacts) {
startTable();

tableHeader(new String[] {"GroupId", "ArtifactId", "Version", "Scope", "Classifier", "Type", "Optional"});

for (Artifact artifact : artifacts) {
tableRow(new String[] {
artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(),
artifact.getScope(),
artifact.getClassifier(),
artifact.getType(),
artifact.isOptional() ? "" : "false"
});
}

endTable();
}
}
Loading