@Override
  public boolean finalLaunchCheck(
      ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
      throws CoreException {
    // Check for existing launches of same resource
    BndPreferences prefs = new BndPreferences();
    if (prefs.getWarnExistingLaunches()) {
      IResource launchResource = LaunchUtils.getTargetResource(configuration);
      if (launchResource == null)
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                Plugin.PLUGIN_ID,
                0,
                "Bnd launch target was not specified or does not exist.",
                null));

      int processCount = 0;
      for (ILaunch l : DebugPlugin.getDefault().getLaunchManager().getLaunches()) {
        // ... is it the same launch resource?
        ILaunchConfiguration launchConfig = l.getLaunchConfiguration();
        if (launchConfig == null) {
          continue;
        }
        if (launchResource.equals(LaunchUtils.getTargetResource(launchConfig))) {
          // Iterate existing processes
          for (IProcess process : l.getProcesses()) {
            if (!process.isTerminated()) processCount++;
          }
        }
      }

      // Warn if existing processes running
      if (processCount > 0) {
        Status status =
            new Status(
                IStatus.WARNING,
                Plugin.PLUGIN_ID,
                0,
                "One or more OSGi Frameworks have already been launched for this configuration. Additional framework instances may interfere with each other due to the shared storage directory.",
                null);
        IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(status);
        if (prompter != null) {
          boolean okay = (Boolean) prompter.handleStatus(status, launchResource);
          if (!okay) return okay;
        }
      }
    }

    IStatus launchStatus = getLauncherStatus();

    IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(launchStatus);
    if (prompter != null) return (Boolean) prompter.handleStatus(launchStatus, model);
    return true;
  }
Esempio n. 2
0
  void showHighestPriorityPage() {
    int selectedPrio = Integer.MIN_VALUE;
    String selected = null;

    BndPreferences prefs = new BndPreferences();
    if (prefs.getEditorOpenSourceTab()) {
      selected = SOURCE_PAGE;
      selectedPrio = 0;
    }

    for (Object pageObj : pages) {
      IFormPage page = (IFormPage) pageObj;
      int priority = 0;
      if (page instanceof IPriority) priority = ((IPriority) page).getPriority();
      if (priority > selectedPrio) {
        selected = page.getId();
        selectedPrio = priority;
      }
    }

    if (selected != null) setActivePage(selected);
  }
    @Override
    public void run(IProgressMonitor progress) throws InvocationTargetException {
      SubMonitor monitor = SubMonitor.convert(progress, 3);
      monitor.setTaskName("Loading Templates...");
      try {
        final Set<Template> templates = new LinkedHashSet<>();
        final List<String> errors = new LinkedList<>();

        // Load from workspace, if one exists
        Workspace ws = Central.getWorkspaceIfPresent();
        if (ws != null) {
          List<Repository> repos = ws.getPlugins(Repository.class);
          RepoPluginsBundleLocator locator = new RepoPluginsBundleLocator(ws.getRepositories());
          templates.addAll(
              new ReposTemplateLoader(repos, locator)
                  .findTemplates(
                      templateType, errors, monitor.newChild(1, SubMonitor.SUPPRESS_NONE)));
        }

        // Load from the preferences-configured template repository
        BndPreferences bndPrefs = new BndPreferences();
        if (bndPrefs.getEnableTemplateRepo()) {
          try {
            FixedIndexedRepo repo = loadRepo(bndPrefs.getTemplateRepoUriList());
            RepoPluginsBundleLocator locator =
                new RepoPluginsBundleLocator(Collections.<RepositoryPlugin>singletonList(repo));
            ReposTemplateLoader loader =
                new ReposTemplateLoader(Collections.<Repository>singletonList(repo), locator);
            templates.addAll(
                loader.findTemplates(
                    templateType, errors, monitor.newChild(1, SubMonitor.SUPPRESS_NONE)));
          } catch (Exception e) {
            throw new InvocationTargetException(e);
          }
        }

        // Log errors
        for (String error : errors) {
          Plugin.getDefault()
              .getLog()
              .log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, error, null));
        }

        // Add the build-in empty template if provided
        if (emptyTemplate != null) templates.add(emptyTemplate);

        // Load from extension registry
        if (templateExtPoint != null) {
          IConfigurationElement[] elements =
              Platform.getExtensionRegistry()
                  .getConfigurationElementsFor(Plugin.PLUGIN_ID, templateExtPoint);
          if (elements == null) elements = new IConfigurationElement[0];
          monitor.setWorkRemaining(elements.length);

          for (IConfigurationElement element : elements) {
            String elementName = element.getName();
            IContributor contributor = element.getContributor();
            try {
              Template extTemplate = (Template) element.createExecutableExtension("class");
              templates.add(extTemplate);
            } catch (CoreException e) {
              Plugin.getDefault()
                  .getLog()
                  .log(
                      new Status(
                          IStatus.ERROR,
                          Plugin.PLUGIN_ID,
                          0,
                          String.format(
                              "Error loading template '%s' from bundle %s",
                              elementName, contributor.getName()),
                          e));
            } finally {
              monitor.worked(1);
            }
          }
        }

        // Display results
        Control control = viewer.getControl();
        if (control != null && !control.isDisposed()) {
          control
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    @Override
                    public void run() {
                      setTemplates(templates);
                      IconLoaderJob iconLoaderJob =
                          new IconLoaderJob(templates, viewer, loadedImages, 5);
                      iconLoaderJob.setSystem(true);
                      iconLoaderJob.schedule(0);
                    }
                  });
        }

      } finally {
        monitor.done();
        // Restore the original message to the page
        if (!shell.isDisposed())
          shell
              .getDisplay()
              .asyncExec(
                  new Runnable() {
                    @Override
                    public void run() {
                      setMessage(originalMessage);
                    }
                  });
      }
    }