@Override
  public boolean performFinish() {
    MultiStatus status =
        new MultiStatus(Plugin.PLUGIN_ID, 0, "Failed to install one or more bundles", null);

    List<File> files = fileSelectionPage.getFiles();
    selectedBundles = new LinkedList<Pair<String, String>>();
    for (File file : files) {
      Jar jar = null;
      try {
        jar = new Jar(file);
        jar.setDoNotTouchManifest();

        Attributes mainAttribs = jar.getManifest().getMainAttributes();
        String bsn = BundleUtils.getBundleSymbolicName(mainAttribs);
        String version = mainAttribs.getValue(Constants.BUNDLE_VERSION);
        if (version == null) version = "0";
        selectedBundles.add(Pair.newInstance(bsn, version));
      } catch (IOException e) {
        status.add(
            new Status(
                IStatus.ERROR,
                Plugin.PLUGIN_ID,
                0,
                MessageFormat.format("Failed to analyse JAR: {0}", file.getPath()),
                e));
        continue;
      }

      try {
        File newFile = repository.put(jar);

        RefreshFileJob refreshJob = new RefreshFileJob(newFile);
        if (refreshJob.isFileInWorkspace()) refreshJob.schedule();
      } catch (Exception e) {
        status.add(
            new Status(
                IStatus.ERROR,
                Plugin.PLUGIN_ID,
                0,
                MessageFormat.format("Failed to add JAR to repository: {0}", file.getPath()),
                e));
        continue;
      }
    }

    if (status.isOK()) {
      return true;
    } else {
      ErrorDialog.openError(getShell(), "Error", null, status);
      return false;
    }
  }
Пример #2
0
  private static URL getURL(IConfigurationElement element) {
    URL result = null;

    String urlAttribute = element.getAttribute("url");
    String resourceAttribute = element.getAttribute("resource");

    if (urlAttribute != null) {
      try {
        result = new URL(urlAttribute);
      } catch (MalformedURLException e) {
        Plugin.logError("Invalid URL defined in built-in OBR configuration.", e);
      }
    } else if (resourceAttribute != null) {
      String bundleId = element.getContributor().getName();
      Bundle bundle =
          BundleUtils.findBundle(Plugin.getDefault().getBundleContext(), bundleId, null);

      if (bundle != null) {
        result = bundle.getEntry(resourceAttribute);
      }
    }

    return result;
  }