Ejemplo n.º 1
0
  public void testCopyFromNonReadableDirectory() throws Exception {
    // We can use source.setReadable(false) when we decide to use java 1.6
    if (!Platform.OS_WIN32.equals(Platform.getOS())) {
      URL resourceURL = Platform.getBundle(BUNDLE_ID).getEntry(RESOURCE_DIR);
      File resourceFolder = ResourceUtil.resourcePathToFile(resourceURL);

      File source = new File(resourceFolder, TEST_DIR);
      File dest = new File(tempDir, "tempdir");

      try {
        Runtime.getRuntime()
            .exec(new String[] {"chmod", "333", source.getAbsolutePath()})
            .waitFor(); //$NON-NLS-1$
        IOUtil.copyDirectory(source, dest);
        assertDirectory(source, dest);
        fail("Expected directories to not match");
      } catch (AssertionError ae) {
        // expected
      } finally {
        FileUtil.deleteRecursively(dest);
        Runtime.getRuntime()
            .exec(new String[] {"chmod", "755", source.getAbsolutePath()})
            .waitFor(); //$NON-NLS-1$
      }
    }
  }
  public static boolean isExecutable(IPath path) {
    if (path == null) {
      return false;
    }
    File file = path.toFile();
    if (file == null || !file.exists() || file.isDirectory()) {
      return false;
    }

    // OK, file exists
    try {
      Method m = File.class.getMethod("canExecute"); // $NON-NLS-1$
      if (m != null) {
        return (Boolean) m.invoke(file);
      }
    } catch (Exception e) {
    }

    // File.canExecute() doesn't exist; do our best to determine if file is executable...
    if (Platform.OS_WIN32.equals(Platform.getOS())) {
      return true;
    }
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
    return fileStore.fetchInfo().getAttribute(EFS.ATTRIBUTE_EXECUTABLE);
  }
Ejemplo n.º 3
0
 static {
   // It appears this call is no longer necessary on Windows as the SWT Mozilla in Eclipse 3.5+ is
   // performing similar
   // initialization tasks, and calling it was causing a crash when initializing the profile
   if (!Platform.OS_WIN32.equals(Platform.getOS())) {
     FirefoxExtensionsSupport.init();
   }
 }
  private void internalSetAuthCredentials(
      ICredentials credentials, URI link, String realm, boolean persist)
      throws CredentialsException {

    /* Store Credentials in In-Memory Store */
    if (!persist) {
      fInMemoryStore.put(toCacheKey(link, realm), credentials);
    }

    /* Store Credentials in secure Storage */
    else {
      ISecurePreferences securePreferences = getSecurePreferences();

      /* Check if Bundle is Stopped */
      if (securePreferences == null) return;

      /* Store in Equinox Security Storage */
      ISecurePreferences allFeedsPreferences = securePreferences.node(SECURE_FEED_NODE);
      ISecurePreferences feedPreferences =
          allFeedsPreferences.node(EncodingUtils.encodeSlashes(link.toString()));
      ISecurePreferences realmPreference =
          feedPreferences.node(EncodingUtils.encodeSlashes(realm != null ? realm : REALM));

      IPreferenceScope globalScope = Owl.getPreferenceService().getGlobalScope();

      /* OS Password is only supported on Windows and Mac */
      boolean useOSPassword = globalScope.getBoolean(DefaultPreferences.USE_OS_PASSWORD);
      if (!Platform.OS_WIN32.equals(Platform.getOS())
          && !Platform.OS_MACOSX.equals(Platform.getOS())) useOSPassword = false;

      boolean encryptPW =
          useOSPassword || globalScope.getBoolean(DefaultPreferences.USE_MASTER_PASSWORD);
      try {
        if (credentials.getUsername() != null)
          realmPreference.put(USERNAME, credentials.getUsername(), encryptPW);

        if (credentials.getPassword() != null)
          realmPreference.put(PASSWORD, credentials.getPassword(), encryptPW);

        if (credentials.getDomain() != null)
          realmPreference.put(DOMAIN, credentials.getDomain(), encryptPW);

        realmPreference.flush(); // Flush to disk early
      } catch (StorageException e) {
        throw new CredentialsException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
      } catch (IOException e) {
        throw new CredentialsException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
      }
    }

    /* Uncache */
    removeUnprotected(link, realm);
  }
Ejemplo n.º 5
0
 private IStatus doCommit(String commitMessage) {
   if (Platform.OS_WIN32.equals(Platform.getOS())) {
     commitMessage = commitMessage.replace("\"", "\\\""); // $NON-NLS-1$ //$NON-NLS-2$
   }
   return repository.execute(
       GitRepository.ReadWrite.WRITE,
       repository.workingDirectory(),
       ShellExecutable.getEnvironment(repository.workingDirectory()),
       "commit",
       "-m",
       commitMessage); //$NON-NLS-1$ //$NON-NLS-2$
 }
Ejemplo n.º 6
0
 public String getCompleteProgramArguments(String os) {
   if (Platform.OS_WIN32.equals(os)) {
     return getCompleteArgs(getProgramArguments(L_ARGS_WIN32), fProgramArgs);
   } else if (Platform.OS_LINUX.equals(os)) {
     return getCompleteArgs(getProgramArguments(L_ARGS_LINUX), fProgramArgs);
   } else if (Platform.OS_MACOSX.equals(os)) {
     return getCompleteArgs(getProgramArguments(L_ARGS_MACOS), fProgramArgs);
   } else if (Platform.OS_SOLARIS.equals(os)) {
     return getCompleteArgs(getProgramArguments(L_ARGS_SOLAR), fProgramArgs);
   } else {
     return getProgramArguments(L_ARGS_ALL);
   }
 }
  private ISecurePreferences getSecurePreferences() {
    if (!InternalOwl.IS_ECLIPSE) {
      IPreferenceScope prefs = Owl.getPreferenceService().getGlobalScope();
      boolean useOSPasswordProvider = prefs.getBoolean(DefaultPreferences.USE_OS_PASSWORD);

      /* Disable OS Password if Master Password shall be used */
      if (prefs.getBoolean(DefaultPreferences.USE_MASTER_PASSWORD)) useOSPasswordProvider = false;

      /* Try storing credentials in profile folder */
      try {
        Activator activator = Activator.getDefault();

        /* Check if Bundle is Stopped */
        if (activator == null) return null;

        IPath stateLocation = activator.getStateLocation();
        stateLocation = stateLocation.append(SECURE_STORAGE_FILE);
        URL location = stateLocation.toFile().toURL();
        Map<String, String> options = null;

        /* Use OS dependent password provider if available */
        if (useOSPasswordProvider) {
          if (Platform.OS_WIN32.equals(Platform.getOS())) {
            options = new HashMap<String, String>();
            options.put(IProviderHints.REQUIRED_MODULE_ID, WIN_PW_PROVIDER_ID);
          } else if (Platform.OS_MACOSX.equals(Platform.getOS())) {
            options = new HashMap<String, String>();
            options.put(IProviderHints.REQUIRED_MODULE_ID, MACOS_PW_PROVIDER_ID);
          }
        }

        /* Use RSSOwl password provider */
        else {
          options = new HashMap<String, String>();
          options.put(IProviderHints.REQUIRED_MODULE_ID, RSSOWL_PW_PROVIDER_ID);
        }

        return SecurePreferencesFactory.open(location, options);
      } catch (MalformedURLException e) {
        Activator.safeLogError(e.getMessage(), e);
      } catch (IllegalStateException e1) {
        Activator.safeLogError(e1.getMessage(), e1);
      } catch (IOException e2) {
        Activator.safeLogError(e2.getMessage(), e2);
      }
    }

    /* Fallback to default location */
    return SecurePreferencesFactory.getDefault();
  }
  private static IPath findExecutable(IPath basename, boolean appendExtension) {
    if (Platform.OS_WIN32.equals(Platform.getOS()) && appendExtension) {
      String[] extensions = System.getenv(PATHEXT).split(File.pathSeparator);
      for (String ext : extensions) {
        if (ext.length() > 0 && ext.charAt(0) == '.') {
          ext = ext.substring(1);
        }
        IPath pathWithExt = basename.addFileExtension(ext);
        if (isExecutable(pathWithExt)) {
          return pathWithExt;
        }
      }

    } else if (isExecutable(basename)) {
      return basename;
    }
    return null;
  }
  private static void setExploreCommands() {
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
      exploreFolderCommandArray =
          new String[] {
            "/usr/bin/open", "-a", "/System/Library/CoreServices/Finder.app", ""
          }; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
      exploreFolderCommand = ""; // $NON-NLS-1$
    } else if (Platform.OS_WIN32.equals(Platform.getOS())) {
      exploreFolderCommandArray = new String[5];
      exploreFolderCommandArray[0] = "cmd"; // $NON-NLS-1$
      exploreFolderCommandArray[1] = "/C"; // $NON-NLS-1$
      exploreFolderCommandArray[2] = "start"; // $NON-NLS-1$
      exploreFolderCommandArray[3] = "explorer"; // $NON-NLS-1$

      exploreFileCommandArray = new String[6];
      exploreFileCommandArray[0] = "cmd"; // $NON-NLS-1$
      exploreFileCommandArray[1] = "/C"; // $NON-NLS-1$
      exploreFileCommandArray[2] = "start"; // $NON-NLS-1$
      exploreFileCommandArray[3] = "explorer"; // $NON-NLS-1$
      exploreFileCommandArray[4] = "/select,"; // $NON-NLS-1$

      exploreFolderCommand =
          "cmd /C start explorer \"" //$NON-NLS-1$
              + PATH
              + "\""; //$NON-NLS-1$
      exploreFileCommand =
          "cmd /C start explorer /select,\"" //$NON-NLS-1$
              + PATH
              + "\""; //$NON-NLS-1$
    } else if (Platform.OS_LINUX.equals(Platform.getOS())) {

      if (new File("/usr/bin/nautilus").exists()) { // $NON-NLS-1$
        exploreFolderCommandArray = new String[3];
        exploreFolderCommandArray[0] = "/usr/bin/nautilus"; // $NON-NLS-1$
        exploreFolderCommandArray[1] = "--no-desktop"; // $NON-NLS-1$
        exploreFolderCommand = ""; // $NON-NLS-1$
      } else if (new File("/usr/bin/konqueror").exists()) { // $NON-NLS-1$
        exploreFolderCommandArray = new String[2];
        exploreFolderCommandArray[0] = "/usr/bin/konqueror"; // $NON-NLS-1$
        exploreFolderCommand = ""; // $NON-NLS-1$
      }
      exploreFileCommand = exploreFolderCommand;
    }
  }
Ejemplo n.º 10
0
  private static IResource findMember(IContainer container, String path) {
    // even though the filesystem is case-insensitive on Windows, Eclipse's Resource
    // APIs only find files in a case-sensitive manner.  since Robot does not do
    // this at runtime, we'll need to lessen the restriction by doing a more
    // expensive segment-by-segment comparison here
    if (Platform.OS_WIN32.equals(Platform.getOS())) {
      List<String> segments = getPathSegments(path);
      while (!segments.isEmpty()) {
        String nextSegment = segments.remove(0);

        if ("..".equals(nextSegment)) {
          container = container.getParent();
        } else if (".".equals(nextSegment)) {
          continue;
        } else {
          try {
            IResource[] members = container.members();
            for (IResource member : members) {
              if (nextSegment.equalsIgnoreCase(member.getName())) {
                if (member instanceof IContainer) {
                  // found the next folder in the path, continue
                  container = (IContainer) member;
                  break;
                } else if (segments.isEmpty()) {
                  // leaf node, this is the file we're looking for
                  return member;
                }
              }
            }
          } catch (CoreException e) {
            // do nothing, we'll just return a null for this path below
          }
        }
      }

      // error condition - for a malformed or non-existent path we return nothing
      return null;
    } else {
      // non-windows OS - simple Eclipse API works well
      return container.findMember(path);
    }
  }
  public static boolean isGemInstallable() {
    if (!Platform.OS_WIN32.equals(Platform.getOS())) {
      // TODO This code is pretty blase about possible nulls/errors/etc. Should probably try and
      // make it
      // more bullet-proof.

      // grab the path to the gem executable dir
      IPath gemBin = find("gem", true, null); // $NON-NLS-1$
      String output =
          ProcessUtil.outputForCommand(gemBin.toOSString(), null, "environment"); // $NON-NLS-1$
      final String searchString = "EXECUTABLE DIRECTORY:"; // $NON-NLS-1$
      int index = output.indexOf(searchString);
      output = output.substring(index + searchString.length());
      // find first newline...
      output = output.split("\r\n|\r|\n")[0].trim(); // $NON-NLS-1$
      // Now see if user has rights to write to this dir to determine if we need to run under sudo
      return new File(output).canWrite();
    }
    return true;
  }
Ejemplo n.º 12
0
 public static ImageCapture getImageCapture() {
   if (instance == null) {
     if (Platform.OS_WIN32.equals(Platform.getOS())) instance = new Win32ImageCapture();
     else if (Platform.WS_GTK.equals(Platform.getWS())) {
       if (Platform.ARCH_IA64.equals(Platform.getOSArch())
           || Platform.ARCH_X86_64.equals(Platform.getOSArch()))
         instance = new org.eclipse.ve.internal.swt.targetvm.unix.bits64.ImageCapture();
       else instance = new org.eclipse.ve.internal.swt.targetvm.unix.ImageCapture();
     } else if (Platform.OS_MACOSX.equals(Platform.getOS())) {
       if (Platform.WS_COCOA.equals(Platform.getWS())) {
         instance = new org.eclipse.ve.internal.swt.targetvm.macosx.cocoa.ImageCapture();
       } else if (Platform.WS_CARBON.equals(Platform.getWS())) {
         instance = new org.eclipse.ve.internal.swt.targetvm.macosx.ImageCapture();
       } else {
         throw new UnsupportedOperationException(Platform.getOS());
       }
     } else {
       throw new UnsupportedOperationException(Platform.getOS());
     }
   }
   return instance;
 }
Ejemplo n.º 13
0
  private static OS create() {
    String os = Platform.getOS();
    String ws = Platform.getWS();
    String arch = Platform.getOSArch();

    if (Platform.OS_WIN32.equals(os)) {
      if (Platform.ARCH_X86_64.equals(arch)) {
        return new Win64(ws);
      }

      return new Win32(ws, arch);
    }

    if (Platform.OS_MACOSX.equals(os)) {
      return new Mac(ws, arch);
    }

    if (Platform.OS_LINUX.equals(os)) {
      return new Linux(ws, arch);
    }

    throw new IllegalStateException("Operating system not supported: " + os);
  }
 /**
  * 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);
     }
   }
 }
Ejemplo n.º 15
0
 public static boolean isWindows() {
   return Platform.OS_WIN32.equals(Platform.getOS());
 }
Ejemplo n.º 16
0
  /**
   * Install Python on the machine.<br>
   * The configuration will grab the installer from the given attributes.<br>
   * We expect an array of attributes with the same structure described at {@link
   * #loadAttributes(Object)}.
   *
   * @param attributes First - A string array of size 1, which contains the URL for the Python
   *     installer (.exe). Second - (optional) map of additional attributes.
   * @see
   *     com.aptana.configurations.processor.AbstractConfigurationProcessor#configure(org.eclipse.core.runtime.IProgressMonitor,
   *     java.lang.Object)
   * @see #loadAttributes(Object)
   */
  @Override
  public ConfigurationStatus configure(IProgressMonitor progressMonitor, Object attributes) {
    // Get a Class lock to avoid multiple installations at the same time even with multiple
    // instances of this
    // processor
    synchronized (this.getClass()) {
      if (installationInProgress) {
        return configurationStatus;
      }
      installationInProgress = true;
    }
    if (!Platform.OS_WIN32.equals(Platform.getOS())) {
      String err = "The Python installer processor is designed to work on Windows."; // $NON-NLS-1$
      IdeLog.logError(PortalUIPlugin.getDefault(), new Exception(err));
      applyErrorAttributes(err);
      installationInProgress = false;
      return configurationStatus;
    }
    try {
      configurationStatus.removeAttribute(CONFIG_ATTR);
      clearErrorAttributes();

      // Load the installer's attributes
      IStatus loadingStatus = loadAttributes(attributes);
      if (!loadingStatus.isOK()) {
        String message = loadingStatus.getMessage();
        applyErrorAttributes(message);
        IdeLog.logError(PortalUIPlugin.getDefault(), new Exception(message));
        return configurationStatus;
      }

      // Check that we got the expected single install URL
      if (urls.length != 1) {
        // structure error
        String err =
            NLS.bind(
                Messages.InstallProcessor_wrongNumberOfInstallLinks,
                new Object[] {PYTHON, 1, urls.length});
        applyErrorAttributes(err);
        IdeLog.logError(PortalUIPlugin.getDefault(), new Exception(err));
        return configurationStatus;
      }
      // Try to get the default install directory from the optional attributes
      installDir = attributesMap.get(INSTALL_DIR_ATTRIBUTE);
      if (installDir == null) {
        installDir = PYTHON_DEFAULT_INSTALL_DIR;
      }
      // Start the installation...
      configurationStatus.setStatus(ConfigurationStatus.PROCESSING);
      IStatus status = download(urls, progressMonitor);
      if (status.isOK()) {
        status = install(progressMonitor);
      }
      switch (status.getSeverity()) {
        case IStatus.OK:
        case IStatus.INFO:
        case IStatus.WARNING:
          displayMessageInUIThread(
              MessageDialog.INFORMATION,
              NLS.bind(Messages.InstallProcessor_installerTitle, PYTHON),
              NLS.bind(Messages.InstallProcessor_installationSuccessful, PYTHON));
          configurationStatus.setStatus(ConfigurationStatus.OK);
          break;
        case IStatus.ERROR:
          configurationStatus.setStatus(ConfigurationStatus.ERROR);
          break;
        case IStatus.CANCEL:
          configurationStatus.setStatus(ConfigurationStatus.INCOMPLETE);
          break;
        default:
          configurationStatus.setStatus(ConfigurationStatus.UNKNOWN);
      }
      return configurationStatus;
    } finally {
      synchronized (this.getClass()) {
        installationInProgress = false;
      }
    }
  }