Source Code Cross Referenced for FindBugsSettingsDialog.java in  » IDE » tIDE » tide » exttools » findbugs » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE » tIDE » tide.exttools.findbugs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tide.exttools.findbugs;
002:
003:        import java.net.URL;
004:        import tide.project.*;
005:        import tide.editor.*;
006:        import javax.swing.*;
007:        import java.awt.*;
008:        import java.awt.event.*;
009:        import javax.swing.border.*;
010:        import java.util.*;
011:        import java.io.*;
012:        import java.util.concurrent.*;
013:        import snow.utils.*;
014:        import snow.utils.storage.*;
015:        import snow.utils.gui.*;
016:
017:        /** Only settings, not launching directly.
018:         *  -include c:/java/findbugs/include.xml -exclude c:/java/findbugs/exclude.xml
019:         */
020:        public class FindBugsSettingsDialog extends JDialog {
021:            private final FileField findBugsPath = new FileField("", false,
022:                    "Give the FindBugs home", JFileChooser.DIRECTORIES_ONLY);
023:            final private JButton viewOpts = new JButton("available options");
024:            // 1.2.0 has en,fr,ja (messages located in plugin/coreplugin.jar)
025:            private final JComboBox messagesLanguage = new JComboBox(
026:                    new String[] { "en", "fr", "ja" });
027:
028:            //final private JComboBox displayUpPriority = new JComboBox(new String[]{"1: High","2: Medium","3: Low"});
029:            public static String defaultFindBugsLocation = "c:/java/tools/findbugs-1.3.1/";
030:            public final static String homepage = "http://findbugs.sourceforge.net/";
031:            public final static String directDownloadLink
032:            //= "http://heanet.dl.sourceforge.net/sourceforge/findbugs/findbugs-1.2.1.zip";
033:            //= "http://puzzle.dl.sourceforge.net/sourceforge/findbugs/findbugs-1.3.1.zip";
034:            = "http://kent.dl.sourceforge.net/sourceforge/findbugs/findbugs-1.3.2.zip";
035:            // C:\java\tools\findbugs-1.2.0\doc\bugDescriptions.html
036:
037:            public boolean dialogWasAccepted = false;
038:
039:            public FindBugsSettingsDialog(final JFrame parent,
040:                    final ProjectSettings settings) {
041:                super (parent, "FindBugs static checker", true);
042:
043:                JComponent ta = GUIUtils
044:                        .createReadOnlyDescriptionArea("FindBugs is an external bug finding tool available at "
045:                                + homepage
046:                                + "."
047:                                + "\r\nIt checks class files for common problems."
048:                                + "\n\nUSAGE: launch FindBugs from the context menu of the sources tree, for single files or branches."
049:
050:                        );
051:                //    ta.setEditable(false);
052:                //    ta.setBackground(getBackground());
053:                //    ta.setBorder(BorderFactory.createEmptyBorder(5,10,10,5));
054:                add(ta, BorderLayout.NORTH);
055:
056:                JPanel inputPanel = new JPanel();
057:                add(inputPanel, BorderLayout.CENTER);
058:                GridLayout3 gl3 = new GridLayout3(2, inputPanel);
059:
060:                gl3.addSeparator();
061:                JButton help = new JButton("Help", Icons.createHelpIcon(16,
062:                        true));
063:                help.setMargin(new Insets(0, 2, 0, 2));
064:                help.setFocusPainted(false);
065:                gl3.add(help);
066:                help.addActionListener(new ActionListener() {
067:                    public void actionPerformed(ActionEvent ae) {
068:                        if (findBugsPath.getPath() != null) {
069:                            try {
070:                                File local = new File(findBugsPath.getPath(),
071:                                        "doc/index.html");
072:                                if (local.exists()) {
073:                                    SysUtils.openBrowser("file://" + local);
074:                                } else {
075:                                    System.out.println("No local help: "
076:                                            + local);
077:                                    SysUtils.openBrowser(homepage);
078:                                }
079:                            } catch (Exception e) {
080:                                JOptionPane.showMessageDialog(null,
081:                                        "Can't open browser\nerr:"
082:                                                + e.getMessage(), "Error",
083:                                        JOptionPane.ERROR_MESSAGE);
084:
085:                            }
086:                        }
087:                    }
088:                });
089:
090:                final JButton down = new JButton(
091:                        "Download and install version 1.3.2",
092:                        Icons.sharedDownArrow);
093:                down.setMargin(new Insets(0, 2, 0, 2));
094:                down.setFocusPainted(false);
095:                gl3.add(down);
096:                down.addActionListener(new ActionListener() {
097:                    public void actionPerformed(ActionEvent ae) {
098:                        final long[] ds;
099:                        final URL url;
100:                        try {
101:                            url = new URL(directDownloadLink);
102:                            ds = NetUtils.getDateAndSizeOnServer(url);
103:                        } catch (Exception ex) {
104:                            JOptionPane.showMessageDialog(null,
105:                                    "Cannot download FindBugs (are you online?):\n   "
106:                                            + ex.getMessage(), "Error",
107:                                    JOptionPane.ERROR_MESSAGE);
108:                            return;
109:                        }
110:
111:                        final JFileChooser fs = new JFileChooser();
112:                        fs
113:                                .setDialogTitle("Choose the folder to install FindBugs in");
114:                        fs.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
115:                        fs
116:                                .setApproveButtonText("Download and install FindBugs in this folder");
117:                        int rep = fs
118:                                .showOpenDialog(FindBugsSettingsDialog.this );
119:                        if (rep != fs.APPROVE_OPTION)
120:                            return;
121:
122:                        final File destFolder = fs.getSelectedFile();
123:
124:                        final ProgressModalDialog pmd = new ProgressModalDialog(
125:                                FindBugsSettingsDialog.this ,
126:                                "Download FindBugs", true);
127:                        pmd.setProgressBounds(100);
128:                        pmd.start();
129:                        final File tempDest = new File(destFolder,
130:                                "findbugs-1.3.2.zip");
131:                        Thread t = new Thread() {
132:                            @Override
133:                            public void run() {
134:                                try {
135:                                    pmd
136:                                            .setProgressSection("Downloading FindBugs from sourceforge");
137:                                    pmd
138:                                            .setProgressComment("findbugs-1.3.2.zip (4MB)");
139:                                    NetUtils
140:                                            .downloadFileFromServer(url,
141:                                                    tempDest,
142:                                                    "findbugs-1.3.2.zip", pmd);
143:
144:                                    // ok, => install
145:                                    pmd
146:                                            .setProgressSection("Unpacking FindBugs locally");
147:                                    FileUtils.extractZipFile(tempDest,
148:                                            destFolder, pmd);
149:
150:                                    // link (to the folder, not to the jar)
151:                                    File pf = new File(destFolder,
152:                                            "findbugs-1.3.2/");
153:
154:                                    findBugsPath.setPath(pf);
155:                                    // todo: look if exist !!
156:                                } catch (Exception ex) {
157:                                    JOptionPane.showMessageDialog(null,
158:                                            "Cannot download FindBugs:\n   "
159:                                                    + ex.getMessage(), "Error",
160:                                            JOptionPane.ERROR_MESSAGE);
161:                                    ex.printStackTrace();
162:                                } finally {
163:                                    pmd.closeDialog();
164:                                }
165:                            }
166:                        };
167:                        t.start();
168:                    }
169:                });
170:
171:                gl3.addSeparator();
172:
173:                gl3.add("FindBugs home");
174:                gl3.add(findBugsPath);
175:                findBugsPath.setPath(settings.getProperty("FindBugs_path",
176:                        defaultFindBugsLocation));
177:                if (MainEditorFrame.instance != null) {
178:                    findBugsPath.offerRememberedGlobalCompletion(
179:                            MainEditorFrame.instance.globalProperties,
180:                            "knownFindBugs");
181:                }
182:                findBugsPath.setComponentWidth(350);
183:                findBugsPath.setAutoColorized();
184:
185:                gl3.add("Options");
186:                JPanel argumentsPanel = new JPanel(new FlowLayout(
187:                        FlowLayout.LEFT, 0, 0));
188:                viewOpts.setMargin(new Insets(0, 2, 0, 2));
189:                viewOpts.setFocusPainted(false);
190:                JTextField argsField = new JTextField(settings.getProperty(
191:                        "FindBugs_Options", ""), 25);
192:                gl3.add(argumentsPanel);
193:                argumentsPanel.add(argsField);
194:                argumentsPanel.add(viewOpts);
195:                viewOpts.addActionListener(new ActionListener() {
196:                    public void actionPerformed(ActionEvent ae) {
197:                        displayOptions();
198:                    }
199:                });
200:
201:                gl3.add("");
202:                final JCheckBox autoRemIrrelevant = new JCheckBox(
203:                        "Auto remove messages declared as irrelevant", settings
204:                                .getBooleanProperty(
205:                                        "FindBugs_ignoreIrrelevant", false));
206:                gl3.add(autoRemIrrelevant);
207:
208:                gl3.add("language");
209:                gl3.add(messagesLanguage);
210:                messagesLanguage.setEditable(true); // if not existing, english!
211:                messagesLanguage.setSelectedItem(settings.getProperty(
212:                        "FindBugs_messagesLanguage", "en")); // enforce english !
213:                //System.getProperty("user.language","en")));
214:
215:                CloseControlPanel ccp = new CloseControlPanel(this , true, true,
216:                        "Ok");
217:                add(ccp, BorderLayout.SOUTH);
218:
219:                gl3.addTitleSeparator("Tools");
220:
221:                /*no sense, can be accessed per right click on the root node in the sources tree
222:                 JButton analyseAll = new JButton("Analyse whole project");
223:                 ccp.add(analyseAll);
224:                 analyseAll.setFocusPainted(false);
225:                 analyseAll.setMargin(new Insets(0,2,0,2));
226:                 analyseAll.addActionListener(new ActionListener()
227:                 {
228:                 public void actionPerformed(ActionEvent ae)
229:                 {
230:                 analyseAllNow = true;
231:                 setVisible(false);
232:                 }
233:                 }); */
234:
235:                JButton launchFBUI = new JButton("Launch Findbugs GUI");
236:                gl3.add(launchFBUI);
237:                launchFBUI
238:                        .setToolTipText("You can open manually the latest full project analysis (if made in tIDE) in the \".tide\" folder.");
239:                launchFBUI.setFocusPainted(false);
240:                launchFBUI.setMargin(new Insets(0, 2, 0, 2));
241:                launchFBUI.addActionListener(new ActionListener() {
242:                    public void actionPerformed(ActionEvent ae) {
243:                        if (findBugsPath.getPath() == null
244:                                || !findBugsPath.getPath().exists()) {
245:                            JOptionPane.showMessageDialog(null,
246:                                    "No valid findbug path given.", "Error",
247:                                    JOptionPane.ERROR_MESSAGE);
248:                            return;
249:                        }
250:
251:                        settings.setProperty("FindBugs_path", findBugsPath
252:                                .getPath().getAbsolutePath());
253:
254:                        try {
255:                            File fbf = new File(settings
256:                                    .getProjectSettingsFolder(),
257:                                    "latest_findbugs_analysis.xml");
258:                            FindBugsLauncher.launchFindBugsGUI(fbf);
259:                        } catch (Exception e) {
260:                            e.printStackTrace();
261:                        }
262:                    }
263:                });
264:
265:                pack();
266:                this .setLocationRelativeTo(parent);
267:                this .setVisible(true); // MODAL => waits
268:
269:                if (ccp.getWasCancelled())
270:                    return;
271:
272:                dialogWasAccepted = true;
273:
274:                // save settings
275:                settings.setProperty("FindBugs_path", findBugsPath.getPath()
276:                        .getAbsolutePath());
277:                settings.setProperty("FindBugs_Options", argsField.getText());
278:                settings.setProperty("FindBugs_messagesLanguage", ""
279:                        + messagesLanguage.getSelectedItem());
280:                settings.setBooleanProperty("FindBugs_ignoreIrrelevant",
281:                        autoRemIrrelevant.isSelected());
282:
283:                findBugsPath.rememberPathForGlobalCompletion(
284:                        MainEditorFrame.instance.globalProperties,
285:                        "knownFindBugs");
286:
287:                /*  if(analyseAllNow)
288:                  {
289:                    final EstimatedProgressDialog progressDialog = new EstimatedProgressDialog(MainEditorFrame.instance, "FindingBugs is running...", false);
290:                    progressDialog.setLocationRelativeTo(MainEditorFrame.instance);
291:                    progressDialog.start();
292:
293:                    Runnable r = new Runnable()
294:                    { public void run() {
295:                     try
296:                     {
297:                        int nClasses = 123; // todo
298:                        File file = File.createTempFile("FindBugs_temp", ".tmp");
299:                        file.deleteOnExit();
300:                        MainEditorFrame.debugOut("findbugs temp res :"+file.getAbsolutePath());
301:                        new FindBugsLauncher(null, nClasses, file,
302:                           //FindBugsLauncher.DETECTION_LEVEL_LOW,
303:                           MainEditorFrame.instance, MainEditorFrame.instance.globalProperties, progressDialog);
304:                     }
305:                     catch(Exception e)
306:                     {
307:                        e.printStackTrace();
308:                        MainEditorFrame.instance.outputPanels.toolsOutputPanel.doc.appendError("\r\nFindbugs error: "+e.getMessage());
309:                     }
310:                    }};
311:                    Future fut = MainEditorFrame.instance.executeTask( r );
312:                    MainEditorFrame.instance.outputPanels.processesManager.addProcess("FindBugs analysis", fut, true);
313:
314:                  }*/
315:
316:            } // Constructor
317:
318:            /** @return true if findbugs jar is present.
319:              Used to detect if a setup dialog should be shown when starting the tool (if not found).
320:             */
321:            public static boolean isConfigured() {
322:                ProjectSettings actualProject = MainEditorFrame.instance
323:                        .getActualProject();
324:                return new File(actualProject.getProperty("FindBugs_path",
325:                        defaultFindBugsLocation)).exists();
326:            }
327:
328:            private void displayOptions() {
329:                String javaExe = "";
330:                if (MainEditorFrame.instance != null) {
331:                    ProjectSettings actualProject = MainEditorFrame.instance
332:                            .getActualProject();
333:                    javaExe = actualProject.getJava_TOOL().getAbsolutePath();
334:                } else {
335:                    javaExe = new File(System.getProperty("java.home"),
336:                            "bin/java.exe").getAbsolutePath();
337:                }
338:
339:                StringBuilder comp = new StringBuilder();
340:                try {
341:                    Vector<String> args = new Vector<String>();
342:                    args.add(javaExe);
343:                    args.add("-Dfindbugs.home="
344:                            + findBugsPath.getPath().getAbsolutePath()); // required since 1.1.2 [Dec2006]
345:                    args.add("-jar");
346:                    args.add(new File(findBugsPath.getPath(),
347:                            "lib/findbugs.jar").getAbsolutePath());
348:                    args.add("-help");
349:                    comp.append(ProcessUtils.readWholeProcessStack(args));
350:                    //? comp.append("\r\nYou can also pass the option -J-Xmx256m to increase the memory for large projects doc creation");
351:                } catch (Exception e) {
352:                    comp.append("\r\nError: " + e.getMessage());
353:                    e.printStackTrace();
354:                }
355:
356:                JDialog optionsDialog = new JDialog(this ,
357:                        "Available FindBugs options", false);
358:                JTextPane tp = new JTextPane();
359:                tp.setFont(MainEditorFrame.fixedWidthFontForProcesses);
360:                tp.setText(comp.toString().trim());
361:                optionsDialog.add(new JScrollPane(tp), BorderLayout.CENTER);
362:                CloseControlPanel ccp = new CloseControlPanel(optionsDialog,
363:                        false, true, "Close");
364:                optionsDialog.add(ccp, BorderLayout.SOUTH);
365:                tp.setEditable(false);
366:                tp.setCaretPosition(0);
367:                optionsDialog.setSize(800, 750);
368:                optionsDialog.setLocationRelativeTo(viewOpts);
369:                optionsDialog.setVisible(true);
370:            }
371:
372:            /*test*/public static void main(String[] aa) {
373:                JFrame f = new JFrame("Test");
374:                f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
375:                ProjectSettings props = new ProjectSettings();
376:                new FindBugsSettingsDialog(f, props);
377:                System.exit(0);
378:            }//*/
379:
380:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.