Skip to content

Commit

Permalink
[DOXIASITETOOLS-271] Overhaul locale support and make telescopic
Browse files Browse the repository at this point in the history
This closes #67
  • Loading branch information
michael-o committed Nov 14, 2022
1 parent 107c5d0 commit ccb23eb
Show file tree
Hide file tree
Showing 14 changed files with 527 additions and 82 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
public interface SiteTool
{
/**
* The locale by default for a Maven Site
* @see Locale#ENGLISH
* The locale by default for a Maven Site.
*
* @see Locale#ROOT
*/
Locale DEFAULT_LOCALE = Locale.ENGLISH;
Locale DEFAULT_LOCALE = Locale.ROOT;

/**
* Get a skin artifact from one of the repositories.
Expand All @@ -63,8 +64,9 @@ Artifact getSkinArtifactFromRepository( ArtifactRepository localRepository,
* Get a site descriptor from the project's site directory.
*
* @param siteDirectory the site directory, not null
* @param locale the locale wanted for the site descriptor. If not null, searching for
* <code>site_<i>localeLanguage</i>.xml</code>, otherwise searching for <code>site.xml</code>.
* @param locale the locale wanted for the site descriptor, not null. Telescoping lookup for
* <code>site_language_country_variant.xml</code>, <code>site_language_country.xml</code>,
* <code>site_language.xml}</code>, or <code>site.xml</code> as last resort for {@link Locale#ROOT}.
* @return the site descriptor file
*/ // used by maven-pdf-plugin (should not?)
File getSiteDescriptor( File siteDirectory, Locale locale );
Expand Down Expand Up @@ -107,7 +109,8 @@ String getInterpolatedSiteDescriptorContent( Map<String, String> props, MavenPro
* Get a decoration model for a project.
*
* @param siteDirectory the site directory, may be null if project from repository
* @param locale the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
* @param locale the locale used for the i18n in DecorationModel, not null.
* See {@link #getSiteDescriptor(File, Locale)} for details.
* @param project the Maven project, not null.
* @param reactorProjects the Maven reactor projects, not null.
* @param localRepository the Maven local repository, not null.
Expand All @@ -128,7 +131,8 @@ DecorationModel getDecorationModel( File siteDirectory, Locale locale, MavenProj
* 2 separate menus: "Project Information" and "Project Reports".
*
* @param decorationModel the Doxia Sitetools DecorationModel, not null.
* @param locale the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
* @param locale the locale used for the i18n in DecorationModel, not null.
* See {@link #getSiteDescriptor(File, Locale)} for details.
* @param reportsPerCategory reports per category to put in "Reports" or "Information" menus, not null.
* @see MavenReport#CATEGORY_PROJECT_INFORMATION
* @see MavenReport#CATEGORY_PROJECT_REPORTS
Expand All @@ -138,11 +142,10 @@ void populateReportsMenu( DecorationModel decorationModel, Locale locale,

/**
* Extracts from a comma-separated list the locales that are available in <code>site-tool</code>
* resource bundle. Notice that <code>default</code> value will be changed to the default locale of
* the JVM.
* resource bundle.
*
* @param locales A comma separated list of locales
* @return a list of <code>Locale</code>, which at least contains the Maven default locale which is english
* @return a list of <code>Locale</code>s.
* @since 1.7, was previously getAvailableLocales(String)
*/
List<Locale> getSiteLocales( String locales );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,50 @@ public void testGetSiteDescriptorFromBasedir()
assertNotNull( tool );

SiteToolMavenProjectStub project = new SiteToolMavenProjectStub( "site-tool-test" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), null ).toString(),
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), SiteTool.DEFAULT_LOCALE ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.ENGLISH ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
String siteDir = "src/blabla";
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), siteDir ), null ).toString(),
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), siteDir ), SiteTool.DEFAULT_LOCALE ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "blabla" + File.separator + "site.xml" );

project = new SiteToolMavenProjectStub( "site-tool-locales-test/full" );
final Locale BAVARIAN = new Locale( "de", "DE", "BY" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), SiteTool.DEFAULT_LOCALE ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), BAVARIAN ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site_de_DE_BY.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.GERMANY ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.ENGLISH ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.GERMAN ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );

project = new SiteToolMavenProjectStub( "site-tool-locales-test/language_country" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), SiteTool.DEFAULT_LOCALE ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), BAVARIAN ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site_de_DE.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.GERMANY ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site_de_DE.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.ENGLISH ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.GERMAN ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );

project = new SiteToolMavenProjectStub( "site-tool-locales-test/language" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), SiteTool.DEFAULT_LOCALE ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), BAVARIAN ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site_de.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.GERMANY ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site_de.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.ENGLISH ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.GERMAN ).toString(),
project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site_de.xml" );
}

/**
Expand All @@ -239,7 +276,7 @@ public void testGetSiteDescriptorFromRepository()
+ "maven-site-1.0-site.xml";

assertEquals( tool.getSiteDescriptorFromRepository( project, getLocalRepo(),
project.getRemoteArtifactRepositories(), Locale.ENGLISH )
project.getRemoteArtifactRepositories(), SiteTool.DEFAULT_LOCALE )
.toString(), result );
}

Expand All @@ -257,7 +294,7 @@ public void testGetDecorationModel()

// model from current local build
DecorationModel model =
tool.getDecorationModel( new File( project.getBasedir(), "src/site" ), Locale.getDefault(), project,
tool.getDecorationModel( new File( project.getBasedir(), "src/site" ), SiteTool.DEFAULT_LOCALE, project,
reactorProjects, getLocalRepo(), project.getRemoteArtifactRepositories() );
assertNotNull( model );
assertNotNull( model.getBannerLeft() );
Expand All @@ -269,24 +306,20 @@ public void testGetDecorationModel()
assertEquals( "http://maven.apache.org/images/maven-small.gif", model.getBannerRight().getSrc() );
assertNull( model.getBannerRight().getHref() );

// model from repo: https://repo1.maven.org/maven2/org/apache/maven/maven-site/1.0/maven-site-1.0-site.xml
// TODO Enable this test as soon as we haven a site.xml with head content as string
/*project.setBasedir( null );
// model from repo: https://repo1.maven.org/maven2/org/apache/maven/maven/3.8.6/maven-3.8.6-site.xml
project.setBasedir( null );
project.setGroupId( "org.apache.maven" );
project.setArtifactId( "maven-site" );
project.setVersion( "1.0" );
project.setArtifactId( "maven" );
project.setVersion( "3.8.6" );
DecorationModel modelFromRepo =
tool.getDecorationModel( null, Locale.getDefault(), project, reactorProjects, getLocalRepo(),
tool.getDecorationModel( null, SiteTool.DEFAULT_LOCALE, project, reactorProjects, getLocalRepo(),
project.getRemoteArtifactRepositories() );
assertNotNull( modelFromRepo );
assertNotNull( modelFromRepo.getBannerLeft() );
assertEquals( "Maven", modelFromRepo.getBannerLeft().getName() );
assertEquals( "images/apache-maven-project-2.png", modelFromRepo.getBannerLeft().getSrc() );
assertEquals( "http://maven.apache.org/", modelFromRepo.getBannerLeft().getHref() );
assertNotNull( modelFromRepo.getBannerRight() );
assertNull( modelFromRepo.getBannerRight().getName() );
assertEquals( "images/maven-logo-2.gif", modelFromRepo.getBannerRight().getSrc() );
assertNull( modelFromRepo.getBannerRight().getHref() );*/
assertEquals( "dummy", modelFromRepo.getBannerLeft().getName() );
assertEquals( "https://maven.apache.org/images/apache-maven-project.png", modelFromRepo.getBannerLeft().getSrc() );
assertEquals( "https://maven.apache.org/", modelFromRepo.getBannerLeft().getHref() );
assertNull( modelFromRepo.getBannerRight() );
}

/**
Expand All @@ -303,7 +336,7 @@ public void testGetDefaultDecorationModel()
List<MavenProject> reactorProjects = new ArrayList<MavenProject>();

DecorationModel model =
tool.getDecorationModel( new File( project.getBasedir(), siteDirectory ), Locale.getDefault(), project,
tool.getDecorationModel( new File( project.getBasedir(), siteDirectory ), SiteTool.DEFAULT_LOCALE, project,
reactorProjects, getLocalRepo(), project.getRemoteArtifactRepositories() );
assertNotNull( model );
}
Expand All @@ -312,10 +345,10 @@ public void testGetDefaultDecorationModel()
public void testGetAvailableLocales()
throws Exception
{
assertEquals( Collections.singletonList( SiteTool.DEFAULT_LOCALE ), tool.getSiteLocales( "en" ) );
assertEquals( Collections.singletonList( SiteTool.DEFAULT_LOCALE ), tool.getSiteLocales( "default" ) );

assertEquals( Arrays.asList( SiteTool.DEFAULT_LOCALE, Locale.FRENCH, Locale.ITALIAN ),
tool.getSiteLocales( "en,fr,it" ) );
tool.getSiteLocales( "default,fr,it" ) );

// by default, only DEFAULT_LOCALE
assertEquals( Collections.singletonList( SiteTool.DEFAULT_LOCALE ), tool.getSiteLocales( "" ) );
Expand Down Expand Up @@ -358,16 +391,16 @@ public void testDecorationModelInheritanceAndInterpolation()
assertNotNull( tool );

SiteToolMavenProjectStub parentProject = new SiteToolMavenProjectStub( "interpolation-parent-test" );
parentProject.setDistgributionManagementSiteUrl( "dav:https://davs.codehaus.org/site" );
parentProject.setDistgributionManagementSiteUrl( "dav+https://davs.codehaus.org/site" );

SiteToolMavenProjectStub childProject = new SiteToolMavenProjectStub( "interpolation-child-test" );
childProject.setParent( parentProject );
childProject.setDistgributionManagementSiteUrl( "dav:https://davs.codehaus.org/site/child" );
childProject.setDistgributionManagementSiteUrl( "dav+https://davs.codehaus.org/site/child" );

List<MavenProject> reactorProjects = Collections.<MavenProject>singletonList( parentProject );

DecorationModel model = tool.getDecorationModel( new File( childProject.getBasedir(), "src/site" ),
Locale.getDefault(), childProject, reactorProjects,
SiteTool.DEFAULT_LOCALE, childProject, reactorProjects,
getLocalRepo(), childProject.getRemoteArtifactRepositories() );
assertNotNull( model );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.shared</groupId>
<artifactId>site-tool-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>dummy</name>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
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.
-->

<project name="Maven Dummy Site">
<bannerLeft>
<name>Maven Site</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-stylus-skin</artifactId>
</skin>
<body>
<links>
<item name="Maven 2" href="http://maven.apache.org/maven2/"/>
</links>

<menu name="Overview">
<item name="Test" href="/test.html"/>
</menu>
<menu ref="reports"/>
</body>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

<!--
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.
-->

<project name="Maven Dummy Site">
<bannerLeft>
<name>Maven Site</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-stylus-skin</artifactId>
</skin>
<body>
<links>
<item name="Maven 2" href="http://maven.apache.org/maven2/"/>
</links>

<menu name="Overview">
<item name="Test" href="/test.html"/>
</menu>
<menu ref="reports"/>
</body>
</project>

0 comments on commit ccb23eb

Please sign in to comment.