2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.
21 import java.io.DataInputStream;
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.util.Enumeration;
25 import java.util.Hashtable;
26 import java.util.jar.JarEntry;
27 import java.util.jar.JarInputStream;
29 public class getJavaVersion
32 * Takes a set of Jars and/or class files as arguments. Reports the java version for the classes
35 public static void main(String[] args) throws IOException
37 Hashtable observed=new Hashtable();
38 for (int i = 0; i < args.length; i++)
40 checkClassVersion(args[i], observed);
42 printVersions(observed, System.out);
44 public static void printVersions(Hashtable observed, java.io.PrintStream outs)
46 if (observed.size()>0)
50 for (Enumeration keys = observed.keys(); keys.hasMoreElements(); ) {
51 key = (String) keys.nextElement();
62 private static void checkClassVersion(String filename, Hashtable observed)
65 String version = checkClassVersion(filename);
68 // System.err.println("Reading "+filename+" as jar:");
71 JarInputStream jis = new JarInputStream(new FileInputStream(
74 Hashtable perjar=new Hashtable();
75 while ((entry = jis.getNextJarEntry()) != null)
79 if (entry.getName().endsWith(".class"))
83 version = getVersion(new DataInputStream(jis));
86 addVersion(version, observed);
87 addVersion(version, perjar);
96 System.err.println("Jar : "+filename);
97 printVersions(perjar,System.err);
105 addVersion(version, observed);
109 private static void addVersion(String version, Hashtable observed)
113 // System.err.println("Version is '"+version+"'");
114 int[] vrs = (int[]) observed.get(version);
121 observed.put(version, vrs);
125 private static String checkClassVersion(String filename)
128 DataInputStream in = new DataInputStream(new FileInputStream(filename));
129 return getVersion(in);
132 private static Hashtable versions = null;
134 private static String parseVersions(int minor, int major)
136 if (versions == null)
138 versions = new Hashtable();
139 versions.put("45.3", "1.0");
140 versions.put("45.3", "1.1");
141 versions.put("46.0", "1.2");
142 versions.put("47.0", "1.3");
143 versions.put("48.0", "1.4");
144 versions.put("49.0", "1.5");
145 versions.put("50.0", "1.6");
146 versions.put("51.0", "1.7");
147 versions.put("52.0", "1.8");
150 String version = (String) versions.get(major + "."
154 // get nearest known version
155 version = (String) versions.get(major + ".0");
157 // System.err.println("Version "+version);
160 versions.put(major + "." + minor, "Class v" + major + ".0");
165 private static String getVersion(DataInputStream in) throws IOException
167 int magic = in.readInt();
168 if (magic != 0xcafebabe)
172 int minor = in.readUnsignedShort();
173 int major = in.readUnsignedShort();
174 // System.err.println("Version "+major+"."+minor);
175 return parseVersions(minor, major);