Пример #1
1
 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);
   }
 }
Пример #2
0
 private void addNewDependency(
     String id, String version, int match, List preservedImports, List newImports)
     throws CoreException {
   if (findFeaturePlugin(id, version, match) != null) {
     // don't add imports to local plug-ins
     return;
   }
   if (findImport(preservedImports, id, version, match) != null) {
     // already seen
     return;
   }
   if (findImport(newImports, id, version, match) != null) {
     // already seen
     return;
   }
   IFeatureImport iimport = findImport(fImports, id, version, match);
   if (iimport != null) {
     // import still valid
     preservedImports.add(iimport);
     return;
   }
   // a new one is needed
   iimport = getModel().getFactory().createImport();
   iimport.setId(id);
   iimport.setVersion(version);
   iimport.setMatch(match);
   ((FeatureImport) iimport).setInTheModel(true);
   newImports.add(iimport);
 }
Пример #3
0
 /**
  * Finds a given import in the list
  *
  * @param imports list of imports
  * @param id
  * @param version
  * @param match
  * @return IFeatureImport or null
  */
 private IFeatureImport findImport(List imports, String id, String version, int match) {
   for (int i = 0; i < imports.size(); i++) {
     IFeatureImport iimport = (IFeatureImport) imports.get(i);
     if (iimport.getId().equals(id)) {
       if (version == null) return iimport;
       if (version.equals(iimport.getVersion()) && match == iimport.getMatch()) return iimport;
     }
   }
   return null;
 }
Пример #4
0
  private boolean hasRequiredAttributes() {
    // Verify that all the required attributes are
    // defined.
    if (id == null) return false;
    if (version == null) return false;

    for (int i = 0; i < fChildren.size(); i++) {
      IFeatureChild child = (IFeatureChild) fChildren.elementAt(i);
      if (child.getId() == null || child.getVersion() == null) return false;
    }
    for (int i = 0; i < fPlugins.size(); i++) {
      IFeaturePlugin plugin = (IFeaturePlugin) fPlugins.elementAt(i);
      if (plugin.getId() == null || plugin.getVersion() == null) return false;
    }
    for (int i = 0; i < fData.size(); i++) {
      IFeatureData entry = (IFeatureData) fData.elementAt(i);
      if (entry.getId() == null) return false;
    }
    for (int i = 0; i < fImports.size(); i++) {
      IFeatureImport iimport = (IFeatureImport) fImports.elementAt(i);
      if (iimport.getId() == null) return false;
    }
    return true;
  }
Пример #5
0
  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$
  }