Path: blob/master/sourcetools/objectmodel/com/ibm/j9tools/om/BuildInfo.java
6004 views
/*******************************************************************************1* Copyright (c) 2007, 2019 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/21package com.ibm.j9tools.om;2223import java.io.PrintStream;24import java.text.NumberFormat;25import java.text.SimpleDateFormat;26import java.util.Calendar;27import java.util.Collection;28import java.util.Collections;29import java.util.Date;30import java.util.HashMap;31import java.util.Map;32import java.util.Set;33import java.util.TreeMap;34import java.util.TreeSet;3536/**37* {@link BuildInfo} is a container class that keeps track of J9 runtime settings such as:38*39* <ul>40* <li>Version Number</li>41* <li>VM Branch</li>42* <li>Stream Name</li>43* <li>Stream Parent</li>44* <li>Stream Split Date</li>45* <li>Repository Branch</li>46* <li>Runtime</li>47* <li>FS Roots</li>48* <li>JCL Configurations</li>49* <li>J9 Projects</li>50* <li>Assembly Builders</li>51* </ul>52*53* @author Maciek Klimkowski54* @author Gabriel Castro55* @author Han Xu56*/57public class BuildInfo extends OMObject {58final public static String DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS"; //$NON-NLS-1$5960private String majorVersion = null;61private String minorVersion = null;62private String prefix = ""; //$NON-NLS-1$63private String parentStream = null;64private Calendar streamSplitDate = null;6566private String productName = null;67private String productRelease = null;6869private String runtime = null;70private boolean validateDefaultSizes = false;7172private final Map<String, String> repositoryBranches = new HashMap<String, String>();7374private final Map<String, String> fsroots = new HashMap<String, String>();75private final Map<String, String> defaultSizes = new TreeMap<String, String>();76private final Set<String> jcls = new TreeSet<String>();77private final Set<String> projects = new TreeSet<String>();78private final Set<String> asmBuilders = new TreeSet<String>();7980/**81* Sets the VM major version number.82*83* @param majorVersion the VM major version number84*/85public void setMajorVersion(String majorVersion) {86this.majorVersion = majorVersion;87}8889/**90* Retrieves the VM major version number.91*92* @return the major version number93*/94public String getMajorVersion() {95return majorVersion;96}9798/**99* Sets the VM minor version number.100*101* @param minorVersion the VM minor version number102*/103public void setMinorVersion(String minorVersion) {104this.minorVersion = minorVersion;105}106107/**108* Retrieves the VM minor version number.109*110* @return the minor version number111*/112public String getMinorVersion() {113return minorVersion;114}115116/**117* Retrieves the VM branch name.118*119* @return the branch name120*/121public String getVmBranch() {122StringBuilder sb = new StringBuilder(getProducName());123124if (getProductRelease() != null && getProductRelease().length() != 0) {125sb.append("_"); //$NON-NLS-1$126sb.append(getProductRelease());127}128return sb.toString();129}130131public void setPrefix(String prefix) {132this.prefix = prefix;133}134135public String getPrefix() {136return prefix;137}138139/**140* Retrieves the name of this VM stream.141*142* @return the name of this VM stream143*/144public String getStreamName() {145return prefix + majorVersion + '.' + minorVersion + ' ' + getVmBranch();146}147148public String getStreamId() {149return prefix + majorVersion + minorVersion + '_' + getVmBranch();150}151152/**153* Retrieves the stream from which the current stream was split from.154*155* @return the parent stream156*/157public String getParentStream() {158return parentStream;159}160161/**162* Sets the stream from which the current stream was split from.163*164* @param parentStream the parent stream name165*/166public void setParentStream(String parentStream) {167this.parentStream = parentStream;168}169170/**171* Retrieves the date of the stream split.172*173* @return the date of the stream split174*/175public Date getStreamSplitDate() {176return streamSplitDate.getTime();177}178179/**180* Converts the stream split date to a valid XML dateTime.181*182* @return the stream split date in XML format183*/184public String getXMLStreamSplitDate() {185// Create a formater with the proper timezone186SimpleDateFormat formater = new SimpleDateFormat(DATE_FORMAT_PATTERN);187formater.setTimeZone(streamSplitDate.getTimeZone());188StringBuilder sb = new StringBuilder(formater.format(streamSplitDate.getTime()));189190// Format timezone as per the XML spec (+|-)zz:zz191int offset = streamSplitDate.getTimeZone().getRawOffset();192if (offset < 0) {193sb.append('-');194offset = -offset;195} else {196sb.append('+');197}198199NumberFormat nf = NumberFormat.getInstance();200nf.setMinimumIntegerDigits(2);201202sb.append(nf.format(offset / 3600000));203sb.append(':');204sb.append(nf.format((offset % 3600000) / 60000));205206return sb.toString();207}208209/**210* Sets the date of the stream split.211*212* @param date the date of the stream split213*/214public void setStreamSplitDate(Calendar date) {215this.streamSplitDate = date;216}217218/**219* Sets the product name for this build info.220*221* @param name the product name222*/223public void setProductName(String name) {224this.productName = name;225}226227/**228* Returns the name of the product defined in this build info. If no product name is defined229* it returns "Unknown".230*231* @return the name of the product232*/233public String getProducName() {234return (productName == null) ? "Unknown" : productName; //$NON-NLS-1$235}236237/**238* Sets the release name for this build info.239*240* @param release the release name241*/242public void setProductRelease(String release) {243this.productRelease = release;244}245246/**247* Returns the release name defined in this build info, or <code>null</code> if none is defined.248*249* @return the release name250*/251public String getProductRelease() {252return productRelease;253}254255/**256* Returns the product information, combining the product name and the product release if one is set.257*258* @return the combination of product name and release259*/260public String getProduct() {261StringBuilder sb = new StringBuilder(getProducName());262263if (getProductRelease() != null && getProductRelease().length() != 0) {264sb.append(" "); //$NON-NLS-1$265sb.append(getProductRelease());266}267return sb.toString().trim();268}269270/**271* Adds a repository name to the list.272*273* @param id the branch type ID274* @param name the branch name275*/276public void addRepositoryBranch(String id, String name) {277repositoryBranches.put(id, name);278}279280/**281* Retrieves the name of the repository branch for a given key.282*283* @return the repository branch name284*/285public String getRepositoryBranch(String id) {286return repositoryBranches.get(id);287}288289/**290* Retrieves the list of repository keys.291*292* @return the repository keys293*/294public Set<String> getRepositoryBranchIds() {295return repositoryBranches.keySet();296}297298/**299* Sets the runtime name for this J9 runtime settings (ie Java, PHP, etc). The300* name must be unique between all runtime settings.301*302* @param runtime the runtime name303*/304public void setRuntime(String runtime) {305this.runtime = runtime;306}307308/**309* Retrieves the runtime name for this J9 runtime settings (ie Java, PHP, etc).310*311* @return the name of the runtime312*/313public String getRuntime() {314return runtime;315}316317/**318* Adds a file system root to this runtime.319*320* @param fsname Name of the file system321* @param fsroot path to root of the build322*/323public void addFSRoot(String fsname, String fsroot) {324fsroots.put(fsname, fsroot);325}326327/**328* Retrieves a file system root.329*330* @param fsname the name of the file system331* @return path to the root of the build332*/333public String getFSRoot(String fsname) {334return fsroots.get(fsname);335}336337/**338* Retrieves the file system root IDs.339*340* @return the IDs341*/342public Set<String> getFSRootsIds() {343return fsroots.keySet();344}345346/**347* Retrieves the list of file system roots.348*349* @return the file system roots350*/351public Collection<String> getFSRoots() {352return fsroots.values();353}354355public void addDefaultSize(String id, String value) {356defaultSizes.put(id, value);357}358359public String getDefaultSize(String id) {360return defaultSizes.get(id);361}362363public Map<String, String> getDefaultSizes() {364return Collections.unmodifiableMap(defaultSizes);365}366367/**368* Adds a JCL profile to this runtime.369*370* @param jcl the name of the profile371*/372public void addJCL(String jcl) {373jcls.add(jcl);374}375376/**377* Retrieves the valid JCL profiles for this runtime.378*379* @return the JCL profiles380*/381public Set<String> getJCLs() {382return jcls;383}384385/**386* Adds a J9 source project to this runtime.387*388* @param project the name of the project389*/390public void addSource(String project) {391projects.add(project);392}393394/**395* Retrieves the name of the valid J9 source projects for this runtime.396*397* @return the valid J9 source projects398*/399public Set<String> getSources() {400return projects;401}402403/**404* Adds an assembly builder to this runtime.405*406* @param asmBuilder407*/408public void addASMBuilder(String asmBuilder) {409asmBuilders.add(asmBuilder);410}411412/**413* Retrieves the valid assembly builders for this runtime414*415* @return the valid assembly builders416*/417public Set<String> getASMBuilders() {418return asmBuilders;419}420421public boolean validateDefaultSizes() {422return validateDefaultSizes;423}424425public void setValidateDefaultSizes(boolean validateDefaultSizes) {426this.validateDefaultSizes = validateDefaultSizes;427}428429/**430* Debug helper used to dump information about this J9 runtime settings.431*432* @param out output stream to dump on433* @param prefix prefix to prepend to each line434* @param indentLevel number of spaces to append to the prefix435*/436public void dump(PrintStream out, String prefix, int indentLevel) {437StringBuffer indent = new StringBuffer(prefix);438for (int i = 0; i < indentLevel; i++) {439indent.append(' ');440}441442out.println(indent + "Build Info"); //$NON-NLS-1$443out.println(indent + " |--- Version "); //$NON-NLS-1$444out.println(indent + " | |--- majorVersion: " + this.getMajorVersion()); //$NON-NLS-1$445out.println(indent + " | |--- minorVersion: " + this.getMinorVersion()); //$NON-NLS-1$446out.println(indent + " | |--- branch: " + this.getVmBranch()); //$NON-NLS-1$447out.println(indent + " | |--- streamName: " + this.getStreamName()); //$NON-NLS-1$448out.println(indent + " |"); //$NON-NLS-1$449out.println(indent + " |--- FS Roots"); //$NON-NLS-1$450for (String fsname : fsroots.keySet()) {451String fsroot = fsroots.get(fsname);452out.println(indent + " | |--- " + fsname + " " + fsroot); //$NON-NLS-1$ //$NON-NLS-2$453}454out.println(indent + " |"); //$NON-NLS-1$455out.println(indent + " |--- JCLs"); //$NON-NLS-1$456for (String jcl : jcls) {457out.println(indent + " | |--- " + jcl); //$NON-NLS-1$458}459}460}461462463