Example #1
0
  public boolean openSystemBrowser(String url) {
    try {
      for (String command : getOpenCommands()) {
        if (openSystemBrowser(command, url)) {
          return true;
        }
      }
    } catch (Throwable ex) {
      // $FALL-THROUGH$
    }

    try {
      // java.awt.Desktop was introduced with Java 1.6!
      Class<?> desktopClass =
          CommonPlugin.loadClass(UtilPlugin.INSTANCE.getSymbolicName(), "java.awt.Desktop");
      Method getDesktopMethod = ReflectUtil.getMethod(desktopClass, "getDesktop");
      Method browseMethod = ReflectUtil.getMethod(desktopClass, "browse", URI.class);

      Object desktop = getDesktopMethod.invoke(null);
      browseMethod.invoke(desktop, new URI(url));
      return true;
    } catch (Throwable ex) {
      UtilPlugin.INSTANCE.log(ex, IStatus.WARNING);
    }

    return false;
  }
  @Override
  public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
    if (!context.getBuiltProject().hasNature(KarelNature.NATURE_ID)) return;

    for (Delta delta : context.getDeltas()) {
      IResourceDescription newRes = delta.getNew();
      if (newRes == null) continue;

      try {
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        URI uri = CommonPlugin.resolve(newRes.getURI());
        if (!uri.isFile()) continue;
        IPath path = new Path(uri.toFileString());
        IFile file = workspaceRoot.getFileForLocation(path);
        if (file == null) continue;
        generate(context.getBuiltProject(), file, monitor);
      } catch (Exception e) {
        IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
      }
    }

    context.getResourceSet();
  }