Package org.apache.maven.doxia.tools
Class DefaultSiteTool
java.lang.Object
org.codehaus.plexus.logging.AbstractLogEnabled
org.apache.maven.doxia.tools.DefaultSiteTool
- All Implemented Interfaces:
SiteTool,org.codehaus.plexus.logging.LogEnabled
@Component(role=SiteTool.class)
public class DefaultSiteTool
extends org.codehaus.plexus.logging.AbstractLogEnabled
implements SiteTool
Default implementation of the site tool.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.apache.maven.artifact.factory.ArtifactFactoryThe component used for creating artifact instances.private org.apache.maven.artifact.resolver.ArtifactResolverThe component that is used to resolve additional artifacts required.protected DecorationModelInheritanceAssemblerThe component for assembling inheritance.protected org.codehaus.plexus.i18n.I18NInternationalization.protected org.apache.maven.project.MavenProjectBuilderProject builder (deprecated in Maven 3: should use ProjectBuilder, which will avoid issues like DOXIASITETOOLS-166)Fields inherited from interface org.apache.maven.doxia.tools.SiteTool
DEFAULT_LOCALE, ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendMenuItem(org.apache.maven.project.MavenProject project, Menu menu, String name, String href, String defaultHref) private static StringbuildRelativePath(String toPath, String fromPath, char separatorChar) private voidcheckNotNull(String name, Object value) private LocalecodeToLocale(String localeCode) Converts a locale code like "en", "en_US" or "en_US_win" to ajava.util.Localeobject.private MenuItemcreateCategoryMenu(String name, String href, List<org.apache.maven.reporting.MavenReport> categoryReports, Locale locale) private StringdecorationModelToString(DecorationModel decoration) private Map.Entry<DecorationModel, org.apache.maven.project.MavenProject> getDecorationModel(int depth, File siteDirectory, Locale locale, org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> repositories) getDecorationModel(File siteDirectory, Locale locale, org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> repositories) Get a decoration model for a project.org.apache.maven.artifact.ArtifactgetDefaultSkinArtifact(org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories) Get the default skin artifact for a project from one of the repositories.private static StringgetDistMgmntSiteUrl(org.apache.maven.model.DistributionManagement distMgmnt) private static StringgetDistMgmntSiteUrl(org.apache.maven.project.MavenProject project) Return distributionManagement.site.url if defined, null otherwise.getInterpolatedSiteDescriptorContent(Map<String, String> props, org.apache.maven.project.MavenProject aProject, String siteDescriptorContent) Interpolating several expressions in the site descriptor content.private StringgetInterpolatedSiteDescriptorContent(org.apache.maven.project.MavenProject aProject, String siteDescriptorContent, boolean isEarly) private static Stringprivate static org.apache.maven.project.MavenProjectgetModuleFromReactor(org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> reactorProjects, String module) protected static StringgetNormalizedPath(String path) org.apache.maven.project.MavenProjectgetParentProject(org.apache.maven.project.MavenProject aProject, List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository) Returns the parent POM with interpolated URLs.private static StringgetRelativeFilePath(String oldPath, String newPath) getRelativePath(String to, String from) Deprecated.getSiteDescriptor(File siteDirectory, Locale locale) Get a site descriptor from the project's site directory.(package private) FilegetSiteDescriptorFromRepository(org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> repositories, Locale locale) Get a site descriptor from one of the repositories.getSiteLocales(String locales) Extracts from a comma-separated list the locales that are available insite-toolresource bundle.org.apache.maven.artifact.ArtifactgetSkinArtifactFromRepository(org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories, DecorationModel decoration) Get a skin artifact from one of the repositories.private static booleanisEmptyList(List<?> list) Convenience method.private static booleanCheck the current Maven version to see if it's Maven 3.0 or newer.private voidpopulateModulesMenu(DecorationModel decorationModel, Locale locale, org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, boolean keepInheritedRefs) Populate the pre-definedmodulesmenu of the decoration model, if used through<menu ref="modules"/>.private voidpopulateParentMenu(DecorationModel decorationModel, Locale locale, org.apache.maven.project.MavenProject project, org.apache.maven.project.MavenProject parentProject, boolean keepInheritedRefs) Populate the pre-definedparentmenu of the decoration model, if used through<menu ref="parent"/>.voidpopulateReportsMenu(DecorationModel decorationModel, Locale locale, Map<String, List<org.apache.maven.reporting.MavenReport>> categories) Populate the pre-definedreportsmenu of the decoration model, if used through<menu ref="reports"/>.private DecorationModelreadDecorationModel(String siteDescriptorContent) private StringreadSiteDescriptor(Reader reader, String projectId) Read site descriptor content from Reader, adding support for deprecated${reports},${parentProject}and${modules}tags.private FileresolveSiteDescriptor(org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> repositories, Locale locale) private static StringMethods inherited from class org.codehaus.plexus.logging.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
artifactResolver
@Requirement private org.apache.maven.artifact.resolver.ArtifactResolver artifactResolverThe component that is used to resolve additional artifacts required. -
artifactFactory
@Requirement private org.apache.maven.artifact.factory.ArtifactFactory artifactFactoryThe component used for creating artifact instances. -
i18n
@Requirement protected org.codehaus.plexus.i18n.I18N i18nInternationalization. -
assembler
The component for assembling inheritance. -
mavenProjectBuilder
@Requirement protected org.apache.maven.project.MavenProjectBuilder mavenProjectBuilderProject builder (deprecated in Maven 3: should use ProjectBuilder, which will avoid issues like DOXIASITETOOLS-166)
-
-
Constructor Details
-
DefaultSiteTool
public DefaultSiteTool()
-
-
Method Details
-
getSkinArtifactFromRepository
public org.apache.maven.artifact.Artifact getSkinArtifactFromRepository(org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories, DecorationModel decoration) throws SiteToolException Description copied from interface:SiteToolGet a skin artifact from one of the repositories.- Specified by:
getSkinArtifactFromRepositoryin interfaceSiteTool- Parameters:
localRepository- the Maven local repository, not null.remoteArtifactRepositories- the Maven remote repositories, not null.decoration- the Doxia site descriptor model, not null.- Returns:
- the
Skinartifact defined in aDecorationModelfrom a given project and a local repository - Throws:
SiteToolException- if any
-
getDefaultSkinArtifact
public org.apache.maven.artifact.Artifact getDefaultSkinArtifact(org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories) throws SiteToolException Description copied from interface:SiteToolGet the default skin artifact for a project from one of the repositories.- Specified by:
getDefaultSkinArtifactin interfaceSiteTool- Parameters:
localRepository- the Maven local repository, not null.remoteArtifactRepositories- the Maven remote repositories, not null.- Returns:
- the default
Skinartifact from a given project and a local repository - Throws:
SiteToolException- if any- See Also:
-
getRelativePath
Deprecated.This method is not implemented according to the URI specification and has many weird corner cases where it doesn't do the right thing. Please consider using a better implemented method from a different library such as org.apache.http.client.utils.URIUtils#resolve.- Specified by:
getRelativePathin interfaceSiteTool- Parameters:
to- thetourl of file as stringfrom- thefromurl of file as string- Returns:
- a relative path from
fromtoto.
-
getRelativeFilePath
-
getSiteDescriptor
Get a site descriptor from the project's site directory.- Specified by:
getSiteDescriptorin interfaceSiteTool- Parameters:
siteDirectory- the site directory, not nulllocale- the locale wanted for the site descriptor. If not null, searching forsite_localeLanguage.xml, otherwise searching forsite.xml.- Returns:
- the site descriptor file
-
getSiteDescriptorFromRepository
File getSiteDescriptorFromRepository(org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> repositories, Locale locale) throws SiteToolException Get a site descriptor from one of the repositories.- Parameters:
project- the Maven project, not null.localRepository- the Maven local repository, not null.repositories- the Maven remote repositories, not null.locale- the locale wanted for the site descriptor. If not null, searching forsite_localeLanguage.xml, otherwise searching forsite.xml.- Returns:
- the site descriptor into the local repository after download of it from repositories or null if not found in repositories.
- Throws:
SiteToolException- if any
-
readSiteDescriptor
Read site descriptor content from Reader, adding support for deprecated${reports},${parentProject}and${modules}tags.- Parameters:
reader-- Returns:
- the input content interpolated with deprecated tags
- Throws:
IOException
-
getDecorationModel
public DecorationModel getDecorationModel(File siteDirectory, Locale locale, org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> repositories) throws SiteToolException Get a decoration model for a project.- Specified by:
getDecorationModelin interfaceSiteTool- Parameters:
siteDirectory- the site directory, may be null if project from repositorylocale- the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.project- the Maven project, not null.reactorProjects- the Maven reactor projects, not null.localRepository- the Maven local repository, not null.repositories- the Maven remote repositories, not null.- Returns:
- the
DecorationModelobject corresponding to thesite.xmlfile with some interpolations. - Throws:
SiteToolException- if any
-
getInterpolatedSiteDescriptorContent
public String getInterpolatedSiteDescriptorContent(Map<String, String> props, org.apache.maven.project.MavenProject aProject, String siteDescriptorContent) throws SiteToolExceptionInterpolating several expressions in the site descriptor content. Actually, the expressions can be in the project, the environment variables and the specific properties likeencoding.For instance:
- ${project.name}
- The value from the POM of:
<project>
<name>myProjectName</name>
</project> - ${my.value}
- The value from the POM of:
<properties>
<my.value>hello</my.value>
</properties> - ${JAVA_HOME}
- The value of JAVA_HOME in the environment variables
- Specified by:
getInterpolatedSiteDescriptorContentin interfaceSiteTool- Parameters:
props- a map used for interpolation, not null.aProject- a Maven project, not null.siteDescriptorContent- the site descriptor file, not null.- Returns:
- the interpolated site descriptor content.
- Throws:
SiteToolException- if errors happened during the interpolation.
-
getInterpolatedSiteDescriptorContent
private String getInterpolatedSiteDescriptorContent(org.apache.maven.project.MavenProject aProject, String siteDescriptorContent, boolean isEarly) throws SiteToolException - Throws:
SiteToolException
-
getParentProject
public org.apache.maven.project.MavenProject getParentProject(org.apache.maven.project.MavenProject aProject, List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository) Returns the parent POM with interpolated URLs. If called from Maven 3, just returnsproject.getParent(), which is already interpolated. But when called from Maven 2, attempts to source this value from thereactorProjectsparameters if available (reactor env model attributes are interpolated), or if the reactor is unavailable (-N) resorts to theproject.getParent().getUrl()value which will NOT have been interpolated.- Specified by:
getParentProjectin interfaceSiteTool- Parameters:
aProject- a Maven project, not null.reactorProjects- the Maven reactor projects, not null.localRepository- the Maven local repository, not null.- Returns:
- the parent project with interpolated URLs.
-
populateParentMenu
private void populateParentMenu(DecorationModel decorationModel, Locale locale, org.apache.maven.project.MavenProject project, org.apache.maven.project.MavenProject parentProject, boolean keepInheritedRefs) Populate the pre-definedparentmenu of the decoration model, if used through<menu ref="parent"/>.- Parameters:
decorationModel- the Doxia Sitetools DecorationModel, not null.locale- the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.project- a Maven project, not null.parentProject- a Maven parent project, not null.keepInheritedRefs- used for inherited references.
-
populateModulesMenu
private void populateModulesMenu(DecorationModel decorationModel, Locale locale, org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, boolean keepInheritedRefs) throws SiteToolException, IOException Populate the pre-definedmodulesmenu of the decoration model, if used through<menu ref="modules"/>.- Parameters:
decorationModel- the Doxia Sitetools DecorationModel, not null.locale- the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.project- a Maven project, not null.reactorProjects- the Maven reactor projects, not null.localRepository- the Maven local repository, not null.keepInheritedRefs- used for inherited references.- Throws:
SiteToolException- if anyIOException
-
getModuleFromReactor
private static org.apache.maven.project.MavenProject getModuleFromReactor(org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> reactorProjects, String module) throws IOException - Throws:
IOException
-
populateReportsMenu
public void populateReportsMenu(DecorationModel decorationModel, Locale locale, Map<String, List<org.apache.maven.reporting.MavenReport>> categories) Populate the pre-definedreportsmenu of the decoration model, if used through<menu ref="reports"/>. Notice this menu reference is translated into 2 separate menus: "Project Information" and "Project Reports".- Specified by:
populateReportsMenuin interfaceSiteTool- Parameters:
decorationModel- the Doxia Sitetools DecorationModel, not null.locale- the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.categories- reports per category to put in "Reports" or "Information" menus, not null.- See Also:
-
getSiteLocales
Extracts from a comma-separated list the locales that are available insite-toolresource bundle. Notice thatdefaultvalue will be changed to the default locale of the JVM.- Specified by:
getSiteLocalesin interfaceSiteTool- Parameters:
locales- A comma separated list of locales- Returns:
- a list of
Locale, which at least contains the Maven default locale which is english
-
codeToLocale
Converts a locale code like "en", "en_US" or "en_US_win" to ajava.util.Localeobject.If localeCode =
default, return the current value of the default locale for this instance of the Java Virtual Machine.- Parameters:
localeCode- the locale code string.- Returns:
- a java.util.Locale object instanced or null if errors occurred
- See Also:
-
getNormalizedPath
- Parameters:
path- could be null.- Returns:
- the path normalized, i.e. by eliminating "/../" and "/./" in the path.
- See Also:
-
resolveSiteDescriptor
private File resolveSiteDescriptor(org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> repositories, Locale locale) throws IOException, org.apache.maven.artifact.resolver.ArtifactResolutionException, org.apache.maven.artifact.resolver.ArtifactNotFoundException - Parameters:
project- not nulllocalRepository- not nullrepositories- not nulllocale- not null- Returns:
- the resolved site descriptor
- Throws:
IOException- if anyorg.apache.maven.artifact.resolver.ArtifactResolutionException- if anyorg.apache.maven.artifact.resolver.ArtifactNotFoundException- if any
-
getDecorationModel
private Map.Entry<DecorationModel,org.apache.maven.project.MavenProject> getDecorationModel(int depth, File siteDirectory, Locale locale, org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, List<org.apache.maven.artifact.repository.ArtifactRepository> repositories) throws SiteToolException - Parameters:
depth- depth of projectsiteDirectory- , can be null if project.basedir is null, ie POM from repositorylocale- not nullproject- not nullreactorProjects- not nulllocalRepository- not nullrepositories- not nullorigProps- not null- Returns:
- the decoration model depending the locale and the parent project
- Throws:
SiteToolException- if any
-
readDecorationModel
- Parameters:
siteDescriptorContent- not null- Returns:
- the decoration model object
- Throws:
SiteToolException- if any
-
decorationModelToString
- Throws:
SiteToolException
-
buildRelativePath
-
appendMenuItem
private void appendMenuItem(org.apache.maven.project.MavenProject project, Menu menu, String name, String href, String defaultHref) - Parameters:
project- not nullmenu- not nullname- not nullhref- could be nulldefaultHref- not null
-
createCategoryMenu
private MenuItem createCategoryMenu(String name, String href, List<org.apache.maven.reporting.MavenReport> categoryReports, Locale locale) - Parameters:
name- not nullhref- not nullcategoryReports- not nulllocale- not null- Returns:
- the menu item object
-
isEmptyList
Convenience method.- Parameters:
list- could be null- Returns:
- true if the list is
nullor empty
-
getDistMgmntSiteUrl
Return distributionManagement.site.url if defined, null otherwise.- Parameters:
project- not null- Returns:
- could be null
-
getDistMgmntSiteUrl
-
urlEncode
-
checkNotNull
-
isMaven3OrMore
private static boolean isMaven3OrMore()Check the current Maven version to see if it's Maven 3.0 or newer. -
getMavenVersion
-