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
Fields Modifier and Type Field Description private org.apache.maven.artifact.factory.ArtifactFactory
artifactFactory
The component used for creating artifact instances.private org.apache.maven.artifact.resolver.ArtifactResolver
artifactResolver
The component that is used to resolve additional artifacts required.protected DecorationModelInheritanceAssembler
assembler
The component for assembling inheritance.protected org.codehaus.plexus.i18n.I18N
i18n
Internationalization.protected org.apache.maven.project.MavenProjectBuilder
mavenProjectBuilder
Project 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 Constructor Description DefaultSiteTool()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
appendMenuItem(org.apache.maven.project.MavenProject project, Menu menu, java.lang.String name, java.lang.String href, java.lang.String defaultHref)
private static java.lang.String
buildRelativePath(java.lang.String toPath, java.lang.String fromPath, char separatorChar)
private void
checkNotNull(java.lang.String name, java.lang.Object value)
private java.util.Locale
codeToLocale(java.lang.String localeCode)
Converts a locale code like "en", "en_US" or "en_US_win" to ajava.util.Locale
object.private MenuItem
createCategoryMenu(java.lang.String name, java.lang.String href, java.util.List<org.apache.maven.reporting.MavenReport> categoryReports, java.util.Locale locale)
private java.lang.String
decorationModelToString(DecorationModel decoration)
private java.util.Map.Entry<DecorationModel,org.apache.maven.project.MavenProject>
getDecorationModel(int depth, java.io.File siteDirectory, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories)
DecorationModel
getDecorationModel(java.io.File siteDirectory, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories)
Get a decoration model for a project.org.apache.maven.artifact.Artifact
getDefaultSkinArtifact(org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories)
Get the default skin artifact for a project from one of the repositories.private static java.lang.String
getDistMgmntSiteUrl(org.apache.maven.model.DistributionManagement distMgmnt)
private static java.lang.String
getDistMgmntSiteUrl(org.apache.maven.project.MavenProject project)
Return distributionManagement.site.url if defined, null otherwise.java.lang.String
getInterpolatedSiteDescriptorContent(java.util.Map<java.lang.String,java.lang.String> props, org.apache.maven.project.MavenProject aProject, java.lang.String siteDescriptorContent)
Interpolating several expressions in the site descriptor content.private java.lang.String
getInterpolatedSiteDescriptorContent(org.apache.maven.project.MavenProject aProject, java.lang.String siteDescriptorContent, boolean isEarly)
private static java.lang.String
getMavenVersion()
private static org.apache.maven.project.MavenProject
getModuleFromReactor(org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, java.lang.String module)
protected static java.lang.String
getNormalizedPath(java.lang.String path)
org.apache.maven.project.MavenProject
getParentProject(org.apache.maven.project.MavenProject aProject, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository)
Returns the parent POM with interpolated URLs.private static java.lang.String
getRelativeFilePath(java.lang.String oldPath, java.lang.String newPath)
java.lang.String
getRelativePath(java.lang.String to, java.lang.String from)
Calculate the relative path between two URLs or between two files.java.io.File
getSiteDescriptor(java.io.File siteDirectory, java.util.Locale locale)
Get a site descriptor from the project's site directory.(package private) java.io.File
getSiteDescriptorFromRepository(org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories, java.util.Locale locale)
Get a site descriptor from one of the repositories.java.util.List<java.util.Locale>
getSiteLocales(java.lang.String locales)
Extracts from a comma-separated list the locales that are available insite-tool
resource bundle.org.apache.maven.artifact.Artifact
getSkinArtifactFromRepository(org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories, DecorationModel decoration)
Get a skin artifact from one of the repositories.private static boolean
isEmptyList(java.util.List<?> list)
Convenience method.private static boolean
isMaven3OrMore()
Check the current Maven version to see if it's Maven 3.0 or newer.private void
populateModulesMenu(DecorationModel decorationModel, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, boolean keepInheritedRefs)
Populate the pre-definedmodules
menu of the decoration model, if used through<menu ref="modules"/>
.private void
populateParentMenu(DecorationModel decorationModel, java.util.Locale locale, org.apache.maven.project.MavenProject project, org.apache.maven.project.MavenProject parentProject, boolean keepInheritedRefs)
Populate the pre-definedparent
menu of the decoration model, if used through<menu ref="parent"/>
.void
populateReportsMenu(DecorationModel decorationModel, java.util.Locale locale, java.util.Map<java.lang.String,java.util.List<org.apache.maven.reporting.MavenReport>> categories)
Populate the pre-definedreports
menu of the decoration model, if used through<menu ref="reports"/>
.private DecorationModel
readDecorationModel(java.lang.String siteDescriptorContent)
private java.lang.String
readSiteDescriptor(java.io.Reader reader, java.lang.String projectId)
Read site descriptor content from Reader, adding support for deprecated${reports}
,${parentProject}
and${modules}
tags.private java.io.File
resolveSiteDescriptor(org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories, java.util.Locale locale)
private static java.lang.String
urlEncode(java.lang.String url)
-
-
-
Field Detail
-
artifactResolver
@Requirement private org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver
The component that is used to resolve additional artifacts required.
-
artifactFactory
@Requirement private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
The component used for creating artifact instances.
-
i18n
@Requirement protected org.codehaus.plexus.i18n.I18N i18n
Internationalization.
-
assembler
@Requirement protected DecorationModelInheritanceAssembler assembler
The component for assembling inheritance.
-
mavenProjectBuilder
@Requirement protected org.apache.maven.project.MavenProjectBuilder mavenProjectBuilder
Project builder (deprecated in Maven 3: should use ProjectBuilder, which will avoid issues like DOXIASITETOOLS-166)
-
-
Method Detail
-
getSkinArtifactFromRepository
public org.apache.maven.artifact.Artifact getSkinArtifactFromRepository(org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories, DecorationModel decoration) throws SiteToolException
Get a skin artifact from one of the repositories.- Specified by:
getSkinArtifactFromRepository
in 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
Skin
artifact defined in aDecorationModel
from 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, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteArtifactRepositories) throws SiteToolException
Get the default skin artifact for a project from one of the repositories.- Specified by:
getDefaultSkinArtifact
in interfaceSiteTool
- Parameters:
localRepository
- the Maven local repository, not null.remoteArtifactRepositories
- the Maven remote repositories, not null.- Returns:
- the default
Skin
artifact from a given project and a local repository - Throws:
SiteToolException
- if any- See Also:
Skin.getDefaultSkin()
,SiteTool.getSkinArtifactFromRepository(ArtifactRepository, List, DecorationModel)
-
getRelativePath
public java.lang.String getRelativePath(java.lang.String to, java.lang.String from)
Calculate the relative path between two URLs or between two files. For example:- to = "http://maven.apache.org" and from = "http://maven.apache.org"
- return ""
- to = "http://maven.apache.org" and from = "http://maven.apache.org/plugins/maven-site-plugin/"
- return "../.."
- to = "http://maven.apache.org/plugins/maven-site-plugin/" and from = "http://maven.apache.org"
- return "plugins/maven-site-plugin"
- to = "/myproject/myproject-module1" and from = "/myproject/myproject"
- return "../myproject-module1"
dav:https://dav.codehaus.org/
orscm:svn:https://svn.apache.org/repos/asf
.- Specified by:
getRelativePath
in interfaceSiteTool
- Parameters:
to
- theto
url of file as stringfrom
- thefrom
url of file as string- Returns:
- a relative path from
from
toto
.
-
getRelativeFilePath
private static java.lang.String getRelativeFilePath(java.lang.String oldPath, java.lang.String newPath)
-
getSiteDescriptor
public java.io.File getSiteDescriptor(java.io.File siteDirectory, java.util.Locale locale)
Get a site descriptor from the project's site directory.- Specified by:
getSiteDescriptor
in 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
java.io.File getSiteDescriptorFromRepository(org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories, java.util.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
private java.lang.String readSiteDescriptor(java.io.Reader reader, java.lang.String projectId) throws java.io.IOException
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:
java.io.IOException
-
getDecorationModel
public DecorationModel getDecorationModel(java.io.File siteDirectory, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories) throws SiteToolException
Get a decoration model for a project.- Specified by:
getDecorationModel
in 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
DecorationModel
object corresponding to thesite.xml
file with some interpolations. - Throws:
SiteToolException
- if any
-
getInterpolatedSiteDescriptorContent
public java.lang.String getInterpolatedSiteDescriptorContent(java.util.Map<java.lang.String,java.lang.String> props, org.apache.maven.project.MavenProject aProject, java.lang.String siteDescriptorContent) throws SiteToolException
Interpolating 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:
getInterpolatedSiteDescriptorContent
in 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 java.lang.String getInterpolatedSiteDescriptorContent(org.apache.maven.project.MavenProject aProject, java.lang.String siteDescriptorContent, boolean isEarly) throws SiteToolException
- Throws:
SiteToolException
-
getParentProject
public org.apache.maven.project.MavenProject getParentProject(org.apache.maven.project.MavenProject aProject, java.util.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 thereactorProjects
parameters 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:
getParentProject
in 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, java.util.Locale locale, org.apache.maven.project.MavenProject project, org.apache.maven.project.MavenProject parentProject, boolean keepInheritedRefs)
Populate the pre-definedparent
menu 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, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, boolean keepInheritedRefs) throws SiteToolException, java.io.IOException
Populate the pre-definedmodules
menu 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 anyjava.io.IOException
-
getModuleFromReactor
private static org.apache.maven.project.MavenProject getModuleFromReactor(org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, java.lang.String module) throws java.io.IOException
- Throws:
java.io.IOException
-
populateReportsMenu
public void populateReportsMenu(DecorationModel decorationModel, java.util.Locale locale, java.util.Map<java.lang.String,java.util.List<org.apache.maven.reporting.MavenReport>> categories)
Populate the pre-definedreports
menu 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:
populateReportsMenu
in 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:
MavenReport.CATEGORY_PROJECT_INFORMATION
,MavenReport.CATEGORY_PROJECT_REPORTS
-
getSiteLocales
public java.util.List<java.util.Locale> getSiteLocales(java.lang.String locales)
Extracts from a comma-separated list the locales that are available insite-tool
resource bundle. Notice thatdefault
value will be changed to the default locale of the JVM.- Specified by:
getSiteLocales
in 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
private java.util.Locale codeToLocale(java.lang.String localeCode)
Converts a locale code like "en", "en_US" or "en_US_win" to ajava.util.Locale
object.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:
- java.util.Locale#getDefault()
-
getNormalizedPath
protected static java.lang.String getNormalizedPath(java.lang.String path)
- Parameters:
path
- could be null.- Returns:
- the path normalized, i.e. by eliminating "/../" and "/./" in the path.
- See Also:
FilenameUtils.normalize(String)
-
resolveSiteDescriptor
private java.io.File resolveSiteDescriptor(org.apache.maven.project.MavenProject project, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> repositories, java.util.Locale locale) throws java.io.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:
java.io.IOException
- if anyorg.apache.maven.artifact.resolver.ArtifactResolutionException
- if anyorg.apache.maven.artifact.resolver.ArtifactNotFoundException
- if any
-
getDecorationModel
private java.util.Map.Entry<DecorationModel,org.apache.maven.project.MavenProject> getDecorationModel(int depth, java.io.File siteDirectory, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.apache.maven.artifact.repository.ArtifactRepository localRepository, java.util.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
private DecorationModel readDecorationModel(java.lang.String siteDescriptorContent) throws SiteToolException
- Parameters:
siteDescriptorContent
- not null- Returns:
- the decoration model object
- Throws:
SiteToolException
- if any
-
decorationModelToString
private java.lang.String decorationModelToString(DecorationModel decoration) throws SiteToolException
- Throws:
SiteToolException
-
buildRelativePath
private static java.lang.String buildRelativePath(java.lang.String toPath, java.lang.String fromPath, char separatorChar)
-
appendMenuItem
private void appendMenuItem(org.apache.maven.project.MavenProject project, Menu menu, java.lang.String name, java.lang.String href, java.lang.String defaultHref)
- Parameters:
project
- not nullmenu
- not nullname
- not nullhref
- could be nulldefaultHref
- not null
-
createCategoryMenu
private MenuItem createCategoryMenu(java.lang.String name, java.lang.String href, java.util.List<org.apache.maven.reporting.MavenReport> categoryReports, java.util.Locale locale)
- Parameters:
name
- not nullhref
- not nullcategoryReports
- not nulllocale
- not null- Returns:
- the menu item object
-
isEmptyList
private static boolean isEmptyList(java.util.List<?> list)
Convenience method.- Parameters:
list
- could be null- Returns:
- true if the list is
null
or empty
-
getDistMgmntSiteUrl
private static java.lang.String getDistMgmntSiteUrl(org.apache.maven.project.MavenProject project)
Return distributionManagement.site.url if defined, null otherwise.- Parameters:
project
- not null- Returns:
- could be null
-
getDistMgmntSiteUrl
private static java.lang.String getDistMgmntSiteUrl(org.apache.maven.model.DistributionManagement distMgmnt)
-
urlEncode
private static java.lang.String urlEncode(java.lang.String url)
-
checkNotNull
private void checkNotNull(java.lang.String name, java.lang.Object value)
-
isMaven3OrMore
private static boolean isMaven3OrMore()
Check the current Maven version to see if it's Maven 3.0 or newer.
-
getMavenVersion
private static java.lang.String getMavenVersion()
-
-