コード例 #1
0
ファイル: FirefoxUtil.java プロジェクト: haoah/studio3
 /**
  * Install an extension using linked method
  *
  * @param extensionURL
  * @param extensionID
  * @param dir
  * @return boolean
  */
 public static boolean installLinkedExtension(URL extensionURL, String extensionID, File dir) {
   File file = new File(dir, extensionID);
   if (file.exists() && file.isDirectory()) {
     return true;
   }
   IPath base = CorePlugin.getDefault().getStateLocation().addTrailingSeparator();
   boolean result = installExtension(extensionURL, extensionID, base.toFile());
   if (result) {
     String linkedPath = base.append(extensionID).toOSString();
     FileOutputStream out = null;
     try {
       out = new FileOutputStream(file);
       out.write(linkedPath.getBytes());
     } catch (IOException e) {
       IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e);
     } finally {
       if (out != null) {
         try {
           out.close();
         } catch (IOException e) {
         }
       }
     }
   }
   return result;
 }
コード例 #2
0
ファイル: FirefoxUtil.java プロジェクト: haoah/studio3
  /**
   * Install an extension directly into profile location
   *
   * @param extensionURL
   * @param extensionID
   * @param dir
   * @return boolean
   */
  public static boolean installExtension(URL extensionURL, String extensionID, File dir) {
    dir = new File(dir, extensionID);
    if (dir.exists()) {
      return true;
    }
    if (!dir.mkdirs()) {
      return false;
    }

    File file = null;
    InputStream in = null;
    FileOutputStream out = null;
    try {
      file = File.createTempFile("ffe", ".zip"); // $NON-NLS-1$ //$NON-NLS-2$
      in = extensionURL.openStream();
      out = new FileOutputStream(file);
      byte[] buffer = new byte[0x1000];
      int n;
      while ((n = in.read(buffer)) > 0) {
        out.write(buffer, 0, n);
      }
    } catch (IOException e) {
      IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e);
      if (file != null) {
        if (!file.delete()) {
          file.deleteOnExit();
        }
      }
      return false;
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
        }
      }
      if (out != null) {
        try {
          out.close();
        } catch (IOException e) {
        }
      }
    }

    try {
      ZipUtil.extract(file, dir, null);
    } catch (IOException e) {
      IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e);
      return false;
    } finally {
      if (!file.delete()) {
        file.deleteOnExit();
      }
    }

    return true;
  }
コード例 #3
0
ファイル: FirefoxUtil.java プロジェクト: haoah/studio3
  /**
   * 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;
  }
コード例 #4
0
ファイル: JSIndexTest.java プロジェクト: celloman/studio3
  /** Test for APSTUD-4289. Make sure we don't allow duplicate user agents into the JS index */
  @Test
  public void testDuplicateUserAgents() {
    // create property
    PropertyElement property = new PropertyElement();
    property.setName("property");

    // add all user agents, twice
    IUserAgentManager manager = CorePlugin.getDefault().getUserAgentManager();

    for (IUserAgent userAgent : manager.getAllUserAgents()) {
      UserAgentElement uaElement = new UserAgentElement();
      uaElement.setPlatform(userAgent.getName());

      property.addUserAgent(uaElement);
      property.addUserAgent(uaElement);
    }

    // create type for property so we can write it to the index
    TypeElement type = new TypeElement();
    type.setName("Testing");
    type.addProperty(property);

    // write type and its properties
    JSIndexWriter writer = new JSIndexWriter();
    writer.writeType(getIndex(), type);

    // read property back again
    JSIndexReader reader = new JSIndexReader();
    List<PropertyElement> properties = reader.getProperties(getIndex(), property.getOwningType());

    // make sure we have only one of each user agent
    assertNotNull(properties);
    assertEquals(1, properties.size());
    assertEquals(manager.getAllUserAgents().length, properties.get(0).getUserAgents().size());
  }
コード例 #5
0
  /*
   * (non-Javadoc)
   * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
   */
  public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;

    ISavedState lastState =
        ResourcesPlugin.getWorkspace().addSaveParticipant(this, new WorkspaceSaveParticipant());
    if (lastState != null) {
      IPath location = lastState.lookup(new Path(SiteConnectionManager.STATE_FILENAME));
      if (location != null) {
        SiteConnectionManager.getInstance().loadState(getStateLocation().append(location));
      }
      location = lastState.lookup(new Path(DefaultSiteConnection.STATE_FILENAME));
      if (location != null) {
        DefaultSiteConnection.getInstance().loadState(getStateLocation().append(location));
      }
    }

    // For 1.5 compatibility
    lastState =
        ResourcesPlugin.getWorkspace()
            .addSaveParticipant(
                CorePlugin.getDefault(),
                new ISaveParticipant() {

                  public void doneSaving(ISaveContext context) {}

                  public void prepareToSave(ISaveContext context) throws CoreException {}

                  public void rollback(ISaveContext context) {}

                  public void saving(ISaveContext context) throws CoreException {}
                });
    if (lastState != null) {
      IPath location = lastState.lookup(new Path("save")); // $NON-NLS-1$
      if (location != null) {
        IPath absoluteLocation = CorePlugin.getDefault().getStateLocation().append(location);
        // only loads it once
        SiteConnectionManager.getInstance().loadState(absoluteLocation);
        File file = absoluteLocation.toFile();
        if (!file.renameTo(new File(absoluteLocation.toOSString() + ".bak"))) { // $NON-NLS-1$
          file.delete();
        }
      }
    }
  }
コード例 #6
0
ファイル: FirefoxUtil.java プロジェクト: haoah/studio3
 /**
  * Get version for the specified Firefox extension ID
  *
  * @param extensionID
  * @param profileDir
  * @return
  */
 public static String getExtensionVersion(String extensionID, IPath profileDir) {
   try {
     IPath dir = profileDir.append("extensions").append(extensionID); // $NON-NLS-1$
     InputStream rdfInputStream = null;
     if (dir.toFile().isFile()) {
       dir = Path.fromOSString(IOUtil.read(new FileInputStream(dir.toFile())));
     }
     if (dir.toFile().isDirectory()) {
       File installRdf = dir.append("install.rdf").toFile(); // $NON-NLS-1$
       if (installRdf.exists()) {
         rdfInputStream = new FileInputStream(installRdf);
       }
     } else if (dir.addFileExtension("xpi").toFile().isFile()) // $NON-NLS-1$
     {
       rdfInputStream =
           ZipUtil.openEntry(
               dir.addFileExtension("xpi").toFile(), // $NON-NLS-1$
               Path.fromPortableString("install.rdf")); // $NON-NLS-1$
     }
     if (rdfInputStream != null) {
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       DocumentBuilder parser = factory.newDocumentBuilder();
       Document document = parser.parse(rdfInputStream);
       Node node = document.getDocumentElement().getFirstChild();
       while (node != null) {
         if ("description".equals(node.getNodeName().toLowerCase()) // $NON-NLS-1$
             || "rdf:description".equals(node.getNodeName().toLowerCase())) { // $NON-NLS-1$
           NamedNodeMap attrs = node.getAttributes();
           Node about = attrs.getNamedItem("about"); // $NON-NLS-1$
           if (about == null) {
             about = attrs.getNamedItem("RDF:about"); // $NON-NLS-1$
           }
           if (about != null) {
             if ("urn:mozilla:install-manifest".equals(about.getNodeValue())) { // $NON-NLS-1$
               break;
             }
           }
         }
         node = node.getNextSibling();
       }
       if (node != null) {
         NamedNodeMap attrs = node.getAttributes();
         Node version = attrs.getNamedItem("em:version"); // $NON-NLS-1$
         if (version != null) {
           return version.getNodeValue();
         }
         node = node.getFirstChild();
       }
       while (node != null) {
         if ("em:version".equals(node.getNodeName().toLowerCase())) { // $NON-NLS-1$
           break;
         }
         node = node.getNextSibling();
       }
       if (node != null) {
         return node.getTextContent();
       }
     }
   } catch (Exception e) {
     IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e);
   }
   return null;
 }
コード例 #7
0
ファイル: FirefoxUtil.java プロジェクト: haoah/studio3
 /**
  * readProfiles
  *
  * @param file
  * @return File[]
  */
 protected static File[] readProfiles(File dir) {
   List<File> list = new ArrayList<File>();
   File profilesIni = new File(dir, "profiles.ini"); // $NON-NLS-1$
   if (profilesIni.exists()) {
     LineNumberReader r = null;
     try {
       r = new LineNumberReader(new FileReader(profilesIni));
       String line;
       Map<String, Map<String, String>> sections =
           new LinkedHashMap<String, Map<String, String>>();
       Map<String, String> last = null;
       Pattern sectionPattern = Pattern.compile(SECTION_PATTERN);
       Pattern valuePattern = Pattern.compile(VALUE_PATTERN);
       while ((line = r.readLine()) != null) {
         Matcher matcher = sectionPattern.matcher(line);
         if (matcher.find()) {
           last = new HashMap<String, String>();
           sections.put(matcher.group(1), last);
           continue;
         } else if (last == null) {
           continue;
         }
         matcher = valuePattern.matcher(line);
         if (matcher.find()) {
           last.put(matcher.group(1), matcher.group(2));
         }
       }
       for (Entry<String, Map<String, String>> entry : sections.entrySet()) {
         if (entry.getKey().startsWith("Profile")) { // $NON-NLS-1$
           Map<String, String> properties = entry.getValue();
           String path = (String) properties.get("Path"); // $NON-NLS-1$
           String isRelative = (String) properties.get("IsRelative"); // $NON-NLS-1$
           File profile;
           if (isRelative != null && "1".equals(isRelative)) { // $NON-NLS-1$
             profile = new File(dir, path);
           } else {
             profile = new File(path); // TODO: base64 decode ?
           }
           boolean def = properties.containsKey("Default"); // $NON-NLS-1$
           if (def) {
             list.add(0, profile);
           } else {
             list.add(profile);
           }
         }
       }
     } catch (IOException e) {
       IdeLog.logWarning(
           CorePlugin.getDefault(),
           MessageFormat.format("Reading '{0}' fails", profilesIni.getAbsolutePath()),
           e,
           null); //$NON-NLS-1$
     } finally {
       if (r != null) {
         try {
           r.close();
         } catch (IOException ignore) {
         }
       }
     }
   }
   return list.toArray(new File[list.size()]);
 }
 /*
  * (non-Javadoc)
  * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
  */
 public void stop(BundleContext context) throws Exception {
   ResourcesPlugin.getWorkspace().removeSaveParticipant(this);
   ResourcesPlugin.getWorkspace().removeSaveParticipant(CorePlugin.getDefault());
   plugin = null;
   super.stop(context);
 }
  /**
   * @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;
  }
コード例 #10
0
 private static void logTrace(String msg) {
   IdeLog.logInfo(CorePlugin.getDefault(), msg, IDebugScopes.BUILDER);
 }
コード例 #11
0
 protected boolean traceLoggingEnabled() {
   return IdeLog.isTraceEnabled(CorePlugin.getDefault(), IDebugScopes.BUILDER);
 }