7
7
*/
8
8
package eu .maveniverse .maven .toolbox .shared ;
9
9
10
- import static java .util .Objects .requireNonNull ;
11
-
12
10
import java .util .Arrays ;
13
11
import java .util .Collection ;
14
12
import java .util .Collections ;
15
13
import java .util .HashSet ;
16
14
import java .util .Objects ;
17
15
import java .util .Set ;
16
+ import java .util .stream .Collectors ;
18
17
19
18
/**
20
19
* The "atoms" of the Toolbox that are used to assemble language specific dependency scopes and resolution scopes.
21
20
* <p>
22
- * Essentially, we deal with 3-dimensional space: project scope, resolution scope, resolution mode. The lagnauges where languages
23
- * place their scopes.
21
+ * Essentially, we deal with 3-dimensional space: project scope, resolution scope, resolution mode. The languages
22
+ * place their scopes into this space (and name them and select the transitive ones) .
24
23
*/
25
24
public final class Atoms {
26
25
/**
@@ -58,113 +57,82 @@ public String toString() {
58
57
}
59
58
60
59
/**
61
- * Dependency scope: all the variations for all resolution scopes .
60
+ * Project scope: like "main", "test", etc.. .
62
61
*/
63
- public static final class DependencyScope extends Atom {
64
- //
65
- // compile | runtime
66
- // none no | no
67
- // both yes | yes
68
- // onlyRuntime no | yes
69
- // onlyCompile yes | no
70
- public static final DependencyScope NONE = new DependencyScope ("none" );
71
- public static final DependencyScope BOTH = new DependencyScope ("both" );
72
- public static final DependencyScope ONLY_RUNTIME = new DependencyScope ("onlyRuntime" );
73
- public static final DependencyScope ONLY_COMPILE = new DependencyScope ("onlyCompile" );
62
+ public static final class ProjectScope extends Atom {
63
+ public static final ProjectScope MAIN = new ProjectScope ("main" );
64
+ public static final ProjectScope TEST = new ProjectScope ("test" );
74
65
75
- public static final Set <DependencyScope > ALL =
76
- Collections .unmodifiableSet (new HashSet <>(Arrays .asList (NONE , BOTH , ONLY_RUNTIME , ONLY_COMPILE )));
66
+ public static final Set <ProjectScope > ALL =
67
+ Collections .unmodifiableSet (new HashSet <>(Arrays .asList (MAIN , TEST )));
77
68
78
- public DependencyScope (String id ) {
69
+ private ProjectScope (String id ) {
79
70
super (id );
80
71
}
81
72
}
82
73
83
74
/**
84
- * Project scope: like "main", "test", etc.. .
75
+ * Resolution scope: "compile" and "runtime" .
85
76
*/
86
- public static final class ProjectScope extends Atom {
87
- public static final ProjectScope NONE = new ProjectScope ("none" );
88
- public static final ProjectScope MAIN = new ProjectScope ("main" );
89
- public static final ProjectScope TEST = new ProjectScope ("test" );
90
- public static final Set <ProjectScope > ALL =
91
- Collections .unmodifiableSet (new HashSet <>(Arrays .asList (NONE , MAIN , TEST )));
92
-
93
- // TODO: this could be even extended? IT, etc
77
+ public static final class ResolutionScope extends Atom {
78
+ public static final ResolutionScope COMPILE = new ResolutionScope ("compile" );
79
+ public static final ResolutionScope RUNTIME = new ResolutionScope ("runtime" );
94
80
95
- public ProjectScope (String id ) {
81
+ public ResolutionScope (String id ) {
96
82
super (id );
97
83
}
98
84
}
99
85
100
86
/**
101
- * Resolution mode: eliminate or just remove.
87
+ * Resolution mode: " eliminate" or ( just) " remove" .
102
88
*/
103
- public enum ResolutionMode {
89
+ public static final class ResolutionMode extends Atom {
104
90
/**
105
- * Mode where non-wanted scopes are eliminated. In other words, this mode ensures that if a dependency was
106
- * removed, as it was in unwanted scope, it will guarantee that no such dependency will appear anywhere else in
107
- * the resulting graph.
91
+ * Mode where artifacts in non-wanted scopes are eliminated. In other words, this mode ensures that if a
92
+ * dependency was removed as it was in unwanted scope, it will guarantee that no such dependency will appear
93
+ * anywhere else in the resulting graph.
108
94
*/
109
- ELIMINATE ,
95
+ public static final ResolutionMode ELIMINATE = new ResolutionMode ( "eliminate" );
110
96
111
97
/**
112
- * Mode where non-wanted scopes are removed only. In other words, they will NOT prevent (as in they will not
113
- * "dominate") perhaps appearing other occurrences of same artifact under some other scope in the graph.
98
+ * Mode where artifacts in non-wanted scopes are removed only. In other words, this mode will NOT prevent
99
+ * (as in, removed will not "dominate") perhaps appearing other occurrences of same artifact under some other
100
+ * scope in the graph.
114
101
*/
115
- REMOVE
102
+ public static final ResolutionMode REMOVE = new ResolutionMode ("remove" );
103
+
104
+ private ResolutionMode (String id ) {
105
+ super (id );
106
+ }
116
107
}
117
108
118
109
/**
119
- * Resolution scope: essentially "compile" and "runtime" .
110
+ * Dependency scope: all the variations for all resolution scopes .
120
111
*/
121
- public static final class ResolutionScope extends Atom {
122
- public static final ResolutionScope NONE =
123
- new ResolutionScope ("none" , Collections .emptySet (), DependencyScope .ALL );
124
- public static final ResolutionScope EMPTY =
125
- new ResolutionScope ("empty" , Collections .emptySet (), Collections .emptySet ());
126
- public static final ResolutionScope COMPILE = new ResolutionScope (
127
- "compile" ,
128
- Arrays .asList (DependencyScope .BOTH , DependencyScope .ONLY_COMPILE ),
129
- Arrays .asList (DependencyScope .NONE , DependencyScope .ONLY_RUNTIME ));
130
- public static final ResolutionScope RUNTIME = new ResolutionScope (
131
- "runtime" ,
132
- Arrays .asList (DependencyScope .BOTH , DependencyScope .ONLY_RUNTIME ),
133
- Arrays .asList (DependencyScope .NONE , DependencyScope .ONLY_COMPILE ));
134
-
135
- private final Set <DependencyScope > contains ;
136
- private final Set <DependencyScope > excludesTransitively ;
137
-
138
- public ResolutionScope (
139
- String id , Collection <DependencyScope > contains , Collection <DependencyScope > excludesTransitively ) {
140
- super (id );
141
- this .contains = Collections .unmodifiableSet (new HashSet <>(contains ));
142
- this .excludesTransitively = Collections .unmodifiableSet (new HashSet <>(excludesTransitively ));
143
- }
112
+ public static final class DependencyScope extends Atom {
113
+ //
114
+ // compile | runtime
115
+ // none no | no
116
+ // both yes | yes
117
+ // onlyRuntime no | yes
118
+ // onlyCompile yes | no
119
+ public static final DependencyScope NONE = new DependencyScope ("none" , Collections .emptySet ());
120
+ public static final DependencyScope BOTH =
121
+ new DependencyScope ("both" , Arrays .asList (ResolutionScope .COMPILE , ResolutionScope .RUNTIME ));
122
+ public static final DependencyScope ONLY_RUNTIME =
123
+ new DependencyScope ("onlyRuntime" , Collections .singleton (ResolutionScope .RUNTIME ));
124
+ public static final DependencyScope ONLY_COMPILE =
125
+ new DependencyScope ("onlyCompile" , Collections .singleton (ResolutionScope .COMPILE ));
144
126
145
- public Set <DependencyScope > getContains () {
146
- return contains ;
147
- }
127
+ private final Set <ResolutionScope > memberOf ;
148
128
149
- public Set <DependencyScope > getExcludesTransitively () {
150
- return excludesTransitively ;
129
+ private DependencyScope (String id , Collection <ResolutionScope > resolutionScopes ) {
130
+ super (id );
131
+ this .memberOf = Collections .unmodifiableSet (new HashSet <>(resolutionScopes ));
151
132
}
152
133
153
- public ResolutionScope plus (DependencyScope dependencyScope ) {
154
- requireNonNull (dependencyScope );
155
- if (this == NONE ) {
156
- throw new IllegalStateException ("NONE is not extensible resolution scope" );
157
- }
158
- if (getContains ().contains (dependencyScope )) {
159
- return this ;
160
- }
161
- if (this == EMPTY ) {
162
- return new ResolutionScope (
163
- dependencyScope .getId (), Collections .singleton (dependencyScope ), Collections .emptySet ());
164
- }
165
- HashSet <DependencyScope > dependencyScopes = new HashSet <>(getContains ());
166
- dependencyScopes .add (dependencyScope );
167
- return new ResolutionScope (getId () + "+" + dependencyScope .getId (), dependencyScopes , excludesTransitively );
134
+ public Set <ResolutionScope > getMemberOf () {
135
+ return memberOf ;
168
136
}
169
137
}
170
138
@@ -189,9 +157,16 @@ public interface LanguageDependencyScope {
189
157
190
158
boolean isTransitive ();
191
159
192
- DependencyScope getDependencyScope ();
160
+ Set < DependencyScope > getDependencyScopes ();
193
161
194
162
Set <ProjectScope > getProjectScopes ();
163
+
164
+ default Set <ResolutionScope > getMemberOf () {
165
+ return getDependencyScopes ().stream ()
166
+ .map (DependencyScope ::getMemberOf )
167
+ .flatMap (Collection ::stream )
168
+ .collect (Collectors .toSet ());
169
+ }
195
170
}
196
171
197
172
/**
@@ -202,9 +177,9 @@ public interface LanguageResolutionScope {
202
177
203
178
Language getLanguage ();
204
179
205
- ProjectScope getProjectScope ();
180
+ Set < ProjectScope > getProjectScopes ();
206
181
207
- ResolutionScope getResolutionScope ();
182
+ Set < ResolutionScope > getResolutionScopes ();
208
183
209
184
ResolutionMode getResolutionMode ();
210
185
}
0 commit comments