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 static org.hamcrest.Matchers.endsWith;
19  import static org.junit.Assert.assertThat;
20  
21  import java.io.File;
22  import java.util.Collections;
23  import java.util.List;
24  import java.util.Properties;
25  import java.util.Set;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.execution.MavenSession;
29  import org.apache.maven.project.MavenProject;
30  import org.codehaus.plexus.component.annotations.Requirement;
31  
32  public class ProjectDependenciesResolverTest
33      extends AbstractCoreMavenComponentTestCase
34  {
35      @Requirement
36      private ProjectDependenciesResolver resolver;
37  
38      protected void setUp()
39          throws Exception
40      {
41          super.setUp();
42          resolver = lookup( ProjectDependenciesResolver.class );
43      }
44  
45      @Override
46      protected void tearDown()
47          throws Exception
48      {
49          resolver = null;
50          super.tearDown();
51      }
52  
53      protected String getProjectsDirectory()
54      {
55          return "src/test/projects/project-dependencies-resolver";
56      }
57  
58      /*
59      public void testExclusionsInDependencies()
60          throws Exception
61      {
62          MavenSession session = createMavenSession( null );
63          MavenProject project = session.getCurrentProject();
64  
65          Exclusion exclusion = new Exclusion();
66          exclusion.setGroupId( "org.apache.maven.its" );
67          exclusion.setArtifactId( "a" );
68  
69          new ProjectBuilder( project ).addDependency( "org.apache.maven.its", "b", "0.1", Artifact.SCOPE_RUNTIME,
70                                                       exclusion );
71  
72          Set<Artifact> artifactDependencies =
73              resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session );
74          assertEquals( 0, artifactDependencies.size() );
75  
76          artifactDependencies = resolver.resolve( project, Collections.singleton( Artifact.SCOPE_RUNTIME ), session );
77          assertEquals( 1, artifactDependencies.size() );
78          assertEquals( "b", artifactDependencies.iterator().next().getArtifactId() );
79      }
80      */
81  
82      public void testSystemScopeDependencies()
83          throws Exception
84      {
85          MavenSession session = createMavenSession( null );
86          MavenProject project = session.getCurrentProject();
87  
88          new ProjectBuilder( project )
89              .addDependency( "com.mycompany", "system-dependency", "1.0", Artifact.SCOPE_SYSTEM, new File( getBasedir(), "pom.xml" ).getAbsolutePath() );
90  
91          Set<Artifact> artifactDependencies =
92              resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session );
93          assertEquals( 1, artifactDependencies.size() );
94      }
95  
96      public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements()
97          throws Exception
98      {
99          File pom = getProject( "it0063" );
100 
101         Properties eps = new Properties();
102         eps.setProperty( "jre.home", new File( pom.getParentFile(), "jdk/jre" ).getPath() );
103 
104         MavenSession session = createMavenSession( pom, eps );
105         MavenProject project = session.getCurrentProject();
106 
107         project.setArtifacts( resolver.resolve( project, Collections.singleton( Artifact.SCOPE_COMPILE ), session ) );
108 
109         List<String> elements = project.getCompileClasspathElements();
110         assertEquals( 2, elements.size() );
111 
112         @SuppressWarnings( "deprecation" )
113         List<Artifact> artifacts = project.getCompileArtifacts();
114         assertEquals( 1, artifacts.size() );
115         assertThat( artifacts.get( 0 ).getFile().getName(), endsWith( "tools.jar" ) );
116     }
117 }