Esempio n. 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);
   }
 }
Esempio n. 2
0
  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;
  }
Esempio n. 3
0
  public void swap(IFeatureChild feature1, IFeatureChild feature2) {
    int index1 = fChildren.indexOf(feature1);
    int index2 = fChildren.indexOf(feature2);
    if (index1 == -1 || index2 == -1) return;

    fChildren.set(index2, feature1);
    fChildren.set(index1, feature2);

    fireStructureChanged(feature1, IModelChangedEvent.CHANGE);
  }
Esempio n. 4
0
 public static Enumeration compoundEnumerations(Enumeration list1, Enumeration list2) {
   if (list2 == null || !list2.hasMoreElements()) return list1;
   if (list1 == null || !list1.hasMoreElements()) return list2;
   Vector compoundResults = new Vector();
   while (list1.hasMoreElements()) compoundResults.add(list1.nextElement());
   while (list2.hasMoreElements()) {
     Object item = list2.nextElement();
     if (!compoundResults.contains(item)) // don't add duplicates
     compoundResults.add(item);
   }
   return compoundResults.elements();
 }
Esempio n. 5
0
 public void addImports(IFeatureImport[] iimports) throws CoreException {
   ensureModelEditable();
   for (int i = 0; i < iimports.length; i++) {
     fImports.add(iimports[i]);
     ((FeatureImport) iimports[i]).setInTheModel(true);
   }
   fireStructureChanged(iimports, IModelChangedEvent.INSERT);
 }
Esempio n. 6
0
 public void addData(IFeatureData[] newData) throws CoreException {
   ensureModelEditable();
   for (int i = 0; i < newData.length; i++) {
     fData.add(newData[i]);
     ((FeatureData) newData[i]).setInTheModel(true);
   }
   fireStructureChanged(newData, IModelChangedEvent.INSERT);
 }
Esempio n. 7
0
 public void addPlugins(IFeaturePlugin[] newPlugins) throws CoreException {
   ensureModelEditable();
   for (int i = 0; i < newPlugins.length; i++) {
     fPlugins.add(newPlugins[i]);
     ((FeaturePlugin) newPlugins[i]).setInTheModel(true);
   }
   fireStructureChanged(newPlugins, IModelChangedEvent.INSERT);
 }
Esempio n. 8
0
 public void removeImports(IFeatureImport[] iimports) throws CoreException {
   ensureModelEditable();
   for (int i = 0; i < iimports.length; i++) {
     fImports.remove(iimports[i]);
     ((FeatureImport) iimports[i]).setInTheModel(false);
   }
   fireStructureChanged(iimports, IModelChangedEvent.REMOVE);
 }
Esempio n. 9
0
 public void removeIncludedFeatures(IFeatureChild[] features) throws CoreException {
   ensureModelEditable();
   for (int i = 0; i < features.length; i++) {
     fChildren.remove(features[i]);
     ((FeatureChild) features[i]).setInTheModel(false);
   }
   fireStructureChanged(features, IModelChangedEvent.REMOVE);
 }
Esempio n. 10
0
 public void removeData(IFeatureData[] removed) throws CoreException {
   ensureModelEditable();
   for (int i = 0; i < removed.length; i++) {
     fData.remove(removed[i]);
     ((FeatureData) removed[i]).setInTheModel(false);
   }
   fireStructureChanged(removed, IModelChangedEvent.REMOVE);
 }
Esempio n. 11
0
 public void addIncludedFeatures(IFeatureChild[] features) throws CoreException {
   ensureModelEditable();
   for (int i = 0; i < features.length; i++) {
     fChildren.add(features[i]);
     ((FeatureChild) features[i]).setInTheModel(true);
   }
   fireStructureChanged(features, IModelChangedEvent.INSERT);
 }
Esempio n. 12
0
 public void reset() {
   super.reset();
   fData.clear();
   fPlugins.clear();
   fImports.clear();
   fChildren.clear();
   fUrl = null;
   fProviderName = null;
   fPlugin = null;
   fOs = null;
   fWs = null;
   fNl = null;
   fArch = null;
   fInfos[0] = null;
   fInfos[1] = null;
   fInfos[2] = null;
   fPrimary = false;
   fExclusive = false;
   fColocationAffinity = null;
   fApplication = null;
   fValid = false;
 }
Esempio n. 13
0
 private void parseRequires(Node node) {
   NodeList children = node.getChildNodes();
   for (int i = 0; i < children.getLength(); i++) {
     Node child = children.item(i);
     if (child.getNodeType() == Node.ELEMENT_NODE) {
       if (child.getNodeName().equalsIgnoreCase("import")) { // $NON-NLS-1$
         IFeatureImport iimport = getModel().getFactory().createImport();
         ((FeatureImport) iimport).parse(child);
         ((FeatureImport) iimport).setInTheModel(true);
         fImports.add(iimport);
       }
     }
   }
 }
Esempio n. 14
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;
  }
Esempio n. 15
0
 public IFeatureImport[] getImports() {
   IFeatureImport[] result = new IFeatureImport[fImports.size()];
   fImports.copyInto(result);
   return result;
 }
Esempio n. 16
0
 public IFeatureChild[] getIncludedFeatures() {
   IFeatureChild[] result = new IFeatureChild[fChildren.size()];
   fChildren.copyInto(result);
   return result;
 }
Esempio n. 17
0
 public IFeatureData[] getData() {
   IFeatureData[] result = new IFeatureData[fData.size()];
   fData.copyInto(result);
   return result;
 }
Esempio n. 18
0
 public IFeaturePlugin[] getPlugins() {
   IFeaturePlugin[] result = new IFeaturePlugin[fPlugins.size()];
   fPlugins.copyInto(result);
   return result;
 }
Esempio n. 19
0
  protected void parse(Node node) {
    super.parse(node);
    fProviderName = getNodeAttribute(node, "provider-name"); // $NON-NLS-1$
    fPlugin = getNodeAttribute(node, "plugin"); // $NON-NLS-1$
    fOs = getNodeAttribute(node, "os"); // $NON-NLS-1$
    fWs = getNodeAttribute(node, "ws"); // $NON-NLS-1$
    fNl = getNodeAttribute(node, "nl"); // $NON-NLS-1$
    fArch = getNodeAttribute(node, "arch"); // $NON-NLS-1$
    fImageName = getNodeAttribute(node, "image"); // $NON-NLS-1$
    fColocationAffinity = getNodeAttribute(node, "colocation-affinity"); // $NON-NLS-1$
    fApplication = getNodeAttribute(node, "application"); // $NON-NLS-1$
    fPrimary = getBooleanAttribute(node, "primary"); // $NON-NLS-1$
    fExclusive = getBooleanAttribute(node, "exclusive"); // $NON-NLS-1$
    NodeList children = node.getChildNodes();
    fValid = true;

    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        String tag = child.getNodeName().toLowerCase(Locale.ENGLISH);
        if (tag.equals("description")) { // $NON-NLS-1$
          IFeatureInfo info = getModel().getFactory().createInfo(IFeature.INFO_DESCRIPTION);
          ((FeatureInfo) info).setInTheModel(true);
          ((FeatureInfo) info).parse(child);
          fInfos[IFeature.INFO_DESCRIPTION] = info;
        } else if (tag.equals("license")) { // $NON-NLS-1$
          IFeatureInfo info = getModel().getFactory().createInfo(IFeature.INFO_LICENSE);
          ((FeatureInfo) info).setInTheModel(true);
          ((FeatureInfo) info).parse(child);
          fInfos[IFeature.INFO_LICENSE] = info;
        } else if (tag.equals("copyright")) { // $NON-NLS-1$
          IFeatureInfo info = getModel().getFactory().createInfo(IFeature.INFO_COPYRIGHT);
          ((FeatureInfo) info).setInTheModel(true);
          ((FeatureInfo) info).parse(child);
          fInfos[IFeature.INFO_COPYRIGHT] = info;
        } else if (tag.equals("url")) { // $NON-NLS-1$
          if (fUrl == null) {
            fUrl = getModel().getFactory().createURL();
            ((FeatureURL) fUrl).setInTheModel(true);
            ((FeatureURL) fUrl).parse(child);
          }
        } else if (tag.equals("requires")) { // $NON-NLS-1$
          parseRequires(child);
        } else if (tag.equals("install-handler")) { // $NON-NLS-1$
          IFeatureInstallHandler handler = getModel().getFactory().createInstallHandler();
          ((FeatureInstallHandler) handler).parse(child);
          ((FeatureInstallHandler) handler).setInTheModel(true);
          this.fHandler = handler;
        } else if (tag.equals("plugin")) { // $NON-NLS-1$
          IFeaturePlugin plugin = getModel().getFactory().createPlugin();
          ((FeaturePlugin) plugin).parse(child);
          ((FeaturePlugin) plugin).setInTheModel(true);
          fPlugins.add(plugin);
        } else if (tag.equals("data")) { // $NON-NLS-1$
          IFeatureData newData = getModel().getFactory().createData();
          ((FeatureData) newData).parse(child);
          ((FeatureData) newData).setInTheModel(true);
          fData.add(newData);
        } else if (tag.equals("includes")) { // $NON-NLS-1$
          IFeatureChild newChild = getModel().getFactory().createChild();
          ((FeatureChild) newChild).parse(child);
          ((FeatureChild) newChild).setInTheModel(true);
          this.fChildren.add(newChild);
        }
      }
    }
    fValid = hasRequiredAttributes();
  }
Esempio n. 20
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$
  }