View Javadoc

1   package org.apache.maven.plugin.dependency;
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.io.IOException;
24  import java.util.HashSet;
25  import java.util.Iterator;
26  import java.util.Set;
27  
28  import org.apache.maven.artifact.Artifact;
29  import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
30  import org.apache.maven.plugin.MojoExecutionException;
31  import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
32  import org.apache.maven.plugin.dependency.utils.DependencyUtil;
33  import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
34  import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
35  import org.apache.maven.plugin.testing.stubs.StubArtifactResolver;
36  import org.apache.maven.project.MavenProject;
37  import org.codehaus.plexus.util.StringUtils;
38  
39  public class TestCopyDependenciesMojo
40      extends AbstractDependencyMojoTestCase
41  {
42  
43      CopyDependenciesMojo mojo;
44  
45      protected void setUp()
46          throws Exception
47      {
48          // required for mojo lookups to work
49          super.setUp( "copy-dependencies", true );
50  
51          File testPom = new File( getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml" );
52          mojo = (CopyDependenciesMojo) lookupMojo( "copy-dependencies", testPom );
53          mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
54          // mojo.silent = true;
55  
56          assertNotNull( mojo );
57          assertNotNull( mojo.getProject() );
58          MavenProject project = mojo.getProject();
59  
60          Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
61          Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
62          artifacts.addAll( directArtifacts );
63  
64          project.setArtifacts( artifacts );
65          project.setDependencyArtifacts( directArtifacts );
66          mojo.markersDirectory = new File( this.testDir, "markers" );
67  
68      }
69  
70      public void assertNoMarkerFile( Artifact artifact )
71      {
72          DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( artifact, mojo.markersDirectory );
73          try
74          {
75              assertFalse( handle.isMarkerSet() );
76          }
77          catch ( MojoExecutionException e )
78          {
79              fail( e.getLongMessage() );
80          }
81  
82      }
83  
84      public void testCopyFile()
85          throws MojoExecutionException, IOException
86      {
87          File src = File.createTempFile( "copy", null );
88  
89          File dest = new File( mojo.outputDirectory, "toMe.jar" );
90  
91          assertFalse( dest.exists() );
92  
93          mojo.copyFile( src, dest );
94          assertTrue( dest.exists() );
95      }
96  
97      /**
98       * tests the proper discovery and configuration of the mojo
99       *
100      * @throws Exception
101      */
102     public void testMojo()
103         throws Exception
104     {
105         mojo.execute();
106         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
107         while ( iter.hasNext() )
108         {
109             Artifact artifact = iter.next();
110             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
111             File file = new File( mojo.outputDirectory, fileName );
112             assertTrue( file.exists() );
113 
114             // there should be no markers for the copy mojo
115             assertNoMarkerFile( artifact );
116         }
117     }
118 
119     public void testStripVersion()
120         throws Exception
121     {
122         mojo.stripVersion = true;
123         mojo.execute();
124 
125         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
126         while ( iter.hasNext() )
127         {
128             Artifact artifact = iter.next();
129             String fileName = DependencyUtil.getFormattedFileName( artifact, true );
130             File file = new File( mojo.outputDirectory, fileName );
131             assertTrue( file.exists() );
132         }
133     }
134 
135     public void testNoTransitive()
136         throws Exception
137     {
138         mojo.excludeTransitive = true;
139         mojo.execute();
140         Iterator<Artifact> iter = mojo.project.getDependencyArtifacts().iterator();
141 
142         while ( iter.hasNext() )
143         {
144             Artifact artifact = iter.next();
145             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
146             File file = new File( mojo.outputDirectory, fileName );
147             assertTrue( file.exists() );
148         }
149     }
150 
151     public void testExcludeType()
152         throws Exception
153     {
154         mojo.project.setArtifacts( stubFactory.getTypedArtifacts() );
155         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
156         mojo.excludeTypes = "jar";
157         mojo.execute();
158 
159         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
160         while ( iter.hasNext() )
161         {
162             Artifact artifact = iter.next();
163             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
164             File file = new File( mojo.outputDirectory, fileName );
165             assertEquals( artifact.getType().equalsIgnoreCase( "jar" ), !file.exists() );
166         }
167     }
168 
169     public void testIncludeType()
170         throws Exception
171     {
172         mojo.project.setArtifacts( stubFactory.getTypedArtifacts() );
173         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
174 
175         mojo.includeTypes = "jar";
176         mojo.excludeTypes = "jar";
177         //shouldn't get anything.
178 
179         mojo.execute();
180 
181         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
182         while ( iter.hasNext() )
183         {
184             Artifact artifact = iter.next();
185             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
186             File file = new File( mojo.outputDirectory, fileName );
187             assertFalse( file.exists() );
188         }
189 
190         mojo.excludeTypes = "";
191         mojo.execute();
192 
193         iter = mojo.project.getArtifacts().iterator();
194         while ( iter.hasNext() )
195         {
196             Artifact artifact = iter.next();
197             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
198             File file = new File( mojo.outputDirectory, fileName );
199             assertEquals( artifact.getType().equalsIgnoreCase( "jar" ), file.exists() );
200         }
201     }
202 
203 
204     public void testExcludeArtifactId()
205         throws Exception
206     {
207         mojo.project.setArtifacts( stubFactory.getArtifactArtifacts() );
208         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
209         mojo.excludeArtifactIds = "one";
210         mojo.execute();
211 
212         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
213         while ( iter.hasNext() )
214         {
215             Artifact artifact = iter.next();
216             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
217             File file = new File( mojo.outputDirectory, fileName );
218             assertEquals( artifact.getArtifactId().equals( "one" ), !file.exists() );
219         }
220     }
221 
222     public void testIncludeArtifactId()
223         throws Exception
224     {
225         mojo.project.setArtifacts( stubFactory.getArtifactArtifacts() );
226         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
227 
228         mojo.includeArtifactIds = "one";
229         mojo.excludeArtifactIds = "one";
230         //shouldn't get anything
231 
232         mojo.execute();
233 
234         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
235         while ( iter.hasNext() )
236         {
237             Artifact artifact = iter.next();
238             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
239             File file = new File( mojo.outputDirectory, fileName );
240             assertFalse( file.exists() );
241         }
242 
243         mojo.excludeArtifactIds = "";
244         mojo.execute();
245 
246         iter = mojo.project.getArtifacts().iterator();
247         while ( iter.hasNext() )
248         {
249             Artifact artifact = iter.next();
250             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
251             File file = new File( mojo.outputDirectory, fileName );
252             assertEquals( artifact.getArtifactId().equals( "one" ), file.exists() );
253         }
254     }
255 
256     public void testIncludeGroupId()
257         throws Exception
258     {
259         mojo.project.setArtifacts( stubFactory.getGroupIdArtifacts() );
260         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
261         mojo.includeGroupIds = "one";
262         mojo.excludeGroupIds = "one";
263         //shouldn't get anything
264 
265         mojo.execute();
266 
267         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
268         while ( iter.hasNext() )
269         {
270             Artifact artifact = iter.next();
271             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
272             File file = new File( mojo.outputDirectory, fileName );
273             assertFalse( file.exists() );
274         }
275 
276         mojo.excludeGroupIds = "";
277         mojo.execute();
278 
279         iter = mojo.project.getArtifacts().iterator();
280         while ( iter.hasNext() )
281         {
282             Artifact artifact = iter.next();
283             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
284             File file = new File( mojo.outputDirectory, fileName );
285             assertEquals( artifact.getGroupId().equals( "one" ), file.exists() );
286         }
287 
288     }
289 
290     public void testExcludeGroupId()
291         throws Exception
292     {
293         mojo.project.setArtifacts( stubFactory.getGroupIdArtifacts() );
294         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
295         mojo.excludeGroupIds = "one";
296         mojo.execute();
297 
298         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
299         while ( iter.hasNext() )
300         {
301             Artifact artifact = iter.next();
302             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
303             File file = new File( mojo.outputDirectory, fileName );
304 
305             assertEquals( artifact.getGroupId().equals( "one" ), !file.exists() );
306         }
307     }
308     public void testExcludeMultipleGroupIds()
309         throws Exception
310     {
311         mojo.project.setArtifacts( stubFactory.getGroupIdArtifacts() );
312         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
313         mojo.excludeGroupIds = "one,two";
314         mojo.execute();
315 
316         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
317         while ( iter.hasNext() )
318         {
319             Artifact artifact = iter.next();
320             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
321             File file = new File( mojo.outputDirectory, fileName );
322 
323             assertEquals( artifact.getGroupId().equals( "one" ) || artifact.getGroupId().equals( "two" ), !file.exists() );
324         }
325     }
326 
327     public void testExcludeClassifier()
328         throws Exception
329     {
330         mojo.project.setArtifacts( stubFactory.getClassifiedArtifacts() );
331         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
332         mojo.excludeClassifiers = "one";
333         mojo.execute();
334 
335         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
336         while ( iter.hasNext() )
337         {
338             Artifact artifact = iter.next();
339             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
340             File file = new File( mojo.outputDirectory, fileName );
341             assertEquals( artifact.getClassifier().equals( "one" ), !file.exists() );
342         }
343     }
344 
345     public void testIncludeClassifier()
346         throws Exception
347     {
348         mojo.project.setArtifacts( stubFactory.getClassifiedArtifacts() );
349         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
350 
351         mojo.includeClassifiers = "one";
352         mojo.excludeClassifiers = "one";
353         //shouldn't get anything
354 
355         mojo.execute();
356 
357         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
358         while ( iter.hasNext() )
359         {
360             Artifact artifact = iter.next();
361             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
362             File file = new File( mojo.outputDirectory, fileName );
363             assertFalse( file.exists() );
364         }
365 
366         mojo.excludeClassifiers = "";
367         mojo.execute();
368 
369         iter = mojo.project.getArtifacts().iterator();
370         while ( iter.hasNext() )
371         {
372             Artifact artifact = iter.next();
373             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
374             File file = new File( mojo.outputDirectory, fileName );
375             assertEquals( artifact.getClassifier().equals( "one" ), file.exists() );
376         }
377 
378     }
379 
380     public void testSubPerType()
381         throws Exception
382     {
383         mojo.project.setArtifacts( stubFactory.getTypedArtifacts() );
384         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
385         mojo.useSubDirectoryPerType = true;
386         mojo.execute();
387 
388         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
389         while ( iter.hasNext() )
390         {
391             Artifact artifact = iter.next();
392             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
393             File folder = DependencyUtil.getFormattedOutputDirectory( false, true, false, false, false, mojo.outputDirectory,
394                                                                       artifact );
395             File file = new File( folder, fileName );
396             assertTrue( file.exists() );
397         }
398     }
399 
400     public void testCDMClassifier()
401         throws Exception
402     {
403         dotestClassifierType( "jdk14", null );
404     }
405 
406     public void testCDMType()
407         throws Exception
408     {
409         dotestClassifierType( null, "sources" );
410     }
411 
412     public void testCDMClassifierType()
413         throws Exception
414     {
415         dotestClassifierType( "jdk14", "sources" );
416     }
417 
418     public void dotestClassifierType( String testClassifier, String testType )
419         throws Exception
420     {
421         mojo.classifier = testClassifier;
422         mojo.type = testType;
423 
424         // init classifier things
425         mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
426         mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) );
427         mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
428 
429         mojo.execute();
430 
431         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
432         while ( iter.hasNext() )
433         {
434             Artifact artifact = iter.next();
435 
436             String useClassifier = artifact.getClassifier();
437             String useType = artifact.getType();
438 
439             if ( StringUtils.isNotEmpty( testClassifier ) )
440             {
441                 useClassifier = "-" + testClassifier;
442                 // type is only used if classifier is used.
443                 if ( StringUtils.isNotEmpty( testType ) )
444                 {
445                     useType = testType;
446                 }
447             }
448             String fileName = artifact.getArtifactId() + "-" + artifact.getVersion() + useClassifier + "." + useType;
449             File file = new File( mojo.outputDirectory, fileName );
450 
451             if ( !file.exists() )
452             {
453                 fail( "Can't find:" + file.getAbsolutePath() );
454             }
455 
456             // there should be no markers for the copy mojo
457             assertNoMarkerFile( artifact );
458         }
459     }
460 
461     public void testArtifactNotFound()
462         throws Exception
463     {
464         dotestArtifactExceptions( false, true );
465     }
466 
467     public void testArtifactResolutionException()
468         throws Exception
469     {
470         dotestArtifactExceptions( true, false );
471     }
472 
473     public void dotestArtifactExceptions( boolean are, boolean anfe )
474         throws Exception
475     {
476         mojo.classifier = "jdk";
477         mojo.type = "java-sources";
478 
479         // init classifier things
480         mojo.factory = DependencyTestUtils.getArtifactFactory();
481         mojo.resolver = new StubArtifactResolver( null, are, anfe );
482         mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
483 
484         try
485         {
486             mojo.execute();
487             fail( "ExpectedException" );
488         }
489         catch ( MojoExecutionException e )
490         {
491 
492         }
493     }
494 
495     /*
496      * public void testOverwrite() { stubFactory.setCreateFiles( false );
497      * Artifact artifact = stubFactory.createArtifact( "test", "artifact", "1.0" );
498      *
499      * File testFile = new File( getBasedir() + File.separatorChar +
500      * "target/test-classes/unit/copy-dependencies-test/test.zip" ); }
501      */
502 
503     public void testDontOverWriteRelease()
504         throws MojoExecutionException, InterruptedException, IOException
505     {
506 
507         Set<Artifact> artifacts = new HashSet<Artifact>();
508         Artifact release = stubFactory.getReleaseArtifact();
509         release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
510 
511         artifacts.add( release );
512 
513         mojo.project.setArtifacts( artifacts );
514         mojo.project.setDependencyArtifacts( artifacts );
515 
516         mojo.overWriteIfNewer = false;
517 
518         mojo.execute();
519 
520         File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) );
521 
522         Thread.sleep( 100 );
523         // round up to the next second
524         long time = System.currentTimeMillis() + 1000;
525         time = time - ( time % 1000 );
526         copiedFile.setLastModified( time );
527         Thread.sleep( 100 );
528 
529         mojo.execute();
530 
531         assertEquals( time, copiedFile.lastModified() );
532     }
533 
534     public void testOverWriteRelease()
535         throws MojoExecutionException, InterruptedException, IOException
536     {
537 
538         Set<Artifact> artifacts = new HashSet<Artifact>();
539         Artifact release = stubFactory.getReleaseArtifact();
540         release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
541 
542         artifacts.add( release );
543 
544         mojo.project.setArtifacts( artifacts );
545         mojo.project.setDependencyArtifacts( artifacts );
546 
547         mojo.overWriteReleases = true;
548         mojo.overWriteIfNewer = false;
549 
550         mojo.execute();
551 
552         File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) );
553 
554         Thread.sleep( 100 );
555         // round down to the last second
556         long time = System.currentTimeMillis();
557         time = time - ( time % 1000 );
558         copiedFile.setLastModified( time );
559         // wait at least a second for filesystems that only record to the
560         // nearest second.
561         Thread.sleep( 1000 );
562 
563         mojo.execute();
564 
565         assertTrue( time < copiedFile.lastModified() );
566     }
567 
568     public void testDontOverWriteSnap()
569         throws MojoExecutionException, InterruptedException, IOException
570     {
571 
572         Set<Artifact> artifacts = new HashSet<Artifact>();
573         Artifact snap = stubFactory.getSnapshotArtifact();
574         snap.getFile().setLastModified( System.currentTimeMillis() - 2000 );
575 
576         artifacts.add( snap );
577 
578         mojo.project.setArtifacts( artifacts );
579         mojo.project.setDependencyArtifacts( artifacts );
580 
581         mojo.overWriteReleases = false;
582         mojo.overWriteSnapshots = false;
583         mojo.overWriteIfNewer = false;
584 
585         mojo.execute();
586 
587         File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) );
588 
589         Thread.sleep( 100 );
590         // round up to the next second
591         long time = System.currentTimeMillis() + 1000;
592         time = time - ( time % 1000 );
593         copiedFile.setLastModified( time );
594         Thread.sleep( 100 );
595 
596         mojo.execute();
597 
598         assertEquals( time, copiedFile.lastModified() );
599     }
600 
601     public void testOverWriteSnap()
602         throws MojoExecutionException, InterruptedException, IOException
603     {
604 
605         Set<Artifact> artifacts = new HashSet<Artifact>();
606         Artifact snap = stubFactory.getSnapshotArtifact();
607         snap.getFile().setLastModified( System.currentTimeMillis() - 2000 );
608 
609         artifacts.add( snap );
610 
611         mojo.project.setArtifacts( artifacts );
612         mojo.project.setDependencyArtifacts( artifacts );
613 
614         mojo.overWriteReleases = false;
615         mojo.overWriteSnapshots = true;
616         mojo.overWriteIfNewer = false;
617 
618         mojo.execute();
619 
620         File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) );
621 
622         Thread.sleep( 100 );
623         // round down to the last second
624         long time = System.currentTimeMillis();
625         time = time - ( time % 1000 );
626         copiedFile.setLastModified( time );
627         // wait at least a second for filesystems that only record to the
628         // nearest second.
629         Thread.sleep( 1000 );
630 
631         mojo.execute();
632 
633         assertTrue( time < copiedFile.lastModified() );
634     }
635 
636     public void testGetDependencies()
637         throws MojoExecutionException
638     {
639         assertEquals( mojo.getResolvedDependencies( true ).toString(), mojo.getDependencySets( true )
640             .getResolvedDependencies().toString() );
641     }
642 
643     public void testExcludeProvidedScope()
644         throws Exception
645     {
646         mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
647         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
648         mojo.excludeScope = "provided";
649         // mojo.silent = false;
650 
651         mojo.execute();
652 
653         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
654         while ( iter.hasNext() )
655         {
656             Artifact artifact = iter.next();
657             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
658             File file = new File( mojo.outputDirectory, fileName );
659             assertEquals( artifact.getScope().equals( "provided" ), !file.exists() );
660             file.delete();
661             assertFalse( file.exists() );
662         }
663 
664     }
665 
666     public void testExcludeSystemScope()
667         throws Exception
668     {
669         mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
670         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
671         mojo.excludeScope = "system";
672         // mojo.silent = false;
673 
674         mojo.execute();
675 
676         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
677         while ( iter.hasNext() )
678         {
679             Artifact artifact = iter.next();
680             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
681             File file = new File( mojo.outputDirectory, fileName );
682             assertEquals( artifact.getScope().equals( "system" ), !file.exists() );
683             file.delete();
684             assertFalse( file.exists() );
685         }
686 
687     }
688 
689     public void testExcludeCompileScope()
690         throws Exception
691     {
692         mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
693         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
694         mojo.excludeScope = "compile";
695         mojo.execute();
696         ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope );
697 
698         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
699         while ( iter.hasNext() )
700         {
701             Artifact artifact = iter.next();
702             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
703             File file = new File( mojo.outputDirectory, fileName );
704 
705             assertEquals( !saf.include( artifact ), file.exists() );
706         }
707     }
708 
709     public void testExcludeTestScope()
710         throws IOException
711     {
712         mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
713         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
714         mojo.excludeScope = "test";
715 
716         try
717         {
718             mojo.execute();
719             fail( "expected an exception" );
720         }
721         catch ( MojoExecutionException e )
722         {
723 
724         }
725 
726     }
727 
728     public void testExcludeRuntimeScope()
729         throws Exception
730     {
731         mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
732         mojo.project.setDependencyArtifacts( new HashSet<Artifact>() );
733         mojo.excludeScope = "runtime";
734         mojo.execute();
735         ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope );
736 
737         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
738         while ( iter.hasNext() )
739         {
740             Artifact artifact = iter.next();
741             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
742             File file = new File( mojo.outputDirectory, fileName );
743 
744             assertEquals( !saf.include( artifact ), file.exists() );
745         }
746     }
747 
748     public void testCopyPom()
749         throws Exception
750     {
751         mojo.setCopyPom( true );
752         mojo.setResolver( new StubArtifactResolver( stubFactory, false, false ) );
753         mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
754 
755         Set<Artifact> set = new HashSet<Artifact>();
756         set.add( stubFactory.createArtifact( "org.apache.maven", "maven-artifact", "2.0.7", Artifact.SCOPE_COMPILE ) );
757         mojo.project.setArtifacts( set );
758         mojo.execute();
759 
760         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
761         while ( iter.hasNext() )
762         {
763             Artifact artifact = iter.next();
764             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
765             File file = new File( mojo.outputDirectory, fileName.substring( 0, fileName.length() - 4 ) + ".pom" );
766             assertTrue( file.exists() );
767         }
768     }
769     
770     public void testPrependGroupId() 
771         throws Exception
772     {
773         mojo.prependGroupId = true;
774         mojo.execute();
775     
776         Iterator<Artifact> iter = mojo.project.getArtifacts().iterator();
777         while ( iter.hasNext() )
778         {
779             Artifact artifact = iter.next();
780             String fileName = DependencyUtil.getFormattedFileName( artifact, false, true );
781             File file = new File( mojo.outputDirectory, fileName );
782             assertTrue( file.exists() );
783         }
784     }
785 }