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);
   }
 }
  /**
   * The fields are populated based on the plug-in attributes. Some fields are set to their default
   * values.
   */
  private FragmentFieldData populateFieldData(IPluginModelBase plugin, Locale locale) {
    FragmentFieldData fragmentData = new FragmentFieldData();

    fragmentData.setId(pluginName(plugin, locale));
    fragmentData.setVersion(DEFAULT_VERSION);
    fragmentData.setMatch(0);

    fragmentData.setPluginId(plugin.getPluginBase().getId());
    fragmentData.setPluginVersion(incrementRelease(plugin.getPluginBase().getVersion()));
    fragmentData.setName(pluginName(plugin, locale) + " Fragment"); // $NON-NLS-1$
    fragmentData.setProvider(EMPTY_STRING);
    fragmentData.setSimple(true);

    if (!(plugin instanceof ExternalPluginModelBase)) {
      fragmentData.setSourceFolderName("src"); // $NON-NLS-1$
      fragmentData.setOutputFolderName("bin"); // $NON-NLS-1$
    }

    fragmentData.setLegacy(false);
    fragmentData.setTargetVersion(
        Double.toString(ensureTargetVersionCompatibility(TargetPlatformHelper.getTargetVersion())));
    fragmentData.setHasBundleStructure(true);
    fragmentData.setOSGiFramework(null);
    fragmentData.setWorkingSets(null);

    return fragmentData;
  }
 /**
  * Validates that the version of the given plug-in is available in the registry. Adds a warning if
  * the plug-in could not be found.
  *
  * @param plugin xml element describing the plug-in to look for in the registry
  * @param attr set of element attributes
  */
 private void validateVersion(Element plugin, Attr attr) {
   String id = plugin.getAttribute("id"); // $NON-NLS-1$
   String version = plugin.getAttribute("version"); // $NON-NLS-1$
   if (id.trim().length() == 0
       || version.trim().length() == 0
       || version.equals("0.0.0")) // $NON-NLS-1$
   return;
   ModelEntry entry = PluginRegistry.findEntry(id);
   if (entry != null) {
     IPluginModelBase[] allModels = entry.getActiveModels();
     for (int i = 0; i < allModels.length; i++) {
       IPluginModelBase availablePlugin = allModels[i];
       if (id.equals(availablePlugin.getPluginBase().getId())) {
         if (version.equals(availablePlugin.getPluginBase().getVersion())) {
           return;
         }
       }
     }
   }
   report(
       NLS.bind(
           PDECoreMessages.Builders_Feature_mismatchPluginVersion, new String[] {version, id}),
       getLine(plugin, attr.getName()),
       CompilerFlags.WARNING,
       PDEMarkerFactory.CAT_OTHER);
 }
Esempio n. 4
0
  private void initializeState() {
    fLaunchConfigCombo.setEnabled(false);
    if (fLaunchConfigCombo.getItemCount() > 0)
      fLaunchConfigCombo.setText(fLaunchConfigCombo.getItem(0));

    if (fModel != null && fModel.getPluginBase().getId() != null) {
      IPluginExtension[] extensions = fModel.getPluginBase().getExtensions();
      for (int i = 0; i < extensions.length; i++) {
        String point = extensions[i].getPoint();
        if ("org.eclipse.core.runtime.products".equals(point)) { // $NON-NLS-1$
          String id = extensions[i].getId();
          if (id != null) {
            String full = fModel.getPluginBase().getId() + "." + id; // $NON-NLS-1$
            if (fProductCombo.indexOf(full) != -1) {
              fProductCombo.setText(full);
              fProductButton.setSelection(true);
              return;
            }
          }
        }
      }
    }

    fBasicButton.setSelection(true);

    fProductCombo.setEnabled(false);
    if (fProductCombo.getItemCount() > 0) fProductCombo.setText(fProductCombo.getItem(0));
  }
 private int compareSimilarObjects(Object o1, Object o2) {
   if (o1 instanceof IPluginModelBase && o2 instanceof IPluginModelBase) {
     IPluginModelBase ipmb1 = (IPluginModelBase) o1;
     IPluginModelBase ipmb2 = (IPluginModelBase) o2;
     return comparePlugins(ipmb1.getPluginBase(), ipmb2.getPluginBase());
   }
   return 0;
 }
 /** @{inheritDoc */
 @Override
 public String getElementName(Object item) {
   if (item instanceof IPluginModelBase) {
     IPluginModelBase model = (IPluginModelBase) item;
     return model.getPluginBase().getId();
   }
   return null;
 }
  /**
   * Returns a {@link Set} of bundle ids for the dependents of the given objects from the given
   * {@link State}. The set additionally only includes the given set of implicit dependencies.
   *
   * @param selected selected the group of objects to compute dependencies for. Any items in this
   *     array that are not {@link IPluginModelBase}s are ignored.
   * @param implicit the array of additional implicit dependencies to add to the {@link Set}
   * @param state the {@link State} to compute the dependencies in
   * @param removeSelf if the id of one of the bundles were are computing dependencies for should be
   *     included in the result {@link Set} or not
   * @param includeOptional if optional bundle ids should be included
   * @param excludeFragments a collection of <b>fragment</b> bundle symbolic names to exclude from
   *     the dependency resolution
   * @return a set of bundle IDs
   */
  private static Set<String> getDependencies(
      Object[] selected,
      String[] implicit,
      State state,
      boolean removeSelf,
      boolean includeOptional,
      Set<String> excludeFragments) {
    Set<String> set = new TreeSet<>();
    for (int i = 0; i < selected.length; i++) {
      if (!(selected[i] instanceof IPluginModelBase)) continue;
      IPluginModelBase model = (IPluginModelBase) selected[i];
      addBundleAndDependencies(
          model.getBundleDescription(), set, includeOptional, excludeFragments);
      IPluginExtension[] extensions = model.getPluginBase().getExtensions();
      for (int j = 0; j < extensions.length; j++) {
        String point = extensions[j].getPoint();
        if (point != null) {
          int dot = point.lastIndexOf('.');
          if (dot != -1) {
            String id = point.substring(0, dot);
            addBundleAndDependencies(
                state.getBundle(id, null), set, includeOptional, excludeFragments);
          }
        }
      }
    }

    for (int i = 0; i < implicit.length; i++) {
      addBundleAndDependencies(
          state.getBundle(implicit[i], null), set, includeOptional, excludeFragments);
    }

    if (removeSelf) {
      for (int i = 0; i < selected.length; i++) {
        if (!(selected[i] instanceof IPluginModelBase)) {
          continue;
        }
        IPluginModelBase model = (IPluginModelBase) selected[i];
        set.remove(model.getPluginBase().getId());
      }
    }
    return set;
  }
    @Override
    public boolean matchItem(Object item) {
      String id = null;
      if (item instanceof IPluginModelBase) {
        IPluginModelBase model = (IPluginModelBase) item;
        id = model.getPluginBase().getId();
      }

      return (matches(id));
    }
  // Adapted from RequiredPluginsClassPathContainer#addPlugin and
  // PDEClasspathContainer#addExternalPlugin
  private void createEntry(BundleDescription desc, LinkedList<IClasspathEntry> entries) {
    IPluginModelBase model = PluginRegistry.findModel(desc);
    IResource resource = model.getUnderlyingResource();
    // Rule[] rules = useInclusions ? getInclusions(map, model) : null;
    if (resource != null) {
      entries.add(JavaCore.newProjectEntry(resource.getProject().getFullPath()));
      // addProjectEntry(resource.getProject(), rules, entries);
    } else {
      if (new File(model.getInstallLocation()).isFile()) {
        String installLocation = model.getInstallLocation();
        // This is to make it work in windows...
        if (!installLocation.startsWith("/")) {
          installLocation = "/" + installLocation;
        }
        IPath libraryLocation_ = Path.fromOSString(installLocation);
        entries.add(JavaCore.newLibraryEntry(libraryLocation_, null, null));

        // IPath libraryLocation_ = Path.fromPortableString(model.getInstallLocation());
        // entries.add( JavaCore.newLibraryEntry(libraryLocation_, null, null) );
      } else {
        IPluginLibrary[] libraries = model.getPluginBase().getLibraries();
        for (int i = 0; i < libraries.length; i++) {
          if (IPluginLibrary.RESOURCE.equals(libraries[i].getType())) continue;
          model = (IPluginModelBase) libraries[i].getModel();

          String name = libraries[i].getName();
          String expandedName = ClasspathUtilCore.expandLibraryName(name);
          IPath path = getPath(model, expandedName);
          if (path == null
              && !model.isFragmentModel()
              && ClasspathUtilCore.containsVariables(name)) {
            model = resolveLibraryInFragments(model, expandedName);
            if (model != null && model.isEnabled()) path = getPath(model, expandedName);
          }
          if (path != null && !path.toFile().isDirectory()) {
            entries.add(
                JavaCore.newLibraryEntry(
                    path, ClasspathUtilCore.getSourceAnnotation(model, expandedName), null));
            // addLibraryEntry(path, ClasspathUtilCore.getSourceAnnotation(model, expandedName),
            // rules, getClasspathAttributes(model), entries);
          } else if (path != null) {
            // is a directory
            entries.add(
                JavaCore.newLibraryEntry(
                    path, ClasspathUtilCore.getSourceAnnotation(model, expandedName), null));
          }
        }
      }
    }
  }
  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();
    }
  }
Esempio n. 11
0
  private void findMatches(IPluginExtensionPoint point) {
    String fullID = point.getFullId();
    if (fullID == null) return;

    IPluginExtension[] extensions = fModel.getPluginBase().getExtensions();
    for (int i = 0; i < extensions.length; i++) {
      if (fullID.equals(extensions[i].getPoint())) {
        int line = ((ISourceObject) extensions[i]).getStartLine() - 1;
        if (line >= 0) {
          fSearchResult.addMatch(new Match(point, Match.UNIT_LINE, line, 1));
          break;
        }
      }
    }
  }
  private void handleAddRequiredPlugins() {
    TableItem[] items = fImportListViewer.getTable().getItems();
    if (items.length == 0) return;
    if (items.length == 1) {
      IPluginModelBase model = (IPluginModelBase) items[0].getData();
      if (model.getPluginBase().getId().equals("org.eclipse.core.boot")) { // $NON-NLS-1$
        return;
      }
    }

    ArrayList<IPluginModelBase> result = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
      addPluginAndDependencies(
          (IPluginModelBase) items[i].getData(), result, fAddFragmentsButton.getSelection());
    }
    ArrayList<Object> resultObject = new ArrayList<>(result.size());
    resultObject.addAll(result);
    handleSetImportSelection(resultObject);
  }
 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()]));
   }
 }
 private String pluginName(IPluginModelBase plugin, Locale locale) {
   return template
       .replaceAll(quote(PLUGIN_NAME_MACRO), plugin.getPluginBase().getId())
       .replaceAll(quote(LOCALE_NAME_MACRO), locale.toString());
 }
  /**
   * Creates a URL describing the location of a included schema. First looks up the plug-in in the
   * schema registry, then tries additional source locations, then looks for a co-located plug-in,
   * then looks in the additional search path locations.
   *
   * @param pluginID ID of the plug-in owning the schema
   * @param path the path to the schema inside the plug-in
   * @param parentURL url of the parent schema file
   * @param additionalSearchPath list of additional locations to search; only used with the <code>
   *     pde.convertSchemaToHTML</code> Ant task
   * @return a url location of the included schema or <code>null</code>
   */
  private static URL getPluginRelativePath(
      String pluginID, IPath path, URL parentURL, List<IPath> additionalSearchPath) {
    // Start by looking in the schema registry
    URL url = SchemaRegistry.getSchemaURL(pluginID, path.toString());

    // Next search source locations
    if (url == null) {
      IPluginModelBase model = PluginRegistry.findModel(pluginID);
      if (model != null)
        url = SchemaRegistry.getSchemaFromSourceExtension(model.getPluginBase(), path);
    }

    File parentFile = null;
    if (url == null && parentURL != null) {
      try {
        parentFile = URIUtil.toFile(URIUtil.toURI(parentURL));
      } catch (URISyntaxException e) {
      }
    }

    // If we are running the ant task, see if another project co-located with the parent contains
    // the schema file
    // The project folder must have the plug-in ID as its file name
    if (url == null && parentFile != null) {
      try {
        // assuming schemas are located in: pluginId/schema/schemaFile.exsd (need to go up to parent
        // of plug-in directory)
        File pluginFile = new File(parentFile + "/../../../" + pluginID); // $NON-NLS-1$
        if (pluginFile.isDirectory()) {
          File schemaFile = new File(pluginFile, path.toOSString());
          if (schemaFile.exists()) {
            url = schemaFile.toURL();
          }
          // This is how we would extract the schema from a jar, but in practice this will never be
          // the case
          // because when a bundle is built, the schema files are moved to the source bundle, not
          // the bundle we are checking
          //					} else if (CoreUtility.jarContainsResource(pluginFile, path.toPortableString(),
          // false)) {
          //						url = new URL("jar:file:" + pluginFile.getAbsolutePath() + "!/" + path);
          // //$NON-NLS-1$ //$NON-NLS-2$
        }
      } catch (MalformedURLException e) {
      }
    }

    // If we are running the ant task, additional search locations may be provided
    // The project folder must have the plug-in ID as its file name
    if (url == null && additionalSearchPath != null) {
      for (IPath searchPath : additionalSearchPath) {
        File pluginFile = null;
        if (searchPath.isAbsolute()) {
          // Append plug-in id directly to absolute paths
          pluginFile = new File(searchPath.toFile(), pluginID);
        } else if (parentFile != null) {
          // Append relative path to parent file location
          File file = new File(parentFile, searchPath.toOSString());
          pluginFile = new File(file, pluginID);
        }

        if (pluginFile != null && pluginFile.isDirectory()) {
          try {
            File schemaFile = new File(pluginFile, path.toOSString());
            if (schemaFile.exists()) {
              url = schemaFile.toURL();
              break;
            }
          } catch (MalformedURLException e) {
          }
        }
      }
    }
    return url;
  }
Esempio n. 16
0
 private void checkForExtensionPointsUsed(IPluginModelBase model) {
   IPluginExtensionPoint[] extPoints = model.getPluginBase().getExtensionPoints();
   for (int i = 0; i < extPoints.length; i++) {
     findMatches(extPoints[i]);
   }
 }