diff options
author | Anton Leherbauer | 2008-04-02 10:37:56 +0000 |
---|---|---|
committer | Anton Leherbauer | 2008-04-02 10:37:56 +0000 |
commit | 7fde922525f0ae8058cf605f31befcd759f3574b (patch) | |
tree | 058d5f91e395d662b6d044e12c20620cb9a9283b | |
parent | cfae4dbc59a2f2c0bee8857ecdaa59ad0590f32b (diff) | |
download | org.eclipse.cdt-7fde922525f0ae8058cf605f31befcd759f3574b.tar.gz org.eclipse.cdt-7fde922525f0ae8058cf605f31befcd759f3574b.tar.xz org.eclipse.cdt-7fde922525f0ae8058cf605f31befcd759f3574b.zip |
Fix for 194578: NPE when attempting to edit a (new type) Makefile on a remote system
Patch by David Inglis
16 files changed, 221 insertions, 246 deletions
diff --git a/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF index b7b81945686..c79d5375629 100644 --- a/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF @@ -22,6 +22,7 @@ Export-Package: org.eclipse.cdt.make.core, Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", - org.eclipse.cdt.core;bundle-version="[5.0.0,6.0.0)" + org.eclipse.cdt.core;bundle-version="[5.0.0,6.0.0)", + org.eclipse.core.filesystem;bundle-version="1.2.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.java index 7ace043b307..1db677ed2f2 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.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 @@ -12,8 +12,11 @@ package org.eclipse.cdt.make.core; import java.io.File; +import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; +import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -33,6 +36,8 @@ import org.eclipse.cdt.make.internal.core.scannerconfig.DiscoveredPathManager; import org.eclipse.cdt.make.internal.core.scannerconfig.ScannerConfigInfoFactory; import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerConfigUtil; import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; @@ -148,26 +153,59 @@ public class MakeCorePlugin extends Plugin { return (String[])v.toArray(new String[v.size()]); } - + /** + * @deprecated + * @param file + * @param isGnuStyle + * @param makefileDirs + * @return + */ static public IMakefile createMakefile(File file, boolean isGnuStyle, String[] makefileDirs) { IMakefile makefile; if (isGnuStyle) { GNUMakefile gnu = new GNUMakefile(); ArrayList includeList = new ArrayList(); + includeList.add(new Path(file.getAbsolutePath()).removeLastSegments(1).toOSString()); + includeList.addAll(Arrays.asList(gnu.getIncludeDirectories())); + includeList.addAll(Arrays.asList(makefileDirs)); + String[] includes = (String[]) includeList.toArray(new String[includeList.size()]); + gnu.setIncludeDirectories(includes); + try { + gnu.parse(file.getAbsolutePath(), new FileReader(file)); + } catch (IOException e) { + } + makefile = gnu; + } else { + PosixMakefile posix = new PosixMakefile(); + try { + posix.parse(file.getAbsolutePath(), new FileReader(file)); + } catch (IOException e) { + } + makefile = posix; + } + return makefile; + } + + static public IMakefile createMakefile(IFileStore file, boolean isGnuStyle, String[] makefileDirs) throws CoreException { + IMakefile makefile; + URI fileURI = file.toURI(); + if (isGnuStyle) { + GNUMakefile gnu = new GNUMakefile(); + ArrayList includeList = new ArrayList(); + includeList.add(new Path(fileURI.getPath()).removeLastSegments(1).toString()); includeList.addAll(Arrays.asList(gnu.getIncludeDirectories())); includeList.addAll(Arrays.asList(makefileDirs)); - includeList.add(new Path(file.getAbsolutePath()).removeLastSegments(1).toOSString()); String[] includes = (String[]) includeList.toArray(new String[includeList.size()]); gnu.setIncludeDirectories(includes); try { - gnu.parse(file.getAbsolutePath()); + gnu.parse(fileURI, new InputStreamReader(file.openInputStream(EFS.NONE, null))); } catch (IOException e) { } makefile = gnu; } else { PosixMakefile posix = new PosixMakefile(); try { - posix.parse(file.getAbsolutePath()); + posix.parse(fileURI, new InputStreamReader(file.openInputStream(EFS.NONE, null))); } catch (IOException e) { } makefile = posix; @@ -175,9 +213,8 @@ public class MakeCorePlugin extends Plugin { return makefile; } - public IMakefile createMakefile(IFile file) { - return createMakefile(file.getLocation().toFile(), isMakefileGNUStyle(), - getMakefileDirs()); + public IMakefile createMakefile(IFile file) throws CoreException { + return createMakefile(EFS.getStore(file.getLocationURI()), isMakefileGNUStyle(), getMakefileDirs()); } public void stop(BundleContext context) throws Exception { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/makefile/IDirective.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/makefile/IDirective.java index 96396b12ac9..5a6d7fd8e32 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/makefile/IDirective.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/makefile/IDirective.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -37,11 +37,11 @@ public interface IDirective { int getEndLine(); /** - * Returns the filename where the directive was found. + * Returns the makefile where the directive was found. * - * @return String - filename + * @return <code>IMakefile</code> */ - String getFileName(); + IMakefile getMakefile(); String toString(); } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/makefile/IMakefile.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/makefile/IMakefile.java index 62a16b64109..aa467ed506f 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/makefile/IMakefile.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/makefile/IMakefile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -12,6 +12,7 @@ package org.eclipse.cdt.make.core.makefile; import java.io.IOException; import java.io.Reader; +import java.net.URI; /** @@ -124,12 +125,25 @@ public interface IMakefile extends IParent { String expandString(String line, boolean recursive); /** - * Clear the all statements and (re)parse the Makefile + * Clear all statements and (re)parse the Makefile * - * @param name + * @param filePath * @param makefile * @throws IOException */ - void parse(String name, Reader makefile) throws IOException; - + void parse(String filePath, Reader makefile) throws IOException; + + /** + * Clear all statements and (re)parse the Makefile + * + * @param fileURI + * @param makefile + * @throws IOException + */ + void parse(URI fileURI, Reader makefile) throws IOException; + + /** + * @return the <code>URI</code> of this makefile + */ + URI getFileURI(); } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java index 3d590fe380e..98fee3cf20a 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -10,14 +10,15 @@ *******************************************************************************/ package org.eclipse.cdt.make.internal.core.makefile; +import java.net.URI; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.make.core.makefile.IDirective; import org.eclipse.cdt.make.core.makefile.IInferenceRule; import org.eclipse.cdt.make.core.makefile.IMacroDefinition; import org.eclipse.cdt.make.core.makefile.IMakefile; import org.eclipse.cdt.make.core.makefile.IRule; -import org.eclipse.cdt.make.core.makefile.IDirective; import org.eclipse.cdt.make.core.makefile.ITargetRule; /** @@ -38,6 +39,8 @@ import org.eclipse.cdt.make.core.makefile.ITargetRule; public abstract class AbstractMakefile extends Parent implements IMakefile { + private URI filename; + public AbstractMakefile(Directive parent) { super(parent); } @@ -261,4 +264,15 @@ public abstract class AbstractMakefile extends Parent implements IMakefile { return buffer.toString(); } + public URI getFileURI() { + return filename; + } + + public void setFileURI(URI filename) { + this.filename = filename; + } + + public IMakefile getMakefile() { + return this; + } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/Directive.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/Directive.java index 89c3acb74bf..33e098997a4 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/Directive.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/Directive.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -11,12 +11,12 @@ package org.eclipse.cdt.make.internal.core.makefile; import org.eclipse.cdt.make.core.makefile.IDirective; +import org.eclipse.cdt.make.core.makefile.IMakefile; public abstract class Directive implements IDirective { int endLine; int startLine; - String filename; Directive parent; public Directive(Directive owner) { @@ -51,15 +51,10 @@ public abstract class Directive implements IDirective { } /* (non-Javadoc) - * @see org.eclipse.cdt.make.core.makefile.IDirective#getFileName() + * @see org.eclipse.cdt.make.core.makefile.IDirective#getMakefile() */ - public String getFileName() { - if (filename == null) { - if (parent != null) { - filename = parent.getFileName(); - } - } - return filename; + public IMakefile getMakefile() { + return parent.getMakefile(); } public void setParent(Directive owner) { @@ -78,9 +73,4 @@ public abstract class Directive implements IDirective { setStartLine(start); setEndLine(end); } - - public void setFilename(String name) { - filename = name; - } - } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/NullMakefile.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/NullMakefile.java index e5c1373f5c6..0b23a014861 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/NullMakefile.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/NullMakefile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -12,6 +12,7 @@ package org.eclipse.cdt.make.internal.core.makefile; import java.io.IOException; import java.io.Reader; +import java.net.URI; import org.eclipse.cdt.make.core.makefile.IDirective; @@ -60,4 +61,6 @@ public class NullMakefile extends AbstractMakefile { public void parse(String name, Reader makefile) throws IOException { } + public void parse(URI fileURI, Reader makefile) throws IOException { + } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/GNUMakefile.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/GNUMakefile.java index 21d3887f772..3d42e3c9f6f 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/GNUMakefile.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/GNUMakefile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -11,11 +11,12 @@ package org.eclipse.cdt.make.internal.core.makefile.gnu; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -50,8 +51,9 @@ import org.eclipse.cdt.make.internal.core.makefile.Target; import org.eclipse.cdt.make.internal.core.makefile.TargetRule; import org.eclipse.cdt.make.internal.core.makefile.Util; import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefileUtil; +import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; /** * Makefile : ( statement ) * @@ -80,23 +82,16 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile { public GNUMakefile() { super(null); } - - public void parse(String name) throws IOException { - FileReader stream = new FileReader(name); - parse(name, stream); - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - } - } + + public void parse(String filePath, Reader reader) throws IOException { + parse(URIUtil.toURI(filePath), new MakefileReader(reader)); } - public void parse(String name, Reader reader) throws IOException { - parse(name, new MakefileReader(reader)); + public void parse(URI filePath, Reader reader) throws IOException { + parse(filePath, new MakefileReader(reader)); } - - protected void parse(String name, MakefileReader reader) throws IOException { + + protected void parse(URI fileURI, MakefileReader reader) throws IOException { String line; Rule[] rules = null; Stack conditions = new Stack(); @@ -107,8 +102,8 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile { // Clear any old directives. clearDirectives(); - setFilename(name); - + setFileURI(fileURI); + while ((line = reader.readLine()) != null) { startLine = endLine + 1; endLine = reader.getLineNumber(); @@ -793,21 +788,21 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile { if (builtins == null) { String location = "builtin" + File.separator + "gnu.mk"; //$NON-NLS-1$ //$NON-NLS-2$ try { - InputStream stream = MakeCorePlugin.getDefault().openStream(new Path(location)); + InputStream stream = FileLocator.openStream(MakeCorePlugin.getDefault().getBundle(), new Path(location), false); GNUMakefile gnu = new GNUMakefile(); - URL url = Platform.find(MakeCorePlugin.getDefault().getBundle(), new Path(location)); - url = Platform.resolve(url); - location = url.getFile(); - gnu.parse(location, new InputStreamReader(stream)); + URL url = FileLocator.find(MakeCorePlugin.getDefault().getBundle(), new Path(location), null); + gnu.parse(url.toURI(), new InputStreamReader(stream)); builtins = gnu.getDirectives(); for (int i = 0; i < builtins.length; i++) { if (builtins[i] instanceof MacroDefinition) { - ((MacroDefinition)builtins[i]).setFromDefault(true); + ((MacroDefinition) builtins[i]).setFromDefault(true); } } - } catch (Exception e) { - //e.printStackTrace(); - } + } catch (IOException e) { + MakeCorePlugin.log(e); + } catch (URISyntaxException e) { + MakeCorePlugin.log(e); + } if (builtins == null) { builtins = new IDirective[0]; } @@ -822,23 +817,4 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile { public String[] getIncludeDirectories() { return includeDirectories; } - - public static void main(String[] args) { - try { - String filename = "Makefile"; //$NON-NLS-1$ - if (args.length == 1) { - filename = args[0]; - } - GNUMakefile makefile = new GNUMakefile(); - makefile.parse(filename); - IDirective[] directive = makefile.getDirectives(); - for (int i = 0; i < directive.length; i++) { - //System.out.println("Rule[" + i +"]"); - System.out.print(directive[i]); - } - } catch (IOException e) { - System.out.println(e); - } - } - } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/GNUMakefileChecker.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/GNUMakefileChecker.java index 37fcd2aa3c9..7b957cb1427 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/GNUMakefileChecker.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/GNUMakefileChecker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -76,9 +76,7 @@ public class GNUMakefileChecker extends ACBuilder { checkProject(getProject(), monitor); } else { MyResourceDeltaVisitor vis = new MyResourceDeltaVisitor(monitor); - if (delta != null) { - delta.accept(vis); - } + delta.accept(vis); } checkCancel(monitor); return new IProject[0]; diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/Include.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/Include.java index 751caf94f89..4ca800e55a1 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/Include.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/gnu/Include.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -10,12 +10,21 @@ *******************************************************************************/ package org.eclipse.cdt.make.internal.core.makefile.gnu; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URISyntaxException; import org.eclipse.cdt.make.core.makefile.IDirective; import org.eclipse.cdt.make.core.makefile.gnu.IInclude; import org.eclipse.cdt.make.internal.core.makefile.Directive; import org.eclipse.cdt.make.internal.core.makefile.Parent; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; public class Include extends Parent implements IInclude { @@ -43,38 +52,44 @@ public class Include extends Parent implements IInclude { public IDirective[] getDirectives() { clearDirectives(); + URI uri = getMakefile().getFileURI(); for (int i = 0; i < filenames.length; i++) { - // Try the current directory. - GNUMakefile gnu = new GNUMakefile(); - try { - gnu.parse(filenames[i]); - addDirective(gnu); - continue; - } catch (IOException e) { - } - if (filenames[i].startsWith(GNUMakefile.FILE_SEPARATOR)) { + IPath includeFilePath = new Path(filenames[i]); + if (includeFilePath.isAbsolute()) { // Try to set the device to that of the parent makefile. - String filename = getFileName(); - if (filename != null) { - String device = new Path(filename).getDevice(); - if (device != null) { - try { - gnu.parse(new Path(filenames[i]).setDevice(device).toOSString()); - addDirective(gnu); - continue; - } catch (IOException e) { - } + final IPath path = URIUtil.toPath(uri); + if (path != null) { + String device = path.getDevice(); + if (device != null && includeFilePath.getDevice() == null) { + includeFilePath = includeFilePath.setDevice(device); + } + try { + GNUMakefile gnu = new GNUMakefile(); + final InputStreamReader reader = new InputStreamReader(new FileInputStream(includeFilePath.toFile())); + gnu.parse(includeFilePath.toOSString(), reader); + addDirective(gnu); + continue; + } catch (IOException e) { } } } else if (dirs != null) { for (int j = 0; j < dirs.length; j++) { try { - String filename = dirs[j] + GNUMakefile.FILE_SEPARATOR + filenames[i]; - gnu = new GNUMakefile(); - gnu.parse(filename); + includeFilePath= new Path(dirs[j]).append(includeFilePath); + String uriPath = includeFilePath.toString(); + if (includeFilePath.getDevice() != null) { + // special case: device prefix is seen as relative path by URI + uriPath = '/' + uriPath; + } + GNUMakefile gnu = new GNUMakefile(); + URI includeURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uriPath, null, null); + IFileStore store = EFS.getStore(includeURI); + gnu.parse(includeURI, new InputStreamReader(store.openInputStream(0, null))); addDirective(gnu); break; } catch (IOException e) { + } catch (URISyntaxException exc) { + } catch (CoreException exc) { } } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/posix/PosixMakefile.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/posix/PosixMakefile.java index 1fe16208ec8..c5f4f2459b1 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/posix/PosixMakefile.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/posix/PosixMakefile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -11,11 +11,12 @@ package org.eclipse.cdt.make.internal.core.makefile.posix; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import org.eclipse.cdt.make.core.MakeCorePlugin; @@ -42,8 +43,9 @@ import org.eclipse.cdt.make.internal.core.makefile.SuffixesRule; import org.eclipse.cdt.make.internal.core.makefile.Target; import org.eclipse.cdt.make.internal.core.makefile.TargetRule; import org.eclipse.cdt.make.internal.core.makefile.Util; +import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; /** * Makefile : ( statement ) * @@ -69,23 +71,16 @@ public class PosixMakefile extends AbstractMakefile { public PosixMakefile() { super(null); } - - public void parse(String name) throws IOException { - FileReader stream = new FileReader(name); - parse(name, stream); - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - } - } + + public void parse(String name, Reader reader) throws IOException { + parse(URIUtil.toURI(name), new MakefileReader(reader)); } - public void parse(String name, Reader reader) throws IOException { - parse(name, new MakefileReader(reader)); + public void parse(URI fileURI, Reader reader) throws IOException { + parse(fileURI, new MakefileReader(reader)); } - protected void parse(String name, MakefileReader reader) throws IOException { + protected void parse(URI fileURI, MakefileReader reader) throws IOException { String line; Rule[] rules = null; int startLine = 0; @@ -94,7 +89,7 @@ public class PosixMakefile extends AbstractMakefile { // Clear any old directives. clearDirectives(); - setFilename(name); + setFileURI(fileURI); while ((line = reader.readLine()) != null) { startLine = endLine + 1; @@ -210,21 +205,21 @@ public class PosixMakefile extends AbstractMakefile { if (builtins == null) { String location = "builtin" + File.separator + "posix.mk"; //$NON-NLS-1$ //$NON-NLS-2$ try { - InputStream stream = MakeCorePlugin.getDefault().openStream(new Path(location)); - PosixMakefile gnu = new PosixMakefile(); - URL url = Platform.find(MakeCorePlugin.getDefault().getBundle(), new Path(location)); - url = Platform.resolve(url); - location = url.getFile(); - gnu.parse(location, new InputStreamReader(stream)); - builtins = gnu.getDirectives(); + InputStream stream = FileLocator.openStream(MakeCorePlugin.getDefault().getBundle(), new Path(location), false); + PosixMakefile posix = new PosixMakefile(); + URL url = FileLocator.find(MakeCorePlugin.getDefault().getBundle(), new Path(location), null); + posix.parse(url.toURI(), new InputStreamReader(stream)); + builtins = posix.getDirectives(); for (int i = 0; i < builtins.length; i++) { if (builtins[i] instanceof MacroDefinition) { ((MacroDefinition)builtins[i]).setFromDefault(true); } } - } catch (Exception e) { - //e.printStackTrace(); - } + } catch (IOException e) { + MakeCorePlugin.log(e); + } catch (URISyntaxException e) { + MakeCorePlugin.log(e); + } if (builtins == null) { builtins = new IDirective[0]; } @@ -337,24 +332,4 @@ public class PosixMakefile extends AbstractMakefile { } return targetRules; } - - public static void main(String[] args) { - try { - String filename = "Makefile"; //$NON-NLS-1$ - if (args.length == 1) { - filename = args[0]; - } - PosixMakefile makefile = new PosixMakefile(); - makefile.parse(filename); - IDirective[] directives = makefile.getDirectives(); - //IDirective[] directives = makefile.getBuiltins(); - for (int i = 0; i < directives.length; i++) { - //System.out.println("Rule[" + i +"]"); - System.out.print(directives[i]); - } - } catch (IOException e) { - System.out.println(e); - } - } - } diff --git a/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF index af0f1514cb7..6a2327e9f7c 100644 --- a/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF @@ -34,6 +34,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)", org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)";resolution:=optional, - org.eclipse.compare;bundle-version="[3.3.0,4.0.0)" + org.eclipse.compare;bundle-version="[3.3.0,4.0.0)", + org.eclipse.core.filesystem;bundle-version="1.2.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java index 1e7a68c0cfe..0d71f170d50 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.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 @@ -61,7 +61,7 @@ public class MakefileDocumentProvider extends TextFileDocumentProvider implement /** */ - private IMakefile createMakefile(IFile file) { + private IMakefile createMakefile(IFile file) throws CoreException { if (file.exists()) { return MakeCorePlugin.getDefault().createMakefile(file); } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/OpenDeclarationAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/OpenDeclarationAction.java index 55a28384a5f..f9f78409ed3 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/OpenDeclarationAction.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/OpenDeclarationAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -10,25 +10,14 @@ *******************************************************************************/ package org.eclipse.cdt.make.internal.ui.editor; -import org.eclipse.cdt.core.resources.FileStorage; -import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; import org.eclipse.cdt.make.core.makefile.IDirective; import org.eclipse.cdt.make.core.makefile.IMakefile; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.internal.ui.text.WordPartDetector; import org.eclipse.cdt.make.ui.IWorkingCopyManager; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IStorageEditorInput; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.ide.IDE; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.TextEditorAction; @@ -77,51 +66,11 @@ public class OpenDeclarationAction extends TextEditorAction { directives = makefile.getTargetRules(name); } if (directives != null && directives.length > 0) { - openInEditor(directives[0]); + OpenIncludeAction.openInEditor(directives[0]); } } catch (Exception x) { // } } } - - private static IEditorPart openInEditor(IDirective directive) throws PartInitException { - String filename = directive.getFileName(); - IPath path = new Path(filename); - IFile file = MakeUIPlugin.getWorkspace().getRoot().getFileForLocation(path); - if (file != null) { - IWorkbenchPage p = MakeUIPlugin.getActivePage(); - if (p != null) { - IEditorPart editorPart = IDE.openEditor(p, file, true); - if (editorPart instanceof MakefileEditor) { - ((MakefileEditor)editorPart).setSelection(directive, true); - } - return editorPart; - } - } else { - // External file - IStorage storage = new FileStorage(path); - IStorageEditorInput input = new ExternalEditorInput(storage); - IWorkbenchPage p = MakeUIPlugin.getActivePage(); - if (p != null) { - String editorID = "org.eclipse.cdt.make.editor"; //$NON-NLS-1$ - IEditorPart editorPart = IDE.openEditor(p, input, editorID, true); - if (editorPart instanceof MakefileEditor) { - ((MakefileEditor)editorPart).setSelection(directive, true); - } - return editorPart; - } - - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.text.ITextSelection) - */ - //public void selectionChanged(ITextSelection selection) { - //setEnabled(fEditor != null); - //} } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/OpenIncludeAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/OpenIncludeAction.java index 01569150c60..fa236c47e99 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/OpenIncludeAction.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/OpenIncludeAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2006 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 @@ -11,26 +11,26 @@ package org.eclipse.cdt.make.internal.ui.editor; +import java.net.URI; import java.util.ArrayList; import java.util.List; -import org.eclipse.cdt.core.resources.FileStorage; -import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; import org.eclipse.cdt.make.core.makefile.IDirective; import org.eclipse.cdt.make.core.makefile.gnu.IInclude; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.action.Action; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IStorageEditorInput; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.ide.FileStoreEditorInput; import org.eclipse.ui.ide.IDE; /** @@ -70,33 +70,35 @@ public class OpenIncludeAction extends Action { } } - private static IEditorPart openInEditor(IDirective directive) throws PartInitException { - String filename = directive.getFileName(); - IPath path = new Path(filename); - IFile file = MakeUIPlugin.getWorkspace().getRoot().getFileForLocation(path); - if (file != null) { - IWorkbenchPage p = MakeUIPlugin.getActivePage(); - if (p != null) { - IEditorPart editorPart = IDE.openEditor(p, file, true); - if (editorPart instanceof MakefileEditor) { - ((MakefileEditor)editorPart).setSelection(directive, true); + public static IEditorPart openInEditor(IDirective directive) throws PartInitException { + try { + URI uri = directive.getMakefile().getFileURI(); + IFileStore store = EFS.getStore(uri); + + IFile[] file = MakeUIPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri); + if (file.length > 0 && file[0] != null) { + IWorkbenchPage p = MakeUIPlugin.getActivePage(); + if (p != null) { + IEditorPart editorPart = IDE.openEditor(p, file[0], true); + if (editorPart instanceof MakefileEditor) { + ((MakefileEditor) editorPart).setSelection(directive, true); + } + return editorPart; } - return editorPart; - } - } else { - // External file - IStorage storage = new FileStorage(path); - IStorageEditorInput input = new ExternalEditorInput(storage); - IWorkbenchPage p = MakeUIPlugin.getActivePage(); - if (p != null) { - String editorID = "org.eclipse.cdt.make.editor"; //$NON-NLS-1$ - IEditorPart editorPart = IDE.openEditor(p, input, editorID, true); - if (editorPart instanceof MakefileEditor) { - ((MakefileEditor)editorPart).setSelection(directive, true); + } else { + // External file + IEditorInput input = new FileStoreEditorInput(store); + IWorkbenchPage p = MakeUIPlugin.getActivePage(); + if (p != null) { + String editorID = "org.eclipse.cdt.make.editor"; //$NON-NLS-1$ + IEditorPart editorPart = IDE.openEditor(p, input, editorID, true); + if (editorPart instanceof MakefileEditor) { + ((MakefileEditor) editorPart).setSelection(directive, true); + } + return editorPart; } - return editorPart; } - + } catch (CoreException e) { } return null; } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileReconcilingStrategy.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileReconcilingStrategy.java index a4224eaaaed..1d33c13c248 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileReconcilingStrategy.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileReconcilingStrategy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -87,7 +87,7 @@ public class MakefileReconcilingStrategy implements IReconcilingStrategy { String content = fDocumentProvider.getDocument(fEditor.getEditorInput()).get(); StringReader reader = new StringReader(content); try { - makefile.parse(makefile.getFileName(), reader); + makefile.parse(makefile.getFileURI(), reader); } catch (IOException e) { } |