1 package org.apache.maven.plugins.dependency.testUtils;
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.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27
28 import org.apache.maven.artifact.Artifact;
29 import org.apache.maven.artifact.ArtifactUtils;
30 import org.apache.maven.artifact.versioning.VersionRange;
31 import org.apache.maven.plugins.dependency.fromConfiguration.ArtifactItem;
32 import org.apache.maven.plugin.testing.ArtifactStubFactory;
33
34 public class DependencyArtifactStubFactory
35 extends ArtifactStubFactory
36 {
37 private boolean flattenedPath = true;
38
39 public DependencyArtifactStubFactory( File theWorkingDir, boolean theCreateFiles, boolean flattenedPath )
40 {
41 this( theWorkingDir, theCreateFiles );
42 this.flattenedPath = flattenedPath;
43 }
44
45
46
47
48
49 public DependencyArtifactStubFactory( File theWorkingDir, boolean theCreateFiles )
50 {
51 super( theWorkingDir, theCreateFiles );
52 }
53
54 public ArtifactItem getArtifactItem( Artifact artifact )
55 {
56 ArtifactItem item = new ArtifactItem( artifact );
57 return item;
58 }
59
60 public List<ArtifactItem> getArtifactItems( Collection<Artifact> artifacts )
61 {
62 List<ArtifactItem> list = new ArrayList<ArtifactItem>();
63 for ( Artifact artifact : artifacts )
64 {
65 list.add( getArtifactItem( artifact ) );
66 }
67 return list;
68 }
69
70 @Override
71 public Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String scope,
72 String type, String classifier, boolean optional )
73 throws IOException
74 {
75 File workingDir = getWorkingDir();
76
77 if ( !flattenedPath )
78 {
79 StringBuilder path = new StringBuilder( 128 );
80
81 path.append( groupId.replace( '.', '/' ) ).append( '/' );
82
83 path.append( artifactId ).append( '/' );
84
85 path.append( ArtifactUtils.toSnapshotVersion( versionRange.getRecommendedVersion().toString() ) );
86
87
88 setWorkingDir( new File( workingDir, path.toString() ) );
89 }
90
91 Artifact artifact =
92 super.createArtifact( groupId, artifactId, versionRange, scope, type, classifier, optional );
93
94 setWorkingDir( workingDir );
95
96 return artifact;
97 }
98 }