19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.extcheck;
27
28 import java.util.*;
29 import java.net.MalformedURLException;
30 import java.util.Vector;
31 import java.io.*;
32 import java.util.StringTokenizer;
33 import java.net.URL;
34 import java.util.jar.JarFile;
35 import java.util.jar.JarEntry;
36 import java.util.jar.Manifest;
37 import java.util.jar.Attributes;
38 import java.util.jar.Attributes.Name;
39 import java.net.URLConnection;
40 import java.security.Permission;
41 import java.util.jar.*;
42 import java.net.JarURLConnection;
43 import sun.net.www.ParseUtil;
44
45 /**
46 * ExtCheck reports on clashes between a specified (target)
47 * jar file and jar files already installed in the extensions
48 * directory.
49 *
50 * @author Benedict Gomes
51 * @since 1.2
52 */
53
54 public class ExtCheck {
55
56 private static final boolean DEBUG = false;
57
58 // The following strings hold the values of the version variables
178 generalMessage("No conflicting installed jar found.");
179 } else {
180 generalMessage("Conflicting installed jar found. "
181 + " Use -verbose for more information.");
182 }
183 return result;
184 }
185
186 /**
187 * Recursively verify that a jar file, and any urls mentioned
188 * in its class path, do not conflict with the target jar file.
189 *
190 * @param indent is the current nesting level
191 * @param url is the path to the jar file being checked.
192 * @return true if there is no newer URL, otherwise false
193 */
194 private boolean checkURLRecursively(int indent, URL url)
195 throws IOException
196 {
197 verboseMessage("Comparing with " + url);
198 JarLoader jarloader = new JarLoader(url);
199 JarFile j = jarloader.getJarFile();
200 Manifest man = j.getManifest();
201 if (man != null) {
202 Attributes attr = man.getMainAttributes();
203 if (attr != null){
204 String title = attr.getValue(Name.SPECIFICATION_TITLE);
205 String version = attr.getValue(Name.SPECIFICATION_VERSION);
206 String vendor = attr.getValue(Name.SPECIFICATION_VENDOR);
207 String implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
208 String implVersion
209 = attr.getValue(Name.IMPLEMENTATION_VERSION);
210 String implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
211 String sealed = attr.getValue(Name.SEALED);
212 if (title != null){
213 if (title.equals(targetSpecTitle)){
214 if (version != null){
215 if (version.equals(targetSpecVersion) ||
216 isNotOlderThan(version,targetSpecVersion)){
217 verboseMessage("");
218 verboseMessage("CONFLICT DETECTED ");
310 * Throws a RuntimeException with a message describing the error.
311 */
312 static void error(String message) throws RuntimeException {
313 throw new RuntimeException(message);
314 }
315
316
317 /**
318 * Inner class used to represent a loader of resources and classes
319 * from a base URL. Somewhat modified version of code in
320 * sun.misc.URLClassPath.JarLoader
321 */
322 private static class JarLoader {
323 private final URL base;
324 private JarFile jar;
325 private URL csu;
326
327 /*
328 * Creates a new Loader for the specified URL.
329 */
330 JarLoader(URL url) {
331 String urlName = url + "!/";
332 URL tmpBaseURL = null;
333 try {
334 tmpBaseURL = new URL("jar","",urlName);
335 jar = findJarFile(url);
336 csu = url;
337 } catch (MalformedURLException e) {
338 ExtCheck.error("Malformed url "+urlName);
339 } catch (IOException e) {
340 ExtCheck.error("IO Exception occurred");
341 }
342 base = tmpBaseURL;
343
344 }
345
346 /*
347 * Returns the base URL for this Loader.
348 */
349 URL getBaseURL() {
350 return base;
351 }
352
353 JarFile getJarFile() {
354 return jar;
355 }
356
357 private JarFile findJarFile(URL url) throws IOException {
358 // Optimize case where url refers to a local jar file
359 if ("file".equals(url.getProtocol())) {
360 String path = url.getFile().replace('/', File.separatorChar);
361 File file = new File(path);
362 if (!file.exists()) {
363 throw new FileNotFoundException(path);
388 }
389
390 /*
391 * Parses value of the Class-Path manifest attribute and returns
392 * an array of URLs relative to the specified base URL.
393 */
394 private URL[] parseClassPath(URL base, String value)
395 throws MalformedURLException
396 {
397 StringTokenizer st = new StringTokenizer(value);
398 URL[] urls = new URL[st.countTokens()];
399 int i = 0;
400 while (st.hasMoreTokens()) {
401 String path = st.nextToken();
402 urls[i] = new URL(base, path);
403 i++;
404 }
405 return urls;
406 }
407 }
408
409
410 }
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.extcheck;
27
28 import java.util.*;
29 import java.net.MalformedURLException;
30 import java.util.Vector;
31 import java.io.*;
32 import java.util.StringTokenizer;
33 import java.net.URL;
34 import java.util.jar.JarFile;
35 import java.util.jar.JarEntry;
36 import java.util.jar.Manifest;
37 import java.util.jar.Attributes;
38 import java.util.jar.Attributes.Name;
39 import java.util.zip.ZipException;
40 import java.net.URLConnection;
41 import java.security.Permission;
42 import java.util.jar.*;
43 import java.net.JarURLConnection;
44 import sun.net.www.ParseUtil;
45
46 /**
47 * ExtCheck reports on clashes between a specified (target)
48 * jar file and jar files already installed in the extensions
49 * directory.
50 *
51 * @author Benedict Gomes
52 * @since 1.2
53 */
54
55 public class ExtCheck {
56
57 private static final boolean DEBUG = false;
58
59 // The following strings hold the values of the version variables
179 generalMessage("No conflicting installed jar found.");
180 } else {
181 generalMessage("Conflicting installed jar found. "
182 + " Use -verbose for more information.");
183 }
184 return result;
185 }
186
187 /**
188 * Recursively verify that a jar file, and any urls mentioned
189 * in its class path, do not conflict with the target jar file.
190 *
191 * @param indent is the current nesting level
192 * @param url is the path to the jar file being checked.
193 * @return true if there is no newer URL, otherwise false
194 */
195 private boolean checkURLRecursively(int indent, URL url)
196 throws IOException
197 {
198 verboseMessage("Comparing with " + url);
199 JarLoader jarloader = null;
200 try {
201 jarloader = new JarLoader(url);
202 } catch (ZipException ze) {
203 verboseMessage("... skipping non-jar file " + url);
204 return true;
205 }
206 JarFile j = jarloader.getJarFile();
207 Manifest man = j.getManifest();
208 if (man != null) {
209 Attributes attr = man.getMainAttributes();
210 if (attr != null){
211 String title = attr.getValue(Name.SPECIFICATION_TITLE);
212 String version = attr.getValue(Name.SPECIFICATION_VERSION);
213 String vendor = attr.getValue(Name.SPECIFICATION_VENDOR);
214 String implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
215 String implVersion
216 = attr.getValue(Name.IMPLEMENTATION_VERSION);
217 String implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
218 String sealed = attr.getValue(Name.SEALED);
219 if (title != null){
220 if (title.equals(targetSpecTitle)){
221 if (version != null){
222 if (version.equals(targetSpecVersion) ||
223 isNotOlderThan(version,targetSpecVersion)){
224 verboseMessage("");
225 verboseMessage("CONFLICT DETECTED ");
317 * Throws a RuntimeException with a message describing the error.
318 */
319 static void error(String message) throws RuntimeException {
320 throw new RuntimeException(message);
321 }
322
323
324 /**
325 * Inner class used to represent a loader of resources and classes
326 * from a base URL. Somewhat modified version of code in
327 * sun.misc.URLClassPath.JarLoader
328 */
329 private static class JarLoader {
330 private final URL base;
331 private JarFile jar;
332 private URL csu;
333
334 /*
335 * Creates a new Loader for the specified URL.
336 */
337 JarLoader(URL url) throws IOException {
338 String urlName = url + "!/";
339 URL tmpBaseURL = null;
340 try {
341 tmpBaseURL = new URL("jar","",urlName);
342 jar = findJarFile(url);
343 csu = url;
344 } catch (MalformedURLException e) {
345 ExtCheck.error("Malformed url "+urlName);
346 }
347 base = tmpBaseURL;
348 }
349
350 /*
351 * Returns the base URL for this Loader.
352 */
353 URL getBaseURL() {
354 return base;
355 }
356
357 JarFile getJarFile() {
358 return jar;
359 }
360
361 private JarFile findJarFile(URL url) throws IOException {
362 // Optimize case where url refers to a local jar file
363 if ("file".equals(url.getProtocol())) {
364 String path = url.getFile().replace('/', File.separatorChar);
365 File file = new File(path);
366 if (!file.exists()) {
367 throw new FileNotFoundException(path);
392 }
393
394 /*
395 * Parses value of the Class-Path manifest attribute and returns
396 * an array of URLs relative to the specified base URL.
397 */
398 private URL[] parseClassPath(URL base, String value)
399 throws MalformedURLException
400 {
401 StringTokenizer st = new StringTokenizer(value);
402 URL[] urls = new URL[st.countTokens()];
403 int i = 0;
404 while (st.hasMoreTokens()) {
405 String path = st.nextToken();
406 urls[i] = new URL(base, path);
407 i++;
408 }
409 return urls;
410 }
411 }
412 }
|