Example #1
0
  /**
   * Find location of user's default(current) Firefox profile.
   *
   * @return IPath
   */
  public static IPath findDefaultProfileLocation() {
    String[] locations = (String[]) LOCATIONS.get(Platform.getOS());
    if (locations != null) {
      for (int i = 0; i < locations.length; ++i) {
        String location = PlatformUtil.expandEnvironmentStrings(locations[i]);
        File dir = new File(location);
        if (!dir.isDirectory()) {
          continue;
        }
        IdeLog.logInfo(
            CorePlugin.getDefault(),
            MessageFormat.format(
                "Check location {0} for default profile", location)); // $NON-NLS-1$

        File[] profiles = readProfiles(dir);
        if (profiles.length == 0) {
          File dirProfiles = new File(dir, "Profiles"); // $NON-NLS-1$
          if (!dirProfiles.exists() || !dirProfiles.isDirectory()) {
            dirProfiles = dir;
          }
          profiles =
              dirProfiles.listFiles(
                  new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                      return name.endsWith(".default"); // $NON-NLS-1$
                    }
                  });
        }

        // Debug output
        StringBuffer sb = new StringBuffer();
        for (int j = 0; j < profiles.length; ++j) {
          if (j != 0) {
            sb.append(',');
          }
          sb.append(profiles[j].toString());
        }
        IdeLog.logInfo(
            CorePlugin.getDefault(),
            MessageFormat.format("Profiles found: {0}", sb.toString())); // $NON-NLS-1$
        // End of Debug output

        for (File profile : profiles) {
          if (profile.isDirectory()) {
            IdeLog.logInfo(
                CorePlugin.getDefault(),
                MessageFormat.format(
                    "Default profile was found at {0}", profile.toString())); // $NON-NLS-1$
            return Path.fromOSString(profile.getAbsolutePath());
          }
        }
      }
    }
    return null;
  }
 /**
  * Returns the defined encoding for the given module.
  *
  * <pre>
  * The search for the encoding is done in this order:
  * 1. Check the encoding that is set specifically to a LocalModule.
  * 2. Check the workspace default charset.
  * 3. If all the above fails, get ResourcesPlugin.getEncoding(), which actually gets the encoding from the system.
  * </pre>
  *
  * @param module an {@link IModule}.
  * @return The module's encoding.
  */
 public static String getModuleEncoding(IModule module) {
   String charset = null;
   try {
     if (module instanceof LocalModule) {
       IFile file = ((LocalModule) module).getFile();
       if (file != null) {
         String fileCharset = file.getCharset(true);
         if (fileCharset != null) {
           charset = fileCharset;
         }
       }
     }
   } catch (Throwable e) {
     // If there is any error, return the default
     IdeLog.logInfo(
         PHPEditorPlugin.getDefault(),
         "PHP encoding utils - Returning the default encoding due to an error (getModuleEncoding)", //$NON-NLS-1$
         e,
         PHPEditorPlugin.DEBUG_SCOPE);
   }
   if (charset == null) {
     try {
       IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
       charset = workspaceRoot.getDefaultCharset(true);
     } catch (CoreException ce) {
       charset = WorkbenchEncoding.getWorkbenchDefaultEncoding();
     }
   }
   if (charset == null) {
     // Use the system's encoding
     charset = ResourcesPlugin.getEncoding();
   }
   return charset;
 }
 /**
  * Extract the given zip file into the target folder on a Windows machine.
  *
  * @param sfxZip Self extracting 7zip file.
  * @param targetFolder
  * @return The status of that extraction result.
  */
 public static IStatus extractWin(IPath sfxZip, IPath targetFolder) {
   IStatus errorStatus =
       new Status(
           IStatus.ERROR,
           PortalUIPlugin.PLUGIN_ID,
           Messages.InstallerConfigurationProcessor_unableToExtractZip);
   if (!Platform.OS_WIN32.equals(Platform.getOS())) {
     IdeLog.logError(
         PortalUIPlugin.getDefault(),
         "Unable to extract the Zip file. A Windows OS extractor was called for a non-Windows platform.",
         new Exception()); //$NON-NLS-1$
     return errorStatus;
   }
   if (sfxZip == null || targetFolder == null) {
     IdeLog.logError(
         PortalUIPlugin.getDefault(),
         "Undefined zip file or target folder",
         new Exception()); //$NON-NLS-1$
     return errorStatus;
   }
   File destinationFolder = targetFolder.toFile();
   if (!destinationFolder.exists() && !destinationFolder.mkdirs()) {
     IdeLog.logError(
         PortalUIPlugin.getDefault(),
         "Failed to create destination directory " + destinationFolder,
         new Exception()); //$NON-NLS-1$
     return errorStatus;
   }
   // TODO Use ProcessUtil!
   ProcessBuilder processBuilder =
       new ProcessBuilder(
           sfxZip.toOSString(),
           "-o" + targetFolder.toOSString(), // $NON-NLS-1$
           "-y", //$NON-NLS-1$
           sfxZip.toOSString());
   processBuilder.directory(destinationFolder);
   processBuilder.redirectErrorStream(true);
   String output = null;
   try {
     Process process = processBuilder.start();
     InputStreamGobbler errorGobbler =
         new InputStreamGobbler(process.getErrorStream(), "\n", null); // $NON-NLS-1$
     InputStreamGobbler outputGobbler =
         new InputStreamGobbler(process.getInputStream(), "\n", null); // $NON-NLS-1$
     outputGobbler.start();
     errorGobbler.start();
     process.waitFor();
     outputGobbler.interrupt();
     errorGobbler.interrupt();
     outputGobbler.join();
     errorGobbler.join();
     output = outputGobbler.getResult();
     String errors = errorGobbler.getResult();
     int exitVal = process.exitValue();
     if (exitVal == 0) {
       return Status.OK_STATUS;
     }
     IdeLog.logError(
         PortalUIPlugin.getDefault(),
         "Zip extraction failed. The process returned " + exitVal,
         new Exception("Process output:\n" + errors)); // $NON-NLS-1$ //$NON-NLS-2$
     return errorStatus;
   } catch (Exception e) {
     IdeLog.logError(PortalUIPlugin.getDefault(), e);
     return errorStatus;
   } finally {
     if (output != null) {
       IdeLog.logInfo(PortalUIPlugin.getDefault(), output);
     }
   }
 }
Example #4
0
 /**
  * logInfo
  *
  * @deprecated Use IdeLog instead
  * @param message
  */
 public static void logInfo(String message) {
   IdeLog.logInfo(getDefault(), message, null);
 }
  /**
   * @param executableName name of the binary.
   * @param appendExtension ".exe" is appended for windows when searching the PATH.
   * @param searchLocations Common locations to search.
   * @param filter File filter
   * @param workingDirectory
   * @return
   */
  public static IPath find(
      String executableName,
      boolean appendExtension,
      List<IPath> searchLocations,
      FileFilter filter,
      IPath workingDirectory) {
    if (executableName == null) {
      return null;
    }

    // Grab PATH from shell if possible
    Map<String, String> env = ShellExecutable.getEnvironment(workingDirectory);
    String pathENV;
    if (env != null && env.containsKey(PATH)) {
      pathENV = PathUtil.convertPATH(env.get(PATH));
    } else {
      pathENV = System.getenv(PATH);
    }

    boolean infoLoggingEnabled = IdeLog.isInfoEnabled(CorePlugin.getDefault(), IDebugScopes.SHELL);
    // Grab PATH...
    String[] paths = pathENV.split(File.pathSeparator);
    if (infoLoggingEnabled) {
      IdeLog.logInfo(
          CorePlugin.getDefault(),
          MessageFormat.format(
              "Searching for {0} in PATH locations: {1}",
              executableName, StringUtil.join(", ", paths)),
          IDebugScopes.SHELL); // $NON-NLS-1$ //$NON-NLS-2$
    }
    // Now search the PATH locations
    for (String pathString : paths) {
      IPath path = Path.fromOSString(pathString).append(executableName);
      IPath result = findExecutable(path, appendExtension);
      if (result != null && (filter == null || filter.accept(result.toFile()))) {
        if (infoLoggingEnabled) {
          IdeLog.logInfo(
              CorePlugin.getDefault(),
              MessageFormat.format("Found executable on PATH: {0}", result),
              IDebugScopes.SHELL); // $NON-NLS-1$
        }
        return result;
      }
    }

    // Still no path. Let's try some default locations.
    if (searchLocations != null) {
      for (IPath location : searchLocations) {
        IPath result = findExecutable(location.append(executableName), appendExtension);
        if (result != null && (filter == null || filter.accept(result.toFile()))) {
          if (infoLoggingEnabled) {
            IdeLog.logInfo(
                CorePlugin.getDefault(),
                MessageFormat.format("Found executable at common location: {0}", result),
                IDebugScopes.SHELL); // $NON-NLS-1$
          }
          return result;
        }
      }
    }

    return null;
  }
Example #6
0
 private static void logTrace(String msg) {
   IdeLog.logInfo(CorePlugin.getDefault(), msg, IDebugScopes.BUILDER);
 }
  /**
   * Do the PYTHON installation.
   *
   * @param progressMonitor
   * @return A status indication of the process success or failure.
   */
  protected IStatus install(IProgressMonitor progressMonitor) {
    if (CollectionsUtil.isEmpty(downloadedPaths)) {
      String failureMessge = Messages.InstallProcessor_couldNotLocateInstaller;
      String err = NLS.bind(Messages.InstallProcessor_failedToInstall, PYTHON);
      displayMessageInUIThread(
          MessageDialog.ERROR,
          Messages.InstallProcessor_installationErrorTitle,
          err + ' ' + failureMessge);
      return new Status(IStatus.ERROR, PortalUIPlugin.PLUGIN_ID, err + ' ' + failureMessge);
    }
    SubMonitor subMonitor =
        SubMonitor.convert(
            progressMonitor,
            Messages.InstallProcessor_installerProgressInfo,
            IProgressMonitor.UNKNOWN);
    final Map<String, Object> installationAttributes = new HashMap<String, Object>();
    try {
      subMonitor.beginTask(
          NLS.bind(Messages.InstallProcessor_installingTaskName, PYTHON), IProgressMonitor.UNKNOWN);
      final String[] installDir = new String[1];
      Job installPythonDialog = new UIJob("Python installer options") // $NON-NLS-1$
          {
            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
              PythonInstallerOptionsDialog dialog = new PythonInstallerOptionsDialog();
              if (dialog.open() == Window.OK) {
                installationAttributes.putAll(dialog.getAttributes());
                return Status.OK_STATUS;
              }
              return Status.CANCEL_STATUS;
            }
          };
      installPythonDialog.schedule();
      try {
        installPythonDialog.join();
      } catch (InterruptedException e) {
      }
      IStatus result = installPythonDialog.getResult();
      if (!result.isOK()) {
        return result;
      }

      IStatus status = installPYTHON(installationAttributes);
      if (!status.isOK()) {
        return status;
      }
      IdeLog.logInfo(
          PortalUIPlugin.getDefault(),
          MessageFormat.format(
              "Successfully installed PYTHON into {0}. PYTHON installation completed.",
              installDir[0])); // $NON-NLS-1$
      // note that we called the finalizeInstallation from the installPYTHON Job.
      return Status.OK_STATUS;
    } catch (Exception e) {
      IdeLog.logError(
          PortalUIPlugin.getDefault(), "Error while installing PYTHON", e); // $NON-NLS-1$
      return new Status(
          IStatus.ERROR,
          PortalUIPlugin.PLUGIN_ID,
          NLS.bind(Messages.InstallProcessor_errorWhileInstalling, PYTHON));
    } finally {
      subMonitor.done();
    }
  }