mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 08:45:44 +02:00
Various changes for EFS
- Fixed many NPEs in the build system that occurred when IProject.getLocation() returned null - Created new IStorage implementation (EFSFileStorage) for the editor which can handle EFS resources - added some utility methods for handling EFS resources
This commit is contained in:
parent
af3f69afb9
commit
504602213a
12 changed files with 410 additions and 28 deletions
|
@ -211,9 +211,13 @@ public class DefaultRunSIProvider implements IExternalScannerInfoProvider {
|
|||
protected String[] setEnvironment(CommandLauncher launcher, Properties initialEnv) {
|
||||
// Set the environmennt, some scripts may need the CWD var to be set.
|
||||
Properties props = initialEnv != null ? initialEnv : launcher.getEnvironment();
|
||||
props.put("CWD", fWorkingDirectory.toOSString()); //$NON-NLS-1$
|
||||
props.put("PWD", fWorkingDirectory.toOSString()); //$NON-NLS-1$
|
||||
// On POSIX (Linux, UNIX) systems reset LANG variable to English with UTF-8 encoding
|
||||
|
||||
if (fWorkingDirectory != null) {
|
||||
props.put("CWD", fWorkingDirectory.toOSString()); //$NON-NLS-1$
|
||||
props.put("PWD", fWorkingDirectory.toOSString()); //$NON-NLS-1$
|
||||
}
|
||||
// On POSIX (Linux, UNIX) systems reset LANG variable to English with
|
||||
// UTF-8 encoding
|
||||
// since GNU compilers can handle only UTF-8 characters. English language is chosen
|
||||
// beacuse GNU compilers inconsistently handle different locales when generating
|
||||
// output of the 'gcc -v' command. Include paths with locale characters will be
|
||||
|
|
|
@ -4071,8 +4071,11 @@ public class ManagedBuildManager extends AbstractCExtension {
|
|||
}
|
||||
} else {
|
||||
buildDirectory = project.getLocation();
|
||||
if(builder.isManagedBuildOn())
|
||||
buildDirectory = buildDirectory.append(cfg.getName());
|
||||
|
||||
if (buildDirectory != null) {
|
||||
if (builder.isManagedBuildOn())
|
||||
buildDirectory = buildDirectory.append(cfg.getName());
|
||||
}
|
||||
}
|
||||
return buildDirectory;
|
||||
}
|
||||
|
|
|
@ -62,8 +62,11 @@ public class MbsEnvironmentSupplier implements IEnvironmentVariableSupplier {
|
|||
//
|
||||
// IPath projectLocation = owner.getLocation();
|
||||
// IPath workingDirectory = projectLocation.append(topBuildDir);
|
||||
// String value = workingDirectory.toOSString();
|
||||
// String value = workingDirectory.toOSString();
|
||||
if(topBuildDir != null) {
|
||||
variable = new BuildEnvVar(name, topBuildDir.toOSString(), IBuildEnvironmentVariable.ENVVAR_REPLACE,null);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2008 QNX Software Systems 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
|
||||
|
@ -8,10 +8,13 @@
|
|||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Corporation - EFS support
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.model;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
|
@ -75,11 +78,19 @@ public class CoreModel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a translation form and IPath. Returns null if not found.
|
||||
* Creates a translation from an IPath. Returns null if not found.
|
||||
*/
|
||||
public ITranslationUnit createTranslationUnitFrom(ICProject cproject, IPath path) {
|
||||
return manager.createTranslationUnitFrom(cproject, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translation from a location URI. Returns null if not found.
|
||||
* @since 5.0
|
||||
*/
|
||||
public ITranslationUnit createTranslationUnitFrom(ICProject cproject, URI locationURI) {
|
||||
return manager.createTranslationUnitFrom(cproject, locationURI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the C model element corresponding to the given handle identifier
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2007 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2008 QNX Software Systems 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
|
||||
|
@ -8,10 +8,12 @@
|
|||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Corporation - EFS support
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.model;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -573,6 +575,43 @@ public class CoreModelUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches for a translation unit within the cprojects. For external files the ones
|
||||
* from the given project are preferred.
|
||||
* @since 5.0
|
||||
*/
|
||||
public static ITranslationUnit findTranslationUnitForLocation(URI locationURI, ICProject preferredProject) throws CModelException {
|
||||
IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(locationURI);
|
||||
if (files.length > 0) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
IFile file = files[i];
|
||||
ITranslationUnit tu= findTranslationUnit(file);
|
||||
if (tu != null) {
|
||||
return tu;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CoreModel coreModel = CoreModel.getDefault();
|
||||
ITranslationUnit tu= null;
|
||||
if (preferredProject != null) {
|
||||
tu= coreModel.createTranslationUnitFrom(preferredProject, locationURI);
|
||||
}
|
||||
if (tu == null) {
|
||||
ICProject[] projects= coreModel.getCModel().getCProjects();
|
||||
for (int i = 0; i < projects.length && tu == null; i++) {
|
||||
ICProject project = projects[i];
|
||||
if (!project.equals(preferredProject)) {
|
||||
tu= coreModel.createTranslationUnitFrom(project, locationURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tu;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translation unit for the location given or <code>null</code>.
|
||||
* @throws CModelException
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Warren Paul (Nokia)
|
||||
* IBM Corporation (EFS Support)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
@ -18,6 +19,7 @@ package org.eclipse.cdt.internal.core.model;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -53,6 +55,9 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
|||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||
import org.eclipse.cdt.internal.core.LocalProjectScope;
|
||||
import org.eclipse.core.filesystem.EFS;
|
||||
import org.eclipse.core.filesystem.IFileInfo;
|
||||
import org.eclipse.core.filesystem.IFileStore;
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
|
@ -429,6 +434,69 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a translation unit in the given project for the given location.
|
||||
*
|
||||
* @param cproject
|
||||
* @param locationURI
|
||||
* @return ITranslationUnit
|
||||
*/
|
||||
public ITranslationUnit createTranslationUnitFrom(ICProject cproject, URI locationURI) {
|
||||
if (locationURI == null || cproject == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!locationURI.isAbsolute()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
final IProject project= cproject.getProject();
|
||||
|
||||
IFileStore fileStore = null;
|
||||
try {
|
||||
fileStore = EFS.getStore(locationURI);
|
||||
} catch (CoreException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
final String contentTypeId = CoreModel.getRegistedContentTypeId(project, fileStore.getName());
|
||||
|
||||
if (! Util.isNonZeroLengthFile(locationURI)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
IIncludeReference[] includeReferences = cproject.getIncludeReferences();
|
||||
for (int i = 0; i < includeReferences.length; i++) {
|
||||
|
||||
|
||||
// crecoskie
|
||||
// TODO FIXME: include entries don't handle URIs yet
|
||||
if (includeReferences[i].isOnIncludeEntry(URIUtil.toPath(locationURI))) {
|
||||
String headerContentTypeId= contentTypeId;
|
||||
if (headerContentTypeId == null) {
|
||||
headerContentTypeId= CoreModel.hasCCNature(project) ? CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER;
|
||||
}
|
||||
|
||||
return new ExternalTranslationUnit(includeReferences[i], locationURI, headerContentTypeId);
|
||||
}
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
}
|
||||
|
||||
// if the file exists and it has a known C/C++ file extension then just create
|
||||
// an external translation unit for it.
|
||||
IFileInfo info = fileStore.fetchInfo();
|
||||
|
||||
if (contentTypeId != null && info != null && info.exists()) {
|
||||
return new ExternalTranslationUnit(cproject, locationURI, contentTypeId);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void releaseCElement(ICElement celement) {
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* Rational Software - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* IBM Corporation - EFS support
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
@ -441,10 +442,10 @@ public class Util implements ICLogConstants {
|
|||
public static boolean isNonZeroLengthFile(IPath path) {
|
||||
return isNonZeroLengthFile(URIUtil.toURI(path));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if the file is not a directory and has length > 0
|
||||
* @param path
|
||||
* Return true if the file referred to by the URI is not a directory and has length > 0
|
||||
* @param uri
|
||||
* @return
|
||||
*/
|
||||
public static boolean isNonZeroLengthFile(URI uri) {
|
||||
|
|
|
@ -137,7 +137,9 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
|||
IStringVariableManager varManager= VariablesPlugin.getDefault().getStringVariableManager();
|
||||
IPath location= new Path(varManager.performStringSubstitution(loc));
|
||||
if (!location.isAbsolute()) {
|
||||
location= project.getLocation().append(location);
|
||||
|
||||
if(project.getLocation() != null)
|
||||
location= project.getLocation().append(location);
|
||||
}
|
||||
return location.toFile();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.core;
|
|||
* (c) Copyright IBM Corp. 2000, 2001. All Rights Reserved.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
@ -103,7 +104,13 @@ public class CommandLauncher {
|
|||
try {
|
||||
// add platform specific arguments (shell invocation)
|
||||
fCommandArgs = constructCommandArray(commandPath.toOSString(), args);
|
||||
fProcess = ProcessFactory.getFactory().exec(fCommandArgs, env, changeToDirectory.toFile());
|
||||
|
||||
File file = null;
|
||||
|
||||
if(changeToDirectory != null)
|
||||
file = changeToDirectory.toFile();
|
||||
|
||||
fProcess = ProcessFactory.getFactory().exec(fCommandArgs, env, file);
|
||||
fErrorMessage = ""; //$NON-NLS-1$
|
||||
} catch (IOException e) {
|
||||
setErrorMessage(e.getMessage());
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.resources;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.core.filesystem.EFS;
|
||||
import org.eclipse.core.filesystem.IFileInfo;
|
||||
import org.eclipse.core.filesystem.IFileStore;
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* A storage object which is backed by an EFS resource.
|
||||
*
|
||||
* @author crecoskie
|
||||
* @since 5.0
|
||||
*
|
||||
*/
|
||||
public class EFSFileStorage extends PlatformObject implements IStorage {
|
||||
|
||||
private URI locationURI;
|
||||
private InputStream inputStream;
|
||||
|
||||
public EFSFileStorage(URI locationURI) {
|
||||
this.locationURI = locationURI;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.resources.IStorage#getContents()
|
||||
*/
|
||||
public InputStream getContents() throws CoreException {
|
||||
if (inputStream == null) {
|
||||
|
||||
IFileStore fileStore = EFS.getStore(locationURI);
|
||||
|
||||
if (fileStore != null) {
|
||||
|
||||
inputStream = fileStore.openInputStream(EFS.NONE,
|
||||
new NullProgressMonitor());
|
||||
}
|
||||
}
|
||||
|
||||
return inputStream;
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.resources.IStorage#getFullPath()
|
||||
*/
|
||||
public IPath getFullPath() {
|
||||
return URIUtil.toPath(locationURI);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.resources.IStorage#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
IFileStore fileStore = null;
|
||||
try {
|
||||
fileStore = EFS.getStore(locationURI);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (fileStore != null) {
|
||||
return fileStore.getName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.resources.IStorage#isReadOnly()
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
IFileStore fileStore = null;
|
||||
try {
|
||||
fileStore = EFS.getStore(locationURI);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (fileStore != null) {
|
||||
IFileInfo info = fileStore.fetchInfo();
|
||||
|
||||
if(info != null)
|
||||
return info.getAttribute(EFS.ATTRIBUTE_READ_ONLY);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location URI corresponding to the EFS resource that
|
||||
* backs this storage.
|
||||
*
|
||||
* @return URI
|
||||
*/
|
||||
public URI getLocationURI() {
|
||||
return locationURI;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -23,8 +25,10 @@ import org.eclipse.jface.text.source.IAnnotationModel;
|
|||
import org.eclipse.ui.IPathEditorInput;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.editors.text.ILocationProvider;
|
||||
import org.eclipse.ui.editors.text.ILocationProviderExtension;
|
||||
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
|
||||
|
||||
import org.eclipse.cdt.core.resources.EFSFileStorage;
|
||||
import org.eclipse.cdt.core.resources.FileStorage;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
|
@ -72,12 +76,23 @@ public class ExternalSearchDocumentProvider extends TextFileDocumentProvider {
|
|||
}
|
||||
if (element instanceof IAdaptable) {
|
||||
IAdaptable adaptable= (IAdaptable) element;
|
||||
ILocationProvider provider= (ILocationProvider) adaptable.getAdapter(ILocationProvider.class);
|
||||
if (provider != null) {
|
||||
IPath path= provider.getPath(element);
|
||||
IStorage storage= new FileStorage(path);
|
||||
|
||||
ILocationProviderExtension extendedProvider = (ILocationProviderExtension) adaptable.getAdapter(ILocationProviderExtension.class);
|
||||
|
||||
if(extendedProvider != null) {
|
||||
URI uri = extendedProvider.getURI(element);
|
||||
IStorage storage = new EFSFileStorage(uri);
|
||||
return createExternalSearchAnnotationModel(storage, null);
|
||||
}
|
||||
else {
|
||||
ILocationProvider provider = (ILocationProvider) adaptable
|
||||
.getAdapter(ILocationProvider.class);
|
||||
if (provider != null) {
|
||||
IPath path = provider.getPath(element);
|
||||
IStorage storage = new FileStorage(path);
|
||||
return createExternalSearchAnnotationModel(storage, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,12 @@ package org.eclipse.cdt.internal.ui.util;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.eclipse.core.filesystem.EFS;
|
||||
import org.eclipse.core.filesystem.IFileStore;
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
|
@ -29,6 +33,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
|
|||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
|
@ -61,6 +66,7 @@ import org.eclipse.cdt.core.model.ISourceRange;
|
|||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.resources.EFSFileStorage;
|
||||
import org.eclipse.cdt.core.resources.FileStorage;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
|
@ -246,7 +252,7 @@ public class EditorUtility {
|
|||
if (resource instanceof IFile) {
|
||||
return new FileEditorInput((IFile) resource);
|
||||
}
|
||||
return new ExternalEditorInput(unit, new FileStorage(unit.getPath()));
|
||||
return new ExternalEditorInput(unit, new EFSFileStorage(unit.getLocationURI()));
|
||||
}
|
||||
|
||||
if (element instanceof IBinary) {
|
||||
|
@ -288,6 +294,11 @@ public class EditorUtility {
|
|||
IEditorInput input= getEditorInputForLocation(location, element);
|
||||
return EditorUtility.openInEditor(input, getEditorID(input, element), true);
|
||||
}
|
||||
|
||||
public static IEditorPart openInEditor(URI locationURI, ICElement element) throws PartInitException {
|
||||
IEditorInput input= getEditorInputForLocation(locationURI, element);
|
||||
return EditorUtility.openInEditor(input, getEditorID(input, element), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to get an editor input for the given file system location.
|
||||
|
@ -301,6 +312,66 @@ public class EditorUtility {
|
|||
* @param context an element related to the target file, may be <code>null</code>
|
||||
* @return an editor input
|
||||
*/
|
||||
public static IEditorInput getEditorInputForLocation(URI locationURI, ICElement context) {
|
||||
IFile resource= getWorkspaceFileAtLocation(locationURI, context);
|
||||
if (resource != null) {
|
||||
return new FileEditorInput(resource);
|
||||
}
|
||||
|
||||
if (context == null) {
|
||||
// try to synthesize a context for a location appearing on a project's
|
||||
// include paths
|
||||
try {
|
||||
ICProject[] projects = CCorePlugin.getDefault().getCoreModel().getCModel().getCProjects();
|
||||
outerFor: for (int i = 0; i < projects.length; i++) {
|
||||
IIncludeReference[] includeReferences = projects[i].getIncludeReferences();
|
||||
for (int j = 0; j < includeReferences.length; j++) {
|
||||
|
||||
// crecoskie test
|
||||
// TODO FIXME
|
||||
// include entries don't handle URIs yet, so fake it out for now
|
||||
if (includeReferences[j].isOnIncludeEntry(URIUtil.toPath(locationURI))) {
|
||||
context = projects[i];
|
||||
break outerFor;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (context == null && projects.length > 0) {
|
||||
// last resort: just take any of them
|
||||
context= projects[0];
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (context != null) {
|
||||
// try to get a translation unit from the location and associated element
|
||||
ICProject cproject= context.getCProject();
|
||||
if (cproject != null) {
|
||||
ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, locationURI);
|
||||
if (unit != null) {
|
||||
IFileStore fileStore = null;
|
||||
try {
|
||||
fileStore = EFS.getStore(locationURI);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
if(fileStore != null)
|
||||
return new ExternalEditorInput(unit, new EFSFileStorage(locationURI));
|
||||
}
|
||||
// no translation unit - still try to get a sensible marker resource
|
||||
// from the associated element
|
||||
IResource markerResource= cproject.getProject();
|
||||
return new ExternalEditorInput(new EFSFileStorage(locationURI), markerResource);
|
||||
}
|
||||
}
|
||||
return new ExternalEditorInput(new EFSFileStorage(locationURI));
|
||||
}
|
||||
|
||||
|
||||
public static IEditorInput getEditorInputForLocation(IPath location, ICElement context) {
|
||||
IFile resource= getWorkspaceFileAtLocation(location, context);
|
||||
if (resource != null) {
|
||||
|
@ -346,7 +417,8 @@ public class EditorUtility {
|
|||
return new ExternalEditorInput(new FileStorage(location));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Utility method to resolve a file system location to a workspace resource.
|
||||
* If a context element is given and there are multiple matches in the workspace,
|
||||
|
@ -399,6 +471,49 @@ public class EditorUtility {
|
|||
return bestMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to resolve a file system location to a workspace resource.
|
||||
* If a context element is given and there are multiple matches in the workspace,
|
||||
* a resource with the same project of the context element are preferred.
|
||||
*
|
||||
* @param location a valid file system location
|
||||
* @param context an element related to the target file, may be <code>null</code>
|
||||
* @return an <code>IFile</code> or <code>null</code>
|
||||
*/
|
||||
public static IFile getWorkspaceFileAtLocation(URI locationURI, ICElement context) {
|
||||
IProject project= null;
|
||||
if (context != null) {
|
||||
ICProject cProject= context.getCProject();
|
||||
if (cProject != null) {
|
||||
project= cProject.getProject();
|
||||
}
|
||||
}
|
||||
IFile bestMatch= null;
|
||||
IFile secondBestMatch= null;
|
||||
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
|
||||
IFile[] files= root.findFilesForLocationURI(locationURI);
|
||||
for (int i= 0; i < files.length; i++) {
|
||||
IFile file= files[i];
|
||||
if (file.isAccessible()) {
|
||||
if (project != null && file.getProject().equals(project)) {
|
||||
bestMatch= file;
|
||||
break;
|
||||
} else if (CoreModel.hasCNature(file.getProject())) {
|
||||
bestMatch= file;
|
||||
if (project == null) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// match in non-CDT project
|
||||
secondBestMatch= file;
|
||||
}
|
||||
}
|
||||
}
|
||||
bestMatch= bestMatch != null ? bestMatch : secondBestMatch;
|
||||
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the current active editor edits a c element return it, else
|
||||
* return null
|
||||
|
@ -601,7 +716,7 @@ public class EditorUtility {
|
|||
try {
|
||||
IBuffer buffer = bin.getBuffer();
|
||||
if (buffer != null) {
|
||||
store = new FileStorage (new ByteArrayInputStream(buffer.getContents().getBytes()), bin.getPath());
|
||||
store = new EFSFileStorage (bin.getLocationURI());
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
// nothing;
|
||||
|
@ -610,13 +725,7 @@ public class EditorUtility {
|
|||
}
|
||||
|
||||
public static IStorage getStorage(ITranslationUnit tu) {
|
||||
IStorage store = null;
|
||||
try {
|
||||
store = new FileStorage (new ByteArrayInputStream(tu.getBuffer().getContents().getBytes()), tu.getPath());
|
||||
} catch (CModelException e) {
|
||||
// nothing;
|
||||
}
|
||||
return store;
|
||||
return new EFSFileStorage (tu.getLocationURI());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue