2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import java.util.jar.JarEntry;
22 import java.util.jar.JarInputStream;
24 public class getJavaVersion
27 * Takes a set of Jars and/or class files as arguments. Reports the java version for the classes
30 public static void main(String[] args) throws IOException
32 Hashtable observed=new Hashtable();
33 for (int i = 0; i < args.length; i++)
35 checkClassVersion(args[i], observed);
37 printVersions(observed, System.out);
39 public static void printVersions(Hashtable observed, java.io.PrintStream outs)
41 if (observed.size()>0)
45 for (Enumeration keys = observed.keys(); keys.hasMoreElements(); ) {
46 key = (String) keys.nextElement();
57 private static void checkClassVersion(String filename, Hashtable observed)
60 String version = checkClassVersion(filename);
63 // System.err.println("Reading "+filename+" as jar:");
66 JarInputStream jis = new JarInputStream(new FileInputStream(
69 Hashtable perjar=new Hashtable();
70 while ((entry = jis.getNextJarEntry()) != null)
74 if (entry.getName().endsWith(".class"))
78 version = getVersion(new DataInputStream(jis));
81 addVersion(version, observed);
82 addVersion(version, perjar);
91 System.err.println("Jar : "+filename);
92 printVersions(perjar,System.err);
100 addVersion(version, observed);
104 private static void addVersion(String version, Hashtable observed)
108 // System.err.println("Version is '"+version+"'");
109 int[] vrs = (int[]) observed.get(version);
116 observed.put(version, vrs);
120 private static String checkClassVersion(String filename)
123 DataInputStream in = new DataInputStream(new FileInputStream(filename));
124 return getVersion(in);
127 private static Hashtable versions = null;
129 private static String parseVersions(int minor, int major)
131 if (versions == null)
133 versions = new Hashtable();
134 versions.put("45.3", "1.0");
135 versions.put("45.3", "1.1");
136 versions.put("46.0", "1.2");
137 versions.put("47.0", "1.3");
138 versions.put("48.0", "1.4");
139 versions.put("49.0", "1.5");
140 versions.put("50.0", "1.6");
142 String version = (String) versions.get(major + "."
146 // get nearest known version
147 version = (String) versions.get(major + ".0");
149 // System.err.println("Version "+version);
153 private static String getVersion(DataInputStream in) throws IOException
155 int magic = in.readInt();
156 if (magic != 0xcafebabe)
160 int minor = in.readUnsignedShort();
161 int major = in.readUnsignedShort();
162 // System.err.println("Version "+major+"."+minor);
163 return parseVersions(minor, major);