1 package org.apache.maven.plugins.dependency.fromDependencies;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
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
110
111
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
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
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
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
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
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
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
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
519
520
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
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
561 assertTrue( release.getFile().setLastModified( 1000L ) );
562 assertEquals( 1000L, release.getFile().lastModified() );
563
564 artifacts.add( release );
565
566 mojo.getProject().setArtifacts( artifacts );
567 mojo.getProject().setDependencyArtifacts( artifacts );
568
569 mojo.overWriteReleases = true;
570 mojo.overWriteIfNewer = false;
571
572 mojo.execute();
573
574 File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( release, false ) );
575
576 assertTrue( copiedFile.setLastModified( 2000L ) );
577 assertEquals( 2000L, copiedFile.lastModified() );
578
579 mojo.execute();
580
581 long timeCopyNow = copiedFile.lastModified();
582 assertEquals( 1000L, timeCopyNow );
583
584 }
585
586 public void testDontOverWriteSnap()
587 throws MojoExecutionException, InterruptedException, IOException, MojoFailureException
588 {
589
590 Set<Artifact> artifacts = new HashSet<Artifact>();
591 Artifact snap = stubFactory.getSnapshotArtifact();
592 assertTrue( snap.getFile().setLastModified( 1000L ) );
593 assertEquals( 1000L, snap.getFile().lastModified() );
594
595 artifacts.add( snap );
596
597 mojo.getProject().setArtifacts( artifacts );
598 mojo.getProject().setDependencyArtifacts( artifacts );
599
600 mojo.overWriteReleases = false;
601 mojo.overWriteSnapshots = false;
602 mojo.overWriteIfNewer = false;
603
604 mojo.execute();
605
606 File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) );
607
608 assertTrue( copiedFile.setLastModified( 2000L ) );
609 assertEquals( 2000L, copiedFile.lastModified() );
610
611 mojo.execute();
612
613 long timeCopyNow = copiedFile.lastModified();
614 assertEquals( 2000L, timeCopyNow );
615 }
616
617 public void testOverWriteSnap()
618 throws MojoExecutionException, InterruptedException, IOException, MojoFailureException
619 {
620
621 Set<Artifact> artifacts = new HashSet<Artifact>();
622 Artifact snap = stubFactory.getSnapshotArtifact();
623 assertTrue( snap.getFile().setLastModified( 1000L ) );
624 assertEquals( 1000L, snap.getFile().lastModified() );
625
626 artifacts.add( snap );
627
628 mojo.getProject().setArtifacts( artifacts );
629 mojo.getProject().setDependencyArtifacts( artifacts );
630
631 mojo.overWriteReleases = false;
632 mojo.overWriteSnapshots = true;
633 mojo.overWriteIfNewer = false;
634
635 mojo.execute();
636
637 File copiedFile = new File( mojo.outputDirectory, DependencyUtil.getFormattedFileName( snap, false ) );
638
639 assertTrue( copiedFile.setLastModified( 2000L ) );
640 assertEquals( 2000L, copiedFile.lastModified() );
641
642 mojo.execute();
643
644 long timeCopyNow = copiedFile.lastModified();
645 assertEquals( 1000L, timeCopyNow );
646 }
647
648 public void testGetDependencies()
649 throws MojoExecutionException
650 {
651 assertEquals( mojo.getResolvedDependencies( true ).toString(),
652 mojo.getDependencySets( true ).getResolvedDependencies().toString() );
653 }
654
655 public void testExcludeProvidedScope()
656 throws Exception
657 {
658 mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() );
659 mojo.getProject().setDependencyArtifacts( new HashSet<Artifact>() );
660 mojo.excludeScope = "provided";
661
662
663 mojo.execute();
664
665 Set<Artifact> artifacts = mojo.getProject().getArtifacts();
666 for ( Artifact artifact : artifacts )
667 {
668 String fileName = DependencyUtil.getFormattedFileName( artifact, false );
669 File file = new File( mojo.outputDirectory, fileName );
670 assertEquals( artifact.getScope().equals( "provided" ), !file.exists() );
671 file.delete();
672 assertFalse( file.exists() );
673 }
674
675 }
676
677 public void testExcludeSystemScope()
678 throws Exception
679 {
680 mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() );
681 mojo.getProject().setDependencyArtifacts( new HashSet<Artifact>() );
682 mojo.excludeScope = "system";
683
684
685 mojo.execute();
686
687 Set<Artifact> artifacts = mojo.getProject().getArtifacts();
688 for ( Artifact artifact : artifacts )
689 {
690 String fileName = DependencyUtil.getFormattedFileName( artifact, false );
691 File file = new File( mojo.outputDirectory, fileName );
692 assertEquals( artifact.getScope().equals( "system" ), !file.exists() );
693 file.delete();
694 assertFalse( file.exists() );
695 }
696
697 }
698
699 public void testExcludeCompileScope()
700 throws Exception
701 {
702 mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() );
703 mojo.getProject().setDependencyArtifacts( new HashSet<Artifact>() );
704 mojo.excludeScope = "compile";
705 mojo.execute();
706 ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope );
707
708 Set<Artifact> artifacts = mojo.getProject().getArtifacts();
709 for ( Artifact artifact : artifacts )
710 {
711 String fileName = DependencyUtil.getFormattedFileName( artifact, false );
712 File file = new File( mojo.outputDirectory, fileName );
713
714 assertEquals( !saf.include( artifact ), file.exists() );
715 }
716 }
717
718 public void testExcludeTestScope()
719 throws IOException, MojoFailureException
720 {
721 mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() );
722 mojo.getProject().setDependencyArtifacts( new HashSet<Artifact>() );
723 mojo.excludeScope = "test";
724
725 try
726 {
727 mojo.execute();
728 fail( "expected an exception" );
729 }
730 catch ( MojoExecutionException e )
731 {
732
733 }
734
735 }
736
737 public void testExcludeRuntimeScope()
738 throws Exception
739 {
740 mojo.getProject().setArtifacts( stubFactory.getScopedArtifacts() );
741 mojo.getProject().setDependencyArtifacts( new HashSet<Artifact>() );
742 mojo.excludeScope = "runtime";
743 mojo.execute();
744 ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.excludeScope );
745
746 Set<Artifact> artifacts = mojo.getProject().getArtifacts();
747 for ( Artifact artifact : artifacts )
748 {
749 String fileName = DependencyUtil.getFormattedFileName( artifact, false );
750 File file = new File( mojo.outputDirectory, fileName );
751
752 assertEquals( !saf.include( artifact ), file.exists() );
753 }
754 }
755
756 public void testCopyPom()
757 throws Exception
758 {
759 mojo.setCopyPom( true );
760
761 Set<Artifact> set = new HashSet<Artifact>();
762 set.add( stubFactory.createArtifact( "org.apache.maven", "maven-artifact", "2.0.7", Artifact.SCOPE_COMPILE ) );
763 stubFactory.createArtifact( "org.apache.maven", "maven-artifact", "2.0.7", Artifact.SCOPE_COMPILE, "pom",
764 null );
765 mojo.getProject().setArtifacts( set );
766 mojo.execute();
767
768 Set<Artifact> artifacts = mojo.getProject().getArtifacts();
769 for ( Artifact artifact : artifacts )
770 {
771 String fileName = DependencyUtil.getFormattedFileName( artifact, false );
772 File file = new File( mojo.outputDirectory, fileName.substring( 0, fileName.length() - 4 ) + ".pom" );
773 assertTrue( file + " doesn't exist", file.exists() );
774 }
775 }
776
777 public void testPrependGroupId()
778 throws Exception
779 {
780 mojo.prependGroupId = true;
781 mojo.execute();
782
783 Set<Artifact> artifacts = mojo.getProject().getArtifacts();
784 for ( Artifact artifact : artifacts )
785 {
786 String fileName = DependencyUtil.getFormattedFileName( artifact, false, true );
787 File file = new File( mojo.outputDirectory, fileName );
788 assertTrue( file.exists() );
789 }
790 }
791 }