1 9 package org.eclipse.pde.internal.build.site; 10 11 import java.io.File ; 12 import java.net.MalformedURLException ; 13 import java.net.URL ; 14 import java.util.*; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.pde.build.Constants; 18 import org.eclipse.pde.internal.build.*; 19 import org.eclipse.update.core.*; 20 import org.eclipse.update.core.model.InvalidSiteTypeException; 21 import org.eclipse.update.core.model.SiteModel; 22 23 public class BuildTimeSiteFactory extends BaseSiteFactory implements ISiteFactory, IPDEBuildConstants { 24 private Site site = null; 26 27 private boolean urlsChanged = false; 29 30 private String [] sitePaths; 32 33 private static String installedBaseLocation = null; 35 36 private boolean reportResolutionErrors; 37 38 private PDEUIStateWrapper pdeUIState; 39 40 private List rootFeaturesForFilter; 42 private List rootPluginsForFilter; 43 private boolean filterState; 44 45 52 public ISite createSite() throws CoreException { 53 if (site != null && urlsChanged == false) 54 return site; 55 56 urlsChanged = false; 57 site = (Site) createSiteMapModel(); 58 59 Collection featureXMLs = findFeatureXMLs(); 61 62 String installedBaseURL = null; 64 if (installedBaseLocation != null && !installedBaseLocation.equals("")) { if (!new File (installedBaseLocation).exists()) { 66 String message = NLS.bind(Messages.error_incorrectDirectoryEntry, installedBaseLocation); 67 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READ_DIRECTORY, message, null)); 68 } 69 70 installedBaseURL = installedBaseLocation; 71 Collection installedFeatures = Utils.findFiles(new File (installedBaseLocation), DEFAULT_FEATURE_LOCATION, Constants.FEATURE_FILENAME_DESCRIPTOR); 72 if (installedFeatures != null) 73 featureXMLs.addAll(installedFeatures); 74 75 File [] featureDirectories = PluginPathFinder.getFeaturePaths(installedBaseURL); 77 for (int i = 0; i < featureDirectories.length; i++) { 78 File featureXML = new File (featureDirectories[i],Constants.FEATURE_FILENAME_DESCRIPTOR); 79 if (featureXML.exists()) 80 featureXMLs.add(featureXML); 81 } 82 83 } 84 85 URL featureURL; 86 SiteFeatureReferenceModel featureRef; 87 88 for (Iterator iter = featureXMLs.iterator(); iter.hasNext();) { 89 File featureXML = (File ) iter.next(); 90 if (featureXML.exists()) { 91 try { 94 featureURL = new URL ("file:" + featureXML.getAbsolutePath()); featureRef = createFeatureReferenceModel(); 96 featureRef.setSiteModel(site); 97 featureRef.setURLString(featureURL.toExternalForm()); 98 featureRef.setType(BuildTimeFeatureFactory.BUILDTIME_FEATURE_FACTORY_ID); 99 site.addFeatureReferenceModel(featureRef); 100 } catch (MalformedURLException e) { 101 BundleHelper.getDefault().getLog().log(new Status(IStatus.WARNING, PI_PDEBUILD, WARNING_MISSING_SOURCE, NLS.bind(Messages.warning_cannotLocateSource, featureXML.getAbsolutePath()), e)); 102 } 103 } 104 } 105 ISiteContentProvider contentProvider = new BuildTimeSiteContentProvider(sitePaths, installedBaseURL, pdeUIState); 106 site.setSiteContentProvider(contentProvider); 107 contentProvider.setSite(site); 108 return site; 109 } 110 111 115 public ISite createSite(URL url) throws CoreException, InvalidSiteTypeException { 116 throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READ_DIRECTORY, Messages.error_incorrectDirectoryEntry, null)); 117 } 118 119 public SiteModel createSiteMapModel() { 120 BuildTimeSite model = new BuildTimeSite(); 121 model.setReportResolutionErrors(reportResolutionErrors); 122 model.setFilter(filterState); 123 model.setRootFeaturesForFilter(rootFeaturesForFilter); 124 model.setRootPluginsForFiler(rootPluginsForFilter); 125 return model; 126 } 127 128 public static void setInstalledBaseSite(String installedBaseSite) { 129 BuildTimeSiteFactory.installedBaseLocation = installedBaseSite; 130 } 131 132 public void setSitePaths(String [] urls) { 133 if (sitePaths == null) { 134 sitePaths = urls; 135 urlsChanged = true; 136 return; 137 } 138 139 int i = 0; 141 boolean found = true; 142 while (found && i < sitePaths.length) { 143 found = false; 144 for (int j = 0; j < urls.length; j++) { 145 if (sitePaths[i].equals(urls[j])) { 146 found = true; 147 break; 148 } 149 } 150 i++; 151 } 152 if (!found) { 153 sitePaths = urls; 154 urlsChanged = true; 155 } 156 } 157 158 163 private Collection findFeatureXMLs() { 164 Collection features = new ArrayList(); 165 for (int i = 0; i < sitePaths.length; i++) { 166 Collection foundFeatures = Utils.findFiles(new File (sitePaths[i]), DEFAULT_FEATURE_LOCATION, Constants.FEATURE_FILENAME_DESCRIPTOR); 167 if (foundFeatures != null) 168 features.addAll(foundFeatures); 169 } 170 return features; 171 } 172 173 public void setReportResolutionErrors(boolean value) { 174 reportResolutionErrors = value; 175 } 176 177 public void setInitialState(PDEUIStateWrapper uiState) { 178 this.pdeUIState = uiState; 179 } 180 181 public void setFilterState(boolean b) { 182 this.filterState = b; 183 } 184 185 public void setFilterRoots(List featuresForFilterRoots, List pluginsForFilterRoots) { 186 this.rootFeaturesForFilter = featuresForFilterRoots; 187 this.rootPluginsForFilter = pluginsForFilterRoots; 188 } 189 190 } 191 | Popular Tags |