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