001: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002: // Released under the terms of the GNU General Public License version 2 or later.
003: package fitnesse.updates;
004:
005: import fitnesse.FitNesseContext;
006: import fitnesse.wiki.WikiPage;
007:
008: import java.util.Properties;
009: import java.io.*;
010:
011: public class Updater {
012: public static boolean testing = false;
013:
014: public FitNesseContext context;
015: public Properties rootProperties;
016:
017: public Update[] updates;
018:
019: public Updater(FitNesseContext context) throws Exception {
020: this .context = context;
021: rootProperties = loadProperties();
022:
023: updates = new Update[] {
024: new ReplacingFileUpdate(this ,
025: "files/images/FitNesseLogo.gif", "files/images"),
026: new ReplacingFileUpdate(this ,
027: "files/images/FitNesseLogoMedium.jpg",
028: "files/images"),
029: new ReplacingFileUpdate(this ,
030: "files/images/virtualPage.jpg", "files/images"),
031: new ReplacingFileUpdate(this ,
032: "files/images/importedPage.jpg", "files/images"),
033: new ReplacingFileUpdate(this ,
034: "files/images/collapsableOpen.gif",
035: "files/images"),
036: new ReplacingFileUpdate(this ,
037: "files/images/collapsableClosed.gif",
038: "files/images"),
039: new ReplacingFileUpdate(this ,
040: "files/images/folder.gif", "files/images"),
041: new ReplacingFileUpdate(this ,
042: "files/images/executionStatus/ok.gif",
043: "files/images/executionStatus"),
044: new ReplacingFileUpdate(this ,
045: "files/images/executionStatus/output.gif",
046: "files/images/executionStatus"),
047: new ReplacingFileUpdate(this ,
048: "files/images/executionStatus/error.gif",
049: "files/images/executionStatus"),
050: new ReplacingFileUpdate(this ,
051: "files/css/fitnesse_base.css", "files/css"),
052: new FileUpdate(this , "files/css/fitnesse.css",
053: "files/css"),
054: new FileUpdate(this , "files/css/fitnesse_print.css",
055: "files/css"),
056: new ReplacingFileUpdate(this ,
057: "files/javascript/fitnesse.js",
058: "files/javascript"),
059: new ReplacingFileUpdate(this ,
060: "files/javascript/clientSideSort.js",
061: "files/javascript"),
062: new ReplacingFileUpdate(this ,
063: "files/javascript/SpreadsheetTranslator.js",
064: "files/javascript"),
065: new ReplacingFileUpdate(this ,
066: "files/javascript/spreadsheetSupport.js",
067: "files/javascript"),
068: new PropertiesToXmlUpdate(this ),
069: new AttributeAdderUpdate(this , "RecentChanges"),
070: new AttributeAdderUpdate(this , "WhereUsed"),
071: new AttributeAdderUpdate(this , "Files"),
072: new SymLinkPropertyFormatUpdate(this ),
073: new WikiImportPropertyFormatUpdate(this ),
074: new VirtualWikiDeprecationUpdate(this ),
075: new FrontPageUpdate(this ) };
076: }
077:
078: public void update() throws Exception {
079: Update[] updates = getUpdates();
080: for (int i = 0; i < updates.length; i++) {
081: Update update = updates[i];
082: if (update.shouldBeApplied())
083: performUpdate(update);
084: }
085: saveProperties();
086: }
087:
088: private void performUpdate(Update update) throws Exception {
089: try {
090: print(update.getMessage());
091: update.doUpdate();
092: print("...done\n");
093: } catch (Exception e) {
094: print("\n\t" + e + "\n");
095: }
096: }
097:
098: private Update[] getUpdates() throws Exception {
099: return updates;
100: }
101:
102: public WikiPage getRoot() {
103: return context.root;
104: }
105:
106: public Properties getProperties() {
107: return rootProperties;
108: }
109:
110: public Properties loadProperties() throws Exception {
111: Properties properties = new Properties();
112: File propFile = getPropertiesFile();
113: if (propFile.exists()) {
114: InputStream is = new FileInputStream(propFile);
115: properties.load(is);
116: is.close();
117: }
118: return properties;
119: }
120:
121: private File getPropertiesFile() throws Exception {
122: String filename = context.rootPagePath + "/properties";
123: return new File(filename);
124: }
125:
126: public void saveProperties() throws Exception {
127: File propFile = getPropertiesFile();
128: OutputStream os = new FileOutputStream(propFile);
129: rootProperties.store(os, "FitNesse properties");
130: os.close();
131: }
132:
133: private void print(String message) {
134: if (!testing)
135: System.out.print(message);
136:
137: }
138:
139: }
|