Skip to content

Commit

Permalink
[MSITE-998] MavenReport#setReportOutputDirectory(File) is called too …
Browse files Browse the repository at this point in the history
…late
  • Loading branch information
michael-o committed Dec 14, 2023
1 parent 5488257 commit a3fe002
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 27 deletions.
37 changes: 37 additions & 0 deletions src/it/projects/site-sd-lang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,43 @@ under the License.
</reportSet>
</reportSets>
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>@pmdPluginVersion@</version>
<reportSets>
<reportSet>
<reports>
<report>pmd</report>
<report>cpd</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<includeXmlInSite>true</includeXmlInSite>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jxr-plugin</artifactId>
<version>@jxrPluginVersion@</version>
<reportSets>
<reportSet>
<reports>
<report>jxr-no-fork</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>@javadocPluginVersion@</version>
<reportSets>
<reportSet>
<reports>
<report>javadoc-no-fork</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected void checkInputEncoding() {
}
}

protected List<MavenReportExecution> getReports() throws MojoExecutionException {
protected List<MavenReportExecution> getReports(File outputDirectory) throws MojoExecutionException {
MavenReportExecutorRequest mavenReportExecutorRequest = new MavenReportExecutorRequest();
mavenReportExecutorRequest.setMavenSession(mavenSession);
mavenReportExecutorRequest.setExecutionId(mojoExecution.getExecutionId());
Expand All @@ -226,6 +226,7 @@ protected List<MavenReportExecution> getReports() throws MojoExecutionException
List<MavenReportExecution> reportExecutions = new ArrayList<>(allReports.size());
for (MavenReportExecution exec : allReports) {
String reportMojoInfo = exec.getPlugin().getId() + ":" + exec.getGoal();
exec.getMavenReport().setReportOutputDirectory(outputDirectory);
try {
if (exec.canGenerateReport()) {
reportExecutions.add(exec);
Expand Down
32 changes: 12 additions & 20 deletions src/main/java/org/apache/maven/plugins/site/render/SiteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.reporting.exec.MavenReportExecution;
import org.apache.maven.shared.utils.logging.MessageBuilder;
Expand Down Expand Up @@ -95,13 +94,6 @@ public void execute() throws MojoExecutionException, MojoFailureException {

checkInputEncoding();

List<MavenReportExecution> reports;
if (generateReports) {
reports = getReports();
} else {
reports = Collections.emptyList();
}

try {
List<Locale> localesList = getLocales();

Expand All @@ -112,7 +104,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
? "locale '" + locale + "'"
: "default locale"))
.toString());
renderLocale(locale, reports, localesList);
File outputDirectory = getOutputDirectory(locale);
List<MavenReportExecution> reports =
generateReports ? getReports(outputDirectory) : Collections.emptyList();
renderLocale(locale, reports, localesList, outputDirectory);
}
} catch (RendererException e) {
if (e.getCause() instanceof MavenReportException) {
Expand All @@ -125,7 +120,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

private void renderLocale(Locale locale, List<MavenReportExecution> reports, List<Locale> supportedLocales)
private void renderLocale(
Locale locale, List<MavenReportExecution> reports, List<Locale> supportedLocales, File outputDirectory)
throws IOException, RendererException, MojoFailureException, MojoExecutionException {
SiteRenderingContext context = createSiteRenderingContext(locale);
context.addSiteLocales(supportedLocales);
Expand All @@ -142,8 +138,6 @@ private void renderLocale(Locale locale, List<MavenReportExecution> reports, Lis
getLog().info("Validation is switched on, xml input documents will be validated!");
}

File outputDirectory = getOutputDirectory(locale);

Map<String, DocumentRenderer> documents = locateDocuments(context, reports, locale);

// copy resources
Expand All @@ -152,12 +146,6 @@ private void renderLocale(Locale locale, List<MavenReportExecution> reports, Lis
// 1. render Doxia documents first
List<DocumentRenderer> nonDoxiaDocuments = renderDoxiaDocuments(documents, context, outputDirectory, false);

// prepare external reports
for (MavenReportExecution mavenReportExecution : reports) {
MavenReport report = mavenReportExecution.getMavenReport();
report.setReportOutputDirectory(outputDirectory);
}

// 2. then non-Doxia documents (e.g., reports)
renderNonDoxiaDocuments(nonDoxiaDocuments, context, outputDirectory);

Expand Down Expand Up @@ -185,7 +173,10 @@ private void renderLocale(Locale locale, List<MavenReportExecution> reports, Lis
* @return the sublist of documents that are not Doxia source files
*/
private List<DocumentRenderer> renderDoxiaDocuments(
Map<String, DocumentRenderer> documents, SiteRenderingContext context, File outputDirectory, boolean generated)
Map<String, DocumentRenderer> documents,
SiteRenderingContext context,
File outputDirectory,
boolean generated)
throws RendererException, IOException {
Map<String, DocumentRenderer> doxiaDocuments = new TreeMap<>();
List<DocumentRenderer> nonDoxiaDocuments = new ArrayList<>();
Expand Down Expand Up @@ -244,7 +235,8 @@ private List<DocumentRenderer> renderDoxiaDocuments(
*
* @param documents a collection of documents containing non-Doxia source files
*/
private void renderNonDoxiaDocuments(List<DocumentRenderer> documents, SiteRenderingContext context, File outputDirectory)
private void renderNonDoxiaDocuments(
List<DocumentRenderer> documents, SiteRenderingContext context, File outputDirectory)
throws RendererException, IOException {
Map<String, Integer> counts = new TreeMap<>();

Expand Down
25 changes: 19 additions & 6 deletions src/main/java/org/apache/maven/plugins/site/run/SiteRunMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ private WebAppContext createWebApplication() throws MojoExecutionException {

// For external reports
project.getReporting().setOutputDirectory(tempWebappDirectory.getAbsolutePath());
for (MavenReportExecution mavenReportExecution : getReports()) {
mavenReportExecution.getMavenReport().setReportOutputDirectory(tempWebappDirectory);
}

List<MavenReportExecution> reports =
getReports(); // TODO: is it sane to call getReports() method a second time?

List<Locale> localesList = getLocales();
webapp.setAttribute(DoxiaFilter.LOCALES_LIST_KEY, localesList);
Expand All @@ -144,6 +138,9 @@ private WebAppContext createWebApplication() throws MojoExecutionException {
i18nGeneratedSiteContext.setOutputEncoding(getOutputEncoding());
i18nGeneratedSiteContext.getSiteDirectories().clear();

File outputDirectory = getOutputDirectory(locale);
List<MavenReportExecution> reports = getReports(outputDirectory);

Map<String, DocumentRenderer> i18nDocuments = locateDocuments(i18nContext, reports, locale);
if (!locale.equals(SiteTool.DEFAULT_LOCALE)) {
i18nGeneratedSiteContext.addSiteDirectory(new File(generatedSiteDirectory, locale.toString()));
Expand Down Expand Up @@ -172,6 +169,22 @@ private WebAppContext createWebApplication() throws MojoExecutionException {
return webapp;
}

private File getOutputDirectory(Locale locale) {
File file;
if (!locale.equals(SiteTool.DEFAULT_LOCALE)) {
file = new File(tempWebappDirectory, locale.toString());
} else {
file = tempWebappDirectory;
}

// Safety
if (!file.exists()) {
file.mkdirs();
}

return file;
}

public void setTempWebappDirectory(File tempWebappDirectory) {
this.tempWebappDirectory = tempWebappDirectory;
}
Expand Down

0 comments on commit a3fe002

Please sign in to comment.