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