Skip to content

Commit

Permalink
[MSITE-936] Sort locale tests from non-default to default one
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Apr 2, 2023
1 parent 34550ec commit 78d1daa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,16 @@ private void push(
final Locale defaultLocale = localesList.get(0);

for (Locale locale : localesList) {
if (locale.equals(defaultLocale)) {
if (!locale.equals(defaultLocale)) {
getLog().info(" >>> to " + appendSlash(repository.getUrl()) + locale + "/" + relativeDir);

wagon.putDirectory(new File(inputDirectory, locale.toString()), locale + "/" + relativeDir);
} else {
// TODO: this also uploads the non-default locales,
// is there a way to exclude directories in wagon?
getLog().info(" >>> to " + appendSlash(repository.getUrl()) + relativeDir);

wagon.putDirectory(inputDirectory, relativeDir);
} else {
getLog().info(" >>> to " + appendSlash(repository.getUrl()) + locale + "/" + relativeDir);

wagon.putDirectory(new File(inputDirectory, locale.toString()), locale + "/" + relativeDir);
}
}
} catch (ResourceDoesNotExistException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected DecorationModel prepareDecorationModel(Locale locale) throws MojoExecu
Locale defaultLocale = localesList.get(0);

// MSITE-658
final String localeUrl = locale.equals(defaultLocale) ? url : append(url, locale.toString());
final String localeUrl = !locale.equals(defaultLocale) ? append(url, locale.toString()) : url;

getLog().info("Relativizing decoration links with respect to localized project URL: " + localeUrl);
assembler.resolvePaths(decorationModel, localeUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {

for (Locale locale : localesList) {
getLog().info("Rendering site for "
+ buffer().strong((locale.equals(defaultLocale) ? "default locale" : "locale '" + locale + "'"))
+ buffer().strong(
(!locale.equals(defaultLocale) ? "locale '" + locale + "'" : "default locale"))
.toString());
renderLocale(locale, reports, localesList);
}
Expand Down Expand Up @@ -248,10 +249,10 @@ private List<DocumentRenderer> renderDoxiaDocuments(

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

// Safety
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/org/apache/maven/plugins/site/run/DoxiaFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.doxia.siterenderer.RendererException;
import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
import org.apache.maven.doxia.tools.SiteTool;
import org.apache.maven.plugins.site.render.ReportDocumentRenderer;
import org.eclipse.jetty.http.MimeTypes;

Expand Down Expand Up @@ -108,31 +109,29 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
Map<String, DocumentRenderer> documents;
SiteRenderingContext generatedSiteContext;

String localeWanted = null;
String localeWanted = "";
for (Locale locale : localesList) {
if (path.startsWith(locale + "/")) {
localeWanted = locale.toString();
path = path.substring(localeWanted.length() + 1);
}
}

if (localeWanted == null) {
DoxiaBean defaultDoxiaBean = i18nDoxiaContexts.get("default");
if (defaultDoxiaBean == null) {
throw new ServletException("No doxia bean found for the default locale");
DoxiaBean doxiaBean;
if (!localeWanted.equals(SiteTool.DEFAULT_LOCALE.toString())) {
doxiaBean = i18nDoxiaContexts.get(localeWanted);
if (doxiaBean == null) {
throw new ServletException("No Doxia bean found for locale '" + localeWanted + "'");
}
context = defaultDoxiaBean.getContext();
documents = defaultDoxiaBean.getDocuments();
generatedSiteContext = defaultDoxiaBean.getGeneratedSiteContext();
} else {
DoxiaBean i18nDoxiaBean = i18nDoxiaContexts.get(localeWanted);
if (i18nDoxiaBean == null) {
throw new ServletException("No doxia bean found for locale '" + localeWanted + "'");
doxiaBean = i18nDoxiaContexts.get("default");
if (doxiaBean == null) {
throw new ServletException("No Doxia bean found for the default locale");
}
context = i18nDoxiaBean.getContext();
documents = i18nDoxiaBean.getDocuments();
generatedSiteContext = i18nDoxiaBean.getGeneratedSiteContext();
}
context = doxiaBean.getContext();
documents = doxiaBean.getDocuments();
generatedSiteContext = doxiaBean.getGeneratedSiteContext();

// ----------------------------------------------------------------------
// Handle report and documents
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/org/apache/maven/plugins/site/run/SiteRunMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,23 @@ private WebAppContext createWebApplication() throws MojoExecutionException {
i18nGeneratedSiteContext.getSiteDirectories().clear();

Map<String, DocumentRenderer> i18nDocuments = locateDocuments(i18nContext, reports, locale);
DoxiaBean doxiaBean;
if (defaultLocale.equals(locale)) {
i18nGeneratedSiteContext.addSiteDirectory(generatedSiteDirectory);
doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);
} else {
if (!defaultLocale.equals(locale)) {
i18nGeneratedSiteContext.addSiteDirectory(new File(generatedSiteDirectory, locale.toString()));
doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);
} else {
i18nGeneratedSiteContext.addSiteDirectory(generatedSiteDirectory);
}
DoxiaBean doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);

i18nDoxiaContexts.put(locale.toString(), doxiaBean);
if (defaultLocale.equals(locale)) {
if (!defaultLocale.equals(locale)) {
i18nDoxiaContexts.put(locale.toString(), doxiaBean);
} else {
i18nDoxiaContexts.put("default", doxiaBean);
}

if (defaultLocale.equals(locale)) {
siteRenderer.copyResources(i18nContext, tempWebappDirectory);
} else {
if (!defaultLocale.equals(locale)) {
siteRenderer.copyResources(i18nContext, new File(tempWebappDirectory, locale.toString()));
} else {
siteRenderer.copyResources(i18nContext, tempWebappDirectory);
}
}

Expand Down

0 comments on commit 78d1daa

Please sign in to comment.