001: /*
002: * ====================================================================
003: * The JRefactory License, Version 1.0
004: *
005: * Copyright (c) 2001 JRefactory. All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by the
022: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "JRefactory" must not be used to endorse or promote
027: * products derived from this software without prior written
028: * permission. For written permission, please contact seguin@acm.org.
029: *
030: * 5. Products derived from this software may not be called "JRefactory",
031: * nor may "JRefactory" appear in their name, without prior written
032: * permission of Chris Seguin.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
038: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045: * SUCH DAMAGE.
046: * ====================================================================
047: *
048: * This software consists of voluntary contributions made by many
049: * individuals on behalf of JRefactory. For more information on
050: * JRefactory, please see
051: * <http://www.sourceforge.org/projects/jrefactory>.
052: */
053: package org.acm.seguin.tools;
054:
055: import java.io.*;
056: import java.text.DateFormat;
057: import java.util.Date;
058: import java.util.GregorianCalendar;
059: import javax.swing.JOptionPane;
060: import org.acm.seguin.awt.ExceptionPrinter;
061: import org.acm.seguin.io.FileCopy;
062: import org.acm.seguin.print.PrintingSettings;
063: import org.acm.seguin.project.Project;
064: import org.acm.seguin.tools.stub.StubPrompter;
065: import org.acm.seguin.util.FileSettings;
066: import org.acm.seguin.util.MissingSettingsException;
067:
068: /**
069: * Installs the refactory
070: *
071: * @author Chris Seguin
072: * @author Mike Atkinson
073: * @created October 1, 1999
074: */
075: public class RefactoryInstaller implements Runnable {
076: private boolean refactory;
077: /** Which version do we have */
078: public final static double PRETTY_CURRENT_VERSION = 4.4;
079: private final static double UML_CURRENT_VERSION = 1.2;
080:
081: /**
082: * Constructor for the RefactoryInstaller object
083: *
084: * @param forRefactory is true when we are installing software for a
085: * refactory
086: */
087: public RefactoryInstaller(boolean forRefactory) {
088: refactory = forRefactory;
089: }
090:
091: /**
092: * Main procedure - actually does the work of installing the various
093: * settings files if they are not present.
094: */
095: public void run() {
096: try {
097: File homeDir = FileSettings.getSettingsRoot();
098: File directory = FileSettings.getRefactorySettingsRoot();
099:
100: if (!directory.exists())
101: directory.mkdirs();
102:
103: File oldUndoStack = new File(homeDir, "undo.stk");
104:
105: if (oldUndoStack.exists()) {
106: File dest = new File(directory, "undo.stk");
107:
108: (new FileCopy(oldUndoStack, dest)).run();
109: oldUndoStack.delete();
110: }
111:
112: File oldLogFile = new File(homeDir, "log.txt");
113:
114: if (oldLogFile.exists()) {
115: File dest = new File(directory, "log.txt");
116:
117: (new FileCopy(oldLogFile, dest)).run();
118: oldLogFile.delete();
119: }
120:
121: File file = new File(directory, "pretty.settings");
122: FileWriter output;
123: PrintWriter printer;
124:
125: if (!file.exists()) {
126: InputStream inputStream = getClass()
127: .getResourceAsStream(
128: "/settings/.Refactory/pretty.settings");
129: byte[] data = new byte[1024 * 16];
130: int len = inputStream.read(data);
131: OutputStream outputStream = new FileOutputStream(file);
132:
133: while (len >= 0) {
134: outputStream.write(data, 0, len);
135: len = inputStream.read(data);
136: }
137: outputStream.close();
138:
139: FileSettings.getRefactoryPrettySettings().setReloadNow(
140: true);
141: } else {
142: FileSettings bundle = FileSettings
143: .getRefactoryPrettySettings();
144:
145: bundle.setReloadNow(true);
146:
147: double version = 1.0;
148:
149: try {
150: String temp = bundle.getString("indent");
151: } catch (MissingSettingsException mse) {
152: version = 0.5;
153: }
154: try {
155: version = bundle.getDouble("version");
156: } catch (MissingSettingsException mse) {
157: }
158:
159: if (version < (PRETTY_CURRENT_VERSION - 0.05)) {
160: output = new FileWriter(file.getPath(), true);
161: printer = new PrintWriter(output);
162: prettySettings(printer, version);
163: printer.flush();
164: output.flush();
165: printer.close();
166: output.close();
167: }
168:
169: bundle.setReloadNow(true);
170: }
171:
172: file = new File(directory, "uml.settings");
173: if (!file.exists()) {
174: output = new FileWriter(file);
175: printer = new PrintWriter(output);
176: umlSettings(printer, 0.0, homeDir);
177: printer.close();
178: output.close();
179: } else {
180: FileSettings bundle = FileSettings
181: .getRefactorySettings("uml");
182:
183: bundle.setReloadNow(true);
184:
185: double version = 1.0;
186:
187: try {
188: String temp = bundle.getString("stub.dir");
189: } catch (MissingSettingsException mse) {
190: version = 0.5;
191: }
192: try {
193: version = bundle.getDouble("version");
194: } catch (MissingSettingsException mse) {
195: }
196:
197: if (version < (UML_CURRENT_VERSION - 0.05)) {
198: output = new FileWriter(file.getPath(), true);
199: printer = new PrintWriter(output);
200: umlSettings(printer, version, homeDir);
201: printer.flush();
202: printer.close();
203: }
204: }
205:
206: file = new File(directory, "printing.settings");
207: if (!file.exists())
208: (new PrintingSettings()).save();
209:
210: file = new File(directory, "vss.settings");
211: if (!file.exists()) {
212: output = new FileWriter(file);
213: printer = new PrintWriter(output);
214: vssSettings(printer);
215: printer.close();
216: output.close();
217: }
218:
219: file = new File(directory, "process.settings");
220: if (!file.exists()) {
221: output = new FileWriter(file);
222: printer = new PrintWriter(output);
223: processSettings(printer);
224: printer.close();
225: output.close();
226: }
227:
228: file = new File(directory, "creation.txt");
229: if (!file.exists())
230: generateCreationText(file);
231: else {
232: GregorianCalendar created = new GregorianCalendar();
233:
234: created.setTime(new Date(file.lastModified()));
235:
236: GregorianCalendar lastMonth = new GregorianCalendar();
237:
238: lastMonth.add(GregorianCalendar.MONTH, -1);
239:
240: File logFile = new File(directory, "log.txt");
241:
242: if (lastMonth.after(created) && logFile.exists()
243: && (logFile.length() > 0)) {
244: generateCreationText(file);
245:
246: String message = "The authors of JRefactory and the JavaStyle plugin\n"
247: + "would appreciate feedback on the use of JRefactory.\n"
248: + "Which components do you use? Are there any\n"
249: + "improvements you would like to see included? Found\n"
250: + "any bugs? What refactorings do you use?\n"
251: + "\n"
252: + "Please report your comments to http://sourceforge.net/projects/jrefactory\n"
253: + "or the discussion forum at http://sourceforge.net/forum/forum.php?forum_id=41646\n"
254: + "\n"
255: + "Thank you for taking the time to do this.\n";
256:
257: JOptionPane.showMessageDialog(null, message,
258: "Research request",
259: JOptionPane.QUESTION_MESSAGE);
260: }
261: }
262: file = new File(directory, "projects");
263: if (!file.exists())
264: Project.storeProjects();
265: else
266: Project.loadProjects();
267:
268: } catch (IOException ioe) {
269: ExceptionPrinter.print(ioe, false);
270: }
271:
272: if (refactory) {
273: jsdkStubInstall();
274: }
275:
276: }
277:
278: /**
279: * Installs properties for the pretty printer
280: *
281: * @param printer The pretty printer
282: * @param version Description of Parameter
283: */
284: private void prettySettings(PrintWriter printer, double version) {
285: System.out.println("updating pretty.settings version="
286: + version);
287: if (version < 3.9) {
288: printer
289: .println("# new in version 3.9 of the pretty printer ");
290: printer.println(" ");
291: printer.println("version=3.9");
292: printer.println("enum.descr=Description of Enumeration");
293: printer.println("enum.tags=author");
294: printer.println("jdk=1.4.2");
295: //printer.println("singleline.comment.ownline=true");
296: //printer.println("date.required=false");// obsolete
297: //printer.println("space.before.javadoc=true");// default (false) looks odd
298: //printer.println("reformat.comments=false");// too many users complained
299: //printer.println("import.sort.important=java,javax");
300:
301: }
302: if (version < 4.1) {
303: printer.println(" ");
304: printer
305: .println("# new in version 4.1 of the pretty printer ");
306: printer.println("version=4.1");
307: printer
308: .println("tostring.descr=Converts to a String representation of the {0} object.");
309: printer
310: .println("tostring.return.descr=A string representation of the {0} object.");
311: printer
312: .println("equals.descr=Compares this {0} to the parameter.");
313: printer
314: .println("equals.param.descr=the reference object with which to compare.");
315: printer
316: .println("equals.return.descr=<tt>true</tt> if this object is the same as the obj argument; <tt>false</tt> otherwise.");
317: printer
318: .println("hashcode.descr=Computes a hash value for this {0} object.");
319: printer
320: .println("hashcode.return.descr=The hash value for this {0} object.");
321: printer
322: .println("clone.descr=Creates an exact copy of this {0} object.");
323: printer
324: .println("clone.return.descr=A clone of this {0} object.");
325: printer
326: .println("copyconstructor.descr=Copy constructor for the {0} object. Creates a copy of the {0} object parameter");
327: printer
328: .println("copyconstructor.param.descr=Object to copy.");
329: printer
330: .println("finalize.descr=Overrides the finalize method to dispose of system resources or to perform other cleanup when the {1} object is garbage collected.");
331: printer
332: .println("listener.add.descr=Adds the specified {0} listener to receive {0} events from this component. If listener l is null, no exception is thrown and no action is performed.");
333: printer
334: .println("listener.remove.descr=Removes the specified {0} listener so that it no longer receives {0} events from this component. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this component. If listener l is null, no exception is thrown and no action is performed.");
335: printer
336: .println("listener.param.descr=Contains the {0}Listener for {0}Event data.");
337: printer
338: .println("instance.descr=Gets an instance of this {0} class.");
339: printer
340: .println("instance.return.descr=An instance of {0}.");
341: }
342: if (version < 4.2) {
343: printer.println(" ");
344: printer
345: .println("# new in version 4.2 of the pretty printer ");
346: printer.println("version=4.2");
347: printer.println("char.stream.type=2");
348: }
349: if (version < 4.3) {
350: printer.println(" ");
351: printer
352: .println("# new in version 4.3 of the pretty printer ");
353: printer.println("version=4.3");
354: printer.println("first.singleline.javadoc=false");
355: printer.println("sort.throws=true");
356: printer.println("sort.extends=true");
357: printer.println("sort.implements=true");
358: }
359: if (version < 4.4) {
360: printer.println(" ");
361: printer
362: .println("# new in version 4.4 of the pretty printer ");
363: printer.println("version=4.4");
364: printer.println("navigator.enable=true");
365: printer.println("annotation.type.descr=An Anotation");
366: printer.println("annotation.type.tags=author");
367: printer.println("annotation.method.descr=Annotation part");
368: printer.println("annotation.method.tags=");
369: printer.println("constant.descr=A constant value");
370: printer.println("constant.tags=");
371: }
372:
373: }
374:
375: /**
376: * Installs properties for visual source safe
377: *
378: * @param printer the printer
379: */
380: private void vssSettings(PrintWriter printer) {
381: printer
382: .println("# This is the full path the visual source safe's executable ");
383: printer
384: .println("vss=c:\\\\program files\\\\microsoft visual studio\\\\win32\\\\ss.exe");
385: printer.println(" ");
386: printer
387: .println("# The following are the extensions of files which are");
388: printer.println("# stored in visual source safe");
389: printer.println("extension.1=.java");
390: printer.println("extension.2=.properties");
391: printer.println("extension.3=.xml");
392: printer.println("extension.4=.html");
393: printer.println("extension.5=.htm");
394: printer.println(" ");
395: printer
396: .println("# The following shows how the projects in Visual Source");
397: printer.println("# Safe map to directories on the hard disk");
398: printer.println("source.1=c:\\\\java\\\\src");
399: printer.println("project.1=$/Source");
400: printer.println(" ");
401: printer.println("source.2=c:\\\\java\\\\properties");
402: printer.println("project.2=$/Properties");
403: printer.println(" ");
404: printer.println("source.3=c:\\\\public_html");
405: printer.println("project.3=$/HTML");
406: printer.println(" ");
407: printer.println("source.4=c:\\\\public_html\\\\xml");
408: printer.println("project.4=$/XML");
409: }
410:
411: /**
412: * Installs properties for process tracking
413: *
414: * @param printer the printer
415: */
416: private void processSettings(PrintWriter printer) {
417: printer.println("# The following settings are used to set");
418: printer.println("# up the process panel.");
419: printer.println("#");
420: printer
421: .println("# The button.name is the value that appears on the button");
422: printer
423: .println("# The button.cmd is the value that is saved to the process");
424: printer.println("# tracking file");
425: printer.println("#");
426: printer
427: .println("# The system loads all properties starting with index 0");
428: printer
429: .println("# and continuing until one or both of the next pair of");
430: printer.println("# values is missing.");
431: printer.println(" ");
432: printer.println("button.name.0=Design");
433: printer.println("button.cmd.0=Design");
434: printer.println(" ");
435: printer.println("button.name.1=Coding");
436: printer.println("button.cmd.1=Coding");
437: printer.println(" ");
438: printer.println("button.name.2=Unit Testing");
439: printer.println("button.cmd.2=Unit Testing");
440: printer.println(" ");
441: printer.println("button.name.3=Verification");
442: printer.println("button.cmd.3=Verification");
443: printer.println(" ");
444: printer.println("button.name.4=Meeting");
445: printer.println("button.cmd.4=Meeting");
446: printer.println(" ");
447: printer.println("button.name.5=Interrupt");
448: printer.println("button.cmd.5=Interrupt");
449: printer.println(" ");
450: printer
451: .println("# The name of the file to store the process data in");
452: printer.println("process.file=c:\\tools\\process.txt");
453: }
454:
455: /**
456: * Installs properties for process tracking
457: *
458: * @param printer the printer
459: * @param version Description of Parameter
460: * @param dir Description of Parameter
461: */
462: private void umlSettings(PrintWriter printer, double version,
463: File dir) {
464: if (version < (UML_CURRENT_VERSION - 0.05)) {
465: printer.println("");
466: printer.println("# UML File Version");
467: printer.println("version=" + UML_CURRENT_VERSION);
468: printer.println("");
469: }
470:
471: if (version < 0.95) {
472: printer
473: .println("# The following settings are used to set");
474: printer.println("# up the uml diagrams.");
475: printer.println("");
476: printer.println("#");
477: printer
478: .println("# The directory containing the stub files");
479: printer.println("#");
480: printer.println("stub.dir="
481: + doubleBackslashes(dir.getPath()));
482: printer.println("");
483: printer.println("#");
484: printer
485: .println("# Size of the box where a segmented line changes direction");
486: printer.println("#");
487: printer.println("sticky.point.size=3");
488: printer.println("");
489: printer.println("#");
490: printer
491: .println("# Size of the area where you must be to select the sticky point");
492: printer.println("#");
493: printer.println("halo.size=6");
494: printer.println("");
495: printer.println("#");
496: printer
497: .println("# The type of icon for the UML diagram. The valid types are:");
498: printer
499: .println("# colored circle - the original for specifying scope");
500: printer
501: .println("# letter - a letter + for public, # for protected, etc");
502: printer.println("#");
503: printer.println("icon.type=colored circle");
504: printer.println("");
505: }
506:
507: if (version < 1.05) {
508: printer.println("#");
509: printer
510: .println("# A pattern to cause the loading to skip");
511: printer
512: .println("# a particular directory. For instance,");
513: printer
514: .println("# .cvs means that JRefactory will skip loading");
515: printer
516: .println("# any directory that matches *.cvs*. Additional");
517: printer
518: .println("# patterns can be separated by the path separator");
519: printer.println("# character");
520: printer.println("#");
521: printer.println("skip.dir=");
522: printer.println("");
523: printer
524: .println("# The extension to add to the existing file when it is");
525: printer
526: .println("# refactored. The # represents the number of the copy");
527: printer.println("# of the file");
528: printer.println("#");
529: printer.println("backup.ext=.#");
530: printer.println("");
531: }
532:
533: if (version < 1.15) {
534: printer.println("#");
535: printer
536: .println("# This is used by the command line version");
537: printer
538: .println("# of the program to launch a source code editor");
539: printer
540: .println("# The command line program can get either 1 or ");
541: printer.println("# 2 arguments. These are:");
542: printer
543: .println("# $FILE - the path to the file for the editor");
544: printer.println("# $LINE - the line number");
545: printer
546: .println("# If your editor cannot accept the line number");
547: printer.println("# command line, leave out that variable");
548: printer.println("#");
549: printer.println("#source.editor=notepad $FILE");
550: printer
551: .println("#source.editor=gnuclientw -F +$LINE $FILE");
552: }
553: }
554:
555: /** Description of the Method */
556: private void jsdkStubInstall() {
557: FileSettings bundle = FileSettings.getRefactoryPrettySettings();
558:
559: bundle.setContinuallyReload(true);
560:
561: File directory;
562:
563: try {
564: net.sourceforge.jrefactory.parser.JavaParser
565: .setTargetJDK(bundle.getString("jdk"));
566: } catch (Exception e) {
567: net.sourceforge.jrefactory.parser.JavaParser
568: .setTargetJDK("1.4.2");
569: }
570: try {
571: FileSettings umlBundle = FileSettings
572: .getRefactorySettings("uml");
573:
574: directory = new File(umlBundle.getString("stub.dir")
575: + File.separator + ".Refactory");
576: } catch (MissingSettingsException mse) {
577: directory = FileSettings.getRefactorySettingsRoot();
578: }
579:
580: if (!directory.exists()) {
581: directory.mkdirs();
582: }
583:
584: File outFile = new File(directory, "JDK.stub");
585:
586: if (!outFile.exists()) {
587: (new StubPrompter(null, outFile, true)).setVisible(true);
588: }
589:
590: bundle.setContinuallyReload(false);
591: }
592:
593: /**
594: * Description of the Method
595: *
596: * @param value Description of Parameter
597: * @return Description of the Returned Value
598: */
599: private String doubleBackslashes(String value) {
600: StringBuffer buffer = new StringBuffer();
601: int last = value.length();
602:
603: for (int ndx = 0; ndx < last; ndx++) {
604: char ch = value.charAt(ndx);
605:
606: if (ch == '\\')
607: buffer.append("\\\\");
608: else
609: buffer.append(ch);
610:
611: }
612: return buffer.toString();
613: }
614:
615: /**
616: * Creates a file that marks when the refactory was installed
617: *
618: * @param file The file to create
619: * @exception IOException Description of Exception
620: */
621: private void generateCreationText(File file) throws IOException {
622: FileWriter output = new FileWriter(file);
623: PrintWriter printer = new PrintWriter(output);
624:
625: printer.println("Created on "
626: + DateFormat.getDateTimeInstance().format(new Date()));
627: printer.close();
628: output.close();
629: }
630:
631: /**
632: * The main program
633: *
634: * @param args command line arguments
635: */
636: public static void main(String[] args) {
637: (new RefactoryInstaller(false)).run();
638: }
639: }
|