jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Maven 2.x and 3.x Site Plugin
  • MSITE-245

parent filesystem site.xml is never be found

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 2.0-beta-5
  • Fix Version/s: None
  • Component/s: inheritance
  • Labels:
    None
  • Environment:
    2.0.7
  • Patch Submitted:
    Yes

Description

The current approach used by the getSiteDescriptorFile(File, Locale) is wrong as the basedir passed in to it is not just the project's own basedir, it's potentially a parent project's basedir and thus the previous code makes no sense as we would need to add on the parent's site.xml site directory and then try and find the relative path to it and as there's no way (that I know of) of a) finding that out from the parent project's object model (even if we passed it in) and b) the current code does not append anything to the passed in basedir so is always looking for a site.xml in the parents root directory. What's more the use of a relative path here is pointless too as we simply read in the descriptor file, not persist it into links where relativePaths are useful.

Current code:

protected File getSiteDescriptorFile( File basedir, Locale locale )
    {
       String relativePath = getRelativePath( siteDirectory.getAbsolutePath(), basedir.getAbsolutePath() );

        File siteDescriptor = new File( relativePath, "site_" + locale.getLanguage() + ".xml" );

        if ( !siteDescriptor.exists() )
        {
            siteDescriptor = new File( relativePath, "site.xml" );
        }
        return siteDescriptor;
    }

Fixed code

protected File getSiteDescriptorFile( File basedir, Locale locale )
    {
        String sitePath;
        
        if ( basedir.equals( project.getBasedir() ))
        {
            // it's this project's basedir so use our siteDirectory (allows this project
            // to use a custom site location)
            
            sitePath = siteDirectory.getAbsolutePath();
        }
        else
        {
            // it's not this project's basedir so it must be one of our parent's,
            // so we'll just have to assume they store their site.xml in the
            // standard location (src/site)
            
            sitePath = basedir.getAbsolutePath() + "/src/site";
        }
        
        File siteDescriptor = new File( sitePath, "site_" + locale.getLanguage() + ".xml" );

        if ( !siteDescriptor.exists() )
        {
            siteDescriptor = new File( sitePath, "site.xml" );
        }

        return siteDescriptor;
  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    site-patch.txt
    18/Jul/07 3:36 PM
    2 kB
    John Allen

Issue Links

is related to

Bug - A problem which impairs or prevents the functions of the product. MSITE-81 Site descriptor resolution never falls back to site.xml

  • Critical - Crashes, loss of data, severe memory leak.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
is superceded by

Bug - A problem which impairs or prevents the functions of the product. MSHARED-18 Inheritance of elements from site descriptor quite broken

  • Critical - Crashes, loss of data, severe memory leak.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
John Allen added a comment - 19/Jul/07 5:46 AM

It's actually a fault with the way the path is built when trying to location a parent's site_en.xml or site.xml via the passed in basedir. I expect MSITE-81 fault is actually the fault described here.

Show
John Allen added a comment - 19/Jul/07 5:46 AM It's actually a fault with the way the path is built when trying to location a parent's site_en.xml or site.xml via the passed in basedir. I expect MSITE-81 fault is actually the fault described here.
Hide
Permalink
John Casey added a comment - 14/Aug/07 2:13 PM

John, do you think we could use the relativePath that you calculate at the top in conjunction with project.getBasedir() in cases where the given basedir points to the wrong location? This would effectively reorient that siteDirectory to the proper basedir with the proper relative path.

I only ask because it looks like you started down this road (in the patch), but then there's a comment about assuming a standard location...I'd like to take advantage of any lessons you learned when making this patch.

Show
John Casey added a comment - 14/Aug/07 2:13 PM John, do you think we could use the relativePath that you calculate at the top in conjunction with project.getBasedir() in cases where the given basedir points to the wrong location? This would effectively reorient that siteDirectory to the proper basedir with the proper relative path. I only ask because it looks like you started down this road (in the patch), but then there's a comment about assuming a standard location...I'd like to take advantage of any lessons you learned when making this patch.
Hide
Permalink
John Allen added a comment - 15/Aug/07 10:48 AM - edited

I'm not sure I exactly follow you John, I've had a look at the patch and the opening line in it is to remove the existing relativePath logic altogether:

-        String relativePath = getRelativePath( siteDirectory.getAbsolutePath(), basedir.getAbsolutePath() );

When i think about this method I see a very simple purpose, namely to try and find a site+locale+xml file for the passed in project, and if a locale specific one can not be found, to assume that a default site.xml will exist. Clients of the method obviously know that the returned File object may or may not exist so it's not necessary for this methods to check for that.

Ideally we would pass in the MavenProject object we're interrogating here rather than it's basedir as this would provide more opportunities in the future to try and find the real site directory for the operand project, however as that is not a model parameter and is instead a configuration parameter of the site plugin itself, we would need a way of looking at the configuration settings of the site plugin for the passed in project and I don't think we have a ppropriate way of doing this at the moment.

This method, as you know, is used for two things. One, to get this project's site.xml (prefering a locale based one) and secondly to try and find other project's site.xml files as the client code tries to peek up the project inheritance hierarchy. Neither of these uses cases seem to warrant a relative path approach, after all there is no need to use a relative path when we have explicit paths to work with and, once we find the file, (or not as the case maybe) we instantiate a File object from it, so we loose any interest in whether the File object's location (i.e. the site.xml filename and path) was found via a relative path approach or not.

The method does have one concession to supporting a site.xml file that is being stored in a 'non default' location but that only comes when looking for 'this' project's site.xml file as we have access to this project's site plugin configuration.

We could take a stance that when trying to find any project's site xml file we assume it will use the same site directory location that this project is using:

protected File getSiteDescriptorFile( File basedir, Locale locale )
 {
        String sitePath;

        if ( basedir.equals( project.getBasedir() ))
        {
            // it's this project's basedir so use our siteDirectory 
            
            sitePath = siteDirectory.getAbsolutePath();
        }
        else
        {
            // it's not this project's basedir so it must be one of our parent's
            // so lets assume they store their site.xml in the same location relative
            // to their basedir as we do

           String ourRelativeSiteDirectory = siteDirectory.getAbsolutePath().substring(
                        0, project.getBasedir().getAbsolutePath().length() );
                
           sitePath = basedir.getAbsolutePath() + "/" + ourRelativeSiteDirectory;
        }          
        
        File siteDescriptor = new File( sitePath, "site_" + locale.getLanguage() + ".xml" );

        if ( !siteDescriptor.exists() )
        {
            siteDescriptor = new File( sitePath, "site.xml" );
        }

        return siteDescriptor;

Thus if this project stores its site files in ${basedir}/src/foo then we will try and find all site.xml files in the directory src/foo. In fact we could go a step further and try that first and if we fail then fall back to trying the standard default location of src/site.

Don't know if I've helped here

ps. The code block above was written in JIRA and has not been tested, its just for illustration

Show
John Allen added a comment - 15/Aug/07 10:48 AM - edited I'm not sure I exactly follow you John, I've had a look at the patch and the opening line in it is to remove the existing relativePath logic altogether:
-        String relativePath = getRelativePath( siteDirectory.getAbsolutePath(), basedir.getAbsolutePath() );
When i think about this method I see a very simple purpose, namely to try and find a site+locale+xml file for the passed in project, and if a locale specific one can not be found, to assume that a default site.xml will exist. Clients of the method obviously know that the returned File object may or may not exist so it's not necessary for this methods to check for that. Ideally we would pass in the MavenProject object we're interrogating here rather than it's basedir as this would provide more opportunities in the future to try and find the real site directory for the operand project, however as that is not a model parameter and is instead a configuration parameter of the site plugin itself, we would need a way of looking at the configuration settings of the site plugin for the passed in project and I don't think we have a ppropriate way of doing this at the moment. This method, as you know, is used for two things. One, to get this project's site.xml (prefering a locale based one) and secondly to try and find other project's site.xml files as the client code tries to peek up the project inheritance hierarchy. Neither of these uses cases seem to warrant a relative path approach, after all there is no need to use a relative path when we have explicit paths to work with and, once we find the file, (or not as the case maybe) we instantiate a File object from it, so we loose any interest in whether the File object's location (i.e. the site.xml filename and path) was found via a relative path approach or not. The method does have one concession to supporting a site.xml file that is being stored in a 'non default' location but that only comes when looking for 'this' project's site.xml file as we have access to this project's site plugin configuration. We could take a stance that when trying to find any project's site xml file we assume it will use the same site directory location that this project is using:
protected File getSiteDescriptorFile( File basedir, Locale locale )
 {
        String sitePath;

        if ( basedir.equals( project.getBasedir() ))
        {
            // it's this project's basedir so use our siteDirectory 
            
            sitePath = siteDirectory.getAbsolutePath();
        }
        else
        {
            // it's not this project's basedir so it must be one of our parent's
            // so lets assume they store their site.xml in the same location relative
            // to their basedir as we do

           String ourRelativeSiteDirectory = siteDirectory.getAbsolutePath().substring(
                        0, project.getBasedir().getAbsolutePath().length() );
                
           sitePath = basedir.getAbsolutePath() + "/" + ourRelativeSiteDirectory;
        }          
        
        File siteDescriptor = new File( sitePath, "site_" + locale.getLanguage() + ".xml" );

        if ( !siteDescriptor.exists() )
        {
            siteDescriptor = new File( sitePath, "site.xml" );
        }

        return siteDescriptor;
Thus if this project stores its site files in ${basedir}/src/foo then we will try and find all site.xml files in the directory src/foo. In fact we could go a step further and try that first and if we fail then fall back to trying the standard default location of src/site. Don't know if I've helped here ps. The code block above was written in JIRA and has not been tested, its just for illustration
Hide
Permalink
Lukas Theussl added a comment - 01/Aug/09 2:43 AM

I believe this has been fixed with MSHARED-18.

Show
Lukas Theussl added a comment - 01/Aug/09 2:43 AM I believe this has been fixed with MSHARED-18.

People

  • Assignee:
    Lukas Theussl
    Reporter:
    John Allen
Vote (0)
Watch (2)

Dates

  • Created:
    18/Jul/07 3:36 PM
    Updated:
    01/Aug/09 2:43 AM
    Resolved:
    01/Aug/09 2:43 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.