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); } }
private IFeaturePlugin findFeaturePlugin(String id, String version, int match) { for (int i = 0; i < fPlugins.size(); i++) { IFeaturePlugin fp = (IFeaturePlugin) fPlugins.get(i); String pid = fp.getId(); String pversion = fp.getVersion(); if (VersionUtil.compare(pid, pversion, id, version, match)) return fp; } return null; }
public void write(String indent, PrintWriter writer) { if (fCopyright != null) { writer.println("<!--" + fCopyright + "-->"); // $NON-NLS-1$ //$NON-NLS-2$ } writer.print(indent + "<feature"); // $NON-NLS-1$ String indent2 = indent + INDENT; String indenta = indent + INDENT + INDENT; writeIfDefined(indenta, writer, "id", getId()); // $NON-NLS-1$ writeIfDefined(indenta, writer, "label", getWritableString(getLabel())); // $NON-NLS-1$ writeIfDefined(indenta, writer, "version", getVersion()); // $NON-NLS-1$ writeIfDefined( indenta, writer, "provider-name", //$NON-NLS-1$ getWritableString(fProviderName)); writeIfDefined( indenta, writer, "plugin", //$NON-NLS-1$ getPlugin()); writeIfDefined(indenta, writer, "os", fOs); // $NON-NLS-1$ writeIfDefined(indenta, writer, "ws", fWs); // $NON-NLS-1$ writeIfDefined(indenta, writer, "nl", fNl); // $NON-NLS-1$ writeIfDefined(indenta, writer, "arch", fArch); // $NON-NLS-1$ if (fImageName != null) writeIfDefined(indenta, writer, "image", getWritableString(fImageName)); // $NON-NLS-1$ if (isPrimary()) { writer.println(); writer.print(indenta + "primary=\"true\""); // $NON-NLS-1$ } if (isExclusive()) { writer.println(); writer.print(indenta + "exclusive=\"true\""); // $NON-NLS-1$ } writeIfDefined(indenta, writer, "colocation-affinity", fColocationAffinity); // $NON-NLS-1$ writeIfDefined(indenta, writer, "application", fApplication); // $NON-NLS-1$ writer.println(">"); // $NON-NLS-1$ if (fHandler != null) { fHandler.write(indent2, writer); } for (int i = 0; i < 3; i++) { IFeatureInfo info = fInfos[i]; if (info != null && !info.isEmpty()) info.write(indent2, writer); } if (fUrl != null) { fUrl.write(indent2, writer); } for (int i = 0; i < fChildren.size(); i++) { IFeatureChild child = (IFeatureChild) fChildren.elementAt(i); writer.println(); child.write(indent2, writer); } if (fImports.size() > 0) { writer.println(); writer.println(indent2 + "<requires>"); // $NON-NLS-1$ for (int i = 0; i < fImports.size(); i++) { IFeatureImport iimport = (IFeatureImport) fImports.get(i); iimport.write(indenta, writer); } writer.println(indent2 + "</requires>"); // $NON-NLS-1$ } for (int i = 0; i < fPlugins.size(); i++) { IFeaturePlugin plugin = (IFeaturePlugin) fPlugins.elementAt(i); writer.println(); plugin.write(indent2, writer); } for (int i = 0; i < fData.size(); i++) { IFeatureData entry = (IFeatureData) fData.elementAt(i); writer.println(); entry.write(indent2, writer); } writer.println(); writer.println(indent + "</feature>"); // $NON-NLS-1$ }