forked from squirrel-sql-client/squirrel-sql-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaVersionChecker.java
More file actions
113 lines (99 loc) · 3.54 KB
/
JavaVersionChecker.java
File metadata and controls
113 lines (99 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import javax.swing.JOptionPane;
/*
* Copyright (C) 2009 Rob Manning
* manningr@users.sourceforge.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* The purpose of this class is to provide a Java2 (1.2.x) compatible class that can simply check the
* JVM version and put up a dialog message if the version isn't sufficiently recent. This class should be
* compiled and jar'd with JDK 1.2.2 so that any JVM 1.2.2 and higher can execute it. This is so that the
* user sees a nice informative message telling them their JVM is old, instead of the dreaded :
* <p>
* Cannot find main class. Program will exit.
*/
public class JavaVersionChecker
{
/**
* The system property which gives the install location of the java that this small app runs in
*/
private static final String JAVA_HOME_PROPERTY = "java.home";
/**
* The system property which gives the version of java that this small application runs in
*/
private static final String JAVA_VERSION_PROPERTY = "java.version";
/**
* @param args should contain at least one version of Java which is the acceptable minimum version. If
* that version is not the latest version of Java available, then newer versions (which are also
* acceptable) should also be specified after the minimum acceptable version.
*/
public static void main(String[] args)
{
if (args.length == 0)
{
System.err.println("JavaVersionChecker: Must specify one or more JVM versions");
System.exit(1);
}
String jvmVersion = System.getProperty(JAVA_VERSION_PROPERTY);
if (!checkVersion(jvmVersion, args))
{
String javaHome = System.getProperty(JAVA_HOME_PROPERTY);
String msg = "Your Java Virtual Machine version must be ";
if(1 == args.length)
{
msg += args[0] + " ";
}
else
{
msg += "one of ";
for (int i = 0; i < args.length; i++)
{
msg += args[i] + " ";
}
}
msg += "to run SQuirreL\n" +
" JVM Version used: " + jvmVersion + "\n" +
" JVM Location: " + javaHome;
JOptionPane.showMessageDialog(null,msg);
System.exit(1);
}
System.exit(0);
}
/**
* Check that the specified JVM version matches one of the jvm versions specified in minimumJavaVersions.
*
* @param jvmVersion the version of the JVM that this app runs in
* @param minimumJavaVersions one or more acceptable versions of the JVM
* @return true if the JVM matches one or more of the minimum JVM versions; false otherwise.
*/
private static boolean checkVersion(String jvmVersion, String[] minimumJavaVersions)
{
if (jvmVersion == null)
{
System.err.println("jvm version could not be determined. The " + JAVA_VERSION_PROPERTY +
" system property is null");
}
boolean result = false;
for (int i = 0; i < minimumJavaVersions.length; i++)
{
if (jvmVersion.startsWith(minimumJavaVersions[i]))
{
result = true;
}
}
return result;
}
}