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.lifecycle.internal;
20  
21  import java.io.File;
22  import java.util.Collection;
23  import java.util.Collections;
24  import java.util.HashSet;
25  import java.util.Properties;
26  import java.util.Set;
27  
28  import org.apache.maven.AbstractCoreMavenComponentTestCase;
29  import org.apache.maven.artifact.Artifact;
30  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
31  import org.apache.maven.execution.MavenSession;
32  import org.apache.maven.project.MavenProject;
33  import org.codehaus.plexus.component.annotations.Requirement;
34  import org.junit.Test;
35  
36  public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentTestCase {
37      @Requirement
38      private LifecycleDependencyResolver resolver;
39  
40      @Override
41      protected String getProjectsDirectory() {
42          return null;
43      }
44  
45      @Override
46      protected void setUp() throws Exception {
47          super.setUp();
48          resolver = lookup(LifecycleDependencyResolver.class);
49      }
50  
51      @Test
52      public void testCachedReactorProjectDependencies() throws Exception {
53          MavenSession session = createMavenSession(
54                  new File("src/test/projects/lifecycle-dependency-resolver/pom.xml"), new Properties(), true);
55          Collection<String> scopesToCollect = null;
56          Collection<String> scopesToResolve = Collections.singletonList("compile");
57          boolean aggregating = false;
58  
59          Set<Artifact> reactorArtifacts = new HashSet<>(3);
60          for (MavenProject reactorProject : session.getProjects()) {
61              reactorProject.setArtifactFilter(new ArtifactFilter() {
62                  @Override
63                  public boolean include(Artifact artifact) {
64                      return true;
65                  }
66              });
67              resolver.resolveProjectDependencies(
68                      reactorProject, scopesToCollect, scopesToResolve, session, aggregating, reactorArtifacts);
69              reactorArtifacts.add(reactorProject.getArtifact());
70          }
71  
72          MavenProject lib = session.getProjects().get(1);
73          MavenProject war = session.getProjects().get(2);
74  
75          assertEquals(
76                  null,
77                  war.getArtifactMap()
78                          .get("org.apache.maven.its.mng6300:mng6300-lib")
79                          .getFile());
80  
81          lib.getArtifact().setFile(new File("lib.jar"));
82  
83          resolver.resolveProjectDependencies(
84                  war, scopesToCollect, scopesToResolve, session, aggregating, reactorArtifacts);
85  
86          assertEquals(
87                  new File("lib.jar"),
88                  war.getArtifactMap()
89                          .get("org.apache.maven.its.mng6300:mng6300-lib")
90                          .getFile());
91      }
92  }