1 package org.codehaus.plexus.languages.java.jpms;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.Collections;
28
29
30
31
32
33
34
35 public abstract class ResolvePathsRequest<T> {
36 private Path jdkHome;
37
38 private Path mainModuleDescriptor;
39
40 private Collection<T> pathElements;
41
42 private Collection<String> additionalModules;
43
44 private boolean includeAllProviders;
45
46 private JavaModuleDescriptor resolvedMainModuleDescriptor;
47
48 private boolean includeStatic;
49
50 private ResolvePathsRequest() {}
51
52
53
54
55 @Deprecated
56 public static ResolvePathsRequest<File> withFiles(Collection<File> files) {
57 return ofFiles(files);
58 }
59
60 public static ResolvePathsRequest<File> ofFiles(File... files) {
61 return ofFiles(Arrays.asList(files));
62 }
63
64 public static ResolvePathsRequest<File> ofFiles(Collection<File> files) {
65 ResolvePathsRequest<File> request = new ResolvePathsRequest<File>() {
66 @Override
67 protected Path toPath(File t) {
68 return t.toPath();
69 }
70 };
71
72 request.pathElements = files;
73 return request;
74 }
75
76
77
78
79 @Deprecated
80 public static ResolvePathsRequest<Path> withPaths(Collection<Path> paths) {
81 return ofPaths(paths);
82 }
83
84 public static ResolvePathsRequest<Path> ofPaths(Path... paths) {
85 return ofPaths(Arrays.asList(paths));
86 }
87
88 public static ResolvePathsRequest<Path> ofPaths(Collection<Path> paths) {
89 ResolvePathsRequest<Path> request = new ResolvePathsRequest<Path>() {
90 @Override
91 protected Path toPath(Path t) {
92 return t;
93 }
94 };
95 request.pathElements = paths;
96 return request;
97 }
98
99
100
101
102 @Deprecated
103 public static ResolvePathsRequest<String> withStrings(Collection<String> strings) {
104 return ofStrings(strings);
105 }
106
107 public static ResolvePathsRequest<String> ofStrings(String... strings) {
108 return ofStrings(Arrays.asList(strings));
109 }
110
111 public static ResolvePathsRequest<String> ofStrings(Collection<String> strings) {
112 ResolvePathsRequest<String> request = new ResolvePathsRequest<String>() {
113 @Override
114 protected Path toPath(String t) {
115 return Paths.get(t);
116 }
117 };
118 request.pathElements = strings;
119 return request;
120 }
121
122 protected abstract Path toPath(T t);
123
124 final ResolvePathsResult<T> createResult() {
125 return new ResolvePathsResult<>();
126 }
127
128 public Path getMainModuleDescriptor() {
129 return mainModuleDescriptor;
130 }
131
132 public JavaModuleDescriptor getModuleDescriptor() {
133 return resolvedMainModuleDescriptor;
134 }
135
136
137
138
139
140
141
142 public ResolvePathsRequest<T> setMainModuleDescriptor(T mainModuleDescriptor) {
143 this.mainModuleDescriptor = toPath(mainModuleDescriptor);
144 return this;
145 }
146
147
148
149
150
151
152
153 public ResolvePathsRequest<T> setModuleDescriptor(JavaModuleDescriptor mainModuleDescriptor) {
154 this.resolvedMainModuleDescriptor = mainModuleDescriptor;
155 return this;
156 }
157
158 public Collection<T> getPathElements() {
159 return pathElements;
160 }
161
162
163
164
165
166
167
168 public ResolvePathsRequest<T> setJdkHome(T jdkHome) {
169 this.jdkHome = toPath(jdkHome);
170 return this;
171 }
172
173 public Path getJdkHome() {
174 return jdkHome;
175 }
176
177
178
179
180
181
182
183 public ResolvePathsRequest<T> setAdditionalModules(Collection<String> additionalModules) {
184 this.additionalModules = additionalModules;
185 return this;
186 }
187
188 public Collection<String> getAdditionalModules() {
189 if (additionalModules == null) {
190 additionalModules = Collections.emptyList();
191 }
192 return additionalModules;
193 }
194
195
196
197
198
199
200
201 public ResolvePathsRequest<T> setIncludeAllProviders(boolean includeAllProviders) {
202 this.includeAllProviders = includeAllProviders;
203 return this;
204 }
205
206 public boolean isIncludeAllProviders() {
207 return includeAllProviders;
208 }
209
210
211
212
213
214
215 public boolean isIncludeStatic() {
216 return includeStatic;
217 }
218
219
220
221
222
223
224
225 public ResolvePathsRequest<T> setIncludeStatic(boolean includeStatic) {
226 this.includeStatic = includeStatic;
227 return this;
228 }
229 }