1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.checkstyle;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.ArtifactUtils;
26 import org.apache.maven.artifact.versioning.VersionRange;
27 import org.apache.maven.plugin.testing.ArtifactStubFactory;
28
29 public class DependencyArtifactStubFactory extends ArtifactStubFactory {
30 private boolean flattenedPath = true;
31
32 public DependencyArtifactStubFactory(File theWorkingDir, boolean theCreateFiles, boolean flattenedPath) {
33 this(theWorkingDir, theCreateFiles);
34 this.flattenedPath = flattenedPath;
35 }
36
37 public DependencyArtifactStubFactory(File theWorkingDir, boolean theCreateFiles) {
38 super(theWorkingDir, theCreateFiles);
39 }
40
41 @Override
42 public Artifact createArtifact(
43 String groupId,
44 String artifactId,
45 VersionRange versionRange,
46 String scope,
47 String type,
48 String classifier,
49 boolean optional)
50 throws IOException {
51 File workingDir = getWorkingDir();
52
53 if (!flattenedPath) {
54
55 String path = groupId.replace('.', '/')
56 + '/'
57 + artifactId
58 + '/'
59 + ArtifactUtils.toSnapshotVersion(
60 versionRange.getRecommendedVersion().toString());
61 setWorkingDir(new File(workingDir, path));
62 }
63
64 Artifact artifact = super.createArtifact(groupId, artifactId, versionRange, scope, type, classifier, optional);
65
66 setWorkingDir(workingDir);
67
68 return artifact;
69 }
70 }