1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.artifact;
20
21
22
23
24
25
26
27
28 public enum ArtifactScopeEnum {
29 compile(1),
30 test(2),
31 runtime(3),
32 provided(4),
33 system(5),
34 runtime_plus_system(6);
35
36 public static final ArtifactScopeEnum DEFAULT_SCOPE = compile;
37
38 private int id;
39
40
41 ArtifactScopeEnum(int id) {
42 this.id = id;
43 }
44
45 int getId() {
46 return id;
47 }
48
49
50
51
52
53
54
55 public static ArtifactScopeEnum checkScope(ArtifactScopeEnum scope) {
56 return scope == null ? DEFAULT_SCOPE : scope;
57 }
58
59
60
61
62
63 public String getScope() {
64 if (id == 1) {
65 return Artifact.SCOPE_COMPILE;
66 } else if (id == 2) {
67 return Artifact.SCOPE_TEST;
68
69 } else if (id == 3) {
70 return Artifact.SCOPE_RUNTIME;
71
72 } else if (id == 4) {
73 return Artifact.SCOPE_PROVIDED;
74 } else if (id == 5) {
75 return Artifact.SCOPE_SYSTEM;
76 } else {
77 return Artifact.SCOPE_RUNTIME_PLUS_SYSTEM;
78 }
79 }
80
81 private static final ArtifactScopeEnum[][][] COMPLIANCY_SETS = {
82 {{compile}, {compile, provided, system}},
83 {{test}, {compile, test, provided, system}},
84 {{runtime}, {compile, runtime, system}},
85 {{provided}, {compile, test, provided}}
86 };
87
88
89
90
91
92
93
94 public boolean encloses(ArtifactScopeEnum scope) {
95 final ArtifactScopeEnum s = checkScope(scope);
96
97
98 if (id == system.id) {
99 return scope.id == system.id;
100 }
101
102 for (ArtifactScopeEnum[][] set : COMPLIANCY_SETS) {
103 if (id == set[0][0].id) {
104 for (ArtifactScopeEnum ase : set[1]) {
105 if (s.id == ase.id) {
106 return true;
107 }
108 }
109 break;
110 }
111 }
112 return false;
113 }
114 }