From 9c73a9327afa3c809cfbbe87a8faedf0114e204b Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 19 Aug 2009 18:40:54 +0000 Subject: [PATCH] Made PathCanonicalizationStrategy friendlier to standalone indexer. --- .../cdt/internal/core/pdom/PDOMManager.java | 9 +---- .../PathCanonicalizationStrategy.java | 38 ++++++++++++++----- 2 files changed, 29 insertions(+), 18 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 2c6dd54d8e1..51483a7c11d 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 fSetupParticipants= new ArrayList(); private HashSet fPostponedProjects= new HashSet(); 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; - public static String getCanonicalPath(File file) { - PathCanonicalizationStrategy strategy = - ((PDOMManager) CCorePlugin.getIndexManager()).getPathCanonicalizationStrategy(); - return strategy.getCanonicalPathInternal(file); + static { + setPathCanonicalization(true); } - public static PathCanonicalizationStrategy getStrategy(boolean canonicalize) { + public static String getCanonicalPath(File file) { + return getInstance().getCanonicalPathInternal(file); + } + + /** + * Sets path canonicalization strategy. If canonicalize is true, + * file paths will be canonicalized by calling File.getCanonicalPath, otherwise + * File.getAbsolutePath is used. + * + * @param canonicalize true to use File.getCanonicalPath, false + * 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); }