You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VerifierAppFrame.java 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. package org.aspectj.apache.bcel.verifier;
  2. /* ====================================================================
  3. * The Apache Software License, Version 1.1
  4. *
  5. * Copyright (c) 2001 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (https://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Apache" and "Apache Software Foundation" and
  28. * "Apache BCEL" must not be used to endorse or promote products
  29. * derived from this software without prior written permission. For
  30. * written permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * "Apache BCEL", nor may "Apache" appear in their name, without
  34. * prior written permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation. For more
  52. * information on the Apache Software Foundation, please see
  53. * <https://www.apache.org/>.
  54. */
  55. import java.awt.AWTEvent;
  56. import java.awt.CardLayout;
  57. import java.awt.Color;
  58. import java.awt.Dimension;
  59. import java.awt.GridLayout;
  60. import java.awt.event.ActionEvent;
  61. import java.awt.event.WindowEvent;
  62. import javax.swing.BorderFactory;
  63. import javax.swing.JFrame;
  64. import javax.swing.JList;
  65. import javax.swing.JMenu;
  66. import javax.swing.JMenuBar;
  67. import javax.swing.JMenuItem;
  68. import javax.swing.JOptionPane;
  69. import javax.swing.JPanel;
  70. import javax.swing.JScrollPane;
  71. import javax.swing.JSplitPane;
  72. import javax.swing.JTextPane;
  73. import javax.swing.ListSelectionModel;
  74. import javax.swing.event.ListSelectionEvent;
  75. import org.aspectj.apache.bcel.Repository;
  76. import org.aspectj.apache.bcel.classfile.JavaClass;
  77. /**
  78. * This class implements a machine-generated frame for use with
  79. * the GraphicalVerfifier.
  80. *
  81. * @version $Id: VerifierAppFrame.java,v 1.2 2008/05/28 23:53:01 aclement Exp $
  82. * @author Enver Haase
  83. * @see GraphicalVerifier
  84. */
  85. public class VerifierAppFrame extends JFrame {
  86. JPanel contentPane;
  87. JSplitPane jSplitPane1 = new JSplitPane();
  88. JPanel jPanel1 = new JPanel();
  89. JPanel jPanel2 = new JPanel();
  90. JSplitPane jSplitPane2 = new JSplitPane();
  91. JPanel jPanel3 = new JPanel();
  92. JList classNamesJList = new JList();
  93. GridLayout gridLayout1 = new GridLayout();
  94. JPanel messagesPanel = new JPanel();
  95. GridLayout gridLayout2 = new GridLayout();
  96. JMenuBar jMenuBar1 = new JMenuBar();
  97. JMenu jMenu1 = new JMenu();
  98. JScrollPane jScrollPane1 = new JScrollPane();
  99. JScrollPane messagesScrollPane = new JScrollPane();
  100. JScrollPane jScrollPane3 = new JScrollPane();
  101. GridLayout gridLayout4 = new GridLayout();
  102. JScrollPane jScrollPane4 = new JScrollPane();
  103. CardLayout cardLayout1 = new CardLayout();
  104. private String JUSTICE_VERSION = "JustIce by Enver Haase";
  105. private String current_class;
  106. GridLayout gridLayout3 = new GridLayout();
  107. JTextPane pass1TextPane = new JTextPane();
  108. JTextPane pass2TextPane = new JTextPane();
  109. JTextPane messagesTextPane = new JTextPane();
  110. JMenuItem newFileMenuItem = new JMenuItem();
  111. JSplitPane jSplitPane3 = new JSplitPane();
  112. JSplitPane jSplitPane4 = new JSplitPane();
  113. JScrollPane jScrollPane2 = new JScrollPane();
  114. JScrollPane jScrollPane5 = new JScrollPane();
  115. JScrollPane jScrollPane6 = new JScrollPane();
  116. JScrollPane jScrollPane7 = new JScrollPane();
  117. JList pass3aJList = new JList();
  118. JList pass3bJList = new JList();
  119. JTextPane pass3aTextPane = new JTextPane();
  120. JTextPane pass3bTextPane = new JTextPane();
  121. JMenu jMenu2 = new JMenu();
  122. JMenuItem whatisMenuItem = new JMenuItem();
  123. JMenuItem aboutMenuItem = new JMenuItem();
  124. /** Constructor. */
  125. public VerifierAppFrame() {
  126. enableEvents(AWTEvent.WINDOW_EVENT_MASK);
  127. try {
  128. jbInit();
  129. }
  130. catch(Exception e) {
  131. e.printStackTrace();
  132. }
  133. }
  134. /** Initizalization of the components. */
  135. private void jbInit() throws Exception {
  136. //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Ihr Symbol]")));
  137. contentPane = (JPanel) this.getContentPane();
  138. contentPane.setLayout(cardLayout1);
  139. this.setJMenuBar(jMenuBar1);
  140. this.setSize(new Dimension(708, 451));
  141. this.setTitle("JustIce");
  142. jPanel1.setMinimumSize(new Dimension(100, 100));
  143. jPanel1.setPreferredSize(new Dimension(100, 100));
  144. jPanel1.setLayout(gridLayout1);
  145. jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
  146. jPanel2.setLayout(gridLayout2);
  147. jPanel3.setMinimumSize(new Dimension(200, 100));
  148. jPanel3.setPreferredSize(new Dimension(400, 400));
  149. jPanel3.setLayout(gridLayout4);
  150. messagesPanel.setMinimumSize(new Dimension(100, 100));
  151. messagesPanel.setLayout(gridLayout3);
  152. jPanel2.setMinimumSize(new Dimension(200, 100));
  153. jMenu1.setText("File");
  154. jScrollPane1.getViewport().setBackground(Color.red);
  155. messagesScrollPane.getViewport().setBackground(Color.red);
  156. messagesScrollPane.setPreferredSize(new Dimension(10, 10));
  157. classNamesJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  158. public void valueChanged(ListSelectionEvent e) {
  159. classNamesJList_valueChanged(e);
  160. }
  161. });
  162. classNamesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  163. jScrollPane3.setBorder(BorderFactory.createLineBorder(Color.black));
  164. jScrollPane3.setPreferredSize(new Dimension(100, 100));
  165. gridLayout4.setRows(4);
  166. gridLayout4.setColumns(1);
  167. gridLayout4.setHgap(1);
  168. jScrollPane4.setBorder(BorderFactory.createLineBorder(Color.black));
  169. jScrollPane4.setPreferredSize(new Dimension(100, 100));
  170. pass1TextPane.setBorder(BorderFactory.createRaisedBevelBorder());
  171. pass1TextPane.setToolTipText("");
  172. pass1TextPane.setEditable(false);
  173. pass2TextPane.setBorder(BorderFactory.createRaisedBevelBorder());
  174. pass2TextPane.setEditable(false);
  175. messagesTextPane.setBorder(BorderFactory.createRaisedBevelBorder());
  176. messagesTextPane.setEditable(false);
  177. newFileMenuItem.setText("New...");
  178. newFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(78, java.awt.event.KeyEvent.CTRL_MASK, true));
  179. newFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
  180. public void actionPerformed(ActionEvent e) {
  181. newFileMenuItem_actionPerformed(e);
  182. }
  183. });
  184. pass3aTextPane.setEditable(false);
  185. pass3bTextPane.setEditable(false);
  186. pass3aJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  187. public void valueChanged(ListSelectionEvent e) {
  188. pass3aJList_valueChanged(e);
  189. }
  190. });
  191. pass3bJList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  192. public void valueChanged(ListSelectionEvent e) {
  193. pass3bJList_valueChanged(e);
  194. }
  195. });
  196. jMenu2.setText("Help");
  197. whatisMenuItem.setText("What is...");
  198. whatisMenuItem.addActionListener(new java.awt.event.ActionListener() {
  199. public void actionPerformed(ActionEvent e) {
  200. whatisMenuItem_actionPerformed(e);
  201. }
  202. });
  203. aboutMenuItem.setText("About");
  204. aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
  205. public void actionPerformed(ActionEvent e) {
  206. aboutMenuItem_actionPerformed(e);
  207. }
  208. });
  209. jSplitPane2.add(messagesPanel, JSplitPane.BOTTOM);
  210. messagesPanel.add(messagesScrollPane, null);
  211. messagesScrollPane.getViewport().add(messagesTextPane, null);
  212. jSplitPane2.add(jPanel3, JSplitPane.TOP);
  213. jPanel3.add(jScrollPane3, null);
  214. jScrollPane3.getViewport().add(pass1TextPane, null);
  215. jPanel3.add(jScrollPane4, null);
  216. jPanel3.add(jSplitPane3, null);
  217. jSplitPane3.add(jScrollPane2, JSplitPane.LEFT);
  218. jScrollPane2.getViewport().add(pass3aJList, null);
  219. jSplitPane3.add(jScrollPane5, JSplitPane.RIGHT);
  220. jScrollPane5.getViewport().add(pass3aTextPane, null);
  221. jPanel3.add(jSplitPane4, null);
  222. jSplitPane4.add(jScrollPane6, JSplitPane.LEFT);
  223. jScrollPane6.getViewport().add(pass3bJList, null);
  224. jSplitPane4.add(jScrollPane7, JSplitPane.RIGHT);
  225. jScrollPane7.getViewport().add(pass3bTextPane, null);
  226. jScrollPane4.getViewport().add(pass2TextPane, null);
  227. jSplitPane1.add(jPanel2, JSplitPane.TOP);
  228. jPanel2.add(jScrollPane1, null);
  229. jSplitPane1.add(jPanel1, JSplitPane.BOTTOM);
  230. jPanel1.add(jSplitPane2, null);
  231. jScrollPane1.getViewport().add(classNamesJList, null);
  232. jMenuBar1.add(jMenu1);
  233. jMenuBar1.add(jMenu2);
  234. contentPane.add(jSplitPane1, "jSplitPane1");
  235. jMenu1.add(newFileMenuItem);
  236. jMenu2.add(whatisMenuItem);
  237. jMenu2.add(aboutMenuItem);
  238. jSplitPane2.setDividerLocation(300);
  239. jSplitPane3.setDividerLocation(150);
  240. jSplitPane4.setDividerLocation(150);
  241. }
  242. /** Overridden to stop the application on a closing window. */
  243. protected void processWindowEvent(WindowEvent e) {
  244. super.processWindowEvent(e);
  245. if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  246. System.exit(0);
  247. }
  248. }
  249. synchronized void classNamesJList_valueChanged(ListSelectionEvent e) {
  250. if (e.getValueIsAdjusting()) return;
  251. current_class = classNamesJList.getSelectedValue().toString();
  252. verify();
  253. classNamesJList.setSelectedValue(current_class, true);
  254. }
  255. private void verify(){
  256. setTitle("PLEASE WAIT");
  257. Verifier v = VerifierFactory.getVerifier(current_class);
  258. v.flush(); // Don't cache the verification result for this class.
  259. VerificationResult vr;
  260. vr = v.doPass1();
  261. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  262. pass1TextPane.setText(vr.getMessage());
  263. pass1TextPane.setBackground(Color.red);
  264. pass2TextPane.setText("");
  265. pass2TextPane.setBackground(Color.yellow);
  266. pass3aTextPane.setText("");
  267. pass3aJList.setListData(new Object[0]);
  268. pass3aTextPane.setBackground(Color.yellow);
  269. pass3bTextPane.setText("");
  270. pass3bJList.setListData(new Object[0]);
  271. pass3bTextPane.setBackground(Color.yellow);
  272. }
  273. else{ // Must be VERIFIED_OK, Pass 1 does not know VERIFIED_NOTYET
  274. pass1TextPane.setBackground(Color.green);
  275. pass1TextPane.setText(vr.getMessage());
  276. vr = v.doPass2();
  277. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  278. pass2TextPane.setText(vr.getMessage());
  279. pass2TextPane.setBackground(Color.red);
  280. pass3aTextPane.setText("");
  281. pass3aTextPane.setBackground(Color.yellow);
  282. pass3aJList.setListData(new Object[0]);
  283. pass3bTextPane.setText("");
  284. pass3bTextPane.setBackground(Color.yellow);
  285. pass3bJList.setListData(new Object[0]);
  286. }
  287. else{ // must be Verified_OK, because Pass1 was OK (cannot be Verified_NOTYET).
  288. pass2TextPane.setText(vr.getMessage());
  289. pass2TextPane.setBackground(Color.green);
  290. JavaClass jc = Repository.lookupClass(current_class);
  291. /*
  292. boolean all3aok = true;
  293. boolean all3bok = true;
  294. String all3amsg = "";
  295. String all3bmsg = "";
  296. */
  297. String[] methodnames = new String[jc.getMethods().length];
  298. for (int i=0; i<jc.getMethods().length; i++){
  299. methodnames[i] = jc.getMethods()[i].toString().replace('\n',' ').replace('\t',' ');
  300. }
  301. pass3aJList.setListData(methodnames);
  302. pass3aJList.setSelectionInterval(0,jc.getMethods().length-1);
  303. pass3bJList.setListData(methodnames);
  304. pass3bJList.setSelectionInterval(0,jc.getMethods().length-1);
  305. }
  306. }
  307. String[] msgs = v.getMessages();
  308. messagesTextPane.setBackground(msgs.length == 0? Color.green : Color.yellow);
  309. String allmsgs = "";
  310. for (int i=0; i<msgs.length; i++){
  311. msgs[i] = msgs[i].replace('\n',' ');
  312. allmsgs += msgs[i] + "\n\n";
  313. }
  314. messagesTextPane.setText(allmsgs);
  315. setTitle(current_class + " - " + JUSTICE_VERSION);
  316. }
  317. void newFileMenuItem_actionPerformed(ActionEvent e) {
  318. String classname = JOptionPane.showInputDialog("Please enter the fully qualified name of a class or interface to verify:");
  319. if ((classname == null) || (classname.equals(""))) return;
  320. VerifierFactory.getVerifier(classname); // let observers do the rest.
  321. classNamesJList.setSelectedValue(classname, true);
  322. }
  323. synchronized void pass3aJList_valueChanged(ListSelectionEvent e) {
  324. if (e.getValueIsAdjusting()) return;
  325. Verifier v = VerifierFactory.getVerifier(current_class);
  326. String all3amsg = "";
  327. boolean all3aok = true;
  328. boolean rejected = false;
  329. for (int i=0; i<pass3aJList.getModel().getSize(); i++){
  330. if (pass3aJList.isSelectedIndex(i)){
  331. VerificationResult vr = v.doPass3a(i);
  332. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  333. all3aok = false;
  334. rejected = true;
  335. }
  336. all3amsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n";
  337. }
  338. }
  339. pass3aTextPane.setText(all3amsg);
  340. pass3aTextPane.setBackground(all3aok? Color.green : (rejected? Color.red : Color.yellow));
  341. }
  342. synchronized void pass3bJList_valueChanged(ListSelectionEvent e) {
  343. if (e.getValueIsAdjusting()) return;
  344. Verifier v = VerifierFactory.getVerifier(current_class);
  345. String all3bmsg = "";
  346. boolean all3bok = true;
  347. boolean rejected = false;
  348. for (int i=0; i<pass3bJList.getModel().getSize(); i++){
  349. if (pass3bJList.isSelectedIndex(i)){
  350. VerificationResult vr = v.doPass3b(i);
  351. if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED){
  352. all3bok = false;
  353. rejected = true;
  354. }
  355. all3bmsg += "Method '"+Repository.lookupClass(v.getClassName()).getMethods()[i]+"': "+vr.getMessage().replace('\n',' ')+"\n\n";
  356. }
  357. }
  358. pass3bTextPane.setText(all3bmsg);
  359. pass3bTextPane.setBackground(all3bok? Color.green : (rejected? Color.red : Color.yellow));
  360. }
  361. void aboutMenuItem_actionPerformed(ActionEvent e) {
  362. JOptionPane.showMessageDialog(this,
  363. "JustIce is a Java class file verifier.\nIt was implemented by Enver Haase in 2001, 2002.\n<https://jakarta.apache.org/bcel/index.html>",
  364. JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE);
  365. }
  366. void whatisMenuItem_actionPerformed(ActionEvent e) {
  367. JOptionPane.showMessageDialog(this,
  368. "The upper four boxes to the right reflect verification passes according to The Java Virtual Machine Specification.\nThese are (in that order): Pass one, Pass two, Pass three (before data flow analysis), Pass three (data flow analysis).\nThe bottom box to the right shows (warning) messages; warnings do not cause a class to be rejected.",
  369. JUSTICE_VERSION, JOptionPane.INFORMATION_MESSAGE);
  370. }
  371. }