View Javadoc
1   package org.apache.maven.lifecycle.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.Collection;
24  import java.util.Collections;
25  import java.util.HashSet;
26  import java.util.Properties;
27  import java.util.Set;
28  
29  import org.apache.maven.AbstractCoreMavenComponentTestCase;
30  import org.apache.maven.artifact.Artifact;
31  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
32  import org.apache.maven.execution.MavenSession;
33  import org.apache.maven.project.MavenProject;
34  import org.codehaus.plexus.component.annotations.Requirement;
35  import org.junit.Test;
36  
37  public class LifecycleDependencyResolverTest extends AbstractCoreMavenComponentTestCase
38  {
39      @Requirement
40      private LifecycleDependencyResolver resolver;
41  
42      @Override
43      protected String getProjectsDirectory()
44      {
45          return null;
46      }
47  
48      @Override
49      protected void setUp()
50          throws Exception
51      {
52          super.setUp();
53          resolver = lookup( LifecycleDependencyResolver.class );
54      }
55  
56      @Test
57      public void testCachedReactorProjectDependencies() throws Exception
58      {
59          MavenSession session = createMavenSession( new File( "src/test/projects/lifecycle-dependency-resolver/pom.xml" ), new Properties(), true );
60          Collection<String> scopesToCollect = null;
61          Collection<String> scopesToResolve = Collections.singletonList( "compile" );
62          boolean aggregating = false;
63  
64          Set<Artifact> reactorArtifacts = new HashSet<>( 3 );
65          for ( MavenProject reactorProject : session.getProjects() )
66          {
67              reactorProject.setArtifactFilter( new ArtifactFilter()
68              {
69                  @Override
70                  public boolean include( Artifact artifact )
71                  {
72                      return true;
73                  }
74              } );
75              resolver.resolveProjectDependencies( reactorProject, scopesToCollect, scopesToResolve, session, aggregating, reactorArtifacts );
76              reactorArtifacts.add( reactorProject.getArtifact() );
77          }
78  
79          MavenProject lib = session.getProjects().get( 1 );
80          MavenProject war = session.getProjects().get( 2 );
81  
82          assertEquals( null , war.getArtifactMap().get("org.apache.maven.its.mng6300:mng6300-lib").getFile() );
83  
84          lib.getArtifact().setFile( new File( "lib.jar" ) );
85  
86          resolver.resolveProjectDependencies( war, scopesToCollect, scopesToResolve, session, aggregating, reactorArtifacts );
87  
88          assertEquals( new File( "lib.jar" ) , war.getArtifactMap().get("org.apache.maven.its.mng6300:mng6300-lib").getFile() );
89      }
90  }