1 package com.atlassian.plugins.codegen;
2
3 import static com.atlassian.fugue.Option.some;
4 import static com.atlassian.plugins.codegen.ArtifactId.artifactId;
5 import static com.atlassian.plugins.codegen.VersionId.version;
6 import static com.google.common.base.Preconditions.checkNotNull;
7
8
9
10
11 public final class ArtifactDependency implements PluginProjectChange
12 {
13 public enum Scope
14 {
15 DEFAULT,
16 COMPILE,
17 PROVIDED,
18 TEST
19 };
20
21 private ArtifactId artifactId;
22 private VersionId versionId;
23 private Scope scope;
24
25
26
27
28
29
30
31
32 public static ArtifactDependency dependency(String groupId, String artifactId, VersionId versionId, Scope scope)
33 {
34 return new ArtifactDependency(artifactId(some(groupId), artifactId), versionId, scope);
35 }
36
37
38
39
40
41
42
43
44 public static ArtifactDependency dependency(String groupId, String artifactId, String version, Scope scope)
45 {
46 return new ArtifactDependency(artifactId(some(groupId), artifactId), version(version), scope);
47 }
48
49
50
51
52
53
54
55 public static ArtifactDependency dependency(ArtifactId groupAndArtifactId, VersionId versionId, Scope scope)
56 {
57 return new ArtifactDependency(groupAndArtifactId, versionId, scope);
58 }
59
60
61
62
63
64
65
66 public static ArtifactDependency dependency(ArtifactId groupAndArtifactId, String version, Scope scope)
67 {
68 return new ArtifactDependency(groupAndArtifactId, version(version), scope);
69 }
70
71 private ArtifactDependency(ArtifactId artifactId, VersionId versionId, Scope scope)
72 {
73 this.artifactId = checkNotNull(artifactId, "artifactId");
74 if (!artifactId.getGroupId().isDefined())
75 {
76 throw new IllegalArgumentException("Group ID must be specified for dependency");
77 }
78 this.versionId = checkNotNull(versionId, "versionId");
79 if (!versionId.getVersion().isDefined())
80 {
81 throw new IllegalArgumentException("Version must be specified for dependency");
82 }
83 this.scope = checkNotNull(scope, "scope");
84 }
85
86 public ArtifactId getGroupAndArtifactId()
87 {
88 return artifactId;
89 }
90
91 public VersionId getVersionId()
92 {
93 return versionId;
94 }
95
96 public Scope getScope()
97 {
98 return scope;
99 }
100
101 @Override
102 public String toString()
103 {
104 return "[dependency: " + artifactId + "]";
105 }
106 }