mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Configurable strategy for canonicalization of file paths.
This commit is contained in:
parent
6d98937144
commit
c5f45c85a3
5 changed files with 95 additions and 34 deletions
|
@ -18,6 +18,7 @@ import java.io.InputStream;
|
|||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.internal.core.resources.PathCanonicalizationStrategy;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceStatus;
|
||||
|
@ -49,10 +50,10 @@ public class InternalParserUtil extends ParserFactory {
|
|||
public static CodeReader createExternalFileReader(String externalLocation, CodeReaderLRUCache cache) throws IOException {
|
||||
File includeFile = new File(externalLocation);
|
||||
if (includeFile.isFile()) {
|
||||
//use the canonical path so that in case of non-case-sensitive OSs
|
||||
//the CodeReader always has the same name as the file on disk with
|
||||
//no differences in case.
|
||||
final String path = includeFile.getCanonicalPath();
|
||||
// Use the canonical path so that in case of non-case-sensitive OSs
|
||||
// the CodeReader always has the same name as the file on disk with
|
||||
// no differences in case.
|
||||
final String path = PathCanonicalizationStrategy.getCanonicalPath(includeFile);
|
||||
if (cache != null) {
|
||||
CodeReader result= cache.get(path);
|
||||
if (result != null)
|
||||
|
|
|
@ -82,6 +82,7 @@ import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
|
|||
import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.TranslationUnitCollector;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.TriggerNotificationTask;
|
||||
import org.eclipse.cdt.internal.core.resources.PathCanonicalizationStrategy;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -149,6 +150,14 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
ILinkage.CPP_LINKAGE_ID, ILinkage.C_LINKAGE_ID, ILinkage.FORTRAN_LINKAGE_ID
|
||||
};
|
||||
|
||||
/**
|
||||
* Boolean preference controlling whether paths to non-workspace files are stored in canonical
|
||||
* form or not.
|
||||
*/
|
||||
// TODO(sprigogin): Move to CPreferencesConstants and add UI support.
|
||||
public static final String PREFERENCES_CONSTANT_PATH_CANONICALIZATION =
|
||||
CCorePlugin.PLUGIN_ID + ".path_canonicalization"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Protects fIndexerJob, fCurrentTask and fTaskQueue.
|
||||
*/
|
||||
|
@ -158,7 +167,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
private int fSourceCount, fHeaderCount, fTickCount;
|
||||
|
||||
/**
|
||||
* Stores mapping from pdom to project, used to serialize\ creation of new pdoms.
|
||||
* Stores mapping from pdom to project, used to serialize creation of new pdoms.
|
||||
*/
|
||||
private Map<IProject, IPDOM> fProjectToPDOM= new HashMap<IProject, IPDOM>();
|
||||
private Map<File, ICProject> fFileToProject= new HashMap<File, ICProject>();
|
||||
|
@ -187,6 +196,7 @@ 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$
|
||||
|
@ -225,6 +235,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
new InstanceScope().getNode(CCorePlugin.PLUGIN_ID).addPreferenceChangeListener(fPreferenceChangeListener);
|
||||
Job.getJobManager().addJobChangeListener(fJobChangeListener);
|
||||
adjustCacheSize();
|
||||
updatePathCanonicalizationStrategy();
|
||||
fIndexProviderManager.startup();
|
||||
|
||||
final CoreModel model = CoreModel.getDefault();
|
||||
|
@ -273,6 +284,9 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
prop.equals(CCorePreferenceConstants.TODO_TASK_PRIORITIES) ||
|
||||
prop.equals(CCorePreferenceConstants.TODO_TASK_CASE_SENSITIVE)) {
|
||||
reindexAll();
|
||||
} else if (prop.equals(PREFERENCES_CONSTANT_PATH_CANONICALIZATION)) {
|
||||
updatePathCanonicalizationStrategy();
|
||||
reindexAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,6 +301,18 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
ChunkCache.getSharedInstance().setMaxSize(m2);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public IndexProviderManager getIndexProviderManager() {
|
||||
return fIndexProviderManager;
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.parser.CodeReader;
|
|||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.pdom.IndexerInputAdapter;
|
||||
import org.eclipse.cdt.internal.core.resources.PathCanonicalizationStrategy;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -99,16 +100,11 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter {
|
|||
if (result == null) {
|
||||
result = doResolveASTPath(includePath);
|
||||
if (result.getFullPath() == null) {
|
||||
try {
|
||||
File location= new File(includePath);
|
||||
String canonicalPath= location.getCanonicalPath();
|
||||
if (!includePath.equals(canonicalPath)) {
|
||||
result= IndexLocationFactory.getExternalIFL(canonicalPath);
|
||||
fIflCache.put(canonicalPath, result);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// just use the original
|
||||
File location= new File(includePath);
|
||||
String canonicalPath= PathCanonicalizationStrategy.getCanonicalPath(location);
|
||||
if (!includePath.equals(canonicalPath)) {
|
||||
result= IndexLocationFactory.getExternalIFL(canonicalPath);
|
||||
fIflCache.put(canonicalPath, result);
|
||||
}
|
||||
}
|
||||
fIflCache.put(includePath, result);
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.resources;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
|
@ -47,13 +46,7 @@ abstract class LocationAdapter<T> {
|
|||
|
||||
@Override
|
||||
public String getCanonicalPath(IPath location) {
|
||||
final File file= location.toFile();
|
||||
try {
|
||||
return file.getCanonicalPath();
|
||||
} catch (IOException e) {
|
||||
// use non-canonical version
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
return PathCanonicalizationStrategy.getCanonicalPath(location.toFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,7 +60,7 @@ abstract class LocationAdapter<T> {
|
|||
public String extractName(URI location) {
|
||||
String path= location.getPath();
|
||||
int idx= path.lastIndexOf('/');
|
||||
return path.substring(idx+1);
|
||||
return path.substring(idx + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,16 +70,11 @@ abstract class LocationAdapter<T> {
|
|||
|
||||
@Override
|
||||
public String getCanonicalPath(URI location) {
|
||||
if (!"file".equals(location.getScheme())) //$NON-NLS-1$
|
||||
IPath path = URIUtil.toPath(location);
|
||||
if (path == null) {
|
||||
return null;
|
||||
|
||||
String path= location.getPath();
|
||||
try {
|
||||
return new File(path).getCanonicalPath();
|
||||
} catch (IOException e) {
|
||||
// use non-canonical version
|
||||
return path;
|
||||
}
|
||||
return PathCanonicalizationStrategy.getCanonicalPath(path.toFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Google, Inc and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Sergey Prigogin (Google) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
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;
|
||||
|
||||
public abstract class PathCanonicalizationStrategy {
|
||||
|
||||
public static String getCanonicalPath(File file) {
|
||||
PathCanonicalizationStrategy strategy =
|
||||
((PDOMManager) CCorePlugin.getIndexManager()).getPathCanonicalizationStrategy();
|
||||
return strategy.getCanonicalPathInternal(file);
|
||||
}
|
||||
|
||||
public static PathCanonicalizationStrategy getStrategy(boolean canonicalize) {
|
||||
if (canonicalize) {
|
||||
return new PathCanonicalizationStrategy() {
|
||||
@Override
|
||||
protected String getCanonicalPathInternal(File file) {
|
||||
try {
|
||||
return file.getCanonicalPath();
|
||||
} catch (IOException e) {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return new PathCanonicalizationStrategy() {
|
||||
@Override
|
||||
protected String getCanonicalPathInternal(File file) {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getCanonicalPathInternal(File file);
|
||||
}
|
Loading…
Add table
Reference in a new issue