Exemple #1
0
 private static String getEclipseHomeLocation(String launcher) {
   if (launcher == null) return null;
   File launcherFile = new File(launcher);
   if (launcherFile.getParent() == null) return null;
   File launcherDir = new File(launcherFile.getParent());
   // check for mac os; the os check is copied from EclipseEnvironmentInfo.
   String macosx = org.eclipse.osgi.service.environment.Constants.OS_MACOSX;
   if (macosx.equals(EclipseEnvironmentInfo.getDefault().getOS()))
     launcherDir = getMacOSEclipsoeHomeLocation(launcherDir);
   return (launcherDir.exists() && launcherDir.isDirectory())
       ? launcherDir.getAbsolutePath()
       : null;
 }
Exemple #2
0
  private synchronized void initialize() {
    if (eclipse != null) {
      return;
    }
    final File p2BridgePluginDir = getP2BridgePluginDir();
    final File p2BridgeRuntimeDir =
        new File(
            applicationConfiguration.getTemporaryDirectory(), "nexus-p2-bridge-plugin/runtime");
    final File p2BridgeTempDir =
        new File(applicationConfiguration.getTemporaryDirectory(), "nexus-p2-bridge-plugin/tmp");
    final File eclipseDir = new File(p2BridgeRuntimeDir, "eclipse");

    // if temporary plugin directory exists, remove it to avoid the fact that eclipse stores
    // absolute paths to
    // installed bundles (see NXCM-4475)
    try {
      DirSupport.deleteIfExists(p2BridgeRuntimeDir.toPath());
    } catch (IOException e) {
      throw new RuntimeException(
          "Cannot delete nexus-p2-bridge temporary directory "
              + p2BridgeRuntimeDir.getAbsolutePath(),
          e);
    }
    try {
      DirSupport.mkdir(p2BridgeRuntimeDir.toPath());
    } catch (IOException e) {
      throw new RuntimeException(
          "Cannot create nexus-p2-bridge temporary directory "
              + p2BridgeRuntimeDir.getAbsolutePath(),
          e);
    }
    // create a fresh eclipse instance
    try {
      unArchiver.setSourceFile(new File(p2BridgePluginDir, "p2-runtime/eclipse.zip"));
      unArchiver.setDestDirectory(p2BridgeRuntimeDir);
      unArchiver.extract();
    } catch (final Exception e) {
      throw new RuntimeException("Cannot unpack Eclipse", e);
    }

    final EclipseLocation eclipseLocation =
        eclipseLocationFactory.createStaticEclipseLocation(eclipseDir);

    eclipse = eclipseBridge.createInstance(eclipseLocation);
    try {
      {
        // TODO is this really necessary?
        final File secureStorage =
            new File(
                applicationConfiguration.getConfigurationDirectory(), "eclipse.secure_storage");
        if (secureStorage.exists() && !secureStorage.delete()) {
          throw new RuntimeException(
              "Could not delete Eclipse secure storage " + secureStorage.getAbsolutePath());
        }
        EclipseEnvironmentInfo.setAppArgs(
            new String[] {"-eclipse.keyring", secureStorage.getAbsolutePath()});
      }
      eclipse.start(initParams(p2BridgePluginDir, eclipseDir, p2BridgeTempDir));
      final File[] bundles =
          new File(p2BridgePluginDir, "p2-runtime/bundles")
              .listFiles(
                  new FilenameFilter() {
                    @Override
                    public boolean accept(final File dir, final String name) {
                      return name.endsWith(".jar");
                    }
                  });
      for (final File bundle : bundles) {
        eclipse.startBundle(eclipse.installBundle(bundle.toURI().toASCIIString()));
      }
    } catch (final Exception e) {
      throw new RuntimeException(e);
    }
  }