public void computeImports() throws CoreException { // some existing imports may valid and can be preserved Vector preservedImports = new Vector(fImports.size()); // new imports ArrayList newImports = new ArrayList(); IPluginModelBase model = null; for (int i = 0; i < fPlugins.size(); i++) { IFeaturePlugin fp = (IFeaturePlugin) fPlugins.get(i); ModelEntry entry = PluginRegistry.findEntry(fp.getId()); if (entry == null) continue; IPluginModelBase[] models = entry.getActiveModels(); for (int j = 0; j < models.length; j++) { IPluginModelBase m = models[j]; if (fp.getVersion().equals(m.getPluginBase().getVersion()) || fp.getVersion().equals("0.0.0")) // $NON-NLS-1$ model = m; } if (model != null) { addPluginImports(preservedImports, newImports, model.getPluginBase()); if (model.isFragmentModel()) { BundleDescription desc = model.getBundleDescription(); if (desc == null) continue; HostSpecification hostSpec = desc.getHost(); String id = hostSpec.getName(); String version = null; int match = IMatchRules.NONE; VersionRange versionRange = hostSpec.getVersionRange(); if (!(versionRange == null || VersionRange.emptyRange.equals(versionRange))) { version = versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : null; match = PluginBase.getMatchRule(versionRange); } addNewDependency(id, version, match, preservedImports, newImports); } } } // preserve imports of features for (int i = 0; i < fImports.size(); i++) { IFeatureImport iimport = (IFeatureImport) fImports.get(i); if (iimport.getType() == IFeatureImport.FEATURE) preservedImports.add(iimport); } // removed = old - preserved Vector removedImports = ((Vector) fImports.clone()); removedImports.removeAll(preservedImports); // perform remove fImports = preservedImports; if (removedImports.size() > 0) { fireStructureChanged( (IFeatureImport[]) removedImports.toArray(new IFeatureImport[removedImports.size()]), IModelChangedEvent.REMOVE); } // perform add if (newImports.size() > 0) { fImports.addAll(newImports); fireStructureChanged( (IFeatureImport[]) newImports.toArray(new IFeatureImport[newImports.size()]), IModelChangedEvent.INSERT); } }
protected void doIncludeVersions(NameVersionDescriptor[] descriptions) throws Exception { String bsn = MULTI_VERSION_LOW_DESCRIPTION.getId(); IPath extras = extractMultiVersionPlugins(); ITargetDefinition target = getNewTarget(); ITargetLocation container = getTargetService().newDirectoryLocation(extras.toOSString()); target.setTargetLocations(new ITargetLocation[] {container}); target.setIncluded(descriptions); try { getTargetService().saveTargetDefinition(target); setTargetPlatform(target); IPluginModelBase[] models = PluginRegistry.getExternalModels(); Set enabled = new HashSet(); for (int i = 0; i < models.length; i++) { IPluginModelBase pm = models[i]; if (pm.getBundleDescription().getSymbolicName().equals(bsn)) { NameVersionDescriptor desc = new NameVersionDescriptor( pm.getPluginBase().getId(), pm.getPluginBase().getVersion()); if (pm.isEnabled()) { enabled.add(desc); } } } if (descriptions == null) { } else { assertEquals("Wrong number of enabled bundles", descriptions.length, enabled.size()); for (int i = 0; i < descriptions.length; i++) { assertTrue("Missing bundle", enabled.contains(descriptions[i])); } } } finally { getTargetService().deleteTarget(target.getHandle()); resetTargetPlatform(); } }
private void handleAddWorkingSet() { IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); IWorkingSetSelectionDialog dialog = manager.createWorkingSetSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), true); if (dialog.open() == Window.OK) { IWorkingSet[] workingSets = dialog.getSelection(); IProduct product = getProduct(); IProductModelFactory factory = product.getModel().getFactory(); ArrayList<IProductPlugin> pluginList = new ArrayList<IProductPlugin>(); for (int i = 0; i < workingSets.length; i++) { IAdaptable[] elements = workingSets[i].getElements(); for (int j = 0; j < elements.length; j++) { IPluginModelBase model = findModel(elements[j]); if (model != null) { IProductPlugin plugin = factory.createPlugin(); IPluginBase base = model.getPluginBase(); plugin.setId(base.getId()); pluginList.add(plugin); } } } product.addPlugins(pluginList.toArray(new IProductPlugin[pluginList.size()])); } }