Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Recoskie2008-04-04 17:48:27 +0000
committerChris Recoskie2008-04-04 17:48:27 +0000
commit504602213a5ed701fc2fb8ebf31bfa7def5a563b (patch)
tree3abcc3cf5944c57b76af5542fa9dbb30acf210db /core/org.eclipse.cdt.core
parentaf3f69afb9ed7804041fdb5d405c411ac22cfd4e (diff)
downloadorg.eclipse.cdt-504602213a5ed701fc2fb8ebf31bfa7def5a563b.tar.gz
org.eclipse.cdt-504602213a5ed701fc2fb8ebf31bfa7def5a563b.tar.xz
org.eclipse.cdt-504602213a5ed701fc2fb8ebf31bfa7def5a563b.zip
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
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java15
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java41
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java68
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java4
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java9
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/EFSFileStorage.java120
7 files changed, 256 insertions, 8 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
index 58358b12c8..95235d43d8 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
@@ -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
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java
index ac6f94f231..faf9a64ac4 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModelUtil.java
@@ -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
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
index d7434be9f9..01c9cac957 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
@@ -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) {
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
index f01a9401a8..482215c16d 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
@@ -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) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java
index bf43aa1a02..3817774c0b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/TeamPDOMImportOperation.java
@@ -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();
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
index 1ff92b2429..d6eebed50b 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
@@ -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());
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/EFSFileStorage.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/EFSFileStorage.java
new file mode 100644
index 0000000000..e0db10a41b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/EFSFileStorage.java
@@ -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;
+ }
+
+}

Back to the top