Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/objectmodel/com/ibm/j9tools/om/BuildInfo.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2007, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.j9tools.om;
23
24
import java.io.PrintStream;
25
import java.text.NumberFormat;
26
import java.text.SimpleDateFormat;
27
import java.util.Calendar;
28
import java.util.Collection;
29
import java.util.Collections;
30
import java.util.Date;
31
import java.util.HashMap;
32
import java.util.Map;
33
import java.util.Set;
34
import java.util.TreeMap;
35
import java.util.TreeSet;
36
37
/**
38
* {@link BuildInfo} is a container class that keeps track of J9 runtime settings such as:
39
*
40
* <ul>
41
* <li>Version Number</li>
42
* <li>VM Branch</li>
43
* <li>Stream Name</li>
44
* <li>Stream Parent</li>
45
* <li>Stream Split Date</li>
46
* <li>Repository Branch</li>
47
* <li>Runtime</li>
48
* <li>FS Roots</li>
49
* <li>JCL Configurations</li>
50
* <li>J9 Projects</li>
51
* <li>Assembly Builders</li>
52
* </ul>
53
*
54
* @author Maciek Klimkowski
55
* @author Gabriel Castro
56
* @author Han Xu
57
*/
58
public class BuildInfo extends OMObject {
59
final public static String DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS"; //$NON-NLS-1$
60
61
private String majorVersion = null;
62
private String minorVersion = null;
63
private String prefix = ""; //$NON-NLS-1$
64
private String parentStream = null;
65
private Calendar streamSplitDate = null;
66
67
private String productName = null;
68
private String productRelease = null;
69
70
private String runtime = null;
71
private boolean validateDefaultSizes = false;
72
73
private final Map<String, String> repositoryBranches = new HashMap<String, String>();
74
75
private final Map<String, String> fsroots = new HashMap<String, String>();
76
private final Map<String, String> defaultSizes = new TreeMap<String, String>();
77
private final Set<String> jcls = new TreeSet<String>();
78
private final Set<String> projects = new TreeSet<String>();
79
private final Set<String> asmBuilders = new TreeSet<String>();
80
81
/**
82
* Sets the VM major version number.
83
*
84
* @param majorVersion the VM major version number
85
*/
86
public void setMajorVersion(String majorVersion) {
87
this.majorVersion = majorVersion;
88
}
89
90
/**
91
* Retrieves the VM major version number.
92
*
93
* @return the major version number
94
*/
95
public String getMajorVersion() {
96
return majorVersion;
97
}
98
99
/**
100
* Sets the VM minor version number.
101
*
102
* @param minorVersion the VM minor version number
103
*/
104
public void setMinorVersion(String minorVersion) {
105
this.minorVersion = minorVersion;
106
}
107
108
/**
109
* Retrieves the VM minor version number.
110
*
111
* @return the minor version number
112
*/
113
public String getMinorVersion() {
114
return minorVersion;
115
}
116
117
/**
118
* Retrieves the VM branch name.
119
*
120
* @return the branch name
121
*/
122
public String getVmBranch() {
123
StringBuilder sb = new StringBuilder(getProducName());
124
125
if (getProductRelease() != null && getProductRelease().length() != 0) {
126
sb.append("_"); //$NON-NLS-1$
127
sb.append(getProductRelease());
128
}
129
return sb.toString();
130
}
131
132
public void setPrefix(String prefix) {
133
this.prefix = prefix;
134
}
135
136
public String getPrefix() {
137
return prefix;
138
}
139
140
/**
141
* Retrieves the name of this VM stream.
142
*
143
* @return the name of this VM stream
144
*/
145
public String getStreamName() {
146
return prefix + majorVersion + '.' + minorVersion + ' ' + getVmBranch();
147
}
148
149
public String getStreamId() {
150
return prefix + majorVersion + minorVersion + '_' + getVmBranch();
151
}
152
153
/**
154
* Retrieves the stream from which the current stream was split from.
155
*
156
* @return the parent stream
157
*/
158
public String getParentStream() {
159
return parentStream;
160
}
161
162
/**
163
* Sets the stream from which the current stream was split from.
164
*
165
* @param parentStream the parent stream name
166
*/
167
public void setParentStream(String parentStream) {
168
this.parentStream = parentStream;
169
}
170
171
/**
172
* Retrieves the date of the stream split.
173
*
174
* @return the date of the stream split
175
*/
176
public Date getStreamSplitDate() {
177
return streamSplitDate.getTime();
178
}
179
180
/**
181
* Converts the stream split date to a valid XML dateTime.
182
*
183
* @return the stream split date in XML format
184
*/
185
public String getXMLStreamSplitDate() {
186
// Create a formater with the proper timezone
187
SimpleDateFormat formater = new SimpleDateFormat(DATE_FORMAT_PATTERN);
188
formater.setTimeZone(streamSplitDate.getTimeZone());
189
StringBuilder sb = new StringBuilder(formater.format(streamSplitDate.getTime()));
190
191
// Format timezone as per the XML spec (+|-)zz:zz
192
int offset = streamSplitDate.getTimeZone().getRawOffset();
193
if (offset < 0) {
194
sb.append('-');
195
offset = -offset;
196
} else {
197
sb.append('+');
198
}
199
200
NumberFormat nf = NumberFormat.getInstance();
201
nf.setMinimumIntegerDigits(2);
202
203
sb.append(nf.format(offset / 3600000));
204
sb.append(':');
205
sb.append(nf.format((offset % 3600000) / 60000));
206
207
return sb.toString();
208
}
209
210
/**
211
* Sets the date of the stream split.
212
*
213
* @param date the date of the stream split
214
*/
215
public void setStreamSplitDate(Calendar date) {
216
this.streamSplitDate = date;
217
}
218
219
/**
220
* Sets the product name for this build info.
221
*
222
* @param name the product name
223
*/
224
public void setProductName(String name) {
225
this.productName = name;
226
}
227
228
/**
229
* Returns the name of the product defined in this build info. If no product name is defined
230
* it returns "Unknown".
231
*
232
* @return the name of the product
233
*/
234
public String getProducName() {
235
return (productName == null) ? "Unknown" : productName; //$NON-NLS-1$
236
}
237
238
/**
239
* Sets the release name for this build info.
240
*
241
* @param release the release name
242
*/
243
public void setProductRelease(String release) {
244
this.productRelease = release;
245
}
246
247
/**
248
* Returns the release name defined in this build info, or <code>null</code> if none is defined.
249
*
250
* @return the release name
251
*/
252
public String getProductRelease() {
253
return productRelease;
254
}
255
256
/**
257
* Returns the product information, combining the product name and the product release if one is set.
258
*
259
* @return the combination of product name and release
260
*/
261
public String getProduct() {
262
StringBuilder sb = new StringBuilder(getProducName());
263
264
if (getProductRelease() != null && getProductRelease().length() != 0) {
265
sb.append(" "); //$NON-NLS-1$
266
sb.append(getProductRelease());
267
}
268
return sb.toString().trim();
269
}
270
271
/**
272
* Adds a repository name to the list.
273
*
274
* @param id the branch type ID
275
* @param name the branch name
276
*/
277
public void addRepositoryBranch(String id, String name) {
278
repositoryBranches.put(id, name);
279
}
280
281
/**
282
* Retrieves the name of the repository branch for a given key.
283
*
284
* @return the repository branch name
285
*/
286
public String getRepositoryBranch(String id) {
287
return repositoryBranches.get(id);
288
}
289
290
/**
291
* Retrieves the list of repository keys.
292
*
293
* @return the repository keys
294
*/
295
public Set<String> getRepositoryBranchIds() {
296
return repositoryBranches.keySet();
297
}
298
299
/**
300
* Sets the runtime name for this J9 runtime settings (ie Java, PHP, etc). The
301
* name must be unique between all runtime settings.
302
*
303
* @param runtime the runtime name
304
*/
305
public void setRuntime(String runtime) {
306
this.runtime = runtime;
307
}
308
309
/**
310
* Retrieves the runtime name for this J9 runtime settings (ie Java, PHP, etc).
311
*
312
* @return the name of the runtime
313
*/
314
public String getRuntime() {
315
return runtime;
316
}
317
318
/**
319
* Adds a file system root to this runtime.
320
*
321
* @param fsname Name of the file system
322
* @param fsroot path to root of the build
323
*/
324
public void addFSRoot(String fsname, String fsroot) {
325
fsroots.put(fsname, fsroot);
326
}
327
328
/**
329
* Retrieves a file system root.
330
*
331
* @param fsname the name of the file system
332
* @return path to the root of the build
333
*/
334
public String getFSRoot(String fsname) {
335
return fsroots.get(fsname);
336
}
337
338
/**
339
* Retrieves the file system root IDs.
340
*
341
* @return the IDs
342
*/
343
public Set<String> getFSRootsIds() {
344
return fsroots.keySet();
345
}
346
347
/**
348
* Retrieves the list of file system roots.
349
*
350
* @return the file system roots
351
*/
352
public Collection<String> getFSRoots() {
353
return fsroots.values();
354
}
355
356
public void addDefaultSize(String id, String value) {
357
defaultSizes.put(id, value);
358
}
359
360
public String getDefaultSize(String id) {
361
return defaultSizes.get(id);
362
}
363
364
public Map<String, String> getDefaultSizes() {
365
return Collections.unmodifiableMap(defaultSizes);
366
}
367
368
/**
369
* Adds a JCL profile to this runtime.
370
*
371
* @param jcl the name of the profile
372
*/
373
public void addJCL(String jcl) {
374
jcls.add(jcl);
375
}
376
377
/**
378
* Retrieves the valid JCL profiles for this runtime.
379
*
380
* @return the JCL profiles
381
*/
382
public Set<String> getJCLs() {
383
return jcls;
384
}
385
386
/**
387
* Adds a J9 source project to this runtime.
388
*
389
* @param project the name of the project
390
*/
391
public void addSource(String project) {
392
projects.add(project);
393
}
394
395
/**
396
* Retrieves the name of the valid J9 source projects for this runtime.
397
*
398
* @return the valid J9 source projects
399
*/
400
public Set<String> getSources() {
401
return projects;
402
}
403
404
/**
405
* Adds an assembly builder to this runtime.
406
*
407
* @param asmBuilder
408
*/
409
public void addASMBuilder(String asmBuilder) {
410
asmBuilders.add(asmBuilder);
411
}
412
413
/**
414
* Retrieves the valid assembly builders for this runtime
415
*
416
* @return the valid assembly builders
417
*/
418
public Set<String> getASMBuilders() {
419
return asmBuilders;
420
}
421
422
public boolean validateDefaultSizes() {
423
return validateDefaultSizes;
424
}
425
426
public void setValidateDefaultSizes(boolean validateDefaultSizes) {
427
this.validateDefaultSizes = validateDefaultSizes;
428
}
429
430
/**
431
* Debug helper used to dump information about this J9 runtime settings.
432
*
433
* @param out output stream to dump on
434
* @param prefix prefix to prepend to each line
435
* @param indentLevel number of spaces to append to the prefix
436
*/
437
public void dump(PrintStream out, String prefix, int indentLevel) {
438
StringBuffer indent = new StringBuffer(prefix);
439
for (int i = 0; i < indentLevel; i++) {
440
indent.append(' ');
441
}
442
443
out.println(indent + "Build Info"); //$NON-NLS-1$
444
out.println(indent + " |--- Version "); //$NON-NLS-1$
445
out.println(indent + " | |--- majorVersion: " + this.getMajorVersion()); //$NON-NLS-1$
446
out.println(indent + " | |--- minorVersion: " + this.getMinorVersion()); //$NON-NLS-1$
447
out.println(indent + " | |--- branch: " + this.getVmBranch()); //$NON-NLS-1$
448
out.println(indent + " | |--- streamName: " + this.getStreamName()); //$NON-NLS-1$
449
out.println(indent + " |"); //$NON-NLS-1$
450
out.println(indent + " |--- FS Roots"); //$NON-NLS-1$
451
for (String fsname : fsroots.keySet()) {
452
String fsroot = fsroots.get(fsname);
453
out.println(indent + " | |--- " + fsname + " " + fsroot); //$NON-NLS-1$ //$NON-NLS-2$
454
}
455
out.println(indent + " |"); //$NON-NLS-1$
456
out.println(indent + " |--- JCLs"); //$NON-NLS-1$
457
for (String jcl : jcls) {
458
out.println(indent + " | |--- " + jcl); //$NON-NLS-1$
459
}
460
}
461
}
462
463