View Javadoc
1   package org.apache.maven.plugins.assembly.artifact;
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 static org.easymock.EasyMock.expect;
23  
24  import java.io.File;
25  import java.util.ArrayList;
26  import java.util.Arrays;
27  import java.util.Collections;
28  import java.util.List;
29  import java.util.Set;
30  
31  import org.apache.maven.artifact.Artifact;
32  import org.apache.maven.artifact.factory.ArtifactFactory;
33  import org.apache.maven.artifact.repository.ArtifactRepository;
34  import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
35  import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager;
36  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
37  import org.apache.maven.execution.DefaultMavenExecutionRequest;
38  import org.apache.maven.execution.DefaultMavenExecutionResult;
39  import org.apache.maven.execution.MavenExecutionRequest;
40  import org.apache.maven.execution.MavenExecutionResult;
41  import org.apache.maven.execution.MavenSession;
42  import org.apache.maven.model.Model;
43  import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
44  import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
45  import org.apache.maven.plugins.assembly.model.Assembly;
46  import org.apache.maven.plugins.assembly.model.DependencySet;
47  import org.apache.maven.plugins.assembly.model.ModuleBinaries;
48  import org.apache.maven.plugins.assembly.model.ModuleSet;
49  import org.apache.maven.plugins.assembly.model.Repository;
50  import org.apache.maven.plugins.assembly.resolved.AssemblyId;
51  import org.apache.maven.project.DefaultProjectBuildingRequest;
52  import org.apache.maven.project.MavenProject;
53  import org.apache.maven.project.ProjectBuildingRequest;
54  import org.apache.maven.repository.internal.MavenRepositorySystemSession;
55  import org.codehaus.plexus.PlexusTestCase;
56  import org.codehaus.plexus.logging.Logger;
57  import org.codehaus.plexus.logging.console.ConsoleLogger;
58  import org.easymock.classextension.EasyMockSupport;
59  import org.sonatype.aether.RepositorySystemSession;
60  import org.sonatype.aether.repository.LocalRepositoryManager;
61  
62  public class DefaultDependencyResolverTest
63      extends PlexusTestCase
64  {
65  
66      private ArtifactFactory factory;
67  
68      private ArtifactRepositoryFactory repoFactory;
69  
70      private ArtifactRepositoryLayout layout;
71  
72      private DefaultDependencyResolver resolver;
73  
74      @Override
75      public void setUp()
76          throws Exception
77      {
78          super.setUp();
79  
80          resolver = (DefaultDependencyResolver) lookup( DependencyResolver.class );
81  
82          factory = lookup( ArtifactFactory.class );
83          repoFactory = lookup( ArtifactRepositoryFactory.class );
84          layout = lookup( ArtifactRepositoryLayout.class, "default" );
85      }
86      
87      protected MavenSession newMavenSession( MavenProject project )
88      {
89          MavenExecutionRequest request = new DefaultMavenExecutionRequest();
90          MavenExecutionResult result = new DefaultMavenExecutionResult();
91  
92          MavenRepositorySystemSession repoSession = new MavenRepositorySystemSession();
93          
94          repoSession.setLocalRepositoryManager( LegacyLocalRepositoryManager.wrap( new StubArtifactRepository( "target/local-repo" ),
95                                                                                    null ) );
96          MavenSession session = new MavenSession( getContainer(), repoSession, request, result );
97          session.setCurrentProject( project );
98          session.setProjects( Arrays.asList( project ) );
99          return session;
100     }
101 
102 
103     public void test_getDependencySetResolutionRequirements()
104         throws DependencyResolutionException
105     {
106         final DependencySet ds1 = new DependencySet();
107         ds1.setScope( Artifact.SCOPE_COMPILE );
108         ds1.setUseTransitiveDependencies( false );
109 
110         final DependencySet ds2 = new DependencySet();
111         ds2.setScope( Artifact.SCOPE_SYSTEM );
112         ds2.setUseTransitiveDependencies( false );
113 
114         final MavenProject project = createMavenProject( "main-group", "main-artifact", "1", null );
115 
116         final ResolutionManagementInfo info = new ResolutionManagementInfo( project );
117 
118         final Assembly assembly = new Assembly();
119         
120         ProjectBuildingRequest buildingRequest = newMavenSession( project ).getProjectBuildingRequest();
121         
122         resolver.updateDependencySetResolutionRequirements( ds1, info, AssemblyId.createAssemblyId( assembly ),
123                                                             buildingRequest, project );
124 
125         assertTrue( info.isResolutionRequired() );
126         assertFalse( info.isResolvedTransitively() );
127 
128         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_COMPILE ) );
129         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_SYSTEM ) );
130 
131         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_PROVIDED ) );
132 
133         assertFalse( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_RUNTIME ) );
134         assertFalse( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_TEST ) );
135     }
136 
137     public void test_getModuleSetResolutionRequirements()
138         throws DependencyResolutionException
139     {
140         final EasyMockSupport mm = new EasyMockSupport();
141 
142         final AssemblerConfigurationSource cs = mm.createMock( AssemblerConfigurationSource.class );
143 
144         final File rootDir = new File( "root" );
145         final MavenProject project = createMavenProject( "main-group", "main-artifact", "1", rootDir );
146 
147         final File module1Dir = new File( rootDir, "module-1" );
148         final MavenProject module1 = createMavenProject( "main-group", "module-1", "1", module1Dir );
149         final MavenProject module1a =
150             createMavenProject( "group1", "module-1a", "1", new File( module1Dir, "module-1a" ) );
151         final MavenProject module1b =
152             createMavenProject( "group1.b", "module-1b", "1", new File( module1Dir, "module-1b" ) );
153 
154         module1.getModel().addModule( module1a.getArtifactId() );
155         module1.getModel().addModule( module1b.getArtifactId() );
156 
157         final File module2Dir = new File( rootDir, "module-2" );
158         final MavenProject module2 = createMavenProject( "main-group", "module-2", "1", module2Dir );
159         final MavenProject module2a =
160             createMavenProject( "main-group", "module-2a", "1", new File( module2Dir, "module-2a" ) );
161 
162         module2.getModel().addModule( module2a.getArtifactId() );
163 
164         project.getModel().addModule( module1.getArtifactId() );
165         project.getModel().addModule( module2.getArtifactId() );
166 
167         final List<MavenProject> allProjects = new ArrayList<MavenProject>();
168         allProjects.add( project );
169         allProjects.add( module1 );
170         allProjects.add( module1a );
171         allProjects.add( module1b );
172         allProjects.add( module2 );
173         allProjects.add( module2a );
174         
175         expect( cs.getReactorProjects() ).andReturn( allProjects ).anyTimes();
176 
177         expect( cs.getProject() ).andReturn( project ).anyTimes();
178         
179         expect( cs.getMavenSession() ).andReturn( newMavenSession( project ) ).anyTimes();
180 
181         final ResolutionManagementInfo info = new ResolutionManagementInfo( project );
182 
183         final List<ModuleSet> moduleSets = new ArrayList<ModuleSet>();
184 
185         final ModuleSet ms1 = new ModuleSet();
186         final DependencySet ds1 = new DependencySet();
187         {
188             ms1.addInclude( "*module1*" );
189             ms1.setIncludeSubModules( false );
190 
191             final ModuleBinaries mb = new ModuleBinaries();
192 
193             ds1.setScope( Artifact.SCOPE_COMPILE );
194 
195             mb.addDependencySet( ds1 );
196             ms1.setBinaries( mb );
197             moduleSets.add( ms1 );
198         }
199 
200         final ModuleSet ms2 = new ModuleSet();
201         final DependencySet ds2 = new DependencySet();
202         {
203             ms2.addInclude( "main-group:*" );
204             ms2.setIncludeSubModules( true );
205 
206             final ModuleBinaries mb = new ModuleBinaries();
207 
208             ds2.setScope( Artifact.SCOPE_TEST );
209 
210             mb.addDependencySet( ds2 );
211             ms2.setBinaries( mb );
212             moduleSets.add( ms2 );
213         }
214 
215         mm.replayAll();
216 
217         resolver.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
218 
219         final Assembly assembly = new Assembly();
220         assembly.setModuleSets( moduleSets );
221 
222         resolver.updateModuleSetResolutionRequirements( AssemblyId.createAssemblyId( assembly ), ms1, ds1, info, cs );
223         resolver.updateModuleSetResolutionRequirements( AssemblyId.createAssemblyId( assembly ), ms2, ds2, info, cs );
224 
225         assertTrue( info.isResolutionRequired() );
226 
227         final Set<MavenProject> enabledProjects = info.getEnabledProjects();
228         assertTrue( enabledProjects.contains( project ) );
229 
230         assertTrue( enabledProjects.contains( module1 ) );
231 
232         // these should be excluded since sub-modules are not traversable
233         assertFalse( enabledProjects.contains( module1a ) );
234         assertFalse( enabledProjects.contains( module1b ) );
235 
236         assertTrue( enabledProjects.contains( module2 ) );
237         assertTrue( enabledProjects.contains( module2a ) );
238 
239         // these are the two we directly set above.
240         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_TEST ) );
241         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_COMPILE ) );
242 
243         // this combination should be implied by the two direct scopes set above.
244         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_RUNTIME ) );
245         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_PROVIDED ) );
246         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_SYSTEM ) );
247 
248         mm.verifyAll();
249     }
250 
251     public void test_getRepositoryResolutionRequirements()
252     {
253         final List<Repository> repositories = new ArrayList<Repository>();
254 
255         {
256             final Repository r = new Repository();
257             r.setScope( Artifact.SCOPE_COMPILE );
258             repositories.add( r );
259         }
260 
261         {
262             final Repository r = new Repository();
263             r.setScope( Artifact.SCOPE_SYSTEM );
264             repositories.add( r );
265         }
266 
267         final MavenProject project = createMavenProject( "group", "artifact", "1.0", null );
268         final Assembly assembly = new Assembly();
269         assembly.setRepositories( repositories );
270 
271         final ResolutionManagementInfo info = new ResolutionManagementInfo( project );
272         resolver.updateRepositoryResolutionRequirements( assembly,
273                                                                                                            info );
274 
275         assertTrue( info.isResolutionRequired() );
276 
277         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_COMPILE ) );
278         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_SYSTEM ) );
279 
280         assertTrue( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_PROVIDED ) );
281 
282         assertFalse( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_RUNTIME ) );
283         assertFalse( info.getScopeFilter().getIncluded().contains( Artifact.SCOPE_TEST ) );
284     }
285 
286     public void test_aggregateRemoteArtifactRepositories()
287     {
288         final List<ArtifactRepository> externalRepos = new ArrayList<ArtifactRepository>();
289 
290         final ArtifactRepository er1 =
291             repoFactory.createArtifactRepository( "test.1", "http://test.com/path", layout, null, null );
292         externalRepos.add( er1 );
293 
294         final ArtifactRepository er2 =
295             repoFactory.createArtifactRepository( "test.2", "http://test2.com/path", layout, null, null );
296         externalRepos.add( er2 );
297 
298         final List<ArtifactRepository> projectRepos = new ArrayList<ArtifactRepository>();
299 
300         final ArtifactRepository pr1 =
301             repoFactory.createArtifactRepository( "project.1", "http://test.com/project", layout, null, null );
302         projectRepos.add( pr1 );
303 
304         final ArtifactRepository pr2 =
305             repoFactory.createArtifactRepository( "project.2", "http://test2.com/path", layout, null, null );
306         projectRepos.add( pr2 );
307 
308         final MavenProject project = createMavenProject( "group", "artifact", "1", new File( "base" ) );
309         project.setRemoteArtifactRepositories( projectRepos );
310 
311         final List<ArtifactRepository> aggregated =
312             resolver.aggregateRemoteArtifactRepositories( externalRepos, Collections.singleton( project ) );
313 
314         assertRepositoryWithId( er1.getId(), aggregated, true );
315         assertRepositoryWithId( er2.getId(), aggregated, true );
316         assertRepositoryWithId( pr1.getId(), aggregated, true );
317         assertRepositoryWithId( pr2.getId(), aggregated, false );
318     }
319 
320     // public void test_manageArtifact()
321     // {
322     // Artifact managed = factory.createArtifact( "group", "artifact", "1", Artifact.SCOPE_PROVIDED, "jar" );
323     //
324     // Artifact target =
325     // factory.createArtifact( managed.getGroupId(), managed.getArtifactId(), "2", Artifact.SCOPE_COMPILE,
326     // managed.getType() );
327     //
328     // Artifact target2 =
329     // factory.createArtifact( "other-group", managed.getArtifactId(), "2", Artifact.SCOPE_COMPILE,
330     // managed.getType() );
331     //
332     // Map managedVersions = Collections.singletonMap( managed.getDependencyConflictId(), managed );
333     //
334     // DefaultDependencyResolver resolver =
335     // new DefaultDependencyResolver().setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
336     //
337     // resolver.manageArtifact( target, managedVersions );
338     // resolver.manageArtifact( target2, managedVersions );
339     //
340     // assertEquals( managed.getVersion(), target.getVersion() );
341     // assertEquals( managed.getScope(), target.getScope() );
342     //
343     // assertEquals( "2", target2.getVersion() );
344     // assertEquals( Artifact.SCOPE_COMPILE, target2.getScope() );
345     // }
346 
347     // public void test_buildManagedVersionMap_NonTransitiveResolution()
348     // throws ArtifactResolutionException, ArchiveCreationException, InvalidVersionSpecificationException,
349     // InvalidDependencyVersionException
350     // {
351     // Assembly assembly = new Assembly();
352     //
353     // DependencySet ds = new DependencySet();
354     // ds.setScope( Artifact.SCOPE_PROVIDED );
355     // ds.setUseTransitiveDependencies( false );
356     //
357     // assembly.addDependencySet( ds );
358     //
359     // ModuleSet ms = new ModuleSet();
360     // ModuleBinaries mb = new ModuleBinaries();
361     // ms.setBinaries( mb );
362     //
363     // DependencySet mds = new DependencySet();
364     // mds.setScope( Artifact.SCOPE_PROVIDED );
365     // mds.setUseTransitiveDependencies( false );
366     //
367     // mb.addDependencySet( mds );
368     //
369     // assembly.addModuleSet( ms );
370     //
371     // MavenProject project = createMavenProject( "group", "artifact", "1", new File( "base" ) );
372     //
373     // Dependency d1 = new Dependency();
374     // d1.setGroupId( "group.dep" );
375     // d1.setArtifactId( "dep1" );
376     // d1.setVersion( "1" );
377     // d1.setScope( Artifact.SCOPE_COMPILE );
378     //
379     // project.getModel().addDependency( d1 );
380     //
381     // Dependency d2 = new Dependency();
382     // d2.setGroupId( "group.dep" );
383     // d2.setArtifactId( "dep2" );
384     // d2.setVersion( "1" );
385     // d2.setScope( Artifact.SCOPE_PROVIDED );
386     //
387     // project.getModel().addDependency( d2 );
388     //
389     // Dependency d3 = new Dependency();
390     // d3.setGroupId( "group.dep" );
391     // d3.setArtifactId( "dep3" );
392     // d3.setVersion( "1" );
393     // d3.setScope( Artifact.SCOPE_PROVIDED );
394     //
395     // project.getModel().addDependency( d3 );
396     //
397     // MavenProject module = createMavenProject( "group", "module", "1", new File( "base/module" ) );
398     //
399     // project.getModel().addModule( module.getArtifactId() );
400     //
401     // Dependency md = new Dependency();
402     // md.setGroupId( "group.dep" );
403     // md.setArtifactId( "dep3" );
404     // md.setVersion( "2" );
405     // md.setScope( Artifact.SCOPE_PROVIDED );
406     //
407     // module.getModel().addDependency( md );
408     //
409     // List allProjects = new ArrayList();
410     // allProjects.add( project );
411     // allProjects.add( module );
412     //
413     // MockManager mm = new MockManager();
414     //
415     // MockControl csControl = MockControl.createControl( AssemblerConfigurationSource.class );
416     // mm.add( csControl );
417     //
418     // AssemblerConfigurationSource cs = (AssemblerConfigurationSource) csControl.getMock();
419     //
420     // cs.getProject();
421     // csControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
422     //
423     // cs.getReactorProjects();
424     // csControl.setReturnValue( allProjects, MockControl.ZERO_OR_MORE );
425     //
426     // cs.getRemoteRepositories();
427     // csControl.setReturnValue( Collections.EMPTY_LIST, MockControl.ZERO_OR_MORE );
428     //
429     // mm.replayAll();
430     //
431     // DefaultDependencyResolver resolver = new DefaultDependencyResolver();
432     // resolver.setArtifactFactory( factory );
433     // resolver.setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
434     //
435     // Map managedVersionMap = resolver.buildManagedVersionMap( assembly, cs );
436     //
437     // {
438     // Dependency d = d1;
439     // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
440     // assertNull( a );
441     // }
442     //
443     // {
444     // Dependency d = d2;
445     // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
446     // assertNotNull( a );
447     // assertEquals( d.getVersion(), a.getVersion() );
448     // assertEquals( d.getScope(), a.getScope() );
449     // }
450     //
451     // {
452     // Dependency d = d3;
453     // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
454     // assertNotNull( a );
455     // assertEquals( d.getVersion(), a.getVersion() );
456     // assertEquals( d.getScope(), a.getScope() );
457     // }
458     //
459     // mm.verifyAll();
460     // }
461     //
462     // public void test_buildManagedVersionMap_TransitiveResolution()
463     // throws ArtifactResolutionException, ArchiveCreationException, InvalidVersionSpecificationException,
464     // InvalidDependencyVersionException
465     // {
466     // Assembly assembly = new Assembly();
467     //
468     // DependencySet ds = new DependencySet();
469     // ds.setScope( Artifact.SCOPE_COMPILE );
470     // ds.setUseTransitiveDependencies( true );
471     //
472     // assembly.addDependencySet( ds );
473     //
474     // MavenProject project = createMavenProject( "group", "artifact", "1", new File( "base" ) );
475     //
476     // Dependency d1 = new Dependency();
477     // d1.setGroupId( "group.dep" );
478     // d1.setArtifactId( "dep1" );
479     // d1.setVersion( "1" );
480     // d1.setScope( Artifact.SCOPE_COMPILE );
481     //
482     // project.getModel().addDependency( d1 );
483     //
484     // Dependency d2 = new Dependency();
485     // d2.setGroupId( "group.dep" );
486     // d2.setArtifactId( "dep2" );
487     // d2.setVersion( "1" );
488     // d2.setScope( Artifact.SCOPE_COMPILE );
489     // final Artifact a2 = factory.createArtifact( d2.getGroupId(), d2.getArtifactId(), d2.getVersion(), d2.getScope(),
490     // "jar" );
491     //
492     // project.getModel().addDependency( d2 );
493     //
494     // Dependency d3 = new Dependency();
495     // d3.setGroupId( "group.dep" );
496     // d3.setArtifactId( "dep3" );
497     // d3.setVersion( "1" );
498     // d3.setScope( Artifact.SCOPE_COMPILE );
499     //
500     // project.getModel().addDependency( d3 );
501     //
502     // final Artifact a2a = factory.createArtifact( d3.getGroupId(), d3.getArtifactId(), "2", Artifact.SCOPE_RUNTIME,
503     // "jar" );
504     //
505     // MockManager mm = new MockManager();
506     //
507     // MockControl msControl = MockControl.createControl( ArtifactMetadataSource.class );
508     // mm.add( msControl );
509     //
510     // ArtifactMetadataSource ms = (ArtifactMetadataSource) msControl.getMock();
511     //
512     // try
513     // {
514     // ms.retrieve( null, null, null );
515     // }
516     // catch ( ArtifactMetadataRetrievalException e )
517     // {
518     // }
519     //
520     // msControl.setDefaultReturnValue( new ResolutionGroup( null, Collections.EMPTY_SET, Collections.EMPTY_LIST ) );
521     // msControl.setMatcher( new ArgumentsMatcher()
522     // {
523     // public boolean matches( Object[] expected, Object[] actual )
524     // {
525     // Artifact a = (Artifact) actual[0];
526     //
527     // return a2.getArtifactId().equals( a.getArtifactId() );
528     // }
529     //
530     // public String toString( Object[] args )
531     // {
532     // return "with artifact: " + args[0] ;
533     // }
534     //
535     // } );
536     // msControl.setReturnValue( new ResolutionGroup( a2, Collections.singleton( a2a ), Collections.EMPTY_LIST ) );
537     //
538     //
539     // MockControl csControl = MockControl.createControl( AssemblerConfigurationSource.class );
540     // mm.add( csControl );
541     //
542     // AssemblerConfigurationSource cs = (AssemblerConfigurationSource) csControl.getMock();
543     //
544     // cs.getProject();
545     // csControl.setReturnValue( project, MockControl.ZERO_OR_MORE );
546     //
547     // String tmpDir = System.getProperty( "java.io.tmpdir" );
548     // ArtifactRepository lr = repoFactory.createArtifactRepository( "local", "file://" + tmpDir, layout, null, null );
549     //
550     // cs.getLocalRepository();
551     // csControl.setReturnValue( lr, MockControl.ZERO_OR_MORE );
552     //
553     // cs.getRemoteRepositories();
554     // csControl.setReturnValue( Collections.EMPTY_LIST, MockControl.ZERO_OR_MORE );
555     //
556     // mm.replayAll();
557     //
558     // DefaultDependencyResolver resolver = new DefaultDependencyResolver();
559     // resolver.setArtifactMetadataSource( ms );
560     // resolver.setArtifactCollector( collector );
561     // resolver.setArtifactFactory( factory );
562     // resolver.setLogger( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );
563     //
564     // Map managedVersionMap = resolver.buildManagedVersionMap( assembly, cs );
565     //
566     // {
567     // Dependency d = d1;
568     // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
569     // assertNotNull( a );
570     // assertEquals( d.getVersion(), a.getVersion() );
571     // assertEquals( d.getScope(), a.getScope() );
572     // }
573     //
574     // {
575     // Dependency d = d2;
576     // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
577     // assertNotNull( a );
578     // assertEquals( d.getVersion(), a.getVersion() );
579     // assertEquals( d.getScope(), a.getScope() );
580     // }
581     //
582     // {
583     // Dependency d = d3;
584     // Artifact a = (Artifact) managedVersionMap.get( d.getManagementKey() );
585     // assertNotNull( a );
586     // assertEquals( d.getVersion(), a.getVersion() );
587     // assertEquals( d.getScope(), a.getScope() );
588     // }
589     //
590     // mm.verifyAll();
591     // }
592 
593     private void assertRepositoryWithId( final String repoId, final List<ArtifactRepository> repos,
594                                          final boolean shouldExist )
595     {
596         if ( ( repos == null || repos.isEmpty() ) )
597         {
598             if ( shouldExist )
599             {
600                 fail( "Repository with id: " + repoId + " should be present, but repository list is null or empty." );
601             }
602         }
603         else
604         {
605             boolean found = false;
606             for ( final ArtifactRepository repo : repos )
607             {
608                 if ( repoId.equals( repo.getId() ) )
609                 {
610                     found = true;
611                     break;
612                 }
613             }
614 
615             if ( shouldExist )
616             {
617                 assertTrue( "Repository with id: " + repoId + " should be present in repository list.", found );
618             }
619             else
620             {
621                 assertFalse( "Repository with id: " + repoId + " should NOT be present in repository list.", found );
622             }
623         }
624     }
625 
626     private MavenProject createMavenProject( final String groupId, final String artifactId, final String version,
627                                              final File basedir )
628     {
629         final Model model = new Model();
630 
631         model.setGroupId( groupId );
632         model.setArtifactId( artifactId );
633         model.setVersion( version );
634         model.setPackaging( "pom" );
635 
636         final MavenProject project = new MavenProject( model );
637 
638         final Artifact pomArtifact = factory.createProjectArtifact( groupId, artifactId, version );
639         project.setArtifact( pomArtifact );
640 
641         project.setFile( new File( basedir, "pom.xml" ) );
642 
643         return project;
644     }
645 
646 }