1 /* 2 * Copyright (c) 2007, 2017 Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package org.jemmy; 25 26 import java.io.IOException; 27 import java.io.InputStream; 28 import java.util.Properties; 29 import java.util.StringTokenizer; 30 31 /** 32 * 33 * @author shura 34 */ 35 public class Version { 36 /** 37 * 38 */ 39 public static final Version VERSION = new Version(); 40 41 private int major; 42 private int minor; 43 private int mini; 44 private String build; 45 46 /** 47 * 48 */ 49 public Version() { 50 this(Version.class.getPackage().getName()); 51 } 52 53 /** 54 * 55 * @param pkg 56 */ 57 public Version(String pkg) { 58 try { 59 Properties props = new Properties(); 60 String fileName = pkg.replace(".", "/") + "/jemmy.properties"; 61 InputStream in = getClass().getClassLoader().getResourceAsStream(fileName); 62 if(in == null) { 63 throw new JemmyException("Can not get version - no " + fileName + " file"); 64 } 65 props.load(in); 66 major = Integer.parseInt(props.getProperty("version.major")); 67 minor = Integer.parseInt(props.getProperty("version.minor")); 68 mini = Integer.parseInt(props.getProperty("version.mini")); 69 build = props.getProperty("build"); 70 } catch (IOException ex) { 71 throw new JemmyException("Can not get version.", ex); 72 } 73 } 74 75 /** 76 * 77 * @return 78 */ 79 public int getMajor() { 80 return major; 81 } 82 83 /** 84 * 85 * @return 86 */ 87 public int getMini() { 88 return mini; 89 } 90 91 /** 92 * 93 * @return 94 */ 95 public int getMinor() { 96 return minor; 97 } 98 99 /** 100 * 101 * @return 102 */ 103 public String getVersion() { 104 return major + "." + minor + "." + mini; 105 } 106 107 /** 108 * 109 * @return 110 */ 111 public String getBuild() { 112 return build; 113 } 114 115 /** 116 * 117 * @param old 118 * @return 119 */ 120 public boolean newer(String old) { 121 StringTokenizer tn = new StringTokenizer(old, "."); 122 if(major >= Integer.parseInt(tn.nextToken())) { 123 if(minor >= Integer.parseInt(tn.nextToken())) { 124 if(mini >= Integer.parseInt(tn.nextToken())) { 125 return true; 126 } 127 } 128 } 129 return false; 130 } 131 132 /** 133 * 134 * @param args 135 */ 136 public static void main(String[] args) { 137 System.out.println("JemmyCore version: " + VERSION.getVersion() + "." + VERSION.build); 138 } 139 }