Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #165

Merged
merged 2 commits into from
Dec 14, 2023
Merged

Fixes #165

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
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 Expand Up @@ -367,11 +368,17 @@ protected Map<String, MavenReport> locateReports(
getLog().info("Skipped \"" + report.getName(locale) + "\" report" + reportMojoInfo + ", file \""
+ filename + "\" already exists.");
} else {
File localizedSiteDirectory;
if (!locale.equals(SiteTool.DEFAULT_LOCALE)) {
localizedSiteDirectory = new File(siteDirectory, locale.toString());
} else {
localizedSiteDirectory = siteDirectory;
}
String generator = mavenReportExecution.getGoal() == null
? null
: mavenReportExecution.getPlugin().getId() + ':' + mavenReportExecution.getGoal();
DocumentRenderingContext docRenderingContext =
new DocumentRenderingContext(siteDirectory, outputName, generator);
new DocumentRenderingContext(localizedSiteDirectory, outputName, generator);
DocumentRenderer docRenderer =
new ReportDocumentRenderer(mavenReportExecution, docRenderingContext, getLog());
documents.put(filename, docRenderer);
Expand Down Expand Up @@ -428,13 +435,20 @@ protected Map<String, DocumentRenderer> locateDocuments(
siteTool.populateReportsMenu(context.getSiteModel(), locale, categories);
populateReportItems(context.getSiteModel(), locale, reportsByOutputName);

File localizedSiteDirectory;
if (!locale.equals(SiteTool.DEFAULT_LOCALE)) {
localizedSiteDirectory = new File(siteDirectory, locale.toString());
} else {
localizedSiteDirectory = siteDirectory;
}

if (categories.containsKey(MavenReport.CATEGORY_PROJECT_INFORMATION) && generateProjectInfo) {
// add "Project Information" category summary document
List<MavenReport> categoryReports = categories.get(MavenReport.CATEGORY_PROJECT_INFORMATION);
MojoExecution subMojoExecution =
new MojoExecution(mojoExecution.getPlugin(), "project-info", mojoExecution.getExecutionId());
DocumentRenderingContext docRenderingContext = new DocumentRenderingContext(
siteDirectory,
localizedSiteDirectory,
subMojoExecution.getGoal(),
subMojoExecution.getPlugin().getId() + ':' + subMojoExecution.getGoal());
String title = i18n.getString("site-plugin", locale, "report.information.title");
Expand All @@ -457,7 +471,7 @@ protected Map<String, DocumentRenderer> locateDocuments(
MojoExecution subMojoExecution =
new MojoExecution(mojoExecution.getPlugin(), "project-reports", mojoExecution.getExecutionId());
DocumentRenderingContext docRenderingContext = new DocumentRenderingContext(
siteDirectory,
localizedSiteDirectory,
subMojoExecution.getGoal(),
subMojoExecution.getPlugin().getId() + ':' + subMojoExecution.getGoal());
String title = i18n.getString("site-plugin", locale, "report.project.title");
Expand All @@ -478,7 +492,7 @@ protected Map<String, DocumentRenderer> locateDocuments(
MojoExecution subMojoExecution =
new MojoExecution(mojoExecution.getPlugin(), "sitemap", mojoExecution.getExecutionId());
DocumentRenderingContext docRenderingContext = new DocumentRenderingContext(
siteDirectory,
localizedSiteDirectory,
subMojoExecution.getGoal(),
subMojoExecution.getPlugin().getId() + ':' + subMojoExecution.getGoal());
String title = i18n.getString("site-plugin", locale, "site.sitemap.title");
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