1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Bug 338936 - Makefile parsers don't close the input streams

This commit is contained in:
Anton Leherbauer 2011-03-07 16:24:27 +00:00
parent 85a953ca4c
commit eb02ad7b69
6 changed files with 329 additions and 280 deletions

View file

@ -11,5 +11,6 @@
source.. = src/ source.. = src/
output.. = bin/ output.. = bin/
bin.includes = .,\ bin.includes = .,\
META-INF/ META-INF/,\
data/
src.includes = about.html src.includes = about.html

View file

@ -0,0 +1,4 @@
VAR = foo
include Makefile.incl
main: $(VAR)
nothing

View file

@ -0,0 +1,2 @@
INCLVAR = bar
foo.o: .PHONY

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Nokia and others. * Copyright (c) 2008, 2011 Nokia 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
@ -7,20 +7,34 @@
* *
* Contributors: * Contributors:
* Nokia (Ed Swartz) - initial API and implementation * Nokia (Ed Swartz) - initial API and implementation
* Wind River Systems - Bug 338936
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.core.tests; package org.eclipse.cdt.make.core.tests;
import org.eclipse.cdt.make.core.MakeCorePlugin; import java.io.File;
import org.eclipse.cdt.make.core.makefile.*; import java.io.FileNotFoundException;
import org.eclipse.core.filesystem.URIUtil; import java.io.IOException;
import org.eclipse.core.runtime.*; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*; import java.io.Reader;
import java.net.*; import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
import org.eclipse.cdt.make.core.makefile.IMakefile;
import org.eclipse.cdt.make.core.makefile.IMakefileReaderProvider;
import org.eclipse.cdt.make.core.makefile.IRule;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class MakefileReaderProviderTests extends TestCase { public class MakefileReaderProviderTests extends TestCase {
private String[] inclDirs; private String[] inclDirs;
@ -91,7 +105,7 @@ public class MakefileReaderProviderTests extends TestCase {
public void testInMemoryReaderProvider() throws Exception { public void testInMemoryReaderProvider() throws Exception {
IMakefile makefile = MakeCorePlugin.createMakefile( IMakefile makefile = MakeCorePlugin.createMakefile(
URIUtil.toURI("Makefile.main"), true, inclDirs, URIUtil.toURI("/memory/Makefile.main"), true, inclDirs,
new IMakefileReaderProvider() { new IMakefileReaderProvider() {
public Reader getReader(URI fileURI) throws IOException { public Reader getReader(URI fileURI) throws IOException {
@ -119,6 +133,25 @@ public class MakefileReaderProviderTests extends TestCase {
assertMakefileContents(makefile); assertMakefileContents(makefile);
} }
public void testReaderIsClosed_Bug338936() throws Exception {
final boolean[] streamIsClosed = { false };
MakeCorePlugin.createMakefile(
URIUtil.toURI("Makefile.main"), true, inclDirs,
new IMakefileReaderProvider() {
public Reader getReader(URI fileURI) throws IOException {
return new StringReader("") {
@Override
public void close() {
super.close();
streamIsClosed[0] = true;
}
};
}
});
assertTrue("Stream is not closed", streamIsClosed[0]);
}
/** /**
* @param makefile * @param makefile
*/ */
@ -152,19 +185,18 @@ public class MakefileReaderProviderTests extends TestCase {
} }
private URL getPluginRelativeURL(IPath path) throws Exception { private URL getPluginRelativeURL(IPath path) throws Exception {
if (MakeTestsPlugin.getDefault() != null) if (MakeTestsPlugin.getDefault() != null) {
return FileLocator.find( URL url = FileLocator.find(
MakeTestsPlugin.getDefault().getBundle(), MakeTestsPlugin.getDefault().getBundle(),
path, null); path, null);
return url != null ? FileLocator.toFileURL(url) : null;
}
else { else {
return new URL("file", null, path.toFile().getAbsolutePath()); return new URL("file", null, path.toFile().getAbsolutePath());
} }
} }
/**
* @return
*/
public static Test suite() { public static Test suite() {
return new MakefileReaderProviderTests(); return new TestSuite(MakefileReaderProviderTests.class);
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2010 QNX Software Systems and others. * Copyright (c) 2000, 2011 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
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Wind River Systems - Bug 338936
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.core.makefile.gnu; package org.eclipse.cdt.make.internal.core.makefile.gnu;
@ -137,6 +138,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
setFileURI(fileURI); setFileURI(fileURI);
try {
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
startLine = endLine + 1; startLine = endLine + 1;
endLine = reader.getLineNumber(); endLine = reader.getLineNumber();
@ -337,6 +339,9 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
} }
setLines(1, endLine); setLines(1, endLine);
} finally {
reader.close();
}
// TEST please remove. // TEST please remove.
//GNUMakefileValidator validator = new GNUMakefileValidator(); //GNUMakefileValidator validator = new GNUMakefileValidator();
//validator.validateDirectives(null, getDirectives()); //validator.validateDirectives(null, getDirectives());

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2010 QNX Software Systems and others. * Copyright (c) 2000, 2011 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
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Wind River Systems - Bug 338936
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.core.makefile.posix; package org.eclipse.cdt.make.internal.core.makefile.posix;
@ -117,6 +118,7 @@ public class PosixMakefile extends AbstractMakefile {
setFileURI(fileURI); setFileURI(fileURI);
try {
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
startLine = endLine + 1; startLine = endLine + 1;
endLine = reader.getLineNumber(); endLine = reader.getLineNumber();
@ -222,6 +224,9 @@ public class PosixMakefile extends AbstractMakefile {
addDirective(stmt); addDirective(stmt);
} }
setLines(1, endLine); setLines(1, endLine);
} finally {
reader.close();
}
} }
/* (non-Javadoc) /* (non-Javadoc)