1 package com.nightlabs.ipanema.update; 2 3 import java.net.MalformedURLException ; 4 import java.net.URL ; 5 import java.util.HashSet ; 6 import java.util.Set ; 7 8 import org.eclipse.core.runtime.CoreException; 9 import org.eclipse.core.runtime.IProgressMonitor; 10 import org.eclipse.core.runtime.IStatus; 11 import org.eclipse.update.configuration.IConfiguredSite; 12 import org.eclipse.update.core.IFeature; 13 import org.eclipse.update.core.ISite; 14 import org.eclipse.update.core.ISiteFeatureReference; 15 import org.eclipse.update.core.SiteManager; 16 import org.eclipse.update.core.VersionedIdentifier; 17 import org.eclipse.update.standalone.DisableCommand; 18 import org.eclipse.update.standalone.InstallCommand; 19 import org.eclipse.update.standalone.UninstallCommand; 20 21 import com.nightlabs.config.Config; 22 import com.nightlabs.config.ConfigException; 23 import com.nightlabs.ipanema.base.IpanemaBasePlugin; 24 import com.nightlabs.ipanema.base.login.LoginConfigModule; 25 import com.nightlabs.rcp.splash.SplashDialog; 26 import com.nightlabs.rcp.splash.SplashPlugin; 27 import com.nightlabs.rcp.splash.SplashScreen; 28 import com.nightlabs.rcp.splash.SplashDialog.SplashDialogResult; 29 30 33 34 public class StartupUpdateManager implements IProgressMonitor, Runnable  35 { 36 private double worked; 37 private String taskName; 38 39 public final static int MODE_INSTALL = 0; 40 public final static int MODE_UPDATE = 0; 41 42 private LoginConfigModule lcm; 43 private boolean doRestart; 44 45 public StartupUpdateManager(LoginConfigModule lcm) 46 { 47 this.lcm = lcm; 48 } 49 50 51 public void run() 52 { 53 SplashScreen.setSplashMessage(IpanemaBasePlugin.getResourceString("update.message.checkingForUpdates")); 54 try 55 { 56 IConfiguredSite[] localSites = 57 SiteManager.getLocalSite().getCurrentConfiguration().getConfiguredSites(); 58 ISite localSite = localSites[(localSites.length - 1)].getSite(); 59 ISiteFeatureReference[] localFeatures = localSite.getRawFeatureReferences(); 60 61 ISite site = SiteManager.getSite(new URL ("http://hermes.nightlabs.de/~nick/ipanema2/update-devel"), false, null); 62 63 64 ISiteFeatureReference[] remoteFeatures = site.getFeatureReferences(); 65 for(int i = 0; i < remoteFeatures.length; i++) 66 { 67 boolean doUpdate = true; 68 boolean doInstall = true; 69 IFeature localFeature = null; 70 for(int j = 0; j < localFeatures.length; j++) 71 { 72 localFeature = localFeatures[j].getFeature(null); 73 if(remoteFeatures[i].getVersionedIdentifier().getIdentifier().equals( 74 localFeature.getVersionedIdentifier().getIdentifier())) 75 { 76 doInstall = false; 77 if(remoteFeatures[i].getVersionedIdentifier().getVersion().equals( 78 localFeature.getVersionedIdentifier().getVersion())) 79 { 80 doUpdate = false; 81 } 82 break; 83 } 84 } 85 if(doInstall) 86 { 87 IStatus stat = SiteManager.getLocalSite().getFeatureStatus(remoteFeatures[i].getFeature(this)); 88 boolean ja = installFeature(remoteFeatures[i], localSite); 89 doRestart = true; 90 } 91 else 92 if(doUpdate) 93 { 94 disableFeature(localFeature, localSite); 95 uninstallFeature(localFeature, localSite); 96 boolean ja = installFeature(remoteFeatures[i], localSite); 97 doRestart = true; 98 } 99 } 100 if(doRestart) 101 { 102 SplashDialog.showSplashDialog(IpanemaBasePlugin.getResourceString("update.message.pleaseRestart"), new SplashDialog.DialogListener(){ 103 public boolean finish(SplashDialogResult dialogResult) 104 { 105 return true; 106 } 107 }); 108 109 } 110 } 111 catch(CoreException e) 112 { 113 e.printStackTrace(); 114 } 115 catch(MalformedURLException e) 116 { 117 e.printStackTrace(); 118 } 119 catch(Exception e) 120 { 121 e.printStackTrace(); 122 } 123 finally 124 { 125 SplashScreen.resetSplashPanel(); 126 } 127 } 128 129 private boolean installFeature(ISiteFeatureReference remoteFeature, ISite localSite) 130 throws Exception  131 { 132 134 InstallCommand cmd; 135 try 136 { 137 cmd = new InstallCommand( 138 remoteFeature.getVersionedIdentifier().getIdentifier(), 139 remoteFeature.getVersionedIdentifier().getVersion().toString(), 140 remoteFeature.getSite().getURL().toString(), 141 localSite.getURL().getFile(), 143 "false"); 144 return cmd.run(this); 145 } 146 catch(CoreException e) 147 { 148 throw e; 149 } 150 } 151 152 private boolean disableFeature(IFeature localFeature, ISite localSite) 153 throws Exception  154 { 155 DisableCommand cmd = new DisableCommand( 156 localFeature.getVersionedIdentifier().getIdentifier(), 157 localFeature.getVersionedIdentifier().getVersion().toString(), 158 localSite.getURL().getFile(), 159 "false"); 160 return cmd.run(); 161 } 162 163 private boolean uninstallFeature(IFeature localFeature, ISite localSite) 164 throws Exception  165 { 166 UninstallCommand cmd = new UninstallCommand( 167 localFeature.getVersionedIdentifier().getIdentifier(), 168 localFeature.getVersionedIdentifier().getVersion().toString(), 169 localSite.getURL().getFile(), 170 "false"); 171 return cmd.run(); 172 } 173 174 public void beginTask(String name, int totalWork) 175 { 176 worked = 0; 177 SplashScreen.setProgressMinMax(0, totalWork * 1000); 178 } 179 180 public void done() 181 { 182 } 183 184 public void internalWorked(double work) 185 { 186 worked += work; 187 SplashScreen.setProgressValue((int)(worked * 1000)); 188 } 198 199 public boolean isCanceled() 200 { 201 return false; 202 } 203 204 public void setCanceled(boolean value) 205 { 206 } 207 208 public void setTaskName(String name) 209 { 210 taskName = name; 211 } 212 213 public void subTask(String name) 214 { 215 if(name != null && !("".equals(name))) 216 SplashScreen.setSplashMessage(name); 217 else 218 if(taskName != null && !("".equals(taskName))) 219 SplashScreen.setSplashMessage(taskName); 220 221 } 232 233 public void worked(int work) 234 { 235 } 237 238 239 public boolean doRestart() 240 { 241 return doRestart; 242 } 243 244 } 245
| Popular Tags
|