protected void handleAdd() {
    ElementListSelectionDialog dialog =
        new ElementListSelectionDialog(getShell(), new StyledBundleLabelProvider(false, false));

    try {
      dialog.setElements(getValidBundles());
    } catch (CoreException e) {
      dialog.setMessage(e.getMessage());
    }

    dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
    dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
    dialog.setMultipleSelection(true);
    if (dialog.open() == Window.OK) {

      Object[] models = dialog.getResult();
      ArrayList<NameVersionDescriptor> pluginsToAdd = new ArrayList<NameVersionDescriptor>();
      for (int i = 0; i < models.length; i++) {
        BundleInfo desc = ((BundleInfo) models[i]);
        pluginsToAdd.add(new NameVersionDescriptor(desc.getSymbolicName(), null));
      }
      Set<NameVersionDescriptor> allDependencies = new HashSet<NameVersionDescriptor>();
      allDependencies.addAll(pluginsToAdd);
      NameVersionDescriptor[] currentBundles = getTargetDefinition().getImplicitDependencies();
      if (currentBundles != null) {
        allDependencies.addAll(Arrays.asList(currentBundles));
      }
      getTargetDefinition()
          .setImplicitDependencies(
              allDependencies.toArray(new NameVersionDescriptor[allDependencies.size()]));
      fElementViewer.refresh();
      updateImpButtons();
    }
  }
  /**
   * Gets a list of all the bundles that can be added as implicit dependencies
   *
   * @return list of possible dependencies
   */
  protected BundleInfo[] getValidBundles() throws CoreException {
    NameVersionDescriptor[] current = getTargetDefinition().getImplicitDependencies();
    Set<String> currentBundles = new HashSet<String>();
    if (current != null) {
      for (int i = 0; i < current.length; i++) {
        if (!currentBundles.contains(current[i].getId())) {
          currentBundles.add(current[i].getId());
        }
      }
    }

    List<BundleInfo> targetBundles = new ArrayList<BundleInfo>();
    TargetBundle[] allTargetBundles = getTargetDefinition().getAllBundles();
    if (allTargetBundles == null || allTargetBundles.length == 0) {
      throw new CoreException(
          new Status(
              IStatus.WARNING,
              PDEPlugin.getPluginId(),
              PDEUIMessages.ImplicitDependenciesSection_0));
    }
    for (int i = 0; i < allTargetBundles.length; i++) {
      BundleInfo bundleInfo = allTargetBundles[i].getBundleInfo();
      if (!currentBundles.contains(bundleInfo.getSymbolicName())) {
        currentBundles.add(bundleInfo.getSymbolicName()); // to avoid duplicate entries
        targetBundles.add(bundleInfo);
      }
    }

    return targetBundles.toArray(new BundleInfo[targetBundles.size()]);
  }
 private org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] convertBundleInfos(
     BundleInfo[] configuration, URI installArea) {
   // convert to SimpleConfigurator BundleInfo Type
   org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[] simpleInfos =
       new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo[configuration.length];
   for (int i = 0; i < configuration.length; i++) {
     BundleInfo bundleInfo = configuration[i];
     URI location = bundleInfo.getLocation();
     if (bundleInfo.getSymbolicName() == null
         || bundleInfo.getVersion() == null
         || location == null)
       throw new IllegalArgumentException(
           "Cannot persist bundleinfo: " + bundleInfo.toString()); // $NON-NLS-1$
     // only need to make a new BundleInfo if we are changing it.
     if (installArea != null) location = URIUtil.makeRelative(location, installArea);
     simpleInfos[i] =
         new org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo(
             bundleInfo.getSymbolicName(),
             bundleInfo.getVersion(),
             location,
             bundleInfo.getStartLevel(),
             bundleInfo.isMarkedAsStarted());
     simpleInfos[i].setBaseLocation(bundleInfo.getBaseLocation());
   }
   return simpleInfos;
 }
  /*
   * InputStream must be closed
   * (non-Javadoc)
   * @see org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator#loadConfiguration(java.io.InputStream, java.net.URI)
   */
  public BundleInfo[] loadConfiguration(InputStream stream, URI installArea) throws IOException {
    if (stream == null) return NULL_BUNDLEINFOS;

    List simpleBundles = SimpleConfiguratorUtils.readConfiguration(stream, installArea);

    // convert to FrameworkAdmin BundleInfo Type
    BundleInfo[] result = new BundleInfo[simpleBundles.size()];
    int i = 0;
    for (Iterator iterator = simpleBundles.iterator(); iterator.hasNext(); ) {
      org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo simpleInfo =
          (org.eclipse.equinox.internal.simpleconfigurator.utils.BundleInfo) iterator.next();
      URI location = simpleInfo.getLocation();
      if (!location.isAbsolute() && simpleInfo.getBaseLocation() != null)
        location = URIUtil.makeAbsolute(location, simpleInfo.getBaseLocation());

      BundleInfo bundleInfo =
          new BundleInfo(
              simpleInfo.getSymbolicName(),
              simpleInfo.getVersion(),
              location,
              simpleInfo.getStartLevel(),
              simpleInfo.isMarkedAsStarted());
      bundleInfo.setBaseLocation(simpleInfo.getBaseLocation());
      result[i++] = bundleInfo;
    }
    return result;
  }
 /*
  * Return a boolean value indicating whether or not a bundle with the given id
  * is listed in the bundles.info file. If the version is non-null, check to ensure the
  * version is the expected one. If the location is non-null then do a String#contains check.
  */
 public boolean isInBundlesInfo(File bundlesInfo, String bundleId, String version, String location)
     throws IOException {
   BundleInfo[] infos = loadBundlesInfo(bundlesInfo);
   for (int i = 0; infos != null && i < infos.length; i++) {
     BundleInfo info = infos[i];
     if (!bundleId.equals(info.getSymbolicName())) continue;
     if (version != null && !version.equals(info.getVersion())) continue;
     if (location == null) return true;
     return info.getLocation().toString().contains(location);
   }
   return false;
 }
 private BundleInfo[] orderingInitialConfig(List setToInitialConfig) {
   List notToBeStarted = new LinkedList();
   List toBeStarted = new LinkedList();
   for (Iterator ite2 = setToInitialConfig.iterator(); ite2.hasNext(); ) {
     BundleInfo bInfo = (BundleInfo) ite2.next();
     if (bInfo.isMarkedAsStarted()) toBeStarted.add(bInfo);
     else notToBeStarted.add(bInfo);
   }
   setToInitialConfig.clear();
   setToInitialConfig.addAll(notToBeStarted);
   setToInitialConfig.addAll(toBeStarted);
   return Utils.getBundleInfosFromList(setToInitialConfig);
 }
 private void processPluginConfiguration(Attributes attributes) {
   BundleInfo info = new BundleInfo();
   info.setSymbolicName(attributes.getValue(ATTRIBUTE_ID));
   info.setVersion(attributes.getValue(ATTRIBUTE_VERSION));
   String value = attributes.getValue(ATTRIBUTE_START_LEVEL);
   if (value != null) {
     int startLevel = Integer.parseInt(value);
     if (startLevel > 0) info.setStartLevel(startLevel);
   }
   value = attributes.getValue(ATTRIBUTE_AUTO_START);
   if (value != null) info.setMarkedAsStarted(Boolean.valueOf(value).booleanValue());
   if (bundleInfos == null) bundleInfos = new ArrayList<BundleInfo>();
   bundleInfos.add(info);
 }
 void setSystemBundles(BundlesState state, LocationInfo info) {
   BundleInfo systemBundleInfo = state.getSystemBundle();
   if (systemBundleInfo == null) {
     // TODO Log
     // throw new IllegalStateException("There is no systemBundle.\n");
     return;
   }
   if (state.isFullySupported())
     if (!this.checkResolve(systemBundleInfo, state)) {
       printoutUnsatisfiedConstraints(systemBundleInfo, state);
       return;
     }
   info.systemBundleLocation = systemBundleInfo.getLocation();
   BundleInfo[] fragments = state.getSystemFragmentedBundles();
   info.systemFragmentedBundleLocations = new URI[fragments.length];
   for (int i = 0; i < fragments.length; i++)
     info.systemFragmentedBundleLocations[i] = fragments[i].getLocation();
 }
  /**
   * Tests that a target definition based on the default target platform restricted to a subset of
   * bundle versions contains the right set.
   *
   * @throws Exception
   */
  public void testVersionRestrictedDefaultTargetPlatform() throws Exception {
    ITargetDefinition definition = getNewTarget();
    ITargetLocation container =
        getTargetService().newProfileLocation(TargetPlatform.getDefaultLocation(), null);
    definition.setTargetLocations(new ITargetLocation[] {container});
    List infos = getAllBundleInfos(definition);
    // find right versions
    String v1 = null;
    String v2 = null;
    Iterator iterator = infos.iterator();
    while (iterator.hasNext() && (v2 == null || v1 == null)) {
      BundleInfo info = (BundleInfo) iterator.next();
      if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) {
        v1 = info.getVersion();
      } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) {
        v2 = info.getVersion();
      }
    }
    assertNotNull(v1);
    assertFalse(v1.equals(BundleInfo.EMPTY_VERSION));
    assertNotNull(v2);
    assertFalse(v2.equals(BundleInfo.EMPTY_VERSION));

    NameVersionDescriptor[] restrictions =
        new NameVersionDescriptor[] {
          new NameVersionDescriptor("org.eclipse.jdt.launching", v1),
          new NameVersionDescriptor("org.eclipse.jdt.debug", v2)
        };
    definition.setIncluded(restrictions);
    infos = getAllBundleInfos(definition);

    assertEquals("Wrong number of bundles", 2, infos.size());
    iterator = infos.iterator();
    while (iterator.hasNext()) {
      BundleInfo info = (BundleInfo) iterator.next();
      if (info.getSymbolicName().equals("org.eclipse.jdt.launching")) {
        assertEquals(v1, info.getVersion());
      } else if (info.getSymbolicName().equals("org.eclipse.jdt.debug")) {
        assertEquals(v2, info.getVersion());
      }
    }
  }
Exemple #10
0
  public static BundleInfo createBundleInfo(File bundleFile, IInstallableUnit unit) {
    BundleInfo bundleInfo = new BundleInfo();
    if (bundleFile != null) bundleInfo.setLocation(bundleFile.toURI());

    Collection<IProvidedCapability> capabilities = unit.getProvidedCapabilities();
    for (IProvidedCapability capability : capabilities) {
      String nameSpace = capability.getNamespace();
      if (nameSpace.equals("osgi.bundle")) { // $NON-NLS-1$
        bundleInfo.setSymbolicName(capability.getName());
        bundleInfo.setVersion(capability.getVersion().toString());
      } else if (nameSpace.equals("osgi.fragment")) { // $NON-NLS-1$
        String fragmentName = capability.getName();
        String fragmentHost = getFragmentHost(unit, fragmentName);
        // shouldn't happen as long as the metadata is well-formed
        if (fragmentHost == null)
          LogHelper.log(createError("Unable to find fragment host for IU: " + unit)); // $NON-NLS-1$
        else bundleInfo.setFragmentHost(fragmentHost);
        bundleInfo.setVersion(capability.getVersion().toString());
      }
    }
    return bundleInfo;
  }
  private void algorithm(
      int initialSl,
      SortedMap bslToList,
      BundleInfo configuratorBInfo,
      List setToInitialConfig,
      List setToSimpleConfig,
      LocationInfo info) {
    int configuratorSL = configuratorBInfo.getStartLevel();

    Integer sL0 = (Integer) bslToList.keySet().iterator().next(); // StartLevel == 0;
    List list0 = (List) bslToList.get(sL0);
    if (sL0.intValue() == 0)
      for (Iterator ite2 = list0.iterator(); ite2.hasNext(); ) {
        BundleInfo bInfo = (BundleInfo) ite2.next();
        if (isSystemBundle(bInfo.getLocation(), info)) {
          setToSimpleConfig.add(bInfo);
          break;
        }
      }

    for (Iterator ite = bslToList.keySet().iterator(); ite.hasNext(); ) {
      Integer sL = (Integer) ite.next();
      List list = (List) bslToList.get(sL);

      if (sL.intValue() < configuratorSL) {
        for (Iterator ite2 = list.iterator(); ite2.hasNext(); ) {
          BundleInfo bInfo = (BundleInfo) ite2.next();
          if (!isSystemBundle(bInfo.getLocation(), info)) setToInitialConfig.add(bInfo);
        }
      } else if (sL.intValue() > configuratorSL) {
        for (Iterator ite2 = list.iterator(); ite2.hasNext(); ) {
          BundleInfo bInfo = (BundleInfo) ite2.next();
          if (isPrerequisiteBundles(bInfo.getLocation(), info)
              || isSystemFragmentBundle(bInfo.getLocation(), info))
            if (!isSystemBundle(bInfo.getLocation(), info)) setToInitialConfig.add(bInfo);
          setToSimpleConfig.add(bInfo);
        }
      } else {
        boolean found = false;
        for (Iterator ite2 = list.iterator(); ite2.hasNext(); ) {
          BundleInfo bInfo = (BundleInfo) ite2.next();
          if (found) {
            if (!isSystemBundle(bInfo.getLocation(), info))
              if (isPrerequisiteBundles(bInfo.getLocation(), info)
                  || isSystemFragmentBundle(bInfo.getLocation(), info))
                setToInitialConfig.add(bInfo);
            setToSimpleConfig.add(bInfo);
            continue;
          }
          if (isTargetConfiguratorBundle(bInfo.getLocation())) found = true;
          else if (!isSystemBundle(bInfo.getLocation(), info)) setToInitialConfig.add(bInfo);
          setToSimpleConfig.add(bInfo);
        }
      }
    }

    setToInitialConfig.add(configuratorBInfo);
  }