001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime; 020 021import java.io.InputStream; 022import java.util.Map; 023 024import lucee.commons.date.TimeZoneConstants; 025import lucee.commons.io.IOUtil; 026import lucee.commons.io.ini.IniFile; 027import lucee.commons.lang.ExceptionUtil; 028import lucee.commons.lang.StringUtil; 029import lucee.runtime.exp.PageRuntimeException; 030import lucee.runtime.op.Caster; 031import lucee.runtime.op.date.DateCaster; 032import lucee.runtime.type.dt.DateTime; 033import lucee.runtime.type.util.ListUtil; 034 035/** 036 * Info to this Version 037 */ 038public final class Info { 039 040 /** 041 * @return the level 042 */ 043 public static String getLevel() { 044 return level; 045 } 046 047 public static final int STATE_ALPHA = 2*100000000; 048 public static final int STATE_BETA = 1*100000000; 049 public static final int STATE_RC = 3*100000000; 050 public static final int STATE_FINAL = 0; 051 052 // Mod this 053 private static DateTime releaseDate;//=DateUtil.toDateTime(TimeZone.getDefault(),2009,6,29,0,0,0,null); 054 055 private static String versionName;//="Barry"; 056 private static String versionNameExplanation;//="http://en.wikipedia.org/wiki/Barry_(dog)"; 057 058 // 3.1 059 private static int state;//=STATE_BETA; 060 private static int major;//=3; 061 private static int minor;//=1; 062 private static int releases;//=0; 063 private static int patches;//=18; 064 065 066 private static final long releaseTime;//=releaseDate.getTime(); 067 private static String version; 068 private static String level; 069 private static final String strState;//=toStringState(state); 070 private static final int intVersion; 071 private static final int fullVersion; 072 073 static { 074 InputStream is = Info.class.getClassLoader().getResourceAsStream("lucee/runtime/Info.ini"); 075 try{ 076 IniFile ini=new IniFile(is); 077 Map verIni=ini.getSection("version"); 078 versionName=(String) verIni.get("name"); 079 versionNameExplanation=(String) verIni.get("name-explanation"); 080 releaseDate=DateCaster.toDateAdvanced((String) verIni.get("release-date"), TimeZoneConstants.EUROPE_ZURICH); 081 state=toIntState((String) verIni.get("state")); 082 level=(String) verIni.get("level"); 083 version=(String) verIni.get("number"); 084 String[] aVersion = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(version,'.')); 085 086 major=Caster.toIntValue(aVersion[0]); 087 minor=Caster.toIntValue(aVersion[1]); 088 releases=Caster.toIntValue(aVersion[2]); 089 patches=Caster.toIntValue(aVersion[3]); 090 } 091 catch (Throwable t) { 092 ExceptionUtil.rethrowIfNecessary(t); 093 throw new PageRuntimeException(Caster.toPageException(t)); 094 } 095 finally{ 096 IOUtil.closeEL(is); 097 } 098 099 releaseTime=releaseDate.getTime(); 100 strState=toStringState(state); 101 version=StringUtil.addZeros(major,1)+'.'+ 102 StringUtil.addZeros(minor,1)+'.'+ 103 StringUtil.addZeros(releases,1)+'.'+ 104 StringUtil.addZeros(patches,3); 105 intVersion=(major*1000000)+(minor*10000)+(releases*100)+patches; 106 fullVersion=intVersion+state; 107 } 108 109 public static int toIntVersion(String version, int defaultValue) { 110 try{ 111 String[] aVersion = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(version,'.')); 112 int ma = Caster.toIntValue(aVersion[0]); 113 int mi = Caster.toIntValue(aVersion[1]); 114 int re = Caster.toIntValue(aVersion[2]); 115 int pa = Caster.toIntValue(aVersion[3]); 116 return (ma*1000000)+(mi*10000)+(re*100)+pa; 117 } 118 catch(Throwable t){ 119 return defaultValue; 120 } 121 } 122 123 // Version <version>.<major>.<minor>.<patches> 124 125 /** 126 * @return Returns the releaseDate. 127 */ 128 public static DateTime getRealeaseDate() { 129 return releaseDate; 130 } 131 132 /** 133 * @return Returns the releaseTime. 134 */ 135 public static long getRealeaseTime() { 136 return releaseTime; 137 } 138 139 /** 140 * @return Returns the version. 141 */ 142 public static String getVersionAsString() { 143 return version; 144 } 145 146 /** 147 * @return Returns the intVersion. 148 */ 149 public static int getVersionAsInt() { 150 return intVersion; 151 } 152 153 /** 154 * @return returns the state 155 */ 156 public static int getStateAsInt() { 157 return state; 158 } 159 160 /** 161 * @return returns the state 162 */ 163 public static String getStateAsString() { 164 return strState; 165 } 166 167 168 /** 169 * @return returns the state 170 */ 171 public static String toStringState(int state) { 172 if(state==STATE_FINAL) return "final"; 173 else if(state==STATE_BETA) return "beta"; 174 else if(state==STATE_RC) return "rc"; 175 else return "alpha"; 176 } 177 178 /** 179 * @return returns the state 180 */ 181 public static int toIntState(String state) { 182 state=state.trim().toLowerCase(); 183 if("final".equals(state)) return STATE_FINAL; 184 else if("beta".equals(state)) return STATE_BETA; 185 else if("rc".equals(state)) return STATE_RC; 186 else return STATE_ALPHA; 187 } 188 189 190 public static int getFullVersionInfo() { 191 return fullVersion; 192 } 193 194 public static String getVersionName() { 195 return versionName; 196 } 197 public static int getMajorVersion() { 198 return major; 199 } 200 public static int getMinorVersion() { 201 return minor; 202 } 203 204 public static String getVersionNameExplanation() { 205 return versionNameExplanation; 206 } 207 208 /*public static void main(String[] args) { 209 print.out("getFullVersionInfo(103010018):"+getFullVersionInfo()); 210 print.out("getStateAsString(beta):"+getStateAsString()); 211 print.out("getStateAsInt(100000000):"+getStateAsInt()); 212 print.out("getVersionAsInt(3010018):"+getVersionAsInt()); 213 print.out("getVersionAsString(3.1.0.018):"+getVersionAsString()); 214 print.out("getVersionName(Barry):"+getVersionName()); 215 print.out("getVersionNameExplanation(http://en.wikipedia.org/wiki/Barry_(dog)):"+getVersionNameExplanation()); 216 print.out("getRealeaseDate({ts '2009-06-29 00:00:00'}):"+getRealeaseDate()); 217 print.out("getRealeaseTime(1246226400000):"+getRealeaseTime()); 218 print.out("getLevel():"+getLevel()); 219 220 221 222 223 }*/ 224 225 226}