1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Fix for 194578: NPE when attempting to edit a (new type) Makefile on a remote system

Patch by David Inglis
This commit is contained in:
Anton Leherbauer 2008-04-02 10:37:56 +00:00
parent cfae4dbc59
commit 7fde922525
16 changed files with 222 additions and 247 deletions

View file

@ -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)", 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.variables;bundle-version="[3.1.100,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,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-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-RequiredExecutionEnvironment: J2SE-1.5

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -12,8 +12,11 @@
package org.eclipse.cdt.make.core; package org.eclipse.cdt.make.core;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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.ScannerConfigInfoFactory;
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerConfigUtil; import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerConfigUtil;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; 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.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
@ -148,26 +153,32 @@ public class MakeCorePlugin extends Plugin {
return (String[])v.toArray(new String[v.size()]); 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) { static public IMakefile createMakefile(File file, boolean isGnuStyle, String[] makefileDirs) {
IMakefile makefile; IMakefile makefile;
if (isGnuStyle) { if (isGnuStyle) {
GNUMakefile gnu = new GNUMakefile(); GNUMakefile gnu = new GNUMakefile();
ArrayList includeList = new ArrayList(); ArrayList includeList = new ArrayList();
includeList.add(new Path(file.getAbsolutePath()).removeLastSegments(1).toOSString());
includeList.addAll(Arrays.asList(gnu.getIncludeDirectories())); includeList.addAll(Arrays.asList(gnu.getIncludeDirectories()));
includeList.addAll(Arrays.asList(makefileDirs)); includeList.addAll(Arrays.asList(makefileDirs));
includeList.add(new Path(file.getAbsolutePath()).removeLastSegments(1).toOSString());
String[] includes = (String[]) includeList.toArray(new String[includeList.size()]); String[] includes = (String[]) includeList.toArray(new String[includeList.size()]);
gnu.setIncludeDirectories(includes); gnu.setIncludeDirectories(includes);
try { try {
gnu.parse(file.getAbsolutePath()); gnu.parse(file.getAbsolutePath(), new FileReader(file));
} catch (IOException e) { } catch (IOException e) {
} }
makefile = gnu; makefile = gnu;
} else { } else {
PosixMakefile posix = new PosixMakefile(); PosixMakefile posix = new PosixMakefile();
try { try {
posix.parse(file.getAbsolutePath()); posix.parse(file.getAbsolutePath(), new FileReader(file));
} catch (IOException e) { } catch (IOException e) {
} }
makefile = posix; makefile = posix;
@ -175,9 +186,35 @@ public class MakeCorePlugin extends Plugin {
return makefile; return makefile;
} }
public IMakefile createMakefile(IFile file) { static public IMakefile createMakefile(IFileStore file, boolean isGnuStyle, String[] makefileDirs) throws CoreException {
return createMakefile(file.getLocation().toFile(), isMakefileGNUStyle(), IMakefile makefile;
getMakefileDirs()); 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));
String[] includes = (String[]) includeList.toArray(new String[includeList.size()]);
gnu.setIncludeDirectories(includes);
try {
gnu.parse(fileURI, new InputStreamReader(file.openInputStream(EFS.NONE, null)));
} catch (IOException e) {
}
makefile = gnu;
} else {
PosixMakefile posix = new PosixMakefile();
try {
posix.parse(fileURI, new InputStreamReader(file.openInputStream(EFS.NONE, null)));
} catch (IOException e) {
}
makefile = posix;
}
return makefile;
}
public IMakefile createMakefile(IFile file) throws CoreException {
return createMakefile(EFS.getStore(file.getLocationURI()), isMakefileGNUStyle(), getMakefileDirs());
} }
public void stop(BundleContext context) throws Exception { public void stop(BundleContext context) throws Exception {

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -37,11 +37,11 @@ public interface IDirective {
int getEndLine(); 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(); String toString();
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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.IOException;
import java.io.Reader; import java.io.Reader;
import java.net.URI;
/** /**
@ -124,12 +125,25 @@ public interface IMakefile extends IParent {
String expandString(String line, boolean recursive); 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 * @param makefile
* @throws IOException * @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();
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -10,14 +10,15 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.core.makefile; package org.eclipse.cdt.make.internal.core.makefile;
import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.IInferenceRule;
import org.eclipse.cdt.make.core.makefile.IMacroDefinition; import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
import org.eclipse.cdt.make.core.makefile.IMakefile; import org.eclipse.cdt.make.core.makefile.IMakefile;
import org.eclipse.cdt.make.core.makefile.IRule; import org.eclipse.cdt.make.core.makefile.IRule;
import org.eclipse.cdt.make.core.makefile.IDirective;
import org.eclipse.cdt.make.core.makefile.ITargetRule; 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 { public abstract class AbstractMakefile extends Parent implements IMakefile {
private URI filename;
public AbstractMakefile(Directive parent) { public AbstractMakefile(Directive parent) {
super(parent); super(parent);
} }
@ -261,4 +264,15 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
return buffer.toString(); return buffer.toString();
} }
public URI getFileURI() {
return filename;
}
public void setFileURI(URI filename) {
this.filename = filename;
}
public IMakefile getMakefile() {
return this;
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,12 +11,12 @@
package org.eclipse.cdt.make.internal.core.makefile; package org.eclipse.cdt.make.internal.core.makefile;
import org.eclipse.cdt.make.core.makefile.IDirective; import org.eclipse.cdt.make.core.makefile.IDirective;
import org.eclipse.cdt.make.core.makefile.IMakefile;
public abstract class Directive implements IDirective { public abstract class Directive implements IDirective {
int endLine; int endLine;
int startLine; int startLine;
String filename;
Directive parent; Directive parent;
public Directive(Directive owner) { public Directive(Directive owner) {
@ -51,15 +51,10 @@ public abstract class Directive implements IDirective {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.make.core.makefile.IDirective#getFileName() * @see org.eclipse.cdt.make.core.makefile.IDirective#getMakefile()
*/ */
public String getFileName() { public IMakefile getMakefile() {
if (filename == null) { return parent.getMakefile();
if (parent != null) {
filename = parent.getFileName();
}
}
return filename;
} }
public void setParent(Directive owner) { public void setParent(Directive owner) {
@ -78,9 +73,4 @@ public abstract class Directive implements IDirective {
setStartLine(start); setStartLine(start);
setEndLine(end); setEndLine(end);
} }
public void setFilename(String name) {
filename = name;
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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.IOException;
import java.io.Reader; import java.io.Reader;
import java.net.URI;
import org.eclipse.cdt.make.core.makefile.IDirective; 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(String name, Reader makefile) throws IOException {
} }
public void parse(URI fileURI, Reader makefile) throws IOException {
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,11 +11,12 @@
package org.eclipse.cdt.make.internal.core.makefile.gnu; package org.eclipse.cdt.make.internal.core.makefile.gnu;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; 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.TargetRule;
import org.eclipse.cdt.make.internal.core.makefile.Util; import org.eclipse.cdt.make.internal.core.makefile.Util;
import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefileUtil; 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.Path;
import org.eclipse.core.runtime.Platform;
/** /**
* Makefile : ( statement ) * * Makefile : ( statement ) *
@ -81,22 +83,15 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
super(null); super(null);
} }
public void parse(String name) throws IOException { public void parse(String filePath, Reader reader) throws IOException {
FileReader stream = new FileReader(name); parse(URIUtil.toURI(filePath), new MakefileReader(reader));
parse(name, stream);
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
}
}
} }
public void parse(String name, Reader reader) throws IOException { public void parse(URI filePath, Reader reader) throws IOException {
parse(name, new MakefileReader(reader)); 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; String line;
Rule[] rules = null; Rule[] rules = null;
Stack conditions = new Stack(); Stack conditions = new Stack();
@ -107,7 +102,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
// Clear any old directives. // Clear any old directives.
clearDirectives(); clearDirectives();
setFilename(name); setFileURI(fileURI);
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
startLine = endLine + 1; startLine = endLine + 1;
@ -793,21 +788,21 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
if (builtins == null) { if (builtins == null) {
String location = "builtin" + File.separator + "gnu.mk"; //$NON-NLS-1$ //$NON-NLS-2$ String location = "builtin" + File.separator + "gnu.mk"; //$NON-NLS-1$ //$NON-NLS-2$
try { try {
InputStream stream = MakeCorePlugin.getDefault().openStream(new Path(location)); InputStream stream = FileLocator.openStream(MakeCorePlugin.getDefault().getBundle(), new Path(location), false);
GNUMakefile gnu = new GNUMakefile(); GNUMakefile gnu = new GNUMakefile();
URL url = Platform.find(MakeCorePlugin.getDefault().getBundle(), new Path(location)); URL url = FileLocator.find(MakeCorePlugin.getDefault().getBundle(), new Path(location), null);
url = Platform.resolve(url); gnu.parse(url.toURI(), new InputStreamReader(stream));
location = url.getFile();
gnu.parse(location, new InputStreamReader(stream));
builtins = gnu.getDirectives(); builtins = gnu.getDirectives();
for (int i = 0; i < builtins.length; i++) { for (int i = 0; i < builtins.length; i++) {
if (builtins[i] instanceof MacroDefinition) { if (builtins[i] instanceof MacroDefinition) {
((MacroDefinition)builtins[i]).setFromDefault(true); ((MacroDefinition) builtins[i]).setFromDefault(true);
} }
} }
} catch (Exception e) { } catch (IOException e) {
//e.printStackTrace(); MakeCorePlugin.log(e);
} } catch (URISyntaxException e) {
MakeCorePlugin.log(e);
}
if (builtins == null) { if (builtins == null) {
builtins = new IDirective[0]; builtins = new IDirective[0];
} }
@ -822,23 +817,4 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
public String[] getIncludeDirectories() { public String[] getIncludeDirectories() {
return includeDirectories; 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);
}
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -76,9 +76,7 @@ public class GNUMakefileChecker extends ACBuilder {
checkProject(getProject(), monitor); checkProject(getProject(), monitor);
} else { } else {
MyResourceDeltaVisitor vis = new MyResourceDeltaVisitor(monitor); MyResourceDeltaVisitor vis = new MyResourceDeltaVisitor(monitor);
if (delta != null) { delta.accept(vis);
delta.accept(vis);
}
} }
checkCancel(monitor); checkCancel(monitor);
return new IProject[0]; return new IProject[0];

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -10,12 +10,21 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.core.makefile.gnu; package org.eclipse.cdt.make.internal.core.makefile.gnu;
import java.io.FileInputStream;
import java.io.IOException; 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.IDirective;
import org.eclipse.cdt.make.core.makefile.gnu.IInclude; 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.Directive;
import org.eclipse.cdt.make.internal.core.makefile.Parent; 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; import org.eclipse.core.runtime.Path;
public class Include extends Parent implements IInclude { public class Include extends Parent implements IInclude {
@ -43,38 +52,44 @@ public class Include extends Parent implements IInclude {
public IDirective[] getDirectives() { public IDirective[] getDirectives() {
clearDirectives(); clearDirectives();
URI uri = getMakefile().getFileURI();
for (int i = 0; i < filenames.length; i++) { for (int i = 0; i < filenames.length; i++) {
// Try the current directory. IPath includeFilePath = new Path(filenames[i]);
GNUMakefile gnu = new GNUMakefile(); if (includeFilePath.isAbsolute()) {
try {
gnu.parse(filenames[i]);
addDirective(gnu);
continue;
} catch (IOException e) {
}
if (filenames[i].startsWith(GNUMakefile.FILE_SEPARATOR)) {
// Try to set the device to that of the parent makefile. // Try to set the device to that of the parent makefile.
String filename = getFileName(); final IPath path = URIUtil.toPath(uri);
if (filename != null) { if (path != null) {
String device = new Path(filename).getDevice(); String device = path.getDevice();
if (device != null) { if (device != null && includeFilePath.getDevice() == null) {
try { includeFilePath = includeFilePath.setDevice(device);
gnu.parse(new Path(filenames[i]).setDevice(device).toOSString()); }
addDirective(gnu); try {
continue; GNUMakefile gnu = new GNUMakefile();
} catch (IOException e) { final InputStreamReader reader = new InputStreamReader(new FileInputStream(includeFilePath.toFile()));
} gnu.parse(includeFilePath.toOSString(), reader);
addDirective(gnu);
continue;
} catch (IOException e) {
} }
} }
} else if (dirs != null) { } else if (dirs != null) {
for (int j = 0; j < dirs.length; j++) { for (int j = 0; j < dirs.length; j++) {
try { try {
String filename = dirs[j] + GNUMakefile.FILE_SEPARATOR + filenames[i]; includeFilePath= new Path(dirs[j]).append(includeFilePath);
gnu = new GNUMakefile(); String uriPath = includeFilePath.toString();
gnu.parse(filename); 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); addDirective(gnu);
break; break;
} catch (IOException e) { } catch (IOException e) {
} catch (URISyntaxException exc) {
} catch (CoreException exc) {
} }
} }
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,11 +11,12 @@
package org.eclipse.cdt.make.internal.core.makefile.posix; package org.eclipse.cdt.make.internal.core.makefile.posix;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import org.eclipse.cdt.make.core.MakeCorePlugin; 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.Target;
import org.eclipse.cdt.make.internal.core.makefile.TargetRule; 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.Util;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
/** /**
* Makefile : ( statement ) * * Makefile : ( statement ) *
@ -70,22 +72,15 @@ public class PosixMakefile extends AbstractMakefile {
super(null); 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 { public void parse(String name, Reader reader) throws IOException {
parse(name, new MakefileReader(reader)); parse(URIUtil.toURI(name), new MakefileReader(reader));
} }
protected void parse(String name, MakefileReader reader) throws IOException { public void parse(URI fileURI, Reader reader) throws IOException {
parse(fileURI, new MakefileReader(reader));
}
protected void parse(URI fileURI, MakefileReader reader) throws IOException {
String line; String line;
Rule[] rules = null; Rule[] rules = null;
int startLine = 0; int startLine = 0;
@ -94,7 +89,7 @@ public class PosixMakefile extends AbstractMakefile {
// Clear any old directives. // Clear any old directives.
clearDirectives(); clearDirectives();
setFilename(name); setFileURI(fileURI);
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
startLine = endLine + 1; startLine = endLine + 1;
@ -210,21 +205,21 @@ public class PosixMakefile extends AbstractMakefile {
if (builtins == null) { if (builtins == null) {
String location = "builtin" + File.separator + "posix.mk"; //$NON-NLS-1$ //$NON-NLS-2$ String location = "builtin" + File.separator + "posix.mk"; //$NON-NLS-1$ //$NON-NLS-2$
try { try {
InputStream stream = MakeCorePlugin.getDefault().openStream(new Path(location)); InputStream stream = FileLocator.openStream(MakeCorePlugin.getDefault().getBundle(), new Path(location), false);
PosixMakefile gnu = new PosixMakefile(); PosixMakefile posix = new PosixMakefile();
URL url = Platform.find(MakeCorePlugin.getDefault().getBundle(), new Path(location)); URL url = FileLocator.find(MakeCorePlugin.getDefault().getBundle(), new Path(location), null);
url = Platform.resolve(url); posix.parse(url.toURI(), new InputStreamReader(stream));
location = url.getFile(); builtins = posix.getDirectives();
gnu.parse(location, new InputStreamReader(stream));
builtins = gnu.getDirectives();
for (int i = 0; i < builtins.length; i++) { for (int i = 0; i < builtins.length; i++) {
if (builtins[i] instanceof MacroDefinition) { if (builtins[i] instanceof MacroDefinition) {
((MacroDefinition)builtins[i]).setFromDefault(true); ((MacroDefinition)builtins[i]).setFromDefault(true);
} }
} }
} catch (Exception e) { } catch (IOException e) {
//e.printStackTrace(); MakeCorePlugin.log(e);
} } catch (URISyntaxException e) {
MakeCorePlugin.log(e);
}
if (builtins == null) { if (builtins == null) {
builtins = new IDirective[0]; builtins = new IDirective[0];
} }
@ -337,24 +332,4 @@ public class PosixMakefile extends AbstractMakefile {
} }
return targetRules; 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);
}
}
} }

View file

@ -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.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.ui;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.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-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.4 Bundle-RequiredExecutionEnvironment: J2SE-1.4

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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()) { if (file.exists()) {
return MakeCorePlugin.getDefault().createMakefile(file); return MakeCorePlugin.getDefault().createMakefile(file);
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -10,25 +10,14 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.ui.editor; 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.IDirective;
import org.eclipse.cdt.make.core.makefile.IMakefile; import org.eclipse.cdt.make.core.makefile.IMakefile;
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
import org.eclipse.cdt.make.internal.ui.text.WordPartDetector; import org.eclipse.cdt.make.internal.ui.text.WordPartDetector;
import org.eclipse.cdt.make.ui.IWorkingCopyManager; 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.IDocument;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelectionProvider; 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.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.TextEditorAction; import org.eclipse.ui.texteditor.TextEditorAction;
@ -77,51 +66,11 @@ public class OpenDeclarationAction extends TextEditorAction {
directives = makefile.getTargetRules(name); directives = makefile.getTargetRules(name);
} }
if (directives != null && directives.length > 0) { if (directives != null && directives.length > 0) {
openInEditor(directives[0]); OpenIncludeAction.openInEditor(directives[0]);
} }
} catch (Exception x) { } 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);
//}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,26 +11,26 @@
package org.eclipse.cdt.make.internal.ui.editor; package org.eclipse.cdt.make.internal.ui.editor;
import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.IDirective;
import org.eclipse.cdt.make.core.makefile.gnu.IInclude; import org.eclipse.cdt.make.core.makefile.gnu.IInclude;
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; 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.IFile;
import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException; import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.ide.IDE; import org.eclipse.ui.ide.IDE;
/** /**
@ -70,33 +70,35 @@ public class OpenIncludeAction extends Action {
} }
} }
private static IEditorPart openInEditor(IDirective directive) throws PartInitException { public static IEditorPart openInEditor(IDirective directive) throws PartInitException {
String filename = directive.getFileName(); try {
IPath path = new Path(filename); URI uri = directive.getMakefile().getFileURI();
IFile file = MakeUIPlugin.getWorkspace().getRoot().getFileForLocation(path); IFileStore store = EFS.getStore(uri);
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;
}
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;
}
} 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;
}
}
} catch (CoreException e) {
} }
return null; return null;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -87,7 +87,7 @@ public class MakefileReconcilingStrategy implements IReconcilingStrategy {
String content = fDocumentProvider.getDocument(fEditor.getEditorInput()).get(); String content = fDocumentProvider.getDocument(fEditor.getEditorInput()).get();
StringReader reader = new StringReader(content); StringReader reader = new StringReader(content);
try { try {
makefile.parse(makefile.getFileName(), reader); makefile.parse(makefile.getFileURI(), reader);
} catch (IOException e) { } catch (IOException e) {
} }