diff options
author | Sergey Prigogin | 2009-08-19 18:40:31 +0000 |
---|---|---|
committer | Sergey Prigogin | 2009-08-19 18:40:31 +0000 |
commit | b85570c48ce016ce6d3ee942e7614dfe5ba889dd (patch) | |
tree | 616a8b1419675dd60be805d64e689113a837eb65 | |
parent | 99a9f6336d1e8aeef2dd7b058c612e1cec6eff54 (diff) | |
download | org.eclipse.cdt-b85570c48ce016ce6d3ee942e7614dfe5ba889dd.tar.gz org.eclipse.cdt-b85570c48ce016ce6d3ee942e7614dfe5ba889dd.tar.xz org.eclipse.cdt-b85570c48ce016ce6d3ee942e7614dfe5ba889dd.zip |
Made PathCanonicalizationStrategy friendlier to standalone indexer.
2 files changed, 28 insertions, 17 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 9c11bbb352b..0090acfa1c5 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -196,7 +196,6 @@ public class PDOMManager implements IWritableIndexManager, IListener { private ArrayList<IndexerSetupParticipant> fSetupParticipants= new ArrayList<IndexerSetupParticipant>(); private HashSet<ICProject> fPostponedProjects= new HashSet<ICProject>(); private int fLastNotifiedState= IndexerStateEvent.STATE_IDLE; - private PathCanonicalizationStrategy fPathCanonicalizationStrategy; public PDOMManager() { PDOM.sDEBUG_LOCKS= "true".equals(Platform.getDebugOption(CCorePlugin.PLUGIN_ID + "/debug/index/locks")); //$NON-NLS-1$//$NON-NLS-2$ @@ -304,13 +303,7 @@ public class PDOMManager implements IWritableIndexManager, IListener { private void updatePathCanonicalizationStrategy() { IPreferencesService prefs = Platform.getPreferencesService(); boolean canonicalize = prefs.getBoolean(CCorePlugin.PLUGIN_ID, PREFERENCES_CONSTANT_PATH_CANONICALIZATION, true, null); - synchronized (this) { - fPathCanonicalizationStrategy = PathCanonicalizationStrategy.getStrategy(canonicalize); - } - } - - public synchronized PathCanonicalizationStrategy getPathCanonicalizationStrategy() { - return fPathCanonicalizationStrategy; + PathCanonicalizationStrategy.setPathCanonicalization(canonicalize); } public IndexProviderManager getIndexProviderManager() { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/PathCanonicalizationStrategy.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/PathCanonicalizationStrategy.java index edca0f6de96..2ac47ca4ba9 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/PathCanonicalizationStrategy.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/PathCanonicalizationStrategy.java @@ -13,20 +13,34 @@ package org.eclipse.cdt.internal.core.resources; import java.io.File; import java.io.IOException; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.internal.core.pdom.PDOMManager; - +/** + * Configurable strategy for canonicalizing file paths. File paths can be canonicalized by calling + * either File.getCanonicalPath or File.getAbsolutePath. File.getCanonicalPath resolves symbolic + * links and guarantees path uniqueness. File.getAbsolutePath can be used when resolution of + * symbolic links is undesirable. The default is to use File.getCanonicalPath. + */ public abstract class PathCanonicalizationStrategy { + private static PathCanonicalizationStrategy instance; + + static { + setPathCanonicalization(true); + } public static String getCanonicalPath(File file) { - PathCanonicalizationStrategy strategy = - ((PDOMManager) CCorePlugin.getIndexManager()).getPathCanonicalizationStrategy(); - return strategy.getCanonicalPathInternal(file); + return getInstance().getCanonicalPathInternal(file); } - public static PathCanonicalizationStrategy getStrategy(boolean canonicalize) { + /** + * Sets path canonicalization strategy. If <code>canonicalize</code> is <code>true</code>, + * file paths will be canonicalized by calling File.getCanonicalPath, otherwise + * File.getAbsolutePath is used. + * + * @param canonicalize <code>true</code> to use File.getCanonicalPath, <code>false</code> + * to use File.getAbsolutePath. + */ + public static synchronized void setPathCanonicalization(boolean canonicalize) { if (canonicalize) { - return new PathCanonicalizationStrategy() { + instance = new PathCanonicalizationStrategy() { @Override protected String getCanonicalPathInternal(File file) { try { @@ -37,7 +51,7 @@ public abstract class PathCanonicalizationStrategy { } }; } else { - return new PathCanonicalizationStrategy() { + instance = new PathCanonicalizationStrategy() { @Override protected String getCanonicalPathInternal(File file) { return file.getAbsolutePath(); @@ -46,5 +60,9 @@ public abstract class PathCanonicalizationStrategy { } } + private static synchronized PathCanonicalizationStrategy getInstance() { + return instance; + } + protected abstract String getCanonicalPathInternal(File file); } |