예제 #1
0
  /** Installs the eclipse plugin used to install eclipse features. */
  public static boolean installInstallerPlugin() throws Exception {
    File updateDir = Installer.tempDir("update");
    Extractor.extractResource("/files/installer-update-site.zip", updateDir);

    String url = "file://" + updateDir;
    Command command =
        new InstallCommand(null, url, "org.eclim.installer", "org.eclipse.equinox.p2.director");

    try {
      command.start();
      command.join();
      if (command.getReturnCode() != 0) {
        if (command.isShutdown()) {
          return false;
        }
        RuntimeException re =
            new RuntimeException(
                "error: " + command.getErrorMessage() + " out: " + command.getResult());

        logger.warn(
            "Error installing eclim installer feature, " + "attempting uninstall/reinstall.");

        // attempt to uninstall the feature
        Command uninstall =
            new UninstallCommand(
                null, url, "org.eclim.installer", "org.eclipse.equinox.p2.director");
        uninstall.start();
        uninstall.join();

        // now try to install again
        command =
            new InstallCommand(null, url, "org.eclim.installer", "org.eclipse.equinox.p2.director");
        command.start();
        command.join();
        if (command.getReturnCode() != 0) {
          if (command.isShutdown()) {
            return false;
          }
          throw re;
        }
      }
      Installer.getProject().setProperty("eclim.installer.feature.installed", "true");
      Installer.getProject().setProperty("eclim.installer.feature.location", url);
    } finally {
      command.destroy();
    }
    return true;
  }
예제 #2
0
  public static EclipseInfo gatherEclipseInfo() throws Exception {
    final Map<String, Feature> installedFeatures = new HashMap<String, Feature>();

    // run eclipse to get a list of existing installed features
    Command command =
        new InfoCommand(
            new OutputHandler() {
              public void process(String line) {
                logger.info(line);
                if (line.startsWith(FEATURE)) {
                  String[] attrs = StringUtils.split(line.substring(FEATURE.length()));
                  File site = null;
                  try {
                    site = new File(new URL(attrs[2]).getFile());
                  } catch (Exception e) {
                    logger.error("Failed to parse feature: " + line, e);
                  }
                  installedFeatures.put(attrs[0], new Feature(attrs[1], site));
                } else if (line.startsWith(CONFIGURATION)) {
                  String config = line.substring(CONFIGURATION.length());
                  if (config.startsWith("file:")) {
                    config = config.substring(5);
                  }
                  if (Os.isFamily(Os.FAMILY_WINDOWS) && config.startsWith("/")) {
                    config = config.substring(1);
                  }
                  String local = new File(config).getParent();
                  logger.info("eclipse.local=" + local);
                  Installer.getContext().setValue("eclipse.local", local);
                } else if (line.startsWith(PROFILE)) {
                  String profile = line.substring(PROFILE.length());
                  logger.info("eclipse.profile=" + profile);
                  Installer.getContext().setValue("eclipse.profile", profile);
                }
              }
            });
    try {
      command.start();
      command.join();
      if (command.getReturnCode() != 0) {
        if (command.isShutdown()) {
          return null;
        }
        throw new RuntimeException(
            "error: " + command.getErrorMessage() + " out: " + command.getResult());
      }
    } finally {
      command.destroy();
    }

    return new EclipseInfo(
        (String) Installer.getContext().getValue("eclipse.profile"),
        (String) Installer.getContext().getValue("eclipse.local"),
        installedFeatures);
  }