1 11 package org.eclipse.update.internal.model; 12 import java.io.File ; 13 import java.io.IOException ; 14 import java.net.URL ; 15 import java.util.Date ; 16 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.FileLocator; 20 import org.eclipse.update.configurator.IPlatformConfiguration; 21 import org.eclipse.update.core.ISite; 22 import org.eclipse.update.core.SiteFeatureReference; 23 import org.eclipse.update.core.SiteManager; 24 import org.eclipse.update.core.model.SiteModel; 25 import org.eclipse.update.internal.configurator.FeatureEntry; 26 import org.eclipse.update.internal.configurator.PlatformConfiguration; 27 import org.eclipse.update.internal.configurator.SiteEntry; 28 import org.eclipse.update.internal.core.BaseSiteLocalFactory; 29 import org.eclipse.update.internal.core.Messages; 30 import org.eclipse.update.internal.core.UpdateCore; 31 import org.eclipse.update.internal.core.UpdateManagerUtils; 32 33 34 37 38 public class InstallConfigurationParser { 39 private PlatformConfiguration platformConfig; 40 private URL siteURL; 41 private InstallConfigurationModel config; 42 private ConfiguredSiteModel configSite; 43 44 47 public InstallConfigurationParser( 48 IPlatformConfiguration platformConfig, 49 InstallConfigurationModel config, boolean light) 50 throws IOException , CoreException { 51 52 Assert.isTrue(platformConfig instanceof PlatformConfiguration); 53 this.platformConfig = (PlatformConfiguration)platformConfig; 54 55 this.config = config; 56 57 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) { 59 UpdateCore.debug("Start parsing Configuration:" + (config).getURL().toExternalForm()); } 61 62 if (light) { 63 processConfigurationLight(this.platformConfig); 64 } else { 65 processConfig(this.platformConfig); 66 } 67 } 68 69 70 71 72 73 76 private void processSite(SiteEntry siteEntry) throws CoreException, IOException { 77 78 siteURL = siteEntry.getURL(); 80 try { 81 siteURL = FileLocator.toFileURL(siteURL); 82 if (siteURL.getProtocol().equals("file")) siteURL = new File (siteURL.getFile()).toURL(); 85 } catch (IOException e) { 86 } 88 89 ISite site = SiteManager.getSite(siteURL,null); 91 92 BaseSiteLocalFactory factory = new BaseSiteLocalFactory(); 94 configSite = factory.createConfigurationSiteModel((SiteModel) site, siteEntry.getSitePolicy().getType()); 95 96 configSite.setPlatformURLString(siteEntry.getURL().toExternalForm()); 98 99 configSite.setEnabled(siteEntry.isEnabled()); 101 102 configSite.setUpdatable(siteEntry.isUpdateable()); 104 105 config.addConfigurationSiteModel(configSite); 107 configSite.setInstallConfigurationModel(config); 108 109 FeatureEntry[] features = siteEntry.getFeatureEntries(); 110 for (int i=0; i<features.length; i++) { 111 processFeature(features[i]); 112 } 113 } 114 115 118 private void processFeature(FeatureEntry feature) throws CoreException, IOException { 119 120 String path = feature.getURL(); 122 URL url = UpdateManagerUtils.getURL(siteURL, path, null); 123 124 if (url != null) { 125 SiteFeatureReference ref = new SiteFeatureReference(); 126 ref.setSite((ISite) configSite.getSiteModel()); 127 ref.setURL(url); 128 (configSite.getConfigurationPolicyModel()).addConfiguredFeatureReference(ref); 129 130 137 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_PARSING) { 139 UpdateCore.debug("End Processing DefaultFeature Tag: url:" + url.toExternalForm()); } 141 142 } else { 143 UpdateCore.log( Messages.InstallConfigurationParser_FeatureReferenceNoURL, new Exception ()); 144 } 145 146 } 147 148 151 186 189 private void processConfig(PlatformConfiguration platformConfig) throws IOException , CoreException { 190 191 processConfigurationLight(platformConfig); 193 194 202 SiteEntry[] sites = platformConfig.getConfiguration().getSites(); 203 for (int i=0; i<sites.length; i++) 204 processSite(sites[i]); 205 206 } 207 208 209 210 private void processConfigurationLight(PlatformConfiguration platformConfig) { 211 Date date = new Date (platformConfig.getChangeStamp()); 212 config.setCreationDate(date); 213 config.setLabel(date.toString()); 214 215 config.setCurrent( date.equals(org.eclipse.update.internal.configurator.PlatformConfiguration.getCurrent().getConfiguration().getDate())); 216 } 217 218 } 219 | Popular Tags |