[ 
https://issues.apache.org/jira/browse/MRESOLVER-8?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Christian Schulte updated MRESOLVER-8:
--------------------------------------
    Description: 
The classes 'ScopeDependencySelector' and 'OptionalDependencySelector' 
inconsistently detected the mode of operation (direct or transitive). Whereas 
the 'ScopeDependencySelector' honours the kind of resolution having been 
requested (dependency vs. POM), the 'OptionalDependencySelector' does not 
honour this difference. As both classes implement the 'DependencySelector', 
they should select the mode of operation (direct vs. transitive) consistently.

This is what things looked liked before the fix:

{panel:title=ScopeDependencySelector}
{code}
public DependencySelector deriveChildSelector( DependencyCollectionContext 
context )
{
    if ( this.transitive || context.getDependency() == null )
    {
        return this;
    }

    return new ScopeDependencySelector( true, included, excluded );
}
{code}
{panel}

{panel:title=OptionalDependencySelector}
{code}
public DependencySelector deriveChildSelector( DependencyCollectionContext 
context )
{
    if ( depth >= 2 )
    {
        return this;
    }

    return new OptionalDependencySelector( depth + 1 );
}
{code}
{panel}

This is what both classes look like after the fix. No difference in mode 
selection any more.

{panel:title=ScopeDependencySelector}
{code}
public DependencySelector deriveChildSelector( DependencyCollectionContext 
context )
{
    ScopeDependencySelector child = this;

    if ( context.getDependency() != null && !child.transitive )
    {
        child = new ScopeDependencySelector( true, this.included, this.excluded 
);
    }
    if ( context.getDependency() == null && child.transitive )
    {
        child = new ScopeDependencySelector( false, this.included, 
this.excluded );
    }

    return child;
}
{code}
{panel}

{panel:title=OptionalDependencySelector}
{code}
public DependencySelector deriveChildSelector( DependencyCollectionContext 
context )
{
    OptionalDependencySelector child = this;

    if ( context.getDependency() != null && !child.transitive )
    {
        child = new OptionalDependencySelector( true );
    }
    if ( context.getDependency() == null && child.transitive )
    {
        child = new OptionalDependencySelector( false );
    }

    return child;
}
{code}
{panel}



  was:
The 'DefaultDependencyCollector' updates the state of the 
'DependencyCollectionContext' when recursively processing dependencies but does 
never return the context to the former state. This context is passed to various 
methods when deriving child components ('DependencyManager.deriveChildManager', 
'DependencySelector.deriveChildSelector', 
'DependencyTraverser.deriveChildTraverser', 'VersionFilter.deriveChildFilter') 
which fail to correctly detect the depth/transitivity of the context passed due 
to that context never getting reset after recursion.



> Direct dependencies incorrectly detected as transitive.
> -------------------------------------------------------
>
>                 Key: MRESOLVER-8
>                 URL: https://issues.apache.org/jira/browse/MRESOLVER-8
>             Project: Maven Resolver
>          Issue Type: Bug
>            Reporter: Christian Schulte
>            Assignee: Christian Schulte
>            Priority: Critical
>             Fix For: Maven Artifact Resolver 1.2.0
>
>
> The classes 'ScopeDependencySelector' and 'OptionalDependencySelector' 
> inconsistently detected the mode of operation (direct or transitive). Whereas 
> the 'ScopeDependencySelector' honours the kind of resolution having been 
> requested (dependency vs. POM), the 'OptionalDependencySelector' does not 
> honour this difference. As both classes implement the 'DependencySelector', 
> they should select the mode of operation (direct vs. transitive) consistently.
> This is what things looked liked before the fix:
> {panel:title=ScopeDependencySelector}
> {code}
> public DependencySelector deriveChildSelector( DependencyCollectionContext 
> context )
> {
>     if ( this.transitive || context.getDependency() == null )
>     {
>         return this;
>     }
>     return new ScopeDependencySelector( true, included, excluded );
> }
> {code}
> {panel}
> {panel:title=OptionalDependencySelector}
> {code}
> public DependencySelector deriveChildSelector( DependencyCollectionContext 
> context )
> {
>     if ( depth >= 2 )
>     {
>         return this;
>     }
>     return new OptionalDependencySelector( depth + 1 );
> }
> {code}
> {panel}
> This is what both classes look like after the fix. No difference in mode 
> selection any more.
> {panel:title=ScopeDependencySelector}
> {code}
> public DependencySelector deriveChildSelector( DependencyCollectionContext 
> context )
> {
>     ScopeDependencySelector child = this;
>     if ( context.getDependency() != null && !child.transitive )
>     {
>         child = new ScopeDependencySelector( true, this.included, 
> this.excluded );
>     }
>     if ( context.getDependency() == null && child.transitive )
>     {
>         child = new ScopeDependencySelector( false, this.included, 
> this.excluded );
>     }
>     return child;
> }
> {code}
> {panel}
> {panel:title=OptionalDependencySelector}
> {code}
> public DependencySelector deriveChildSelector( DependencyCollectionContext 
> context )
> {
>     OptionalDependencySelector child = this;
>     if ( context.getDependency() != null && !child.transitive )
>     {
>         child = new OptionalDependencySelector( true );
>     }
>     if ( context.getDependency() == null && child.transitive )
>     {
>         child = new OptionalDependencySelector( false );
>     }
>     return child;
> }
> {code}
> {panel}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to