Ejemplo n.º 1
0
  /**
   * Write the version of the metadata into a known file overwriting any existing file contents.
   * Writing the version file isn't really crucial, so the function is silent about failure
   */
  private static void writeWorkspaceVersion() {
    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null || instanceLoc.isReadOnly()) {
      return;
    }

    File versionFile = getVersionFile(instanceLoc.getURL(), true);
    if (versionFile == null) {
      return;
    }

    OutputStream output = null;
    try {
      String versionLine = WORKSPACE_VERSION_KEY + '=' + WORKSPACE_VERSION_VALUE;

      output = new FileOutputStream(versionFile);
      output.write(versionLine.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
      Logger logger = new WorkbenchLogger(PLUGIN_ID);
      logger.error(e);
    } finally {
      try {
        if (output != null) {
          output.close();
        }
      } catch (IOException e) {
        // do nothing
      }
    }
  }
Ejemplo n.º 2
0
 public static File getInstallRoot() throws Exception {
   Location installLocation = Platform.getInstallLocation();
   if (installLocation == null) return null;
   log.trace("get install location {}", installLocation.getURL());
   File installDir = new File(installLocation.getURL().getFile());
   return installDir;
 }
Ejemplo n.º 3
0
  /**
   * Simplified copy of IDEAplication processing that does not offer to choose a workspace location.
   */
  private boolean checkInstanceLocation(
      Location instanceLocation, Shell shell, IEclipseContext context) {

    // Eclipse has been run with -data @none or -data @noDefault options so
    // we don't need to validate the location
    if (instanceLocation == null && Boolean.FALSE.equals(context.get(IWorkbench.PERSIST_STATE))) {
      return true;
    }

    if (instanceLocation == null) {
      MessageDialog.openError(
          shell,
          WorkbenchSWTMessages.IDEApplication_workspaceMandatoryTitle,
          WorkbenchSWTMessages.IDEApplication_workspaceMandatoryMessage);
      return false;
    }

    // -data "/valid/path", workspace already set
    if (instanceLocation.isSet()) {
      // make sure the meta data version is compatible (or the user
      // has
      // chosen to overwrite it).
      if (!checkValidWorkspace(shell, instanceLocation.getURL())) {
        return false;
      }

      // at this point its valid, so try to lock it and update the
      // metadata version information if successful
      try {
        if (instanceLocation.lock()) {
          writeWorkspaceVersion();
          return true;
        }

        // we failed to create the directory.
        // Two possibilities:
        // 1. directory is already in use
        // 2. directory could not be created
        File workspaceDirectory = new File(instanceLocation.getURL().getFile());
        if (workspaceDirectory.exists()) {
          MessageDialog.openError(
              shell,
              WorkbenchSWTMessages.IDEApplication_workspaceCannotLockTitle,
              WorkbenchSWTMessages.IDEApplication_workspaceCannotLockMessage);
        } else {
          MessageDialog.openError(
              shell,
              WorkbenchSWTMessages.IDEApplication_workspaceCannotBeSetTitle,
              WorkbenchSWTMessages.IDEApplication_workspaceCannotBeSetMessage);
        }
      } catch (IOException e) {
        Logger logger = new WorkbenchLogger(PLUGIN_ID);
        logger.error(e);
        MessageDialog.openError(shell, WorkbenchSWTMessages.InternalError, e.getMessage());
      }
      return false;
    }
    return false;
  }
 /*
  * Helper method to return the install location. Return null if it is unavailable.
  */
 public static File getInstallLocation() {
   Location installLocation =
       ServiceHelper.getService(
           TestActivator.getContext(), Location.class, Location.INSTALL_FILTER);
   if (installLocation == null || !installLocation.isSet()) return null;
   URL url = installLocation.getURL();
   if (url == null) return null;
   return URLUtil.toFile(url);
 }
Ejemplo n.º 5
0
 /*
  * Do a look-up and return the OSGi install area if it is set.
  */
 public static URL getOSGiInstallArea() {
   Location location =
       (Location)
           ServiceHelper.getService(
               Activator.getContext(), Location.class.getName(), Location.INSTALL_FILTER);
   if (location == null) return null;
   if (!location.isSet()) return null;
   return location.getURL();
 }
Ejemplo n.º 6
0
 /*
  * Helper method to return the eclipse.home location. Return
  * null if it is unavailable.
  */
 public static File getEclipseHome() {
   Location eclipseHome =
       (Location)
           ServiceHelper.getService(
               Activator.getContext(), Location.class.getName(), Location.ECLIPSE_HOME_FILTER);
   if (eclipseHome == null || !eclipseHome.isSet()) return null;
   URL url = eclipseHome.getURL();
   if (url == null) return null;
   return URLUtil.toFile(url);
 }
Ejemplo n.º 7
0
 /**
  * Answer the configuration location for this plug-in.
  *
  * @param none
  * @return URI The GEM plugin's configuration directory (not <code>null</code>)
  */
 public URI getConfigDir() {
   final Location location = Platform.getConfigurationLocation();
   if (location != null) {
     final URL configURL = location.getURL();
     if (configURL != null && configURL.getProtocol().startsWith("file")) { // $NON-NLS-1$
       try {
         return configURL.toURI();
       } catch (final URISyntaxException e) {
         GemUtilities.logExceptionDetail(e);
       }
     }
   }
   return null;
 }
  private void doSetup() throws Exception {

    // root of workspace directory
    Location platformLocation = Platform.getInstanceLocation();

    ProjectUnzipUtility unzipUtil = new ProjectUnzipUtility();
    File zipFile =
        FileUtil.makeFileFor(
            ProjectUnzipUtility.PROJECT_ZIPS_FOLDER,
            fZipFileName,
            ProjectUnzipUtility.PROJECT_ZIPS_FOLDER);
    unzipUtil.unzipAndImport(zipFile, platformLocation.getURL().getFile());
    unzipUtil.initJavaProject(fProjectName);
  }
Ejemplo n.º 9
0
 public URL getConfigURL() {
   Filter filter = null;
   if (configTracker == null) {
     try {
       filter = bundleContext.createFilter(Location.CONFIGURATION_FILTER);
     } catch (InvalidSyntaxException e) {
       // should never happen
     }
     configTracker = new ServiceTracker(bundleContext, filter, null);
     configTracker.open();
   }
   Location location = (Location) configTracker.getService();
   if (location == null) return null;
   return location.getURL();
 }
Ejemplo n.º 10
0
  /**
   * Write the version of the metadata into a known file overwriting any existing file contents.
   * Writing the version file isn't really crucial, so the function is silent about failure
   */
  private static void writeWorkspaceVersion() {
    if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) {
      // no reference bundle installed, no check possible
      return;
    }

    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null || instanceLoc.isReadOnly()) {
      return;
    }

    File versionFile = getVersionFile(instanceLoc.getURL(), true);
    if (versionFile == null) {
      return;
    }

    OutputStream output = null;
    try {
      output = new FileOutputStream(versionFile);
      Properties props = new Properties();

      // write new property
      props.setProperty(
          WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME,
          WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION.toString());

      // write legacy property with an incremented version,
      // so that pre-4.4 IDEs will also warn about the workspace
      props.setProperty(
          WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME_LEGACY, WORKSPACE_CHECK_LEGACY_VERSION_INCREMENTED);

      props.store(output, null);
    } catch (IOException e) {
      IDEWorkbenchPlugin.log(
          "Could not write version file", //$NON-NLS-1$
          StatusUtil.newStatus(IStatus.ERROR, e.getMessage(), e));
    } finally {
      try {
        if (output != null) {
          output.close();
        }
      } catch (IOException e) {
        // do nothing
      }
    }
  }
Ejemplo n.º 11
0
  private MApplication loadApplicationModel(
      IApplicationContext appContext, IEclipseContext eclipseContext) {
    MApplication theApp = null;

    Location instanceLocation = WorkbenchSWTActivator.getDefault().getInstanceLocation();

    URI applicationModelURI = determineApplicationModelURI(appContext);
    eclipseContext.set(E4Workbench.INITIAL_WORKBENCH_MODEL_URI, applicationModelURI);

    // Save and restore
    Boolean saveAndRestore =
        getArgValue(IWorkbench.PERSIST_STATE, appContext, false)
            .map(value -> Boolean.parseBoolean(value))
            .orElse(Boolean.TRUE);

    eclipseContext.set(IWorkbench.PERSIST_STATE, saveAndRestore);

    // when -data @none or -data @noDefault options
    if (instanceLocation != null && instanceLocation.getURL() != null) {
      eclipseContext.set(E4Workbench.INSTANCE_LOCATION, instanceLocation);
    } else {
      eclipseContext.set(IWorkbench.PERSIST_STATE, false);
    }

    // Persisted state
    Boolean clearPersistedState =
        getArgValue(IWorkbench.CLEAR_PERSISTED_STATE, appContext, true)
            .map(value -> Boolean.parseBoolean(value))
            .orElse(Boolean.FALSE);
    eclipseContext.set(IWorkbench.CLEAR_PERSISTED_STATE, clearPersistedState);

    String resourceHandler =
        getArgValue(IWorkbench.MODEL_RESOURCE_HANDLER, appContext, false)
            .orElse("bundleclass://org.eclipse.e4.ui.workbench/" + ResourceHandler.class.getName());

    IContributionFactory factory = eclipseContext.get(IContributionFactory.class);

    handler = (IModelResourceHandler) factory.create(resourceHandler, eclipseContext);
    eclipseContext.set(IModelResourceHandler.class, handler);

    Resource resource = handler.loadMostRecentModel();
    theApp = (MApplication) resource.getContents().get(0);

    return theApp;
  }
Ejemplo n.º 12
0
 private void importSamples(IProject project)
     throws InvocationTargetException, InterruptedException, CoreException {
   Location installLocation = Platform.getInstallLocation();
   if (installLocation == null) {
     return;
   }
   String installFileStr = installLocation.getURL().getFile();
   File installFile = new File(installFileStr, "sample_data");
   if (installFile.isDirectory()) {
     IFolder sampleData = project.getFolder("sample_data");
     sampleData.create(true, true, new NullProgressMonitor());
     ImportOperation importOperation =
         new ImportOperation(
             sampleData.getFullPath(),
             installFile,
             FileSystemStructureProvider.INSTANCE,
             overwriteQuery);
     importOperation.setCreateContainerStructure(false);
     importOperation.run(new NullProgressMonitor());
   }
 }
Ejemplo n.º 13
0
  @Override
  public Object start(IApplicationContext applicationContext) throws Exception {
    // set the display name before the Display is
    // created to ensure the app name is used in any
    // platform menus, etc. See
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329456#c14
    IProduct product = Platform.getProduct();
    if (product != null && product.getName() != null) {
      Display.setAppName(product.getName());
    }
    Display display = getApplicationDisplay();
    Location instanceLocation = null;
    try {
      E4Workbench workbench = createE4Workbench(applicationContext, display);

      instanceLocation = (Location) workbench.getContext().get(E4Workbench.INSTANCE_LOCATION);
      Shell shell = display.getActiveShell();
      if (shell == null) {
        shell = new Shell();
        // place it off so it's not visible
        shell.setLocation(0, 10000);
      }
      if (!checkInstanceLocation(instanceLocation, shell, workbench.getContext())) return EXIT_OK;

      // Create and run the UI (if any)
      workbench.createAndRunUI(workbench.getApplication());

      saveModel();
      workbench.close();

      if (workbench.isRestart()) {
        return EXIT_RESTART;
      }

      return EXIT_OK;
    } finally {
      if (display != null) display.dispose();
      if (instanceLocation != null) instanceLocation.release();
    }
  }
  public BundleInfo[] loadConfiguration(BundleContext context, String infoPath) throws IOException {
    URI installArea = EquinoxUtils.getInstallLocationURI(context);

    URL configURL = null;
    InputStream stream = null;

    if (infoPath == null) {
      SimpleConfiguratorImpl simpleImpl = new SimpleConfiguratorImpl(context, null);
      configURL = simpleImpl.getConfigurationURL();
    } else {
      // == (not .equals) use the default source info, currently SOURCE_INFO_PATH
      boolean defaultSource = (infoPath == SOURCE_INFO);
      if (defaultSource) infoPath = SOURCE_INFO_PATH;

      Location configLocation = EquinoxUtils.getConfigLocation(context);
      configURL = configLocation.getDataArea(infoPath);
      try {
        stream = configURL.openStream();
      } catch (FileNotFoundException e) {
        if (defaultSource && configLocation.getParentLocation() != null) {
          configURL = configLocation.getParentLocation().getDataArea(infoPath);
        } else {
          return new BundleInfo[0];
        }
      }
    }
    if (configURL == null) return new BundleInfo[0];
    else if (stream == null) {
      try {
        stream = configURL.openStream();
      } catch (FileNotFoundException e) {
        return new BundleInfo[0];
      }
    }

    // stream will be closed
    return loadConfiguration(stream, installArea);
  }
Ejemplo n.º 15
0
  // @Override
  public Object startX(IApplicationContext context) throws Exception {

    final Display display = PlatformUI.createDisplay();
    final TakariWorkbenchAdvisor advisor = new TakariWorkbenchAdvisor();
    display.addListener(SWT.OpenDocument, advisor.getOpenDocumentHandler());

    // FIXME: Check unhandled arguments for a pom.xml file and treat like an
    // OpenDocument
    for (String arg : (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS)) {
      File f = new File(arg);
      if (f.exists()) {
        if ("pom.xml".equals(f.getName())) {
          Event e = new Event();
          e.text = arg;
          advisor.getOpenDocumentHandler().handleEvent(e);
        } else if (f.isDirectory() && (f = new File(f, "pom.xml")).exists()) {
          Event e = new Event();
          e.text = f.getPath();
          advisor.getOpenDocumentHandler().handleEvent(e);
        }
      }
    }

    try {
      int returnCode = PlatformUI.createAndRunWorkbench(display, advisor);
      if (returnCode == PlatformUI.RETURN_RESTART) {
        return IApplication.EXIT_RESTART;
      }
      return IApplication.EXIT_OK;
    } finally {
      Location loc = Platform.getInstanceLocation();
      if (loc != null) {
        loc.release();
      }
      display.dispose();
    }
  }
Ejemplo n.º 16
0
  private void addIcon(String os, String value) {
    if (value == null) return;

    File iconFile = new File(value);
    if (!iconFile.isFile()) {
      // workspace
      Location instanceLocation =
          (Location)
              ServiceHelper.getService(
                  Activator.getContext(), Location.class.getName(), Location.INSTANCE_FILTER);
      if (instanceLocation != null && instanceLocation.getURL() != null) {
        File workspace = URLUtil.toFile(instanceLocation.getURL());
        if (workspace != null) iconFile = new File(workspace, value);
      }
    }
    if (!iconFile.isFile()) iconFile = new File(location.getParentFile(), value);

    Collection<String> list = icons.get(os);
    if (list == null) {
      list = new ArrayList<String>(6);
      icons.put(os, list);
    }
    list.add(iconFile.getAbsolutePath());
  }
  public EquinoxLogServices(EquinoxConfiguration environmentInfo, Location configuration) {
    String logFilePath = environmentInfo.getConfiguration(EclipseStarter.PROP_LOGFILE);
    if (logFilePath == null) {
      logFilePath = Long.toString(System.currentTimeMillis()) + EquinoxLogServices.LOG_EXT;
    }

    File logFile = new File(logFilePath);
    if (!logFile.isAbsolute()) {
      File configAreaDirectory = null;
      if (configuration != null)
        // TODO assumes the URL is a file: url
        configAreaDirectory = new File(configuration.getURL().getFile());

      if (configAreaDirectory != null) {
        logFile = new File(configAreaDirectory, logFilePath);
      } else {
        logFile = null;
      }
    }

    boolean enabled =
        "true"
            .equals(
                environmentInfo.getConfiguration(
                    PROP_LOG_ENABLED, "true")); // $NON-NLS-1$ //$NON-NLS-2$
    if (logFile != null) {
      environmentInfo.setConfiguration(EclipseStarter.PROP_LOGFILE, logFile.getAbsolutePath());
      logWriter = new EquinoxLogWriter(logFile, EQUINOX_LOGGER_NAME, enabled, environmentInfo);

      File perfLogFile = new File(logFile.getParentFile(), "performance.log"); // $NON-NLS-1$
      perfWriter = new EquinoxLogWriter(perfLogFile, PERF_LOGGER_NAME, true, environmentInfo);
    } else {
      logWriter =
          new EquinoxLogWriter((Writer) null, EQUINOX_LOGGER_NAME, enabled, environmentInfo);
      perfWriter = new EquinoxLogWriter((Writer) null, PERF_LOGGER_NAME, true, environmentInfo);
    }

    if ("true"
        .equals(environmentInfo.getConfiguration(EclipseStarter.PROP_CONSOLE_LOG))) // $NON-NLS-1$
    logWriter.setConsoleLog(true);
    logServiceManager = new LogServiceManager(logWriter, perfWriter);
    eclipseLogFactory = new EquinoxLogFactory(logWriter, logServiceManager);
    rootFrameworkLog = eclipseLogFactory.createFrameworkLog(null, logWriter);
  }
Ejemplo n.º 18
0
 private static URL computeSharedConfigurationLocation() {
   String property = FrameworkProperties.getProperty(PROP_SHARED_CONFIG_AREA);
   if (property == null) return null;
   try {
     URL sharedConfigurationURL = LocationHelper.buildURL(property, true);
     if (sharedConfigurationURL == null) return null;
     if (sharedConfigurationURL.getPath().startsWith("/")) // $NON-NLS-1$
       // absolute
       return sharedConfigurationURL;
     URL installURL = installLocation.getURL();
     if (!sharedConfigurationURL.getProtocol().equals(installURL.getProtocol()))
       // different protocol
       return sharedConfigurationURL;
     sharedConfigurationURL = new URL(installURL, sharedConfigurationURL.getPath());
     FrameworkProperties.setProperty(
         PROP_SHARED_CONFIG_AREA, sharedConfigurationURL.toExternalForm());
   } catch (MalformedURLException e) {
     // do nothing here since it is basically impossible to get a bogus url
   }
   return null;
 }
Ejemplo n.º 19
0
  /** Initializes the Location objects for the LocationManager. */
  public static void initializeLocations() {
    // do install location initialization first since others may depend on it
    // assumes that the property is already set
    installLocation = buildLocation(PROP_INSTALL_AREA, null, "", true, false, null); // $NON-NLS-1$

    // TODO not sure what the data area prefix should be here for the user area
    Location temp =
        buildLocation(PROP_USER_AREA_DEFAULT, null, "", false, false, null); // $NON-NLS-1$
    URL defaultLocation = temp == null ? null : temp.getURL();
    if (defaultLocation == null)
      defaultLocation =
          buildURL(
              new File(FrameworkProperties.getProperty(PROP_USER_HOME), "user").getAbsolutePath(),
              true); //$NON-NLS-1$
    userLocation =
        buildLocation(PROP_USER_AREA, defaultLocation, "", false, false, null); // $NON-NLS-1$

    temp =
        buildLocation(
            PROP_INSTANCE_AREA_DEFAULT,
            null,
            "",
            false,
            false,
            INSTANCE_DATA_AREA_PREFIX); //$NON-NLS-1$
    defaultLocation = temp == null ? null : temp.getURL();
    if (defaultLocation == null)
      defaultLocation =
          buildURL(
              new File(FrameworkProperties.getProperty(PROP_USER_DIR), "workspace")
                  .getAbsolutePath(),
              true); //$NON-NLS-1$
    instanceLocation =
        buildLocation(
            PROP_INSTANCE_AREA,
            defaultLocation,
            "",
            false,
            false,
            INSTANCE_DATA_AREA_PREFIX); //$NON-NLS-1$

    mungeConfigurationLocation();
    // compute a default but it is very unlikely to be used since main will have computed everything
    temp = buildLocation(PROP_CONFIG_AREA_DEFAULT, null, "", false, false, null); // $NON-NLS-1$
    defaultLocation = temp == null ? null : temp.getURL();
    if (defaultLocation == null && FrameworkProperties.getProperty(PROP_CONFIG_AREA) == null)
      // only compute the default if the configuration area property is not set
      defaultLocation = buildURL(computeDefaultConfigurationLocation(), true);
    configurationLocation =
        buildLocation(PROP_CONFIG_AREA, defaultLocation, "", false, false, null); // $NON-NLS-1$
    // get the parent location based on the system property. This will have been set on the
    // way in either by the caller/user or by main.  There will be no parent location if we are not
    // cascaded.
    URL parentLocation = computeSharedConfigurationLocation();
    if (parentLocation != null && !parentLocation.equals(configurationLocation.getURL())) {
      Location parent = new BasicLocation(null, parentLocation, true, null);
      ((BasicLocation) configurationLocation).setParent(parent);
    }
    initializeDerivedConfigurationLocations();

    if (FrameworkProperties.getProperty(PROP_HOME_LOCATION_AREA) == null) {
      String eclipseLauncher = FrameworkProperties.getProperty(PROP_LAUNCHER);
      String eclipseHomeLocationPath = getEclipseHomeLocation(eclipseLauncher);
      if (eclipseHomeLocationPath != null)
        FrameworkProperties.setProperty(PROP_HOME_LOCATION_AREA, eclipseHomeLocationPath);
    }
    // if eclipse.home.location is not set then default to osgi.install.area
    if (FrameworkProperties.getProperty(PROP_HOME_LOCATION_AREA) == null
        && FrameworkProperties.getProperty(PROP_INSTALL_AREA) != null)
      FrameworkProperties.setProperty(
          PROP_HOME_LOCATION_AREA, FrameworkProperties.getProperty(PROP_INSTALL_AREA));
    eclipseHomeLocation =
        buildLocation(PROP_HOME_LOCATION_AREA, null, "", true, true, null); // $NON-NLS-1$
  }
  /** 修改产品 ini 文件中的语言 */
  private void changeLocale(String locale) {
    Location configArea = Platform.getInstallLocation();
    if (configArea == null) {
      return;
    }

    URL location = null;
    try {
      location =
          new URL(
              configArea.getURL().toExternalForm()
                  + "configuration"
                  + File.separator
                  + "config.ini");
    } catch (MalformedURLException e) {
      // This should never happen
    }
    // System.out.println("LanguageSwitchHandler.loadConfigurationInfo(): "
    // + location);

    try {
      String fileName = location.getFile();
      File file = new File(fileName);
      fileName += ".bak";
      file.renameTo(new File(fileName));
      BufferedReader in = new BufferedReader(new FileReader(fileName));
      BufferedWriter out = new BufferedWriter(new FileWriter(location.getFile()));
      try {
        String line = in.readLine();
        while (line != null) {
          if (line.startsWith("osgi.nl=")) {
            out.write("osgi.nl=" + locale);
          } else {
            out.write(line);
          }
          out.newLine();
          line = in.readLine();
        }
        out.flush();
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
        if (out != null) {
          try {
            out.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
        File tmpFile = new File(location.getFile() + ".bak");
        if (tmpFile.exists()) {
          tmpFile.delete();
        }
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 private static String getConfiguration() throws IOException {
   Location configLocation = Platform.getConfigurationLocation();
   URL configURL = configLocation.getURL();
   String configuration = FileLocator.resolve(configURL).getPath();
   return configuration;
 }
Ejemplo n.º 22
0
 /** @return the AUTAgent installation directory */
 public static File getInstallDir() {
   Location installLoc = Platform.getInstallLocation();
   String installDir = installLoc.getURL().getFile();
   return new File(installDir);
 }
Ejemplo n.º 23
0
 /**
  * Returns the File object under the configuration location used for the OSGi configuration
  *
  * @return the OSGi configuration directory
  */
 public static File getOSGiConfigurationDir() {
   // TODO assumes the URL is a file: url
   return new File(
       configurationLocation.getURL().getFile(), FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME);
 }
  /*
   * (non-Javadoc)
   * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext context)
   */
  public Object start(IApplicationContext context) throws Exception {
    System.out.println("S2MaterializerApplication.start");
    Display display = PlatformUI.createDisplay();

    try {
      // look and see if there's a splash shell we can parent off of
      Shell shell = WorkbenchPlugin.getSplashShell(display);
      if (shell != null) {
        // should should set the icon and message for this shell to be the
        // same as the chooser dialog - this will be the guy that lives in
        // the task bar and without these calls you'd have the default icon
        // with no message.
        shell.setText(ChooseWorkspaceDialog.getWindowTitle());
        shell.setImages(Dialog.getDefaultImages());
      }
      //
      // if ( !checkInstanceLocation( shell ) )
      // {
      // WorkbenchPlugin.unsetSplashShell( display );
      // Platform.endSplash();
      // return EXIT_OK;
      // }

      String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
      String s2ProjectURL = null;
      String nexusBaseURL = null;
      for (int i = 0; i < args.length - 1; i++) {
        if (ARG_DESCRIPTOR_URL.equals(args[i])) {
          s2ProjectURL = args[i + 1];
        }

        if (ARG_NEXUS_BASE_URL.equals(args[i])) {
          nexusBaseURL = args[i + 1];
        }
      }

      if (s2ProjectURL == null || nexusBaseURL == null) {
        System.err.println(
            "Syntax: "
                + ARG_DESCRIPTOR_URL
                + " <descriptor url> "
                + ARG_NEXUS_BASE_URL
                + " <nexus server url>");
        return EXIT_OK;
      }

      NexusFacade.setMainNexusServerData(
          nexusBaseURL, null /* username */, null /* password */, new NullProgressMonitor());

      // Dump some useful debug info :)
      System.out.println(PROP_LAUNCHER + "=" + System.getProperty(PROP_LAUNCHER));
      System.out.println(PROP_VM + "=" + System.getProperty(PROP_VM));
      System.out.println(PROP_VMARGS + "=" + System.getProperty(PROP_VMARGS));
      System.out.println(PROP_COMMANDS + "=" + System.getProperty(PROP_COMMANDS));

      // Save the current workspace location in the eclipse preferences
      Location instanceLoc = Platform.getInstanceLocation();
      File workspaceFile = new File(instanceLoc.getURL().getFile());
      Preferences node = new ConfigurationScope().getNode(IDEWorkbenchPlugin.IDE_WORKBENCH);
      node.put(IDE.Preferences.RECENT_WORKSPACES, workspaceFile.getCanonicalPath());
      node.putInt(
          IDE.Preferences.RECENT_WORKSPACES_PROTOCOL, PERS_ENCODING_VERSION_CONFIG_PREFS_NO_COMMAS);
      node.flush();

      // create the workbench with this advisor and run it until it exits
      // N.B. createWorkbench remembers the advisor, and also registers
      // the workbench globally so that all UI plug-ins can find it using
      // PlatformUI.getWorkbench() or AbstractUIPlugin.getWorkbench()
      int returnCode =
          PlatformUI.createAndRunWorkbench(
              display, new S2MaterializerWorkbenchAdvisor(s2ProjectURL));

      // the workbench doesn't support relaunch yet (bug 61809) so
      // for now restart is used, and exit data properties are checked
      // here to substitute in the relaunch return code if needed
      if (returnCode != PlatformUI.RETURN_RESTART) {
        return EXIT_OK;
      }

      // if the exit code property has been set to the relaunch code, then
      // return that code now, otherwise this is a normal restart
      String command_line = buildCommandLine();
      System.out.println("New command line=" + command_line);
      System.setProperty(PROP_EXIT_DATA, command_line);
      System.out.println(PROP_EXIT_DATA + "=" + System.getProperty(PROP_EXIT_DATA));
      System.setProperty(PROP_EXIT_CODE, "" + Integer.toString(EXIT_RELAUNCH));
      System.out.println(PROP_EXIT_CODE + "=" + System.getProperty(PROP_EXIT_CODE));

      return EXIT_RELAUNCH;
    } finally {
      if (display != null) {
        display.dispose();
      }
      Location instanceLoc = Platform.getInstanceLocation();
      if (instanceLoc != null) instanceLoc.release();
    }
  }
Ejemplo n.º 25
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext context)
   */
  @Override
  public Object start(IApplicationContext appContext) throws Exception {

    // Display display = createDisplay();
    // processor must be created before we start event loop
    // DelayedEventsProcessor processor = new DelayedEventsProcessor(display);

    final Display display = PlatformUI.createDisplay();
    final TakariWorkbenchAdvisor advisor = new TakariWorkbenchAdvisor();
    display.addListener(SWT.OpenDocument, advisor.getOpenDocumentHandler());

    // FIXME: Check unhandled arguments for a pom.xml file and treat like an
    // OpenDocument
    for (String arg :
        (String[]) appContext.getArguments().get(IApplicationContext.APPLICATION_ARGS)) {
      File f = new File(arg);
      if (f.exists()) {
        if ("pom.xml".equals(f.getName())) {
          Event e = new Event();
          e.text = arg;
          advisor.getOpenDocumentHandler().handleEvent(e);
        } else if (f.isDirectory() && (f = new File(f, "pom.xml")).exists()) {
          Event e = new Event();
          e.text = f.getPath();
          advisor.getOpenDocumentHandler().handleEvent(e);
        }
      }
    }

    try {

      // look and see if there's a splash shell we can parent off of
      Shell shell = WorkbenchPlugin.getSplashShell(display);
      if (shell != null) {
        // should should set the icon and message for this shell to be the
        // same as the chooser dialog - this will be the guy that lives in
        // the task bar and without these calls you'd have the default icon
        // with no message.
        shell.setText(ChooseWorkspaceDialog.getWindowTitle());
        shell.setImages(Window.getDefaultImages());
      }

      Object instanceLocationCheck = checkInstanceLocation(shell, appContext.getArguments());
      if (instanceLocationCheck != null) {
        WorkbenchPlugin.unsetSplashShell(display);
        appContext.applicationRunning();
        return instanceLocationCheck;
      }

      // create the workbench with this advisor and run it until it exits
      // N.B. createWorkbench remembers the advisor, and also registers
      // the workbench globally so that all UI plug-ins can find it using
      // PlatformUI.getWorkbench() or AbstractUIPlugin.getWorkbench()
      // int returnCode = PlatformUI.createAndRunWorkbench(display, new
      // TakariWorkbenchAdvisor(processor));
      int returnCode = PlatformUI.createAndRunWorkbench(display, advisor);

      // the workbench doesn't support relaunch yet (bug 61809) so
      // for now restart is used, and exit data properties are checked
      // here to substitute in the relaunch return code if needed
      if (returnCode != PlatformUI.RETURN_RESTART) {
        return EXIT_OK;
      }

      // if the exit code property has been set to the relaunch code, then
      // return that code now, otherwise this is a normal restart
      return EXIT_RELAUNCH.equals(Integer.getInteger(PROP_EXIT_CODE))
          ? EXIT_RELAUNCH
          : EXIT_RESTART;
    } finally {
      if (display != null) {
        display.dispose();
      }
      Location instanceLoc = Platform.getInstanceLocation();
      if (instanceLoc != null) {
        instanceLoc.release();
      }
    }
  }
Ejemplo n.º 26
0
  /**
   * Return <code>null</code> if a valid workspace path has been set and an exit code otherwise.
   * Prompt for and set the path if possible and required.
   *
   * @param applicationArguments the command line arguments
   * @return <code>null</code> if a valid instance location has been set and an exit code otherwise
   */
  private Object checkInstanceLocation(Shell shell, Map applicationArguments) {
    // -data @none was specified but an ide requires workspace
    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null) {
      MessageDialog.openError(
          shell,
          IDEWorkbenchMessages.IDEApplication_workspaceMandatoryTitle,
          IDEWorkbenchMessages.IDEApplication_workspaceMandatoryMessage);
      return EXIT_OK;
    }

    // -data "/valid/path", workspace already set
    if (instanceLoc.isSet()) {
      // make sure the meta data version is compatible (or the user has
      // chosen to overwrite it).
      if (!checkValidWorkspace(shell, instanceLoc.getURL())) {
        return EXIT_OK;
      }

      // at this point its valid, so try to lock it and update the
      // metadata version information if successful
      try {
        if (instanceLoc.lock()) {
          writeWorkspaceVersion();
          return null;
        }

        // we failed to create the directory.
        // Two possibilities:
        // 1. directory is already in use
        // 2. directory could not be created
        File workspaceDirectory = new File(instanceLoc.getURL().getFile());
        if (workspaceDirectory.exists()) {
          if (isDevLaunchMode(applicationArguments)) {
            return EXIT_WORKSPACE_LOCKED;
          }
          MessageDialog.openError(
              shell,
              IDEWorkbenchMessages.IDEApplication_workspaceCannotLockTitle,
              NLS.bind(
                  IDEWorkbenchMessages.IDEApplication_workspaceCannotLockMessage,
                  workspaceDirectory.getAbsolutePath()));
        } else {
          MessageDialog.openError(
              shell,
              IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
              IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
        }
      } catch (IOException e) {
        IDEWorkbenchPlugin.log(
            "Could not obtain lock for workspace location", //$NON-NLS-1$
            e);
        MessageDialog.openError(shell, IDEWorkbenchMessages.InternalError, e.getMessage());
      }
      return EXIT_OK;
    }

    // -data @noDefault or -data not specified, prompt and set
    ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLoc.getDefault());

    boolean force = false;
    while (true) {
      URL workspaceUrl = promptForWorkspace(shell, launchData, force);
      if (workspaceUrl == null) {
        return EXIT_OK;
      }

      // if there is an error with the first selection, then force the
      // dialog to open to give the user a chance to correct
      force = true;

      try {
        // the operation will fail if the url is not a valid
        // instance data area, so other checking is unneeded
        if (instanceLoc.set(workspaceUrl, true)) {
          launchData.writePersistedData();
          writeWorkspaceVersion();
          return null;
        }
      } catch (IllegalStateException e) {
        MessageDialog.openError(
            shell,
            IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
            IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
        return EXIT_OK;
      } catch (IOException e) {
        MessageDialog.openError(
            shell,
            IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
            IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
      }

      // by this point it has been determined that the workspace is
      // already in use -- force the user to choose again
      MessageDialog.openError(
          shell,
          IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle,
          NLS.bind(
              IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage, workspaceUrl.getFile()));
    }
  }