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