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 public static ArtifactScopeEnum checkScope(ArtifactScopeEnum scope) {
53 return scope == null ? DEFAULT_SCOPE : scope;
54 }
55
56
57
58
59
60 public String getScope() {
61 if (id == 1) {
62 return Artifact.SCOPE_COMPILE;
63 } else if (id == 2) {
64 return Artifact.SCOPE_TEST;
65
66 } else if (id == 3) {
67 return Artifact.SCOPE_RUNTIME;
68
69 } else if (id == 4) {
70 return Artifact.SCOPE_PROVIDED;
71 } else if (id == 5) {
72 return Artifact.SCOPE_SYSTEM;
73 } else {
74 return Artifact.SCOPE_RUNTIME_PLUS_SYSTEM;
75 }
76 }
77
78 private static final ArtifactScopeEnum[][][] COMPLIANCY_SETS = {
79 {{compile}, {compile, provided, system}},
80 {{test}, {compile, test, provided, system}},
81 {{runtime}, {compile, runtime, system}},
82 {{provided}, {compile, test, provided}}
83 };
84
85
86
87
88
89
90
91 public boolean encloses(ArtifactScopeEnum scope) {
92 final ArtifactScopeEnum s = checkScope(scope);
93
94
95 if (id == system.id) {
96 return scope.id == system.id;
97 }
98
99 for (ArtifactScopeEnum[][] set : COMPLIANCY_SETS) {
100 if (id == set[0][0].id) {
101 for (ArtifactScopeEnum ase : set[1]) {
102 if (s.id == ase.id) {
103 return true;
104 }
105 }
106 break;
107 }
108 }
109 return false;
110 }
111 }