maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From schu...@apache.org
Subject maven git commit: [MNG-6139] Addition of command line option 'legacy-dependency-management'.
Date Wed, 21 Dec 2016 16:47:00 GMT
Repository: maven
Updated Branches:
  refs/heads/master a4fe9ec79 -> 7e70c59e4


[MNG-6139] Addition of command line option 'legacy-dependency-management'.


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/7e70c59e
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/7e70c59e
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/7e70c59e

Branch: refs/heads/master
Commit: 7e70c59e43f112c12282de49d937e870c9545fc9
Parents: a4fe9ec
Author: Christian Schulte <schulte@apache.org>
Authored: Wed Dec 21 17:45:54 2016 +0100
Committer: Christian Schulte <schulte@apache.org>
Committed: Wed Dec 21 17:45:54 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/maven/DefaultMaven.java     | 43 +++++++++++---------
 .../java/org/apache/maven/RepositoryUtils.java  | 23 +++++++----
 .../execution/DefaultMavenExecutionRequest.java | 26 ++++++++++++
 .../maven/execution/MavenExecutionRequest.java  | 11 +++++
 .../DefaultRepositorySystemSessionFactory.java  |  7 ++++
 .../maven/project/DefaultProjectBuilder.java    |  1 +
 .../project/DefaultProjectBuildingRequest.java  | 22 ++++++++++
 .../maven/project/ProjectBuildingRequest.java   | 10 +++++
 .../java/org/apache/maven/cli/CLIManager.java   |  3 ++
 .../java/org/apache/maven/cli/MavenCli.java     |  9 +++-
 .../building/DefaultModelBuildingRequest.java   | 21 ++++++++++
 .../building/FilterModelBuildingRequest.java    | 15 ++++++-
 .../model/building/ModelBuildingRequest.java    | 10 +++++
 .../DefaultDependencyManagementInjector.java    | 27 ++++++++++--
 .../ArtifactDescriptorReaderDelegate.java       | 19 +++++----
 15 files changed, 207 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
index 6954e9b..d6f6e17 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -102,30 +102,35 @@ public class DefaultMaven
     {
         MavenExecutionResult result;
 
-        try
-        {
-            result = doExecute( request );
-        }
-        catch ( OutOfMemoryError e )
-        {
-            result = addExceptionToResult( new DefaultMavenExecutionResult(), e );
-        }
-        catch ( RuntimeException e )
+        synchronized ( RepositoryUtils.class )
         {
-            // TODO Hack to make the cycle detection the same for the new graph builder
-            if ( e.getCause() instanceof ProjectCycleException )
+            try
             {
-                result = addExceptionToResult( new DefaultMavenExecutionResult(), e.getCause()
);
+                RepositoryUtils.legacyDependencyManagement = request.isLegacyDependencyManagementRequested();
+                result = doExecute( request );
             }
-            else
+            catch ( OutOfMemoryError e )
             {
-                result = addExceptionToResult( new DefaultMavenExecutionResult(),
-                                               new InternalErrorException( "Internal error:
" + e, e ) );
+                result = addExceptionToResult( new DefaultMavenExecutionResult(), e );
+            }
+            catch ( RuntimeException e )
+            {
+                // TODO Hack to make the cycle detection the same for the new graph builder
+                if ( e.getCause() instanceof ProjectCycleException )
+                {
+                    result = addExceptionToResult( new DefaultMavenExecutionResult(), e.getCause()
);
+                }
+                else
+                {
+                    result = addExceptionToResult( new DefaultMavenExecutionResult(),
+                                                   new InternalErrorException( "Internal
error: " + e, e ) );
+                }
+            }
+            finally
+            {
+                legacySupport.setSession( null );
+                RepositoryUtils.legacyDependencyManagement = false;
             }
-        }
-        finally
-        {
-            legacySupport.setSession( null );
         }
 
         return result;

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
index 08749ea..d844254 100644
--- a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java
@@ -55,6 +55,15 @@ import org.eclipse.aether.util.repository.AuthenticationBuilder;
 public class RepositoryUtils
 {
 
+    /**
+     * Package private field set on every invocation of the
+     * {@link DefaultMaven#execute(org.apache.maven.execution.MavenExecutionRequest)}. A
very good example for why
+     * {@code public static} helper/utility/whatever methods are crap.
+     *
+     * @since 3.4.0
+     */
+    static boolean legacyDependencyManagement = false;
+
     private static String nullify( String string )
     {
         return ( string == null || string.length() <= 0 ) ? null : string;
@@ -320,14 +329,14 @@ public class RepositoryUtils
             exclusions.add( toExclusion( exclusion ) );
         }
 
-        Dependency result = new Dependency( artifact,
-                                            dependency.getScope(),
-                                            dependency.getOptional() != null
-                                                ? dependency.isOptional()
-                                                : null,
-                                            exclusions );
+        return RepositoryUtils.legacyDependencyManagement
+                   ? new Dependency( artifact, dependency.getScope(), dependency.isOptional(),
exclusions )
+                   : new Dependency( artifact, dependency.getScope(),
+                                     dependency.getOptional() != null
+                                         ? dependency.isOptional()
+                                         : null,
+                                     exclusions );
 
-        return result;
     }
 
     private static Exclusion toExclusion( org.apache.maven.model.Exclusion exclusion )

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
index d67061f..769bd3b 100644
--- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
+++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
@@ -163,6 +163,8 @@ public class DefaultMavenExecutionRequest
 
     private boolean useLegacyLocalRepositoryManager = false;
 
+    private boolean legacyDependencyManagementRequested = false;
+
     private Map<String, Object> data;
 
     public DefaultMavenExecutionRequest()
@@ -210,6 +212,7 @@ public class DefaultMavenExecutionRequest
         copy.setExecutionListener( original.getExecutionListener() );
         copy.setUseLegacyLocalRepository( original.isUseLegacyLocalRepository() );
         copy.setBuilderId( original.getBuilderId() );
+        copy.setLegacyDependencyManagementRequested( original.isLegacyDependencyManagementRequested()
);
         return copy;
     }
 
@@ -1105,6 +1108,9 @@ public class DefaultMavenExecutionRequest
             projectBuildingRequest.setProfiles( getProfiles() );
             projectBuildingRequest.setProcessPlugins( true );
             projectBuildingRequest.setBuildStartTime( getStartTime() );
+            projectBuildingRequest.
+                setLegacyDependencyManagementRequested( this.isLegacyDependencyManagementRequested()
);
+
         }
 
         return projectBuildingRequest;
@@ -1285,4 +1291,24 @@ public class DefaultMavenExecutionRequest
 
         return data;
     }
+
+    /**
+     * @since 3.4.0
+     */
+    @Override
+    public boolean isLegacyDependencyManagementRequested()
+    {
+        return this.legacyDependencyManagementRequested;
+    }
+
+    /**
+     * @since 3.4.0
+     */
+    @Override
+    public MavenExecutionRequest setLegacyDependencyManagementRequested( final boolean value
)
+    {
+        this.legacyDependencyManagementRequested = value;
+        return this;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
index 203b2b7..d758676 100644
--- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
+++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
@@ -442,4 +442,15 @@ public interface MavenExecutionRequest
      * @since 3.3.0
      */
     Map<String, Object> getData();
+
+    /**
+     * @since 3.4.0
+     */
+    boolean isLegacyDependencyManagementRequested();
+
+    /**
+     * @since 3.4.0
+     */
+    MavenExecutionRequest setLegacyDependencyManagementRequested( boolean value );
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
index 248a3b6..0253b5b 100644
--- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
+++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
@@ -58,6 +58,7 @@ import java.io.InputStream;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Properties;
+import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
 
 /**
  * @since 3.3.0
@@ -238,6 +239,12 @@ public class DefaultRepositorySystemSessionFactory
         mavenRepositorySystem.injectProxy( session, request.getPluginArtifactRepositories()
);
         mavenRepositorySystem.injectAuthentication( session, request.getPluginArtifactRepositories()
);
 
+        if ( request.isLegacyDependencyManagementRequested() )
+        {
+            session.setDependencyManager( new ClassicDependencyManager() );
+            session.getData().set( "maven.legacyDependencyManagement", Boolean.TRUE );
+        }
+
         return session;
     }
 

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
index 25124e4..e6692d8 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
@@ -272,6 +272,7 @@ public class DefaultProjectBuilder
         request.setBuildStartTime( configuration.getBuildStartTime() );
         request.setModelResolver( resolver );
         request.setModelCache( config.modelCache );
+        request.setLegacyDependencyManagementRequested( config.request.isLegacyDependencyManagementRequested()
);
 
         return request;
     }

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
index d42da04..fee94b7 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java
@@ -68,6 +68,8 @@ public class DefaultProjectBuildingRequest
 
     private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
 
+    private boolean legacyDependencyManagementRequested = false;
+
     public DefaultProjectBuildingRequest()
     {
         processPlugins = true;
@@ -100,6 +102,7 @@ public class DefaultProjectBuildingRequest
         setSystemProperties( request.getSystemProperties() );
         setUserProperties( request.getUserProperties() );
         setValidationLevel( request.getValidationLevel() );
+        setLegacyDependencyManagementRequested( request.isLegacyDependencyManagementRequested()
);
     }
 
     public MavenProject getProject()
@@ -344,4 +347,23 @@ public class DefaultProjectBuildingRequest
         return repositoryMerging;
     }
 
+    /**
+     * @since 3.4.0
+     */
+    @Override
+    public boolean isLegacyDependencyManagementRequested()
+    {
+        return this.legacyDependencyManagementRequested;
+    }
+
+    /**
+     * @since 3.4.0
+     */
+    @Override
+    public ProjectBuildingRequest setLegacyDependencyManagementRequested( final boolean value
)
+    {
+        this.legacyDependencyManagementRequested = value;
+        return this;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
index 17a53b1..2dc854f 100644
--- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
+++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java
@@ -185,6 +185,16 @@ public interface ProjectBuildingRequest
     ProjectBuildingRequest setResolveVersionRanges( boolean value );
 
     /**
+     * @since 3.4.0
+     */
+    boolean isLegacyDependencyManagementRequested();
+
+    /**
+     * @since 3.4.0
+     */
+    ProjectBuildingRequest setLegacyDependencyManagementRequested( boolean value );
+
+    /**
      * The possible merge modes for combining remote repositories.
      */
     enum RepositoryMerging

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
index f86f48b..7c01ef7 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
@@ -99,6 +99,8 @@ public class CLIManager
 
     public static final String LEGACY_LOCAL_REPOSITORY = "llr";
 
+    public static final String LEGACY_DEPENDENCY_MANAGEMENT = "ldm";
+  
     public static final String BUILDER = "b";
 
     protected Options options;
@@ -140,6 +142,7 @@ public class CLIManager
         options.addOption( OptionBuilder.withLongOpt( "threads" ).hasArg().withDescription(
"Thread count, for instance 2.0C where C is core multiplied" ).create( THREADS ) );
         options.addOption( OptionBuilder.withLongOpt( "legacy-local-repository" ).withDescription(
"Use Maven 2 Legacy Local Repository behaviour, ie no use of _remote.repositories. Can also
be activated by using -Dmaven.legacyLocalRepo=true" ).create( LEGACY_LOCAL_REPOSITORY ) );
         options.addOption( OptionBuilder.withLongOpt( "builder" ).hasArg().withDescription(
"The id of the build strategy to use" ).create( BUILDER ) );
+        options.addOption( OptionBuilder.withLongOpt( "legacy-dependency-management" ).withDescription(
"Use Maven 2 legacy dependency management behaviour. Can also be activated by using -Dmaven.legacyDependencyManagement=true"
).create( LEGACY_DEPENDENCY_MANAGEMENT ) );
 
         // Adding this back in for compatibility with the verifier that hard codes this option.
         options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription(
"Ineffective, only kept for backward compatibility" ).create( "npr" ) );

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 90ff927..ed71861 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -301,6 +301,7 @@ public class MavenCli
         try
         {
             initialize( cliRequest );
+            legacy( cliRequest );
             cli( cliRequest );
             logging( cliRequest );
             version( cliRequest );
@@ -311,7 +312,6 @@ public class MavenCli
             toolchains( cliRequest );
             populateRequest( cliRequest );
             encryption( cliRequest );
-            repository( cliRequest );
             profiles( cliRequest );
             return execute( cliRequest );
         }
@@ -908,7 +908,7 @@ public class MavenCli
         }
     }
 
-    private void repository( CliRequest cliRequest )
+    private void legacy( CliRequest cliRequest )
         throws Exception
     {
         if ( cliRequest.commandLine.hasOption( CLIManager.LEGACY_LOCAL_REPOSITORY )
@@ -916,6 +916,11 @@ public class MavenCli
         {
             cliRequest.request.setUseLegacyLocalRepository( true );
         }
+        if ( cliRequest.commandLine.hasOption( CLIManager.LEGACY_DEPENDENCY_MANAGEMENT )
+                 || Boolean.getBoolean( "maven.legacyDependencyManagement" ) )
+        {
+            cliRequest.request.setLegacyDependencyManagementRequested( true );
+        }
     }
 
     private void profiles( final CliRequest request )

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
index 84a68f7..e9b36ba 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
@@ -73,6 +73,8 @@ public class DefaultModelBuildingRequest
 
     private WorkspaceModelResolver workspaceResolver;
 
+    private boolean legacyDependencyManagementRequested = false;
+
     /**
      * Creates an empty request.
      */
@@ -408,4 +410,23 @@ public class DefaultModelBuildingRequest
         return this;
     }
 
+    /**
+     * @since 3.4.0
+     */
+    @Override
+    public boolean isLegacyDependencyManagementRequested()
+    {
+        return this.legacyDependencyManagementRequested;
+    }
+
+    /**
+     * @since 3.4.0
+     */
+    @Override
+    public ModelBuildingRequest setLegacyDependencyManagementRequested( final boolean value
)
+    {
+        this.legacyDependencyManagementRequested = value;
+        return this;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java
b/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java
index c5c2cbf..1717081 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java
@@ -282,4 +282,17 @@ class FilterModelBuildingRequest
         return this;
     }
 
-}
\ No newline at end of file
+    @Override
+    public boolean isLegacyDependencyManagementRequested()
+    {
+        return request.isLegacyDependencyManagementRequested();
+    }
+
+    @Override
+    public ModelBuildingRequest setLegacyDependencyManagementRequested( final boolean value
)
+    {
+        this.request.setLegacyDependencyManagementRequested( value );
+        return this;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
index bc6d85d..c2c0caf 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
@@ -339,4 +339,14 @@ public interface ModelBuildingRequest
 
     ModelBuildingRequest setWorkspaceModelResolver( WorkspaceModelResolver workspaceResolver
);
 
+    /**
+     * @since 3.4.0
+     */
+    boolean isLegacyDependencyManagementRequested();
+
+    /**
+     * @since 3.4.0
+     */
+    ModelBuildingRequest setLegacyDependencyManagementRequested( boolean value );
+
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultDependencyManagementInjector.java
----------------------------------------------------------------------
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultDependencyManagementInjector.java
b/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultDependencyManagementInjector.java
index 731cdd8..02f6bb6 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultDependencyManagementInjector.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/management/DefaultDependencyManagementInjector.java
@@ -43,18 +43,29 @@ public class DefaultDependencyManagementInjector
     implements DependencyManagementInjector
 {
 
-    private ManagementModelMerger merger = new ManagementModelMerger();
-
     @Override
     public void injectManagement( Model model, ModelBuildingRequest request, ModelProblemCollector
problems )
     {
-        merger.mergeManagedDependencies( model );
+        new ManagementModelMerger( request.isLegacyDependencyManagementRequested() ).mergeManagedDependencies(
model );
     }
 
     protected static class ManagementModelMerger
         extends MavenModelMerger
     {
 
+        private final boolean legacyDependencyManagementRequested;
+
+        ManagementModelMerger()
+        {
+            this( true );
+        }
+
+        ManagementModelMerger( final boolean legacyDependencyManagementRequested )
+        {
+            super();
+            this.legacyDependencyManagementRequested = legacyDependencyManagementRequested;
+        }
+
         public void mergeManagedDependencies( Model model )
         {
             DependencyManagement dependencyManagement = model.getDependencyManagement();
@@ -82,6 +93,16 @@ public class DefaultDependencyManagementInjector
         }
 
         @Override
+        protected void mergeDependency_Optional( Dependency target, Dependency source, boolean
sourceDominant,
+                                                 Map<Object, Object> context )
+        {
+            if ( !this.legacyDependencyManagementRequested )
+            {
+                super.mergeDependency_Optional( target, source, sourceDominant, context );
+            }
+        }
+
+        @Override
         protected void mergeDependency_Exclusions( Dependency target, Dependency source,
boolean sourceDominant,
                                                    Map<Object, Object> context )
         {

http://git-wip-us.apache.org/repos/asf/maven/blob/7e70c59e/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/ArtifactDescriptorReaderDelegate.java
----------------------------------------------------------------------
diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/ArtifactDescriptorReaderDelegate.java
b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/ArtifactDescriptorReaderDelegate.java
index 284ee86..e494b1d 100644
--- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/ArtifactDescriptorReaderDelegate.java
+++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/ArtifactDescriptorReaderDelegate.java
@@ -62,7 +62,7 @@ public class ArtifactDescriptorReaderDelegate
 
         for ( org.apache.maven.model.Dependency dependency : model.getDependencies() )
         {
-            result.addDependency( convert( dependency, stereotypes ) );
+            result.addDependency( convert( session, dependency, stereotypes ) );
         }
 
         DependencyManagement mngt = model.getDependencyManagement();
@@ -70,7 +70,7 @@ public class ArtifactDescriptorReaderDelegate
         {
             for ( org.apache.maven.model.Dependency dependency : mngt.getDependencies() )
             {
-                result.addManagedDependency( convert( dependency, stereotypes ) );
+                result.addManagedDependency( convert( session, dependency, stereotypes )
);
             }
         }
 
@@ -98,7 +98,8 @@ public class ArtifactDescriptorReaderDelegate
         setArtifactProperties( result, model );
     }
 
-    private Dependency convert( org.apache.maven.model.Dependency dependency, ArtifactTypeRegistry
stereotypes )
+    private Dependency convert( RepositorySystemSession session, org.apache.maven.model.Dependency
dependency,
+                                ArtifactTypeRegistry stereotypes )
     {
         ArtifactType stereotype = stereotypes.get( dependency.getType() );
         if ( stereotype == null )
@@ -124,11 +125,13 @@ public class ArtifactDescriptorReaderDelegate
             exclusions.add( convert( exclusion ) );
         }
 
-        Dependency result = new Dependency( artifact, dependency.getScope(),
-                                            dependency.getOptional() != null
-                                                ? dependency.isOptional()
-                                                : null,
-                                            exclusions );
+        final Dependency result =
+            session.getData().get( "maven.legacyDependencyManagement" ) != null
+                ? new Dependency( artifact, dependency.getScope(), dependency.isOptional(),
exclusions )
+                : new Dependency( artifact, dependency.getScope(), dependency.getOptional()
!= null
+                                                                       ? dependency.isOptional()
+                                                                       : null,
+                                  exclusions );
 
         return result;
     }


Mime
View raw message