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:
016: public Properties rootProperties;
017:
018: public Update[] updates;
019:
020: public Updater(FitNesseContext context) throws Exception {
021: this .context = context;
022: rootProperties = loadProperties();
023:
024: updates = new Update[] {
025: new ReplacingFileUpdate(this ,
026: "files/images/FitNesseLogo.gif", "files/images"),
027: new ReplacingFileUpdate(this ,
028: "files/images/FitNesseLogoMedium.jpg",
029: "files/images"),
030: new ReplacingFileUpdate(this ,
031: "files/images/virtualPage.jpg", "files/images"),
032: new ReplacingFileUpdate(this ,
033: "files/images/importedPage.jpg", "files/images"),
034: new ReplacingFileUpdate(this ,
035: "files/images/collapsableOpen.gif",
036: "files/images"),
037: new ReplacingFileUpdate(this ,
038: "files/images/collapsableClosed.gif",
039: "files/images"),
040: new ReplacingFileUpdate(this ,
041: "files/images/folder.gif", "files/images"),
042: new ReplacingFileUpdate(this ,
043: "files/images/executionStatus/ok.gif",
044: "files/images/executionStatus"),
045: new ReplacingFileUpdate(this ,
046: "files/images/executionStatus/output.gif",
047: "files/images/executionStatus"),
048: new ReplacingFileUpdate(this ,
049: "files/images/executionStatus/error.gif",
050: "files/images/executionStatus"),
051: new ReplacingFileUpdate(this ,
052: "files/css/fitnesse_base.css", "files/css"),
053: new FileUpdate(this , "files/css/fitnesse.css",
054: "files/css"),
055: new FileUpdate(this , "files/css/fitnesse_print.css",
056: "files/css"),
057: new ReplacingFileUpdate(this ,
058: "files/javascript/fitnesse.js",
059: "files/javascript"),
060: new ReplacingFileUpdate(this ,
061: "files/javascript/SpreadsheetTranslator.js",
062: "files/javascript"),
063: new ReplacingFileUpdate(this ,
064: "files/javascript/spreadsheetSupport.js",
065: "files/javascript"),
066: new PropertiesToXmlUpdate(this ),
067: new AttributeAdderUpdate(this ,
068: WikiPage.ACTION_RECENT_CHANGES),
069: new AttributeAdderUpdate(this ,
070: WikiPage.ACTION_WHERE_USED),
071: new AttributeAdderUpdate(this , WikiPage.ACTION_FILES),
072: new VirtualWikiDeprecationUpdate(this ),
073: new FrontPageUpdate(this ) };
074: }
075:
076: public void update() throws Exception {
077: Update[] updates = getUpdates();
078: for (int i = 0; i < updates.length; i++) {
079: Update update = updates[i];
080: if (update.shouldBeApplied())
081: performUpdate(update);
082: }
083: saveProperties();
084: }
085:
086: private void performUpdate(Update update) throws Exception {
087: try {
088: print(update.getMessage());
089: update.doUpdate();
090: print("...done\n");
091: } catch (Exception e) {
092: print("\n\t" + e + "\n");
093: }
094: }
095:
096: private Update[] getUpdates() throws Exception {
097: return updates;
098: }
099:
100: public WikiPage getRoot() {
101: return context.root;
102: }
103:
104: public Properties getProperties() {
105: return rootProperties;
106: }
107:
108: public Properties loadProperties() throws Exception {
109: Properties properties = new Properties();
110: File propFile = getPropertiesFile();
111: if (propFile.exists()) {
112: InputStream is = new FileInputStream(propFile);
113: properties.load(is);
114: is.close();
115: }
116: return properties;
117: }
118:
119: private File getPropertiesFile() throws Exception {
120: String filename = context.rootPagePath + "/properties";
121: File propFile = new File(filename);
122: return propFile;
123: }
124:
125: public void saveProperties() throws Exception {
126: File propFile = getPropertiesFile();
127: OutputStream os = new FileOutputStream(propFile);
128: rootProperties.store(os, "FitNesse properties");
129: os.close();
130: }
131:
132: private void print(String message) {
133: if (!testing)
134: System.out.print(message);
135:
136: }
137:
138: }
|