protected void appendSpaceBefore(ICSSNode node, String toAppend, StringBuffer source) {
    if (node == null || source == null) return;
    if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
      return; // for not formatting case on cleanup action

    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (toAppend != null
        && toAppend.startsWith("{")
        && preferences.getBoolean(
            CSSCorePreferenceNames.WRAPPING_NEWLINE_ON_OPEN_BRACE)) { // $NON-NLS-1$
      source.append(getLineDelimiter(node));
      source.append(getIndent(node));
      return;
    } else if (
    /* ! mgr.isOnePropertyPerLine() && */ preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0
        && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR)
            || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
      int n = getLastLineLength(node, source);
      int append =
          (toAppend != null)
              ? TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, toAppend, 0)[0]
              : 0;
      if (toAppend != null) append = (append < 0) ? toAppend.length() : append;
      if (n + append + 1 > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
        source.append(getLineDelimiter(node));
        source.append(getIndent(node));
        source.append(getIndentString());
        return;
      }
    }
    source.append(" "); // $NON-NLS-1$
  }
  public WorkspacePreferences() {
    super("Workspace"); // $NON-NLS-1$
    this.preferences = ResourcesPlugin.getPlugin().getPluginPreferences();

    final String version = preferences.getString(ICoreConstants.PREF_VERSION_KEY);
    if (!ICoreConstants.PREF_VERSION.equals(version)) upgradeVersion(version);

    // initialize cached preferences (for better performance)
    super.setAutoBuilding(preferences.getBoolean(ResourcesPlugin.PREF_AUTO_BUILDING));
    super.setSnapshotInterval(preferences.getInt(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL));
    super.setMaxBuildIterations(preferences.getInt(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS));
    super.setApplyFileStatePolicy(
        preferences.getBoolean(ResourcesPlugin.PREF_APPLY_FILE_STATE_POLICY));
    super.setMaxFileStates(preferences.getInt(ResourcesPlugin.PREF_MAX_FILE_STATES));
    super.setMaxFileStateSize(preferences.getLong(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE));
    super.setFileStateLongevity(preferences.getLong(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY));
    super.setOperationsPerSnapshot(
        preferences.getInt(PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT));
    super.setDeltaExpiration(preferences.getLong(PreferenceInitializer.PREF_DELTA_EXPIRATION));

    // This property listener ensures we are being updated properly when changes
    // are done directly to the preference store.
    preferences.addPropertyChangeListener(
        new Preferences.IPropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            synchronizeWithPreferences(event.getProperty());
          }
        });
  }
 protected void synchronizeWithPreferences(String property) {
   // do not use the value in the event - may be a string instead
   // of the expected type. Retrieve it from the preferences store
   // using the type-specific method
   if (property.equals(ResourcesPlugin.PREF_AUTO_BUILDING))
     super.setAutoBuilding(preferences.getBoolean(ResourcesPlugin.PREF_AUTO_BUILDING));
   else if (property.equals(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL))
     super.setSnapshotInterval(preferences.getLong(ResourcesPlugin.PREF_SNAPSHOT_INTERVAL));
   else if (property.equals(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS))
     super.setMaxBuildIterations(preferences.getInt(ResourcesPlugin.PREF_MAX_BUILD_ITERATIONS));
   else if (property.equals(ResourcesPlugin.PREF_APPLY_FILE_STATE_POLICY))
     super.setApplyFileStatePolicy(
         preferences.getBoolean(ResourcesPlugin.PREF_APPLY_FILE_STATE_POLICY));
   else if (property.equals(ResourcesPlugin.PREF_MAX_FILE_STATES))
     super.setMaxFileStates(preferences.getInt(ResourcesPlugin.PREF_MAX_FILE_STATES));
   else if (property.equals(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE))
     super.setMaxFileStateSize(preferences.getLong(ResourcesPlugin.PREF_MAX_FILE_STATE_SIZE));
   else if (property.equals(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY))
     super.setFileStateLongevity(preferences.getLong(ResourcesPlugin.PREF_FILE_STATE_LONGEVITY));
   else if (property.equals(PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT))
     super.setOperationsPerSnapshot(
         preferences.getInt(PreferenceInitializer.PREF_OPERATIONS_PER_SNAPSHOT));
   else if (property.equals(PreferenceInitializer.PREF_DELTA_EXPIRATION))
     super.setDeltaExpiration(preferences.getLong(PreferenceInitializer.PREF_DELTA_EXPIRATION));
 }
  /**
   * Tests reading a 3.0.2 install with a mix of classic and OSGi plug-ins.
   *
   * @throws Exception
   */
  public void testClassicPlugins() throws Exception {
    // extract the 3.0.2 skeleton
    IPath location = extractClassicPlugins();

    // the new way
    ITargetDefinition definition = getNewTarget();
    ITargetLocation container = getTargetService().newDirectoryLocation(location.toOSString());
    definition.setTargetLocations(new ITargetLocation[] {container});
    Set urls = getAllBundleURLs(definition);
    assertTrue("Must be bundles", urls.size() > 0);

    Preferences store = PDECore.getDefault().getPluginPreferences();
    boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
    try {
      store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
      // the old way
      URL[] pluginPaths = PluginPathFinder.getPluginPaths(location.toOSString());
      for (int i = 0; i < pluginPaths.length; i++) {
        URL url = pluginPaths[i];
        if (!urls.contains(url)) {
          System.err.println(url.toString());
        }
      }
      assertEquals("Wrong number of bundles", pluginPaths.length, urls.size());
    } finally {
      store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
    }
  }
예제 #5
0
 /**
  * Checks for changes to the PREF_AUTO_UPDATE property.
  *
  * @see Preferences.IPropertyChangeListener#propertyChange(Preferences.PropertyChangeEvent)
  */
 public void propertyChange(PropertyChangeEvent event) {
   String property = event.getProperty();
   if (ResourcesPlugin.PREF_AUTO_REFRESH.equals(property)) {
     Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
     boolean autoRefresh = preferences.getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH);
     manageAutoRefresh(autoRefresh);
   }
 }
예제 #6
0
  /**
   * Initializes the refresh manager. This does a minimal amount of work if auto-refresh is turned
   * off.
   */
  public void startup(IProgressMonitor monitor) {
    Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
    preferences.addPropertyChangeListener(this);

    refreshJob = new RefreshJob();
    monitors = new MonitorManager(workspace, this);
    boolean autoRefresh = preferences.getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH);
    if (autoRefresh) manageAutoRefresh(autoRefresh);
  }
 private void upgradeVersion(String oldVersion) {
   if (oldVersion.length() == 0) {
     // only need to convert the build order if we are not using the default order
     if (!preferences.getBoolean(ResourcesPlugin.PREF_DEFAULT_BUILD_ORDER)) {
       String oldOrder = preferences.getString(ResourcesPlugin.PREF_BUILD_ORDER);
       setBuildOrder(convertStringToStringArray(oldOrder, ":")); // $NON-NLS-1$
     }
   }
   preferences.setValue(ICoreConstants.PREF_VERSION_KEY, ICoreConstants.PREF_VERSION);
 }
  /**
   * Tests that a bundle directory container is equivalent to scanning locations when it uses a
   * variable to specify its location.
   *
   * @throws Exception
   */
  public void testVariableDirectoryBundleContainer() throws Exception {
    // the new way
    ITargetDefinition definition = getNewTarget();
    ITargetLocation container = getTargetService().newDirectoryLocation("${eclipse_home}/plugins");
    definition.setTargetLocations(new ITargetLocation[] {container});
    Set urls = getAllBundleURLs(definition);

    Preferences store = PDECore.getDefault().getPluginPreferences();
    boolean restore = store.getBoolean(ICoreConstants.TARGET_PLATFORM_REALIZATION);
    try {
      store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, false);
      // the old way
      URL[] pluginPaths = PluginPathFinder.getPluginPaths(TargetPlatform.getDefaultLocation());
      assertEquals("Should have same number of bundles", pluginPaths.length, urls.size());
      for (int i = 0; i < pluginPaths.length; i++) {
        URL url = pluginPaths[i];
        assertTrue("Missing plug-in " + url.toString(), urls.contains(url));
      }
    } finally {
      store.setValue(ICoreConstants.TARGET_PLATFORM_REALIZATION, restore);
    }
  }
예제 #9
0
 /** Read preferences */
 protected void readPreferences() {
   Preferences pref = CommonPlugin.getDefault().getPluginPreferences();
   forceEcho = pref.getBoolean(IDs.P_ECHO_FORCE);
 }
 /** @see org.eclipse.core.resources.IWorkspaceDescription#getBuildOrder() */
 public String[] getBuildOrder() {
   boolean defaultBuildOrder = preferences.getBoolean(ResourcesPlugin.PREF_DEFAULT_BUILD_ORDER);
   if (defaultBuildOrder) return null;
   return convertStringToStringArray(
       preferences.getString(ResourcesPlugin.PREF_BUILD_ORDER), PROJECT_SEPARATOR);
 }
  protected void appendDelimBefore(ICSSNode node, CompoundRegion toAppend, StringBuffer source) {
    if (node == null || source == null) return;
    if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
      return; // for not formatting case on cleanup action
    String delim = getLineDelimiter(node);

    boolean needIndent = !(node instanceof ICSSStyleSheet);
    if (toAppend == null) {
      source.append(delim);
      source.append(getIndent(node));
      if (needIndent) source.append(getIndentString());
    } else {
      String type = toAppend.getType();
      if (type == CSSRegionContexts.CSS_COMMENT) {
        RegionIterator it =
            new RegionIterator(toAppend.getDocumentRegion(), toAppend.getTextRegion());
        it.prev();
        ITextRegion prev = it.prev();
        int[] result = null;
        if (prev == null
            || (prev.getType() == CSSRegionContexts.CSS_S
                && (result =
                            TextUtilities.indexOf(
                                DefaultLineTracker.DELIMITERS,
                                it.getStructuredDocumentRegion().getText(prev),
                                0))
                        [0]
                    >= 0)) {
          // Collapse to one empty line if there's more than one.
          int offset = result[0] + DefaultLineTracker.DELIMITERS[result[1]].length();
          if (offset < it.getStructuredDocumentRegion().getText(prev).length()) {
            if (TextUtilities.indexOf(
                    DefaultLineTracker.DELIMITERS,
                    it.getStructuredDocumentRegion().getText(prev),
                    offset)[0]
                >= 0) {
              source.append(delim);
            }
          }
          source.append(delim);
          source.append(getIndent(node));
          if (needIndent) source.append(getIndentString());
        } else if (prev.getType() == CSSRegionContexts.CSS_COMMENT) {
          String fullText = toAppend.getDocumentRegion().getFullText(prev);
          String trimmedText = toAppend.getDocumentRegion().getText(prev);
          String whiteSpaces = ""; // $NON-NLS-1$
          if (fullText != null && trimmedText != null)
            whiteSpaces = fullText.substring(trimmedText.length());
          int[] delimiterFound =
              TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, whiteSpaces, 0);
          if (delimiterFound[0] != -1) {
            source.append(delim);
          } else {
            appendSpaceBefore(node, toAppend.getText(), source);

            /*If two comments can't be adjusted in one line(combined length exceeds line width),
             * a tab is also appended along with next line delimiter , we need to remove that.
             */
            if (source.toString().endsWith(getIndentString())) {
              source.delete((source.length() - getIndentString().length()), source.length());
            }
          }
        } else {
          appendSpaceBefore(node, toAppend.getText(), source);
        }
      } else if (type == CSSRegionContexts.CSS_DELIMITER
          || type == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
        RegionIterator it =
            new RegionIterator(toAppend.getDocumentRegion(), toAppend.getTextRegion());
        it.prev();
        ITextRegion prev = it.prev();

        Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();

        if (prev.getType() == CSSRegionContexts.CSS_S
            && TextUtilities.indexOf(
                    DefaultLineTracker.DELIMITERS,
                    it.getStructuredDocumentRegion().getText(prev),
                    0)[0]
                >= 0) {
          source.append(delim);
          source.append(getIndent(node));
          if (needIndent) source.append(getIndentString());
        } else if (preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0
            && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR)
                || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
          int length = getLastLineLength(node, source);
          int append = 1;
          if (length + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
            source.append(getLineDelimiter(node));
            source.append(getIndent(node));
            if (needIndent) source.append(getIndentString());
          }
        }
      } else if (type == CSSRegionContexts.CSS_RBRACE || type == CSSRegionContexts.CSS_LBRACE) {
        source.append(delim);
        source.append(getIndent(node));
      } else {
        source.append(delim);
        source.append(getIndent(node));
        if (needIndent) source.append(getIndentString());
      }
    }
  }
  protected String decoratedRegion(CompoundRegion region, int type, CSSCleanupStrategy stgy) {
    if (isFormat()) return region.getText();

    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();

    String text = null;
    if (!stgy.isFormatSource()) text = region.getFullText();
    else text = region.getText();

    String regionType = region.getType();
    if (regionType == CSSRegionContexts.CSS_URI
        || regionType == CSSRegionContexts.CSS_DECLARATION_VALUE_URI) {
      String uri = CSSLinkConverter.stripFunc(text);

      boolean prefIsUpper =
          preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER)
              == CSSCorePreferenceNames.UPPER;
      boolean upper =
          (type == 0)
              ? prefIsUpper
              : ((type == 1)
                  ? preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME)
                      == CSSCorePreferenceNames.UPPER
                  : preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE)
                      == CSSCorePreferenceNames.UPPER);
      String func = text.substring(0, 4);
      if (isCleanup()) {
        upper =
            ((type == 0)
                    ? stgy.getIdentCase()
                    : ((type == 1) ? stgy.getPropNameCase() : stgy.getPropValueCase()))
                == CSSCleanupStrategy.UPPER;
        func =
            ((type == 0)
                        ? stgy.getIdentCase()
                        : ((type == 1) ? stgy.getPropNameCase() : stgy.getPropValueCase()))
                    == CSSCleanupStrategy.ASIS
                ? text.substring(0, 4)
                : (upper ? "URL(" : "url("); // $NON-NLS-2$//$NON-NLS-1$
      }
      if ((!isCleanup() && preferences.getBoolean(CSSCorePreferenceNames.FORMAT_QUOTE_IN_URI))
          || (isCleanup() && stgy.isQuoteValues())) {
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        quote = CSSUtil.detectQuote(uri, quote);
        text = func + quote + uri + quote + ")"; // $NON-NLS-1$
      } else if (isCleanup() && !stgy.isQuoteValues()) {
        text = func + CSSLinkConverter.removeFunc(text) + ")"; // $NON-NLS-1$
      } else {
        text = func + uri + ")"; // $NON-NLS-1$
      }
    } else if (region.getType() == CSSRegionContexts.CSS_STRING
        && (!isCleanup() || stgy.isQuoteValues())) {
      String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
      // begginning
      if (!text.startsWith(quote)) {
        if (text.startsWith("\"") || text.startsWith("\'")) // $NON-NLS-1$ //$NON-NLS-2$
        text = quote + text.substring(1);
        else text = quote + text;
      }
      // ending
      if (!text.endsWith(quote)) {
        if (text.endsWith("\"") || text.endsWith("\'")) // $NON-NLS-1$ //$NON-NLS-2$
        text = text.substring(0, text.length() - 1) + quote;
        else text = text + quote;
      }
    }
    return text;
  }
  protected void appendSpaceBefore(ICSSNode node, CompoundRegion toAppend, StringBuffer source) {
    if (node == null || toAppend == null || source == null) return;
    if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
      return; // for not formatting case on cleanup action
    String type = toAppend.getType();

    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();

    boolean needIndent = !(node instanceof ICSSStyleSheet);
    if (type == CSSRegionContexts.CSS_COMMENT) {
      // check whether previous region is 'S' and has CR-LF
      String delim = getLineDelimiter(node);
      RegionIterator it =
          new RegionIterator(toAppend.getDocumentRegion(), toAppend.getTextRegion());
      it.prev();
      ITextRegion prev = it.prev();
      // bug390904
      if (prev.getType() == CSSRegionContexts.CSS_LBRACE
          && TextUtilities.indexOf(
                  DefaultLineTracker.DELIMITERS,
                  it.getStructuredDocumentRegion().getFullText(prev),
                  0)[0]
              > 0) {
        source.append(delim);
        source.append(getIndent(node));
        source.append(getIndentString());
      } else if (prev.getType() == CSSRegionContexts.CSS_S
          && TextUtilities.indexOf(
                  DefaultLineTracker.DELIMITERS, it.getStructuredDocumentRegion().getText(prev), 0)[
                  0]
              >= 0) {
        source.append(delim);
        source.append(getIndent(node));
        if (needIndent) source.append(getIndentString());
      } else {
        appendSpaceBefore(node, toAppend.getText(), source);
      }
    } else if (type == CSSRegionContexts.CSS_LBRACE
        && preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_NEWLINE_ON_OPEN_BRACE)) {
      String delim = getLineDelimiter(node);
      source.append(delim);
      source.append(getIndent(node));
      // } else if (type == CSSRegionContexts.CSS_CURLY_BRACE_CLOSE) {
      // } else if (type == CSSRegionContexts.CSS_INCLUDES || type ==
      // CSSRegionContexts.CSS_DASHMATCH) {
    } else if (type == CSSRegionContexts.CSS_DECLARATION_SEPARATOR
        && node instanceof ICSSStyleDeclItem) {
      int n = preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_PRE_DELIM);
      // no delimiter case
      while (n-- > 0) source.append(" "); // $NON-NLS-1$
    } else if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR
        || type == CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE) {
      if (preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0
          && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR)
              || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
        int length = getLastLineLength(node, source);
        int append = 1;
        if (length + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
          source.append(getLineDelimiter(node));
          source.append(getIndent(node));
          if (needIndent) source.append(getIndentString());
        }
      }
    } else if (CSSRegionContexts.CSS_FOREIGN_ELEMENT == type
        || CSSRegionContexts.CSS_DECLARATION_DELIMITER == type) {
      return;
    } else appendSpaceBefore(node, toAppend.getText(), source);
  }
예제 #14
0
 /** {@inheritDoc} */
 public boolean getBoolean(String name) {
   return fPreferences.getBoolean(name);
 }