mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +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:
parent
cfae4dbc59
commit
7fde922525
16 changed files with 222 additions and 247 deletions
|
@ -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
|
||||
|
|
|
@ -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,32 @@ 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));
|
||||
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(file.getAbsolutePath(), new FileReader(file));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
makefile = gnu;
|
||||
} else {
|
||||
PosixMakefile posix = new PosixMakefile();
|
||||
try {
|
||||
posix.parse(file.getAbsolutePath());
|
||||
posix.parse(file.getAbsolutePath(), new FileReader(file));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
makefile = posix;
|
||||
|
@ -175,9 +186,35 @@ public class MakeCorePlugin extends Plugin {
|
|||
return makefile;
|
||||
}
|
||||
|
||||
public IMakefile createMakefile(IFile file) {
|
||||
return createMakefile(file.getLocation().toFile(), isMakefileGNUStyle(),
|
||||
getMakefileDirs());
|
||||
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));
|
||||
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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
//}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue