Issue Details (XML | Word | Printable)

Key: MNG-3244
Type: Bug Bug
Status: Reopened Reopened
Priority: Major Major
Assignee: Brian Fox
Reporter: Jacob Robertson
Votes: 23
Watchers: 23
Operations

If you were logged in you would be able to see more operations.
Maven 2

inherited site url not properly handling parameters

Created: 30/May/06 09:54 AM   Updated: 24/Nov/08 12:47 AM
Component/s: Inheritance and Interpolation, Sites & Reporting
Affects Version/s: 2.0.7
Fix Version/s: 3.0-alpha-3

Time Tracking:
Not Specified

File Attachments: 1. Text File fix-inherited-site-url.patch (3 kB)
2. Text File guide-site.patch (4 kB)

Issue Links:
Related
 
Supercedes
 


 Description  « Hide
Here is the test case to reroduce this problem. Take the following two pom.xml files

<?xml version="1.0" encoding="UTF-8"?>
<project>
<groupId>org.bar</groupId>
<artifactId>foo</artifactId>
<name>foo</name>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>

<distributionManagement>
<site>
<id>foo-site</id>
<url>file://C:/Documents and Settings/foo/.m2/site/${project.artifactId}</url>
</site>
</distributionManagement>
</project>

<?xml version="1.0" encoding="UTF-8"?>
<project>
<groupId>org.bar</groupId>
<artifactId>baz</artifactId>
<name>baz</name>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>foo</artifactId>
<groupId>org.bar</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
</project>

And run the site-deploy goal on each. What you get under the site directory is this

  • site
    /- foo
    ---/site docs
    /- baz
    --/ baz (extra directory)
      • ---/site docs

This is the simplest test case. In the case where I have a "grandparent" pom, the site directory uses the grandparent/parent as the path to the site, and doesn't use the actual artifactId of the artifact I'm creating the site for.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Joe Cool added a comment - 26/Sep/06 03:38 AM
I hereby kindly ask you to fix the bug.

I really have problems convincing my colleagues to switch to Maven when such a bug is not fixed for month.


Steffan added a comment - 26/Sep/06 08:50 AM
The issue origins seems to be the DefaultModelInheritanceAssembler.class wich automatically adds the parents artifactId no matter what.
According to the site-plugin in documentation the inheritance of the parents artifactId can enabled by adding a trailing / to the url.
But the InheritanceModel doesnt apply this rule.

Details on: http://maven.apache.org/guides/mini/guide-site.html
Note: the trailing slash in the URL above indicates that any subprojects that inherit this value should append their artifact ID to the path instead of using it as-is.

My solution, the method assembleDistributionInheritence(...) should be modified like this:

...
if ( childDistMgmt.getSite() == null )
{
if ( parentDistMgmt.getSite() != null )
{
Site site = new Site();
childDistMgmt.setSite( site );
site.setId( parentDistMgmt.getSite().getId() );
site.setName( parentDistMgmt.getSite().getName() );
site.setUrl( parentDistMgmt.getSite().getUrl() );
// modification, add the .endWith("/") to the condition
if ( site.getUrl() != null && site.getUrl().endsWith( "/" ) )

{ site.setUrl( appendPath( site.getUrl(), child.getArtifactId(), appendPaths ) ); }

}
}
...



Brian Fox added a comment - 17/Oct/07 10:12 PM
Thanks for the patch. I updated it to handle \ in the path and another small issue I found while testing.

Brian Fox added a comment - 24/Oct/07 07:17 PM
This patch breaks existing behavior (the docs are wrong).

William Ferguson added a comment - 08/Nov/07 10:10 PM
Brian, we all seem to want this fix, but don't want to break existing behaviour (however bizarre it may be).

The proper solution seems to be to add a POM attribute/element like either:

  • use-inherited-urls with a default of false
  • append-artifactId-to-parent-urls with a default of true
    But this requires a change to the POM schema which I suspect will be much harder to organise..

A temporary solution might be to do the same thing using well-documented POM properties, eg

  • mng-3244-use-inherited-urls with a default of false
  • mng-3244-append-artifactId-to-parent-urls with a default of true
    And when (hopefully not if) the POM schema is changed to accomodate the proper solution the implementation can be readily switched from one to the other and even handle fallback and notification of the appropriate configuration.

Benjamin Bentmann added a comment - 11/Nov/07 06:03 AM

This patch breaks existing behavior (the docs are wrong).

Well, then you might find this patch useful, intended to save users from confusion and providing some further tweaks to the guide. It's one thing to have a controversal behavior but it's definitively a bad thing to have incorrect documentation.


Brian Fox added a comment - 27/Nov/07 11:22 AM
Site patch is applied.

John Allen added a comment - 31/Dec/07 12:33 PM
remember that the site distro URL and the project URL are related. If you add the documented but missing feature of being '/' aware for one of them (i.e. as you have with this patch and its handling of site distro url) you will need to add the same feature to the project url assembly.

We have had to declare explicit project.url and distroManagement.site.url elements in EVERY pom of our multi-module proejcts because we also use real identifying information in these URLS, namely the ${project.groupId}/${project.artifactId}/${project.version}


John Allen added a comment - 02/Jan/08 03:17 PM - edited
After playing with some patch some more i came across another problem beyond the one mentioned above. You need to ensure that the trailing slash is propagated to the child projects URLs (distroManagement.site.url and project.url) otherwise the logic based upon the presence of the trailing slash stop working. i.e. if you call appendPaths you must ensure that the resulting path ends with a '/'.

Stefan Seidel added a comment - 21/Feb/08 05:01 AM
Will this also be implemented for the SCM URLs and the various other places where the artifactid is automatically appended? Because this bug here supercedes MNG-2290, which supercedes MNG-2219, which is about SCM URLs. And can someone, please, document that? Because a guide is not a place to put such an important piece of information. Maybe the right place would be the docs for the pom.xml structure?

Jens Riboe added a comment - 23/Feb/08 04:52 AM
[I sent this comment to the list, without any repsonse, so I decided to put them here - where they belong]

As I understand it; the current rule implements implicit URLs as
${parent.url}/${project.artifactId}

For example:
<scm>
<connection>${parentPOM.scm.connection}/${project.artifactId}</connection>
...
/scm>
Where parentPOM is a made-up symbol denoting an upward search for the pom property that follows (scm.connection).

So, how about the following suggestion:
The Super POM contains this kind of definition for all URLs where this rule applies today. When the effective POM
is computed for a sub-project it uses the "closest" url definition that contains the symbol parentPOM. If none is
found expect the def in super pom, this one is used and the rule applies as it always has.

On the other hand, if one decides to put an url expression containing parentPOM into a POM of type 'pom',
then there is a new definition and will be used. That means, we have a way to define how sub-project urls should
be constructed. I would be delighted if I could define an expression like
${parentPOM.scm.connection}/${project.name}/trunk

There is a residual problem, however: I cannot define both an url expansion expression and an actual url expression
that is intended to be used in sub-projects. The easiest solution, is just to have two organization poms, the top-most
pom contains the url expansion expressions (overriding the rule from the super pom) and the one beneath is the
original org pom, containing actual urls that will be used in the expansions further down.

I'm convinced there are other more elegant solutions. However, the suggestion above would be fairly easy to implement
without breaking existing code and poms (or require a POM version increment), but still provide a way for org-pom
designers to tweak the url expansions the way they want.

Comments / Objections ???


Brian Fox added a comment - 28/Feb/08 08:21 PM
There isn't a way that i know of to refer to a value in the parent pom. This would require defining a whole new property and is more than I think we want to do in 2.0.x.

Brian Fox added a comment - 03/Mar/08 12:05 PM

Brian Fox added a comment - 11/Mar/08 02:05 PM
There seems to be no solution available to fix this in 2.0.x

Kenneth Flynn added a comment - 24/Nov/08 12:47 AM
I'm fairly new to Maven, but I find the default behavior for all URLs very confusing. I understand the desired behavior, but many projects are just not arranged like the default behavior implies. The same URL alteration happens for SCM urls, the overall project URL, etc. I had initially created a corporate parent POM that I had hoped could work about 85% of our SVN repos by default, but I will have to override every one in the actual POM for each project (the suggested workaround).

I would strongly argue for a change to the POM to be able to turn this off globally (not just for site URLs). I'd prefer for that to be the default (I think the current behavior violates the principle of least surprise), but that's water under the bridge in terms of compatibility at this point. We really need a way of turning this off though--I really think it will lead to simpler POMs.