View Javadoc
1   package org.apache.maven;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  import java.io.File;
19  import java.util.Collections;
20  import java.util.List;
21  import java.util.Properties;
22  import java.util.Set;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.execution.MavenSession;
26  import org.apache.maven.project.MavenProject;
27  import org.codehaus.plexus.component.annotations.Requirement;
28  
29  public class ProjectDependenciesResolverTest
30      extends AbstractCoreMavenComponentTestCase
31  {
32      @Requirement
33      private ProjectDependenciesResolver resolver;
34  
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39          resolver = lookup( ProjectDependenciesResolver.class );
40      }
41  
42      @Override
43      protected void tearDown()
44          throws Exception
45      {
46          resolver = null;
47          super.tearDown();
48      }
49  
50      protected String getProjectsDirectory()
51      {
52          return "src/test/projects/project-dependencies-resolver";
53      }
54  
55      /*
56      public void testExclusionsInDependencies()
57          throws Exception
58      {
59          MavenSession session = createMavenSession( null );
60          MavenProject project = session.getCurrentProject();
61  
62          Exclusion exclusion = new Exclusion();
63          exclusion.setGroupId( "org.apache.maven.its" );
64          exclusion.setArtifactId( "a" );
65  
66          new ProjectBuilder( project ).addDependency( "org.apache.maven.its", "b", "0.1", Artifact.SCOPE_RUNTIME,
67                                                       exclusion );
68  
69          Set<Artifact> artifactDependencies =
70              resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session );
71          assertEquals( 0, artifactDependencies.size() );
72  
73          artifactDependencies = resolver.resolve( project, Collections.singleton( Artifact.SCOPE_RUNTIME ), session );
74          assertEquals( 1, artifactDependencies.size() );
75          assertEquals( "b", artifactDependencies.iterator().next().getArtifactId() );
76      }
77      */
78  
79      public void testSystemScopeDependencies()
80          throws Exception
81      {
82          MavenSession session = createMavenSession( null );
83          MavenProject project = session.getCurrentProject();
84  
85          new ProjectBuilder( project )
86              .addDependency( "com.mycompany", "system-dependency", "1.0", Artifact.SCOPE_SYSTEM, new File( getBasedir(), "pom.xml" ).getAbsolutePath() );
87  
88          Set<Artifact> artifactDependencies =
89              resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session );
90          assertEquals( 1, artifactDependencies.size() );
91      }
92  
93      public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements()
94          throws Exception
95      {
96          File pom = getProject( "it0063" );
97  
98          Properties eps = new Properties();
99          eps.setProperty( "jre.home", new File( pom.getParentFile(), "jdk/jre" ).getPath() );
100 
101         MavenSession session = createMavenSession( pom, eps );
102         MavenProject project = session.getCurrentProject();
103 
104         project.setArtifacts( resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session ) );
105 
106         List<String> elements = project.getCompileClasspathElements();
107         assertEquals( 2, elements.size() );
108 
109         @SuppressWarnings( "deprecation" )
110         List<Artifact> artifacts = project.getCompileArtifacts();
111         assertEquals( 1, artifacts.size() );
112         assertTrue( artifacts.get( 0 ).getFile().getName().endsWith( "tools.jar" ) );
113     }
114 }