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