1 package org.apache.maven.plugins.checkstyle;
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
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.ArtifactUtils;
27 import org.apache.maven.artifact.versioning.VersionRange;
28 import org.apache.maven.plugin.testing.ArtifactStubFactory;
29
30 public class DependencyArtifactStubFactory
31 extends ArtifactStubFactory
32 {
33 private boolean flattenedPath = true;
34
35 public DependencyArtifactStubFactory( File theWorkingDir, boolean theCreateFiles, boolean flattenedPath )
36 {
37 this( theWorkingDir, theCreateFiles );
38 this.flattenedPath = flattenedPath;
39 }
40
41 public DependencyArtifactStubFactory( File theWorkingDir, boolean theCreateFiles )
42 {
43 super( theWorkingDir, theCreateFiles );
44 }
45
46 @Override
47 public Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String scope,
48 String type, String classifier, boolean optional )
49 throws IOException
50 {
51 File workingDir = getWorkingDir();
52
53 if ( !flattenedPath )
54 {
55
56 String path = groupId.replace( '.', '/' ) + '/' +
57 artifactId + '/' +
58 ArtifactUtils.toSnapshotVersion( versionRange.getRecommendedVersion().toString() );
59 setWorkingDir( new File( workingDir, path ) );
60 }
61
62 Artifact artifact =
63 super.createArtifact( groupId, artifactId, versionRange, scope, type, classifier, optional );
64
65 setWorkingDir( workingDir );
66
67 return artifact;
68 }
69 }