Source Code Cross Referenced for RefactoryInstaller.java in  » UML » jrefactory » org » acm » seguin » tools » install » 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 » UML » jrefactory » org.acm.seguin.tools.install 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         * The JRefactory License, Version 1.0
003:         *
004:         * Copyright (c) 2001 JRefactory.  All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution,
019:         *    if any, must include the following acknowledgment:
020:         *       "This product includes software developed by the
021:         *        JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022:         *    Alternately, this acknowledgment may appear in the software itself,
023:         *    if and wherever such third-party acknowledgments normally appear.
024:         *
025:         * 4. The names "JRefactory" must not be used to endorse or promote
026:         *    products derived from this software without prior written
027:         *    permission. For written permission, please contact seguin@acm.org.
028:         *
029:         * 5. Products derived from this software may not be called "JRefactory",
030:         *    nor may "JRefactory" appear in their name, without prior written
031:         *    permission of Chris Seguin.
032:         *
033:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036:         * DISCLAIMED.  IN NO EVENT SHALL THE CHRIS SEGUIN OR
037:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044:         * SUCH DAMAGE.
045:         * ====================================================================
046:         *
047:         * This software consists of voluntary contributions made by many
048:         * individuals on behalf of JRefactory.  For more information on
049:         * JRefactory, please see
050:         * <http://www.sourceforge.org/projects/jrefactory>.
051:         */
052:        package org.acm.seguin.tools.install;
053:
054:        import java.io.*;
055:        import java.text.DateFormat;
056:        import java.util.Date;
057:        import java.util.GregorianCalendar;
058:        import javax.swing.JOptionPane;
059:        import org.acm.seguin.awt.ExceptionPrinter;
060:        import org.acm.seguin.io.FileCopy;
061:        import org.acm.seguin.print.PrintingSettings;
062:        import org.acm.seguin.project.Project;
063:        import org.acm.seguin.tools.stub.StubPrompter;
064:        import org.acm.seguin.util.FileSettings;
065:        import org.acm.seguin.util.MissingSettingsException;
066:
067:        /**
068:         *  Installs the refactory
069:         *
070:         *@author     Chris Seguin
071:         *@author     Mike Atkinson
072:         *@created    October 1, 1999
073:         */
074:        public class RefactoryInstaller implements  Runnable {
075:            private boolean refactory;
076:            /**
077:             *  Which version do we have
078:             */
079:            public final static double PRETTY_CURRENT_VERSION = 3.8;
080:            private final static double UML_CURRENT_VERSION = 1.2;
081:
082:            /**
083:             *  Constructor for the RefactoryInstaller object
084:             *
085:             *@param  forRefactory  is true when we are installing software for a
086:             *      refactory
087:             */
088:            public RefactoryInstaller(boolean forRefactory) {
089:                refactory = forRefactory;
090:            }
091:
092:            /**
093:             *  Main procedure - actually does the work of installing the various
094:             *  settings files if they are not present.
095:             */
096:            public void run() {
097:                try {
098:                    File homeDir = FileSettings.getSettingsRoot();
099:                    File directory = FileSettings.getRefactorySettingsRoot();
100:                    if (!directory.exists()) {
101:                        directory.mkdirs();
102:                    }
103:
104:                    File oldUndoStack = new File(homeDir, "undo.stk");
105:                    if (oldUndoStack.exists()) {
106:                        File dest = new File(directory, "undo.stk");
107:                        (new FileCopy(oldUndoStack, dest)).run();
108:                        oldUndoStack.delete();
109:                    }
110:
111:                    File oldLogFile = new File(homeDir, "log.txt");
112:                    if (oldLogFile.exists()) {
113:                        File dest = new File(directory, "log.txt");
114:                        (new FileCopy(oldLogFile, dest)).run();
115:                        oldLogFile.delete();
116:                    }
117:
118:                    File file = new File(directory, "pretty.settings");
119:                    FileWriter output;
120:                    PrintWriter printer;
121:                    if (!file.exists()) {
122:                        output = new FileWriter(file);
123:                        printer = new PrintWriter(output);
124:                        prettySettings(printer, 0.0);
125:                        printer.flush();
126:                        output.flush();
127:                        printer.close();
128:                        output.close();
129:
130:                        FileSettings bundle = FileSettings
131:                                .getRefactoryPrettySettings();
132:                        bundle.setReloadNow(true);
133:                    } else {
134:                        FileSettings bundle = FileSettings
135:                                .getRefactoryPrettySettings();
136:                        bundle.setReloadNow(true);
137:
138:                        double version = 1.0;
139:                        try {
140:                            String temp = bundle.getString("indent");
141:                        } catch (MissingSettingsException mse) {
142:                            version = 0.5;
143:                        }
144:                        try {
145:                            version = bundle.getDouble("version");
146:                        } catch (MissingSettingsException mse) {
147:                        }
148:
149:                        if (version < (PRETTY_CURRENT_VERSION - 0.05)) {
150:                            output = new FileWriter(file.getPath(), true);
151:                            printer = new PrintWriter(output);
152:                            prettySettings(printer, version);
153:                            printer.flush();
154:                            output.flush();
155:                            printer.close();
156:                            output.close();
157:                        }
158:
159:                        bundle.setReloadNow(true);
160:                    }
161:
162:                    file = new File(directory, "uml.settings");
163:                    if (!file.exists()) {
164:                        output = new FileWriter(file);
165:                        printer = new PrintWriter(output);
166:                        umlSettings(printer, 0.0, homeDir);
167:                        printer.close();
168:                        output.close();
169:                    } else {
170:                        FileSettings bundle = FileSettings
171:                                .getRefactorySettings("uml");
172:                        bundle.setReloadNow(true);
173:
174:                        double version = 1.0;
175:                        try {
176:                            String temp = bundle.getString("stub.dir");
177:                        } catch (MissingSettingsException mse) {
178:                            version = 0.5;
179:                        }
180:                        try {
181:                            version = bundle.getDouble("version");
182:                        } catch (MissingSettingsException mse) {
183:                        }
184:
185:                        if (version < (UML_CURRENT_VERSION - 0.05)) {
186:                            output = new FileWriter(file.getPath(), true);
187:                            printer = new PrintWriter(output);
188:                            umlSettings(printer, version, homeDir);
189:                            printer.flush();
190:                            printer.close();
191:                        }
192:                    }
193:
194:                    file = new File(directory, "printing.settings");
195:                    if (!file.exists()) {
196:                        (new PrintingSettings()).save();
197:                    }
198:
199:                    file = new File(directory, "vss.settings");
200:                    if (!file.exists()) {
201:                        output = new FileWriter(file);
202:                        printer = new PrintWriter(output);
203:                        vssSettings(printer);
204:                        printer.close();
205:                        output.close();
206:                    }
207:
208:                    file = new File(directory, "process.settings");
209:                    if (!file.exists()) {
210:                        output = new FileWriter(file);
211:                        printer = new PrintWriter(output);
212:                        processSettings(printer);
213:                        printer.close();
214:                        output.close();
215:                    }
216:
217:                    file = new File(directory, "creation.txt");
218:                    if (!file.exists()) {
219:                        generateCreationText(file);
220:                    } else {
221:                        GregorianCalendar created = new GregorianCalendar();
222:                        created.setTime(new Date(file.lastModified()));
223:                        GregorianCalendar lastMonth = new GregorianCalendar();
224:                        lastMonth.add(GregorianCalendar.MONTH, -1);
225:
226:                        File logFile = new File(directory, "log.txt");
227:                        if (lastMonth.after(created) && logFile.exists()
228:                                && (logFile.length() > 0)) {
229:                            generateCreationText(file);
230:
231:                            String message = "Chris Seguin wrote JRefactory to discover\n"
232:                                    + "how people use refactorings.  While you have\n"
233:                                    + "used this tool, it has created a log of which\n"
234:                                    + "refactorings you used.  This log contains a\n"
235:                                    + "number representing the refactoring and a date.\n"
236:                                    + "\n"
237:                                    + "I would really appreciate it if you could e-mail\n"
238:                                    + "the following file to seguin@acm.org.\n"
239:                                    + "\n"
240:                                    + logFile.toString()
241:                                    + "\n"
242:                                    + "\n"
243:                                    + "Thank you for taking the time to do this.\n";
244:
245:                            JOptionPane.showMessageDialog(null, message,
246:                                    "Research request",
247:                                    JOptionPane.QUESTION_MESSAGE);
248:                        }
249:                    }
250:                    file = new File(directory, "projects");
251:                    if (!file.exists()) {
252:                        Project.storeProjects();
253:                    } else {
254:                        Project.loadProjects();
255:                    }
256:                } catch (IOException ioe) {
257:                    ExceptionPrinter.print(ioe, false);
258:                }
259:
260:                if (refactory) {
261:                    jsdkStubInstall();
262:                }
263:            }
264:
265:            /**
266:             *  Installs properties for the pretty printer
267:             *
268:             *@param  printer  The pretty printer
269:             *@param  version  Description of Parameter
270:             */
271:            private void prettySettings(PrintWriter printer, double version) {
272:                PrettyPrinterConfigGUI gui = new PrettyPrinterConfigGUI(false);
273:                gui.initializeFrame(false);
274:                gui.save();
275:                FileSettings.getRefactoryPrettySettings().setReloadNow(true);
276:            }
277:
278:            /**
279:             *  Installs properties for visual source safe
280:             *
281:             *@param  printer  the printer
282:             */
283:            private void vssSettings(PrintWriter printer) {
284:                printer
285:                        .println("#  This is the full path the visual source safe's executable ");
286:                printer
287:                        .println("vss=c:\\\\program files\\\\microsoft visual studio\\\\win32\\\\ss.exe");
288:                printer.println(" ");
289:                printer
290:                        .println("#  The following are the extensions of files which are");
291:                printer.println("#  stored in visual source safe");
292:                printer.println("extension.1=.java");
293:                printer.println("extension.2=.properties");
294:                printer.println("extension.3=.xml");
295:                printer.println("extension.4=.html");
296:                printer.println("extension.5=.htm");
297:                printer.println(" ");
298:                printer
299:                        .println("#  The following shows how the projects in Visual Source");
300:                printer.println("#  Safe map to directories on the hard disk");
301:                printer.println("source.1=c:\\\\java\\\\src");
302:                printer.println("project.1=$/Source");
303:                printer.println(" ");
304:                printer.println("source.2=c:\\\\java\\\\properties");
305:                printer.println("project.2=$/Properties");
306:                printer.println(" ");
307:                printer.println("source.3=c:\\\\public_html");
308:                printer.println("project.3=$/HTML");
309:                printer.println(" ");
310:                printer.println("source.4=c:\\\\public_html\\\\xml");
311:                printer.println("project.4=$/XML");
312:            }
313:
314:            /**
315:             *  Installs properties for process tracking
316:             *
317:             *@param  printer  the printer
318:             */
319:            private void processSettings(PrintWriter printer) {
320:                printer.println("#  The following settings are used to set");
321:                printer.println("#  up the process panel.");
322:                printer.println("#");
323:                printer
324:                        .println("#  The button.name is the value that appears on the button");
325:                printer
326:                        .println("#  The button.cmd is the value that is saved to the process");
327:                printer.println("#      tracking file");
328:                printer.println("#");
329:                printer
330:                        .println("#  The system loads all properties starting with index 0");
331:                printer
332:                        .println("#  and continuing until one or both of the next pair of");
333:                printer.println("#  values is missing.");
334:                printer.println(" ");
335:                printer.println("button.name.0=Design");
336:                printer.println("button.cmd.0=Design");
337:                printer.println(" ");
338:                printer.println("button.name.1=Coding");
339:                printer.println("button.cmd.1=Coding");
340:                printer.println(" ");
341:                printer.println("button.name.2=Unit Testing");
342:                printer.println("button.cmd.2=Unit Testing");
343:                printer.println(" ");
344:                printer.println("button.name.3=Verification");
345:                printer.println("button.cmd.3=Verification");
346:                printer.println(" ");
347:                printer.println("button.name.4=Meeting");
348:                printer.println("button.cmd.4=Meeting");
349:                printer.println(" ");
350:                printer.println("button.name.5=Interrupt");
351:                printer.println("button.cmd.5=Interrupt");
352:                printer.println(" ");
353:                printer
354:                        .println("#  The name of the file to store the process data in");
355:                printer.println("process.file=c:\\tools\\process.txt");
356:            }
357:
358:            /**
359:             *  Installs properties for process tracking
360:             *
361:             *@param  printer  the printer
362:             *@param  version  Description of Parameter
363:             *@param  dir      Description of Parameter
364:             */
365:            private void umlSettings(PrintWriter printer, double version,
366:                    File dir) {
367:                if (version < (UML_CURRENT_VERSION - 0.05)) {
368:                    printer.println("");
369:                    printer.println("#  UML File Version");
370:                    printer.println("version=" + UML_CURRENT_VERSION);
371:                    printer.println("");
372:                }
373:
374:                if (version < 0.95) {
375:                    printer
376:                            .println("#  The following settings are used to set");
377:                    printer.println("#  up the uml diagrams.");
378:                    printer.println("");
379:                    printer.println("#");
380:                    printer
381:                            .println("#  The directory containing the stub files");
382:                    printer.println("#");
383:                    printer.println("stub.dir="
384:                            + doubleBackslashes(dir.getPath()));
385:                    printer.println("");
386:                    printer.println("#");
387:                    printer
388:                            .println("#  Size of the box where a segmented line changes direction");
389:                    printer.println("#");
390:                    printer.println("sticky.point.size=3");
391:                    printer.println("");
392:                    printer.println("#");
393:                    printer
394:                            .println("#  Size of the area where you must be to select the sticky point");
395:                    printer.println("#");
396:                    printer.println("halo.size=6");
397:                    printer.println("");
398:                    printer.println("#");
399:                    printer
400:                            .println("#  The type of icon for the UML diagram.  The valid types are:");
401:                    printer
402:                            .println("#    colored circle - the original for specifying scope");
403:                    printer
404:                            .println("#    letter - a letter + for public, # for protected, etc");
405:                    printer.println("#");
406:                    printer.println("icon.type=colored circle");
407:                    printer.println("");
408:                }
409:
410:                if (version < 1.05) {
411:                    printer.println("#");
412:                    printer
413:                            .println("#  A pattern to cause the loading to skip");
414:                    printer
415:                            .println("#  a particular directory.  For instance,");
416:                    printer
417:                            .println("#  .cvs means that JRefactory will skip loading");
418:                    printer
419:                            .println("#  any directory that matches *.cvs*.  Additional");
420:                    printer
421:                            .println("#  patterns can be separated by the path separator");
422:                    printer.println("#  character");
423:                    printer.println("#");
424:                    printer.println("skip.dir=");
425:                    printer.println("");
426:                    printer
427:                            .println("#  The extension to add to the existing file when it is");
428:                    printer
429:                            .println("#  refactored.  The # represents the number of the copy");
430:                    printer.println("#  of the file");
431:                    printer.println("#");
432:                    printer.println("backup.ext=.#");
433:                    printer.println("");
434:                }
435:
436:                if (version < 1.15) {
437:                    printer.println("#");
438:                    printer
439:                            .println("#  This is used by the command line version");
440:                    printer
441:                            .println("#  of the program to launch a source code editor");
442:                    printer
443:                            .println("#  The command line program can get either 1 or ");
444:                    printer.println("#  2 arguments.  These are:");
445:                    printer
446:                            .println("#     $FILE - the path to the file for the editor");
447:                    printer.println("#     $LINE - the line number");
448:                    printer
449:                            .println("#  If your editor cannot accept the line number");
450:                    printer.println("#  command line, leave out that variable");
451:                    printer.println("#");
452:                    printer.println("#source.editor=notepad $FILE");
453:                    printer
454:                            .println("#source.editor=gnuclientw -F +$LINE $FILE");
455:                }
456:            }
457:
458:            /**
459:             *  Description of the Method
460:             */
461:            private void jsdkStubInstall() {
462:                FileSettings bundle = FileSettings.getRefactoryPrettySettings();
463:                bundle.setContinuallyReload(true);
464:
465:                File directory;
466:                try {
467:                    FileSettings umlBundle = FileSettings
468:                            .getRefactorySettings("uml");
469:                    directory = new File(umlBundle.getString("stub.dir")
470:                            + File.separator + ".Refactory");
471:                } catch (MissingSettingsException mse) {
472:                    directory = FileSettings.getRefactorySettingsRoot();
473:                }
474:
475:                if (!directory.exists()) {
476:                    directory.mkdirs();
477:                }
478:
479:                File outFile = new File(directory, "JDK.stub");
480:                if (!outFile.exists()) {
481:                    (new StubPrompter(null, outFile, true)).setVisible(true);
482:                }
483:
484:                bundle.setContinuallyReload(false);
485:            }
486:
487:            /**
488:             *  Description of the Method
489:             *
490:             *@param  value  Description of Parameter
491:             *@return        Description of the Returned Value
492:             */
493:            private String doubleBackslashes(String value) {
494:                StringBuffer buffer = new StringBuffer();
495:                int last = value.length();
496:                for (int ndx = 0; ndx < last; ndx++) {
497:                    char ch = value.charAt(ndx);
498:                    if (ch == '\\') {
499:                        buffer.append("\\\\");
500:                    } else {
501:                        buffer.append(ch);
502:                    }
503:                }
504:                return buffer.toString();
505:            }
506:
507:            /**
508:             *  Creates a file that marks when the refactory was installed
509:             *
510:             *@param  file             The file to create
511:             *@exception  IOException  Description of Exception
512:             */
513:            private void generateCreationText(File file) throws IOException {
514:                FileWriter output = new FileWriter(file);
515:                PrintWriter printer = new PrintWriter(output);
516:                printer.println("Created on "
517:                        + DateFormat.getDateTimeInstance().format(new Date()));
518:                printer.close();
519:                output.close();
520:            }
521:
522:            /**
523:             *  The main program
524:             *
525:             *@param  args  command line arguments
526:             */
527:            public static void main(String[] args) {
528:                (new RefactoryInstaller(false)).run();
529:            }
530:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.