equal
deleted
inserted
replaced
34 import java.io.PrintWriter; |
34 import java.io.PrintWriter; |
35 import java.io.Reader; |
35 import java.io.Reader; |
36 import java.io.StringWriter; |
36 import java.io.StringWriter; |
37 import java.io.Writer; |
37 import java.io.Writer; |
38 import java.net.URI; |
38 import java.net.URI; |
|
39 import java.net.URISyntaxException; |
|
40 import java.net.URL; |
|
41 import java.net.URLConnection; |
|
42 import java.nio.file.NoSuchFileException; |
39 import java.security.DigestInputStream; |
43 import java.security.DigestInputStream; |
40 import java.security.MessageDigest; |
44 import java.security.MessageDigest; |
41 import java.security.NoSuchAlgorithmException; |
45 import java.security.NoSuchAlgorithmException; |
42 import java.text.MessageFormat; |
46 import java.text.MessageFormat; |
43 import java.util.ArrayList; |
47 import java.util.ArrayList; |
59 import javax.tools.JavaFileObject; |
63 import javax.tools.JavaFileObject; |
60 import javax.tools.StandardJavaFileManager; |
64 import javax.tools.StandardJavaFileManager; |
61 import javax.tools.StandardLocation; |
65 import javax.tools.StandardLocation; |
62 |
66 |
63 import com.sun.tools.classfile.*; |
67 import com.sun.tools.classfile.*; |
64 import java.net.URISyntaxException; |
|
65 import java.net.URL; |
|
66 import java.net.URLConnection; |
|
67 |
|
68 import com.sun.tools.javac.util.DefinedBy; |
68 import com.sun.tools.javac.util.DefinedBy; |
69 import com.sun.tools.javac.util.DefinedBy.Api; |
69 import com.sun.tools.javac.util.DefinedBy.Api; |
70 |
70 |
71 /** |
71 /** |
72 * "Main" class for javap, normally accessed from the command line |
72 * "Main" class for javap, normally accessed from the command line |
566 reportError("err.bad.constant.pool", className, e.getLocalizedMessage()); |
566 reportError("err.bad.constant.pool", className, e.getLocalizedMessage()); |
567 result = EXIT_ERROR; |
567 result = EXIT_ERROR; |
568 } catch (EOFException e) { |
568 } catch (EOFException e) { |
569 reportError("err.end.of.file", className); |
569 reportError("err.end.of.file", className); |
570 result = EXIT_ERROR; |
570 result = EXIT_ERROR; |
571 } catch (FileNotFoundException e) { |
571 } catch (FileNotFoundException | NoSuchFileException e) { |
572 reportError("err.file.not.found", e.getLocalizedMessage()); |
572 reportError("err.file.not.found", e.getLocalizedMessage()); |
573 result = EXIT_ERROR; |
573 result = EXIT_ERROR; |
574 } catch (IOException e) { |
574 } catch (IOException e) { |
575 //e.printStackTrace(); |
575 //e.printStackTrace(); |
576 Object msg = e.getLocalizedMessage(); |
576 Object msg = e.getLocalizedMessage(); |
666 if (!className.endsWith(".class")) |
666 if (!className.endsWith(".class")) |
667 return null; |
667 return null; |
668 |
668 |
669 if (fileManager instanceof StandardJavaFileManager) { |
669 if (fileManager instanceof StandardJavaFileManager) { |
670 StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager; |
670 StandardJavaFileManager sfm = (StandardJavaFileManager) fileManager; |
671 fo = sfm.getJavaFileObjects(className).iterator().next(); |
671 try { |
672 if (fo != null && fo.getLastModified() != 0) { |
672 fo = sfm.getJavaFileObjects(className).iterator().next(); |
673 return fo; |
673 if (fo != null && fo.getLastModified() != 0) { |
|
674 return fo; |
|
675 } |
|
676 } catch (IllegalArgumentException ignore) { |
674 } |
677 } |
675 } |
678 } |
676 |
679 |
677 // see if it is a URL, and if so, wrap it in just enough of a JavaFileObject |
680 // see if it is a URL, and if so, wrap it in just enough of a JavaFileObject |
678 // to suit javap's needs |
681 // to suit javap's needs |
858 defaultFileManager = JavapFileManager.create(dl, log); |
861 defaultFileManager = JavapFileManager.create(dl, log); |
859 return defaultFileManager; |
862 return defaultFileManager; |
860 } |
863 } |
861 |
864 |
862 private JavaFileObject getClassFileObject(String className) throws IOException { |
865 private JavaFileObject getClassFileObject(String className) throws IOException { |
863 JavaFileObject fo; |
866 try { |
864 fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS); |
867 JavaFileObject fo; |
865 if (fo == null) |
868 fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS); |
866 fo = fileManager.getJavaFileForInput(StandardLocation.CLASS_PATH, className, JavaFileObject.Kind.CLASS); |
869 if (fo == null) |
867 return fo; |
870 fo = fileManager.getJavaFileForInput(StandardLocation.CLASS_PATH, className, JavaFileObject.Kind.CLASS); |
|
871 return fo; |
|
872 } catch (IllegalArgumentException e) { |
|
873 return null; |
|
874 } |
868 } |
875 } |
869 |
876 |
870 private void showHelp() { |
877 private void showHelp() { |
871 printLines(getMessage("main.usage", progname)); |
878 printLines(getMessage("main.usage", progname)); |
872 for (Option o: recognizedOptions) { |
879 for (Option o: recognizedOptions) { |