| 1 10 11 package org.mmbase.applications.packaging; 12 13 import java.io.File ; 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 17 import org.mmbase.applications.packaging.bundlehandlers.BundleInterface; 18 import org.mmbase.applications.packaging.installhandlers.installThread; 19 import org.mmbase.applications.packaging.packagehandlers.PackageInterface; 20 import org.mmbase.util.logging.Logger; 21 import org.mmbase.util.logging.Logging; 22 23 29 public class InstallManager { 30 private static Logger log = Logging.getLoggerInstance(InstallManager.class); 31 32 private static boolean active = false; 34 35 private static boolean bundle = false; 37 38 private static PackageInterface pkg; 40 41 private static BundleInterface bnd; 42 43 private static installThread runner; 44 45 private static String state; 46 47 private static boolean running = false; 48 49 private static ArrayList autoresetfiles = null; 50 51 public static synchronized void init() { 52 if (!PackageManager.isRunning()) PackageManager.init(); 53 if (!BundleManager.isRunning()) BundleManager.init(); 54 if (!ProviderManager.isRunning()) ProviderManager.init(); 55 if (!ShareManager.isRunning()) ShareManager.init(); 56 if (!ProjectManager.isRunning()) ProjectManager.init(); 57 running = true; 58 } 59 60 63 public static synchronized boolean installPackage(PackageInterface p) { 64 if (!active) { 65 active = true; 67 68 bundle = false; 70 71 autoresetfiles = null; 73 74 pkg = p; 76 77 state = "installing"; 78 79 p.clearInstallSteps(); 80 81 runner = new installThread(); 82 83 return true; 84 } else { 85 return false; 88 } 89 } 90 91 92 95 public static synchronized boolean installBundle(BundleInterface b) { 96 if (!active) { 97 active = true; 99 100 bundle = true; 102 103 autoresetfiles = null; 105 106 bnd = b; 108 state = "installing"; 109 b.clearInstallSteps(); 110 runner = new installThread(); 111 112 return true; 113 } else { 114 return false; 117 } 118 } 119 120 124 public static void performInstall() { 125 try { 126 if (bnd != null) { 127 bnd.install(); 128 state = "waiting"; 129 active = false; 130 131 } else if (pkg != null) { 132 pkg.install(); 133 state = "waiting"; 134 active = false; 135 } 136 renameAutoResetFiles(); 138 } catch(Exception e) { 139 log.error("perform Install problem",e); 140 } 141 } 142 143 public void setState(String state) { 144 this.state=state; 145 } 146 147 public String getState() { 148 return state; 149 } 150 151 public static boolean isActive() { 152 return active; 153 } 154 155 public static boolean isRunning() { 156 return running; 157 } 158 159 public static PackageInterface getInstallingPackage() { 160 return pkg; 161 } 162 163 public static BundleInterface getInstallingBundle() { 164 return bnd; 165 } 166 167 public static Iterator getInstallSteps() { 168 return pkg.getInstallSteps(); 169 } 170 171 172 public static void addAutoResetFile(String path) { 173 if (autoresetfiles == null) autoresetfiles = new ArrayList (); 174 autoresetfiles.add(path); 175 } 176 177 private static void renameAutoResetFiles() { 178 if (autoresetfiles != null) { 179 Iterator e=autoresetfiles.iterator(); 180 while (e.hasNext()) { 181 String name=(String )e.next(); 182 File oldfile = new File (name); 183 File newfile = new File (name.substring(0,name.length()-4)); 184 if (oldfile.exists()) { 185 oldfile.renameTo(newfile); 186 } 187 } 188 } 189 } 190 191 } 192 | Popular Tags |