2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.util.jar.JarEntry;
24 import java.util.jar.JarInputStream;
26 public class getJavaVersion
29 * Takes a set of Jars and/or class files as arguments. Reports the java version for the classes
32 public static void main(String[] args) throws IOException
34 Hashtable observed=new Hashtable();
35 for (int i = 0; i < args.length; i++)
37 checkClassVersion(args[i], observed);
39 printVersions(observed, System.out);
41 public static void printVersions(Hashtable observed, java.io.PrintStream outs)
43 if (observed.size()>0)
47 for (Enumeration keys = observed.keys(); keys.hasMoreElements(); ) {
48 key = (String) keys.nextElement();
59 private static void checkClassVersion(String filename, Hashtable observed)
62 String version = checkClassVersion(filename);
65 // System.err.println("Reading "+filename+" as jar:");
68 JarInputStream jis = new JarInputStream(new FileInputStream(
71 Hashtable perjar=new Hashtable();
72 while ((entry = jis.getNextJarEntry()) != null)
76 if (entry.getName().endsWith(".class"))
80 version = getVersion(new DataInputStream(jis));
83 addVersion(version, observed);
84 addVersion(version, perjar);
93 System.err.println("Jar : "+filename);
94 printVersions(perjar,System.err);
102 addVersion(version, observed);
106 private static void addVersion(String version, Hashtable observed)
110 // System.err.println("Version is '"+version+"'");
111 int[] vrs = (int[]) observed.get(version);
118 observed.put(version, vrs);
122 private static String checkClassVersion(String filename)
125 DataInputStream in = new DataInputStream(new FileInputStream(filename));
126 return getVersion(in);
129 private static Hashtable versions = null;
131 private static String parseVersions(int minor, int major)
133 if (versions == null)
135 versions = new Hashtable();
136 versions.put("45.3", "1.0");
137 versions.put("45.3", "1.1");
138 versions.put("46.0", "1.2");
139 versions.put("47.0", "1.3");
140 versions.put("48.0", "1.4");
141 versions.put("49.0", "1.5");
142 versions.put("50.0", "1.6");
144 String version = (String) versions.get(major + "."
148 // get nearest known version
149 version = (String) versions.get(major + ".0");
151 // System.err.println("Version "+version);
155 private static String getVersion(DataInputStream in) throws IOException
157 int magic = in.readInt();
158 if (magic != 0xcafebabe)
162 int minor = in.readUnsignedShort();
163 int major = in.readUnsignedShort();
164 // System.err.println("Version "+major+"."+minor);
165 return parseVersions(minor, major);