maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-components/maven-core/src/test/resources/projects/scope project-with-scoped-dependencies.xml transitive-compile-dep.xml
Date Thu, 17 Mar 2005 02:04:35 GMT
brett       2005/03/16 18:04:35

  Modified:    maven-core/src/main/java/org/apache/maven/artifact/factory
                        DefaultArtifactFactory.java
               maven-core/src/main/java/org/apache/maven/plugin
                        DefaultPluginManager.java
               maven-core/src/main/java/org/apache/maven/project
                        DefaultMavenProjectBuilder.java MavenProject.java
               maven-core/src/test/java/org/apache/maven/project
                        ProjectClasspathTest.java
               maven-core/src/test/resources/projects/scope
                        project-with-scoped-dependencies.xml
                        transitive-compile-dep.xml
  Log:
  PR: MNG-207
  scope must be considered globally - redefining it weaker must not win.
  
  Revision  Changes    Path
  1.9       +7 -0      maven-components/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java
  
  Index: DefaultArtifactFactory.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultArtifactFactory.java	16 Mar 2005 07:36:01 -0000	1.8
  +++ DefaultArtifactFactory.java	17 Mar 2005 02:04:34 -0000	1.9
  @@ -73,6 +73,13 @@
               desiredScope = Artifact.SCOPE_COMPILE;
           }
   
  +        // vvv added to retain compile scope. Remove if you want compile inherited as runtime
  +        else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals(
inheritedScope ) )
  +        {
  +            desiredScope = Artifact.SCOPE_COMPILE;
  +        }
  +        // ^^^ added to retain compile scope. Remove if you want compile inherited as runtime
  +
           if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_TEST.equals( inheritedScope
) )
           {
               desiredScope = Artifact.SCOPE_TEST;
  
  
  
  1.54      +3 -3      maven-components/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
  
  Index: DefaultPluginManager.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- DefaultPluginManager.java	16 Mar 2005 06:29:34 -0000	1.53
  +++ DefaultPluginManager.java	17 Mar 2005 02:04:35 -0000	1.54
  @@ -85,7 +85,7 @@
       protected PathTranslator pathTranslator;
   
       protected ArtifactRepositoryFactory artifactRepositoryFactory;
  -    
  +
       protected MavenSettingsBuilder mavenSettingsBuilder;
   
       public DefaultPluginManager()
  @@ -605,7 +605,7 @@
           Repository pluginRepo = new Repository();
           pluginRepo.setId( "plugin-repository" );
           pluginRepo.setUrl( "http://repo1.maven.org" );
  -        
  +
           ArtifactRepository pluginRepository = artifactRepositoryFactory.createArtifactRepository(
pluginRepo, settings );
   
           remotePluginRepositories.add( pluginRepository );
  @@ -628,7 +628,7 @@
                                                                                   context.getLocalRepository(),
                                                                                   sourceReader
);
   
  -        project.getArtifacts().addAll( result.getArtifacts().values() );
  +        project.addArtifacts( result.getArtifacts().values() );
       }
   
       // ----------------------------------------------------------------------
  
  
  
  1.53      +2 -2      maven-components/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
  
  Index: DefaultMavenProjectBuilder.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- DefaultMavenProjectBuilder.java	16 Mar 2005 06:56:03 -0000	1.52
  +++ DefaultMavenProjectBuilder.java	17 Mar 2005 02:04:35 -0000	1.53
  @@ -78,7 +78,7 @@
       private ModelDefaultsInjector modelDefaultsInjector;
   
       private ModelInterpolator modelInterpolator;
  -    
  +
       private MavenSettingsBuilder mavenSettingsBuilder;
   
       private ArtifactRepositoryFactory artifactRepositoryFactory;
  @@ -198,7 +198,7 @@
               ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
repos,
                                                                                       localRepository,
sourceReader );
   
  -            project.getArtifacts().addAll( result.getArtifacts().values() );
  +            project.addArtifacts( result.getArtifacts().values() );
           }
   
           ModelValidationResult validationResult = validator.validate( model );
  
  
  
  1.30      +51 -0     maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
  
  Index: MavenProject.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- MavenProject.java	16 Mar 2005 04:21:03 -0000	1.29
  +++ MavenProject.java	17 Mar 2005 02:04:35 -0000	1.30
  @@ -18,6 +18,7 @@
    */
   
   import org.apache.maven.artifact.Artifact;
  +import org.apache.maven.artifact.DefaultArtifact;
   import org.apache.maven.model.Build;
   import org.apache.maven.model.CiManagement;
   import org.apache.maven.model.Contributor;
  @@ -40,8 +41,10 @@
   
   import java.io.File;
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.Collections;
   import java.util.HashMap;
  +import java.util.HashSet;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  @@ -644,5 +647,53 @@
   
           return sortedProjects;
       }
  +
  +    public void addArtifacts( Collection newArtifacts )
  +    {
  +//        project.getArtifacts().addAll( result.getArtifacts().values() );
  +        // We need to override the scope if one declared it higher
  +        // TODO: could surely be more efficient, and use the scope handler, be part of
maven-artifact...
  +        Map artifacts = new HashMap();
  +        for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
  +        {
  +            Artifact a = (Artifact) i.next();
  +            artifacts.put( a.getId(), a );
  +        }
  +        for ( Iterator i = newArtifacts.iterator(); i.hasNext(); )
  +        {
  +            Artifact a = (Artifact) i.next();
  +            String id = a.getId();
  +            if ( artifacts.containsKey( id ) )
  +            {
  +                Artifact existing = (Artifact) artifacts.get( id );
  +                boolean updateScope = false;
  +                if ( Artifact.SCOPE_RUNTIME.equals( a.getScope() ) &&
  +                    Artifact.SCOPE_TEST.equals( existing.getScope() ) )
  +                {
  +                    updateScope = true;
  +                }
  +
  +                if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) &&
  +                    !Artifact.SCOPE_COMPILE.equals( existing.getScope() ) )
  +                {
  +                    updateScope = true;
  +                }
  +
  +                if ( updateScope )
  +                {
  +                    // TODO: Artifact factory?
  +                    Artifact artifact = new DefaultArtifact( existing.getGroupId(), existing.getArtifactId(),
  +                                                             existing.getVersion(), a.getScope(),
existing.getType(),
  +                                                             existing.getExtension() );
  +                    artifacts.put( id, artifact );
  +                }
  +            }
  +            else
  +            {
  +                artifacts.put( id, a );
  +            }
  +        }
  +        setArtifacts( new HashSet( artifacts.values() ) );
  +    }
   }
   
  
  
  
  1.5       +16 -5     maven-components/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java
  
  Index: ProjectClasspathTest.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProjectClasspathTest.java	16 Mar 2005 05:08:50 -0000	1.4
  +++ ProjectClasspathTest.java	17 Mar 2005 02:04:35 -0000	1.5
  @@ -58,6 +58,10 @@
           checkArtifactIdScope( project, "runtime", "runtime" );
           checkArtifactIdScope( project, "default", "compile" );
   
  +        checkInheritedArtifactIdScope( project, "compile", "compile" );
  +        checkInheritedArtifactIdScope( project, "runtime", "runtime" );
  +        checkInheritedArtifactIdScope( project, "default", "compile" );
  +
           // check all transitive deps of a test dependency are test, except test which is
skipped
           artifact = getArtifact( project, "maven-test-test", "scope-test" );
           assertNull( "Check no test dependencies are transitive", artifact );
  @@ -71,11 +75,11 @@
           // check all transitive deps of a runtime dependency are runtime scope, except
for test
           checkGroupIdScope( project, "runtime", "runtime" );
   
  -        // check all transitive deps of a compile dependency are runtime scope, except
for test
  -        checkGroupIdScope( project, "compile", "runtime" );
  +        // check all transitive deps of a compile dependency are compile scope, except
for runtime and test
  +        checkGroupIdScope( project, "compile", "compile" );
   
  -        // check all transitive deps of a default dependency are runtime scope, except
for test
  -        checkGroupIdScope( project, "default", "runtime" );
  +        // check all transitive deps of a default dependency are compile scope, except
for runtime and test
  +        checkGroupIdScope( project, "default", "compile" );
       }
   
       private void checkGroupIdScope( MavenProject project, String scope, String scopeValue
)
  @@ -89,7 +93,7 @@
           artifact = getArtifact( project, groupId, "scope-default" );
           assertEquals( "Check scope", scopeValue, artifact.getScope() );
           artifact = getArtifact( project, groupId, "scope-runtime" );
  -        assertEquals( "Check scope", scopeValue, artifact.getScope() );
  +        assertEquals( "Check scope", "runtime", artifact.getScope() );
       }
   
       private void checkArtifactIdScope( MavenProject project, String scope, String scopeValue
)
  @@ -99,6 +103,13 @@
           assertEquals( "Check scope", scopeValue, artifact.getScope() );
       }
   
  +    private void checkInheritedArtifactIdScope( MavenProject project, String scope, String
scopeValue )
  +    {
  +        String artifactId = "scope-" + scope;
  +        Artifact artifact = getArtifact( project, "maven-inherited", artifactId );
  +        assertEquals( "Check scope", scopeValue, artifact.getScope() );
  +    }
  +
       private Artifact getArtifact( MavenProject project, String groupId, String artifactId
)
       {
           for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
  
  
  
  1.3       +19 -0     maven-components/maven-core/src/test/resources/projects/scope/project-with-scoped-dependencies.xml
  
  Index: project-with-scoped-dependencies.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/test/resources/projects/scope/project-with-scoped-dependencies.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project-with-scoped-dependencies.xml	10 Mar 2005 01:35:16 -0000	1.2
  +++ project-with-scoped-dependencies.xml	17 Mar 2005 02:04:35 -0000	1.3
  @@ -34,6 +34,25 @@
         <scope>compile</scope>
       </dependency>
   
  +    <dependency>
  +      <groupId>maven-inherited</groupId>
  +      <artifactId>scope-default</artifactId>
  +      <version>1.0</version>
  +    </dependency>
  +
  +    <dependency>
  +      <groupId>maven-inherited</groupId>
  +      <artifactId>scope-compile</artifactId>
  +      <version>1.0</version>
  +      <scope>runtime</scope>
  +    </dependency>
  +
  +    <dependency>
  +      <groupId>maven-inherited</groupId>
  +      <artifactId>scope-runtime</artifactId>
  +      <version>1.0</version>
  +      <scope>runtime</scope>
  +    </dependency>
     </dependencies>
   
   </model>
  
  
  
  1.3       +20 -0     maven-components/maven-core/src/test/resources/projects/scope/transitive-compile-dep.xml
  
  Index: transitive-compile-dep.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/src/test/resources/projects/scope/transitive-compile-dep.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- transitive-compile-dep.xml	10 Mar 2005 01:35:16 -0000	1.2
  +++ transitive-compile-dep.xml	17 Mar 2005 02:04:35 -0000	1.3
  @@ -33,6 +33,26 @@
         <scope>compile</scope>
       </dependency>
   
  +    <dependency>
  +      <groupId>maven-inherited</groupId>
  +      <artifactId>scope-compile</artifactId>
  +      <version>1.0</version>
  +      <scope>compile</scope>
  +    </dependency>
  +
  +    <dependency>
  +      <groupId>maven-inherited</groupId>
  +      <artifactId>scope-default</artifactId>
  +      <version>1.0</version>
  +      <scope>runtime</scope>
  +    </dependency>
  +
  +    <dependency>
  +      <groupId>maven-inherited</groupId>
  +      <artifactId>scope-runtime</artifactId>
  +      <version>1.0</version>
  +      <scope>test</scope>
  +    </dependency>
     </dependencies>
   
   </model>
  
  
  

Mime
View raw message