Class DefaultSiteTool

  • All Implemented Interfaces:
    SiteTool

    @Singleton
    @Named
    public class DefaultSiteTool
    extends java.lang.Object
    implements SiteTool
    Default implementation of the site tool.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager
      The component used for getting artifact handlers.
      protected SiteModelInheritanceAssembler assembler
      The component for assembling inheritance.
      protected org.codehaus.plexus.i18n.I18N i18n
      Internationalization.
      private static org.slf4j.Logger LOGGER  
      protected org.eclipse.aether.RepositorySystem repositorySystem
      The component that is used to resolve additional required artifacts.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultSiteTool()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated 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 java.util.Locale codeToLocale​(java.lang.String localeCode)
      Converts a locale code like "en", "en_US" or "en_US_win" to a java.util.Locale object.
      private Banner convertBanner​(Banner oldBanner)  
      private Image convertImage​(java.lang.String src, java.lang.String position, java.lang.String height, java.lang.String width, java.lang.String border, java.lang.String alt)  
      private LinkItem convertLinkItem​(LinkItem oldLinkItem)  
      private java.util.List<MenuItem> convertMenuItems​(java.util.List<MenuItem> oldMenuItems)  
      private SiteModel convertOldToNewSiteModel​(DecorationModel oldModel)  
      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 org.eclipse.aether.resolution.ArtifactRequest createSiteDescriptorArtifactRequest​(org.apache.maven.project.MavenProject project, java.lang.String localeStr, java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories)  
      private void deletePseudoSiteDescriptorMarkerFile​(org.eclipse.aether.RepositorySystemSession repoSession, org.eclipse.aether.resolution.ArtifactRequest request)  
      private SiteModel getDefaultSiteModel()  
      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 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)  
      private static org.apache.maven.model.Plugin getPlugin​(org.apache.maven.project.MavenProject project, java.lang.String pluginId)  
      private static java.lang.String getPluginParameter​(org.apache.maven.project.MavenProject project, java.lang.String pluginId, java.lang.String param)  
      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)
      Deprecated.
      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.eclipse.aether.RepositorySystemSession repoSession, java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories, 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 in site-tool resource bundle.
      private java.util.Map.Entry<SiteModel,​org.apache.maven.project.MavenProject> getSiteModel​(int depth, java.io.File siteDirectory, java.util.Locale locale, org.apache.maven.project.MavenProject project, org.eclipse.aether.RepositorySystemSession repoSession, java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories)  
      SiteModel getSiteModel​(java.io.File siteDirectory, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, org.eclipse.aether.RepositorySystemSession repoSession, java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories)
      Get a site model for a project.
      org.apache.maven.artifact.Artifact getSkinArtifactFromRepository​(org.eclipse.aether.RepositorySystemSession repoSession, java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories, Skin skin)
      Get a skin artifact from one of the repositories.
      private static boolean isEmptyList​(java.util.List<?> list)
      Convenience method.
      private boolean isOldSiteModel​(java.lang.String siteDescriptorContent)  
      private void populateModulesMenu​(SiteModel siteModel, java.util.Locale locale, org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.project.MavenProject> reactorProjects, boolean keepInheritedRefs)
      Populate the pre-defined modules menu of the model, if used through <menu ref="modules"/>.
      private void populateParentMenu​(SiteModel siteModel, java.util.Locale locale, org.apache.maven.project.MavenProject project, org.apache.maven.project.MavenProject parentProject, boolean keepInheritedRefs)
      Populate the pre-defined parent menu of the site model, if used through <menu ref="parent"/>.
      void populateReportsMenu​(SiteModel siteModel, java.util.Locale locale, java.util.Map<java.lang.String,​java.util.List<org.apache.maven.reporting.MavenReport>> categories)
      Populate the pre-defined reports menu of the site model, if used through <menu ref="reports"/>.
      private SiteModel readSiteModel​(java.lang.String siteDescriptorContent, org.apache.maven.project.MavenProject project, java.util.Locale locale)  
      private java.io.File resolveSiteDescriptor​(org.apache.maven.project.MavenProject project, org.eclipse.aether.RepositorySystemSession repoSession, java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories, java.util.Locale locale)  
      private java.lang.String siteModelToString​(SiteModel siteModel)  
      private static java.lang.String urlEncode​(java.lang.String url)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • repositorySystem

        @Inject
        protected org.eclipse.aether.RepositorySystem repositorySystem
        The component that is used to resolve additional required artifacts.
      • artifactHandlerManager

        @Inject
        private org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager
        The component used for getting artifact handlers.
      • i18n

        @Inject
        protected org.codehaus.plexus.i18n.I18N i18n
        Internationalization.
    • Constructor Detail

      • DefaultSiteTool

        public DefaultSiteTool()
    • Method Detail

      • getSkinArtifactFromRepository

        public org.apache.maven.artifact.Artifact getSkinArtifactFromRepository​(org.eclipse.aether.RepositorySystemSession repoSession,
                                                                                java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories,
                                                                                Skin skin)
                                                                         throws SiteToolException
        Get a skin artifact from one of the repositories.
        Specified by:
        getSkinArtifactFromRepository in interface SiteTool
        Parameters:
        repoSession - the repository system session, not null.
        remoteProjectRepositories - the Maven remote project repositories, not null.
        skin - the Skin model, not null.
        Returns:
        the Skin artifact defined in a SiteModel from a given project
        Throws:
        SiteToolException - if any
      • getRelativePath

        @Deprecated
        public java.lang.String getRelativePath​(java.lang.String to,
                                                java.lang.String from)
        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:
        getRelativePath in interface SiteTool
        Parameters:
        to - the to url of file as string
        from - the from url of file as string
        Returns:
        a relative path from from to to.
      • 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 interface SiteTool
        Parameters:
        siteDirectory - the site directory, not null
        locale - the locale wanted for the site descriptor, not null. Most specific to least specific lookup from site_language_country_variant.xml, site_language_country.xml, site_language.xml}, to site.xml as last resort for Locale.ROOT, if provided locale defines a variant and/or a country and/or a language.
        Returns:
        the most specific site descriptor file for the given locale
      • getSiteDescriptorFromRepository

        java.io.File getSiteDescriptorFromRepository​(org.apache.maven.project.MavenProject project,
                                                     org.eclipse.aether.RepositorySystemSession repoSession,
                                                     java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories,
                                                     java.util.Locale locale)
                                              throws SiteToolException
        Get a site descriptor from one of the repositories.
        Parameters:
        project - the Maven project, not null.
        repoSession - the repository system session, not null.
        remoteProjectRepositories - the Maven remote project repositories, not null.
        locale - the locale wanted for the site descriptor, not null. See getSiteDescriptor(File, Locale) for details.
        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
      • getSiteModel

        public SiteModel getSiteModel​(java.io.File siteDirectory,
                                      java.util.Locale locale,
                                      org.apache.maven.project.MavenProject project,
                                      java.util.List<org.apache.maven.project.MavenProject> reactorProjects,
                                      org.eclipse.aether.RepositorySystemSession repoSession,
                                      java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories)
                               throws SiteToolException
        Get a site model for a project.
        Specified by:
        getSiteModel in interface SiteTool
        Parameters:
        siteDirectory - the site directory, may be null if project from repository
        locale - the locale used for the i18n in SiteModel, not null. See SiteTool.getSiteDescriptor(File, Locale) for details.
        project - the Maven project, not null.
        reactorProjects - the Maven reactor projects, not null.
        repoSession - the repository system session, not null.
        remoteProjectRepositories - the Maven remote project repositories, not null.
        Returns:
        the SiteModel object corresponding to the site.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 like encoding.

        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 interface SiteTool
        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
      • populateParentMenu

        private void populateParentMenu​(SiteModel siteModel,
                                        java.util.Locale locale,
                                        org.apache.maven.project.MavenProject project,
                                        org.apache.maven.project.MavenProject parentProject,
                                        boolean keepInheritedRefs)
        Populate the pre-defined parent menu of the site model, if used through <menu ref="parent"/>.
        Parameters:
        siteModel - the Doxia Sitetools SiteModel, not null.
        locale - the locale used for the i18n in SiteModel, not null.
        project - a Maven project, not null.
        parentProject - a Maven parent project, not null.
        keepInheritedRefs - used for inherited references.
      • populateModulesMenu

        private void populateModulesMenu​(SiteModel siteModel,
                                         java.util.Locale locale,
                                         org.apache.maven.project.MavenProject project,
                                         java.util.List<org.apache.maven.project.MavenProject> reactorProjects,
                                         boolean keepInheritedRefs)
                                  throws SiteToolException,
                                         java.io.IOException
        Populate the pre-defined modules menu of the model, if used through <menu ref="modules"/>.
        Parameters:
        siteModel - the Doxia Sitetools SiteModel, not null.
        locale - the locale used for the i18n in SiteModel, not null.
        project - a Maven project, not null.
        reactorProjects - the Maven reactor projects, not null.
        keepInheritedRefs - used for inherited references.
        Throws:
        SiteToolException - if any
        java.io.IOException
      • getModuleFromReactor

        private 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​(SiteModel siteModel,
                                        java.util.Locale locale,
                                        java.util.Map<java.lang.String,​java.util.List<org.apache.maven.reporting.MavenReport>> categories)
        Populate the pre-defined reports menu of the site 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 interface SiteTool
        Parameters:
        siteModel - the Doxia Sitetools SiteModel, not null.
        locale - the locale used for the i18n in SiteModel, not null. See SiteTool.getSiteDescriptor(File, Locale) for details.
        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 in site-tool resource bundle.
        Specified by:
        getSiteLocales in interface SiteTool
        Parameters:
        locales - A comma separated list of locales
        Returns:
        a list of Locales.
      • codeToLocale

        private java.util.Locale codeToLocale​(java.lang.String localeCode)
        Converts a locale code like "en", "en_US" or "en_US_win" to a java.util.Locale object.

        If localeCode = system, return the current value of the default locale for this instance of the Java Virtual Machine.

        If localeCode = default, return the root locale.

        Parameters:
        localeCode - the locale code string.
        Returns:
        a java.util.Locale object instanced or null if errors occurred
        See Also:
        Locale.getDefault(), SiteTool.DEFAULT_LOCALE
      • 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)
      • createSiteDescriptorArtifactRequest

        private org.eclipse.aether.resolution.ArtifactRequest createSiteDescriptorArtifactRequest​(org.apache.maven.project.MavenProject project,
                                                                                                  java.lang.String localeStr,
                                                                                                  java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories)
        Parameters:
        project - not null
        localeStr - not null
        remoteProjectRepositories - not null
        Returns:
        the site descriptor artifact request
      • resolveSiteDescriptor

        private java.io.File resolveSiteDescriptor​(org.apache.maven.project.MavenProject project,
                                                   org.eclipse.aether.RepositorySystemSession repoSession,
                                                   java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories,
                                                   java.util.Locale locale)
                                            throws org.eclipse.aether.resolution.ArtifactResolutionException
        Parameters:
        project - not null
        repoSession - the repository system session not null
        remoteProjectRepositories - not null
        locale - not null
        Returns:
        the resolved site descriptor or null if not found in repositories.
        Throws:
        org.eclipse.aether.resolution.ArtifactResolutionException - if any
      • deletePseudoSiteDescriptorMarkerFile

        private void deletePseudoSiteDescriptorMarkerFile​(org.eclipse.aether.RepositorySystemSession repoSession,
                                                          org.eclipse.aether.resolution.ArtifactRequest request)
      • getSiteModel

        private java.util.Map.Entry<SiteModel,​org.apache.maven.project.MavenProject> getSiteModel​(int depth,
                                                                                                        java.io.File siteDirectory,
                                                                                                        java.util.Locale locale,
                                                                                                        org.apache.maven.project.MavenProject project,
                                                                                                        org.eclipse.aether.RepositorySystemSession repoSession,
                                                                                                        java.util.List<org.eclipse.aether.repository.RemoteRepository> remoteProjectRepositories)
                                                                                                 throws SiteToolException
        Parameters:
        depth - depth of project
        siteDirectory - , can be null if project.basedir is null, ie POM from repository
        locale - not null
        project - not null
        repoSession - not null
        remoteProjectRepositories - not null
        Returns:
        the site model depending the locale and the parent project
        Throws:
        SiteToolException - if any
      • readSiteModel

        private SiteModel readSiteModel​(java.lang.String siteDescriptorContent,
                                        org.apache.maven.project.MavenProject project,
                                        java.util.Locale locale)
                                 throws SiteToolException
        Parameters:
        siteDescriptorContent - not null
        Returns:
        the site model object
        Throws:
        SiteToolException - if any
      • convertBanner

        private Banner convertBanner​(Banner oldBanner)
      • convertImage

        private Image convertImage​(java.lang.String src,
                                   java.lang.String position,
                                   java.lang.String height,
                                   java.lang.String width,
                                   java.lang.String border,
                                   java.lang.String alt)
      • convertMenuItems

        private java.util.List<MenuItem> convertMenuItems​(java.util.List<MenuItem> oldMenuItems)
      • isOldSiteModel

        private boolean isOldSiteModel​(java.lang.String siteDescriptorContent)
                                throws org.codehaus.plexus.util.xml.pull.XmlPullParserException,
                                       java.io.IOException
        Throws:
        org.codehaus.plexus.util.xml.pull.XmlPullParserException
        java.io.IOException
      • 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 null
        menu - not null
        name - not null
        href - could be null
        defaultHref - could be 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 null
        href - not null
        categoryReports - not null
        locale - 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)
      • getPlugin

        private static org.apache.maven.model.Plugin getPlugin​(org.apache.maven.project.MavenProject project,
                                                               java.lang.String pluginId)
        Parameters:
        project - the project
        pluginId - The id of the plugin
        Returns:
        The information about the plugin.
      • getPluginParameter

        private static java.lang.String getPluginParameter​(org.apache.maven.project.MavenProject project,
                                                           java.lang.String pluginId,
                                                           java.lang.String param)
        Parameters:
        project - the project
        pluginId - The pluginId
        param - The child which should be checked.
        Returns:
        The value of the dom tree.
      • urlEncode

        private static java.lang.String urlEncode​(java.lang.String url)