1 12 package org.eclipse.update.core; 13 14 import java.net.*; 15 import java.util.ArrayList ; 16 import java.util.Collections ; 17 import java.util.HashMap ; 18 import java.util.HashSet ; 19 import java.util.List ; 20 import java.util.Map ; 21 import java.util.Set ; 22 23 import org.eclipse.core.runtime.*; 24 import org.eclipse.osgi.util.NLS; 25 import org.eclipse.update.configuration.*; 26 import org.eclipse.update.core.model.*; 27 import org.eclipse.update.internal.core.*; 28 29 44 public class Site extends SiteModel implements ISiteWithMirrors { 45 46 51 public static final String DEFAULT_INSTALLED_FEATURE_PATH = "features/"; 53 58 public static final String DEFAULT_PLUGIN_PATH = "plugins/"; 60 65 public static final String DEFAULT_FEATURE_PATH = "features/"; 67 72 public static final String SITE_FILE = "site"; 74 79 public static final String SITE_XML = SITE_FILE + ".xml"; 81 private ISiteContentProvider siteContentProvider; 82 83 private Map featureCache = Collections.synchronizedMap(new HashMap ()); 85 88 public Site() { 89 super(); 90 } 91 92 100 public boolean equals(Object obj) { 101 if (!(obj instanceof ISite)) 102 return false; 103 if (getURL() == null) 104 return false; 105 ISite otherSite = (ISite) obj; 106 107 return UpdateManagerUtils.sameURL(getURL(), otherSite.getURL()); 108 } 109 110 116 public URL getURL() { 117 URL url = null; 118 try { 119 url = getSiteContentProvider().getURL(); 120 } catch (CoreException e) { 121 UpdateCore.warn(null, e); 122 } 123 return url; 124 } 125 126 132 public IURLEntry getDescription() { 133 return (IURLEntry) getDescriptionModel(); 134 } 135 136 142 public ICategory[] getCategories() { 143 CategoryModel[] result = getCategoryModels(); 144 if (result.length == 0) 145 return new ICategory[0]; 146 else 147 return (ICategory[]) result; 148 } 149 150 156 public ICategory getCategory(String key) { 157 ICategory result = null; 158 boolean found = false; 159 int length = getCategoryModels().length; 160 161 for (int i = 0; i < length; i++) { 162 if (getCategoryModels()[i].getName().equals(key)) { 163 result = (ICategory) getCategoryModels()[i]; 164 found = true; 165 break; 166 } 167 } 168 169 if (!found) { 171 String URLString = (this.getURL() != null) ? this.getURL().toExternalForm() : "<no site url>"; UpdateCore.warn(NLS.bind(Messages.Site_CannotFindCategory, (new String [] { key, URLString }))); 173 if (getCategoryModels().length <= 0) 174 UpdateCore.warn(Messages.Site_NoCategories); 175 } 176 177 return result; 178 } 179 180 186 public ISiteFeatureReference[] getRawFeatureReferences() { 187 FeatureReferenceModel[] result = getFeatureReferenceModels(); 188 if (result.length == 0) 189 return new ISiteFeatureReference[0]; 190 else 191 return (ISiteFeatureReference[]) result; 192 } 193 194 197 public ISiteFeatureReference[] getFeatureReferences() { 198 if (getCurrentConfiguredSite()!=null) 200 return filterFeatures(getRawFeatureReferences()); 201 else 202 return getRawFeatureReferences(); 203 204 } 205 206 213 private ISiteFeatureReference[] filterFeatures(ISiteFeatureReference[] allIncluded) { 214 List list = new ArrayList (); 215 if (allIncluded!=null){ 216 for (int i = 0; i < allIncluded.length; i++) { 217 ISiteFeatureReference included = allIncluded[i]; 218 if (UpdateManagerUtils.isValidEnvironment(included)) 219 list.add(included); 220 else{ 221 if (UpdateCore.DEBUG && UpdateCore.DEBUG_SHOW_WARNINGS){ 222 UpdateCore.warn("Filtered out feature reference:"+included); } 224 } 225 } 226 } 227 228 ISiteFeatureReference[] result = new ISiteFeatureReference[list.size()]; 229 if (!list.isEmpty()){ 230 list.toArray(result); 231 } 232 233 return result; 234 } 235 236 242 public ISiteFeatureReference getFeatureReference(IFeature feature) { 243 244 if (feature == null) { 245 UpdateCore.warn("Site:getFeatureReference: The feature is null"); return null; 247 } 248 249 ISiteFeatureReference[] references = getFeatureReferences(); 250 ISiteFeatureReference currentReference = null; 251 for (int i = 0; i < references.length; i++) { 252 currentReference = references[i]; 253 try { 256 if (feature.getVersionedIdentifier().equals(currentReference.getVersionedIdentifier())) 257 return currentReference; 258 } catch (CoreException e) { 259 e.printStackTrace(); 261 } 262 } 263 264 UpdateCore.warn("Feature " + feature + " not found on site" + this.getURL()); return null; 266 } 267 268 275 public IArchiveReference[] getArchives() { 276 ArchiveReferenceModel[] result = getArchiveReferenceModels(); 277 if (result.length == 0) 278 return new IArchiveReference[0]; 279 else 280 return (IArchiveReference[]) result; 281 } 282 283 289 public ISiteContentProvider getSiteContentProvider() throws CoreException { 290 if (siteContentProvider == null) { 291 throw Utilities.newCoreException(Messages.Site_NoContentProvider, null); 292 } 293 return siteContentProvider; 294 } 295 296 302 public String getDefaultPackagedFeatureType() { 303 return DEFAULT_PACKAGED_FEATURE_TYPE; 304 } 305 306 313 public IPluginEntry[] getPluginEntries() { 314 throw new UnsupportedOperationException (); 315 } 316 317 323 public int getPluginEntryCount() { 324 throw new UnsupportedOperationException (); 325 } 326 327 335 public IPluginEntry[] getPluginEntriesOnlyReferencedBy(IFeature feature) throws CoreException { 336 337 IPluginEntry[] pluginsToRemove = new IPluginEntry[0]; 338 if (feature == null) 339 return pluginsToRemove; 340 341 IPluginEntry[] entries = feature.getPluginEntries(); 343 if (entries != null) { 344 Set allPluginID = new HashSet (); 346 ISiteFeatureReference[] features = getFeatureReferences(); 347 if (features != null) { 348 for (int indexFeatures = 0; indexFeatures < features.length; indexFeatures++) { 349 IFeature featureToCompare = null; 350 try { 351 featureToCompare = features[indexFeatures].getFeature(null); 352 } catch (CoreException e) { 353 UpdateCore.warn(null, e); 354 } 355 if (!feature.equals(featureToCompare)) { 356 IPluginEntry[] pluginEntries = features[indexFeatures].getFeature(null).getPluginEntries(); 357 if (pluginEntries != null) { 358 for (int indexEntries = 0; indexEntries < pluginEntries.length; indexEntries++) { 359 allPluginID.add(pluginEntries[indexEntries].getVersionedIdentifier()); 360 } 361 } 362 } 363 } 364 } 365 366 List plugins = new ArrayList (); 368 for (int indexPlugins = 0; indexPlugins < entries.length; indexPlugins++) { 369 if (!allPluginID.contains(entries[indexPlugins].getVersionedIdentifier())) { 370 plugins.add(entries[indexPlugins]); 371 } 372 } 373 374 if (!plugins.isEmpty()) { 376 pluginsToRemove = new IPluginEntry[plugins.size()]; 377 plugins.toArray(pluginsToRemove); 378 } 379 } 380 381 return pluginsToRemove; 382 } 383 384 393 public void addPluginEntry(IPluginEntry pluginEntry) { 394 throw new UnsupportedOperationException (); 395 } 396 397 406 public long getDownloadSizeFor(IFeature feature) { 407 throw new UnsupportedOperationException (); 408 } 409 410 419 public long getInstallSizeFor(IFeature feature) { 420 throw new UnsupportedOperationException (); 421 } 422 423 434 public IFeatureReference install(IFeature sourceFeature, IVerificationListener verificationListener, IProgressMonitor progress) throws InstallAbortedException, CoreException { 435 throw new UnsupportedOperationException (); 436 } 437 438 449 public IFeatureReference install(IFeature sourceFeature, IFeatureReference[] optionalFeatures, IVerificationListener verificationListener, IProgressMonitor progress) throws InstallAbortedException, CoreException { 450 throw new UnsupportedOperationException (); 451 } 452 453 469 public IFeatureReference install(IFeature sourceFeature, IFeatureReference[] optionalFeatures, IFeatureContentConsumer parentContentConsumer, IVerifier parentVerifier, IVerificationListener verificationListener, IProgressMonitor progress) 470 throws CoreException { 471 throw new UnsupportedOperationException (); 472 } 473 474 483 public void remove(IFeature feature, IProgressMonitor progress) throws CoreException { 484 throw new UnsupportedOperationException (); 485 } 486 487 493 public void setSiteContentProvider(ISiteContentProvider siteContentProvider) { 494 this.siteContentProvider = siteContentProvider; 495 } 496 499 public IConfiguredSite getCurrentConfiguredSite() { 500 return (IConfiguredSite) getConfiguredSiteModel(); 501 } 502 503 507 public IFeature createFeature(String type, URL url) throws CoreException { 508 return createFeature(type,url,null); 509 } 510 511 515 public IFeature createFeature(String type, URL url, IProgressMonitor monitor) throws CoreException { 516 517 if(url == null) { 518 UpdateCore.warn("The feature URL passed is null"); 519 return null; 520 } 521 522 URLKey key = new URLKey(url); 524 IFeature feature = (IFeature) featureCache.get(key); 525 if (feature != null) return feature; 526 527 if (type == null || type.equals("")) { type = getDefaultPackagedFeatureType(); 531 } 532 533 IFeatureFactory factory = FeatureTypeFactory.getInstance().getFactory(type); 534 feature = factory.createFeature(url, this, monitor); 535 if (feature != null) { 536 featureCache.put(key, feature); 538 } 539 return feature; 540 } 541 542 protected void removeFeatureFromCache(URL featureURL) { 543 URLKey key = new URLKey(featureURL); 544 featureCache.remove(key); 545 } 546 547 553 public IURLEntry[] getMirrorSiteEntries() { 554 URLEntryModel[] result = getMirrorSiteEntryModels(); 555 if (result.length == 0) 556 return new IURLEntry[0]; 557 else 558 return (IURLEntry[]) result; 559 } 560 } 561 | Popular Tags |