Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 158095 Details for
Bug 301562
[JSR269] Error in EclipseFileManager.collectAllMatchingFiles
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression tests
patch_301562.txt (text/plain), 17.28 KB, created by
Olivier Thomann
on 2010-02-03 15:32:16 EST
(
hide
)
Description:
Proposed fix + regression tests
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-02-03 15:32:16 EST
Size:
17.28 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.compiler.apt >Index: src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java,v >retrieving revision 1.8 >diff -u -r1.8 EclipseFileManager.java >--- src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java 9 Oct 2009 13:01:12 -0000 1.8 >+++ src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java 3 Feb 2010 20:31:44 -0000 >@@ -147,25 +147,19 @@ > if (File.separatorChar == '/') { > if (!path.endsWith(normalizedPackageName)) return; > } else if (!path.endsWith(normalizedPackageName.replace('/', File.separatorChar))) return; >- File[] files = currentFile.listFiles(); >- if (files != null) { >- // this was a directory >- for (File f : files) { >- if (f.isDirectory() && recurse) { >- collectAllMatchingFiles(file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector); >- } else { >- final Kind kind = getKind(f); >- if (kinds.contains(kind)) { >- collector.add(new EclipseFileObject(normalizedPackageName + currentFile.getName(), currentFile.toURI(), kind, this.charset)); >- } >- } >- } >- } >- // currentFile is not a directory >- // check if it matches the criteria >- final Kind kind = getKind(file); >- if (kinds.contains(kind)) { >- collector.add(new EclipseFileObject(normalizedPackageName + currentFile.getName(), currentFile.toURI(), kind, this.charset)); >+ File[] files = currentFile.listFiles(); >+ if (files != null) { >+ // this was a directory >+ for (File f : files) { >+ if (f.isDirectory() && recurse) { >+ collectAllMatchingFiles(file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector); >+ } else { >+ final Kind kind = getKind(f); >+ if (kinds.contains(kind)) { >+ collector.add(new EclipseFileObject(normalizedPackageName + f.getName(), f.toURI(), kind, this.charset)); >+ } >+ } >+ } > } > } else { > Archive archive = this.getArchive(file); >@@ -180,10 +174,10 @@ > ArrayList<String> types = archive.getTypes(packageName); > if (types != null) { > for (String typeName : types) { >- final Kind kind = getKind(getExtension(typeName)); >- if (kinds.contains(kind)) { >- collector.add(archive.getArchiveFileObject(packageName + typeName, this.charset)); >- } >+ final Kind kind = getKind(getExtension(typeName)); >+ if (kinds.contains(kind)) { >+ collector.add(archive.getArchiveFileObject(packageName + typeName, this.charset)); >+ } > } > } > } >@@ -192,10 +186,10 @@ > ArrayList<String> types = archive.getTypes(key); > if (types != null) { > for (String typeName : types) { >- final Kind kind = getKind(typeName); >- if (kinds.contains(kind)) { >- collector.add(archive.getArchiveFileObject(normalizedPackageName + typeName, this.charset)); >- } >+ final Kind kind = getKind(typeName); >+ if (kinds.contains(kind)) { >+ collector.add(archive.getArchiveFileObject(normalizedPackageName + typeName, this.charset)); >+ } > } > } > } >#P org.eclipse.jdt.compiler.apt.tests >Index: src/org/eclipse/jdt/compiler/apt/tests/AllTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AllTests.java,v >retrieving revision 1.12 >diff -u -r1.12 AllTests.java >--- src/org/eclipse/jdt/compiler/apt/tests/AllTests.java 26 Mar 2008 00:39:09 -0000 1.12 >+++ src/org/eclipse/jdt/compiler/apt/tests/AllTests.java 3 Feb 2010 20:31:45 -0000 >@@ -22,6 +22,7 @@ > // run all tests > public static Test suite() { > TestSuite suite = new TestSuite(); >+ suite.addTestSuite(FileManagerTests.class); > suite.addTestSuite(BatchDispatchTests.class); > suite.addTestSuite(ModelTests.class); > suite.addTestSuite(MessagerTests.class); >Index: src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java >=================================================================== >RCS file: src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java >diff -N src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jdt/compiler/apt/tests/FileManagerTests.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,103 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 BEA Systems, Inc. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * wharley@bea.com - initial API and implementation >+ * >+ *******************************************************************************/ >+ >+package org.eclipse.jdt.compiler.apt.tests; >+ >+import java.io.BufferedWriter; >+import java.io.File; >+import java.io.FileWriter; >+import java.io.IOException; >+import java.nio.charset.Charset; >+import java.util.ArrayList; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Locale; >+import java.util.Set; >+ >+import javax.tools.JavaFileManager; >+import javax.tools.JavaFileObject; >+import javax.tools.StandardJavaFileManager; >+ >+import org.eclipse.jdt.internal.compiler.apt.util.EclipseFileManager; >+ >+import junit.framework.TestCase; >+ >+/** >+ * Test the implementation of the Filer interface, >+ * in more detail than BatchDispatchTests does. >+ * @since 3.4 >+ */ >+public class FileManagerTests extends TestCase { >+ >+ /* (non-Javadoc) >+ * @see junit.framework.TestCase#setUp() >+ */ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ BatchTestUtils.init(); >+ } >+ >+ public void testFileManager() { >+ String tmpFolder = System.getProperty("java.io.tmpdir"); >+ File dir = new File(tmpFolder, "src" + System.currentTimeMillis()); >+ dir.mkdirs(); >+ File inputFile = new File(dir, "X.java"); >+ BufferedWriter writer = null; >+ try { >+ writer = new BufferedWriter(new FileWriter(inputFile)); >+ writer.write("public class X {}"); >+ writer.flush(); >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } finally { >+ if (writer != null) { >+ try { >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } >+ } >+ } >+ try { >+ StandardJavaFileManager fileManager = new EclipseFileManager(Locale.getDefault(), Charset.defaultCharset()); >+ >+ List<File> fins = new ArrayList<File>(); >+ fins.add(dir); >+ >+ JavaFileManager.Location sourceLoc = javax.tools.StandardLocation.SOURCE_PATH; >+ fileManager.setLocation(sourceLoc, fins); >+ >+ Set<JavaFileObject.Kind> fileTypes = new HashSet<JavaFileObject.Kind>(); >+ fileTypes.add(JavaFileObject.Kind.SOURCE); >+ >+ Iterable<? extends JavaFileObject> compilationUnits = fileManager.list(sourceLoc, "", fileTypes, true); >+ >+ Iterator<? extends JavaFileObject> it = compilationUnits.iterator(); >+ StringBuilder builder = new StringBuilder(); >+ while (it.hasNext()) { >+ JavaFileObject next = it.next(); >+ String name = next.getName(); >+ name = name.replace('\\', '/'); >+ int lastIndexOf = name.lastIndexOf('/'); >+ builder.append(name.substring(lastIndexOf + 1)); >+ } >+ assertEquals("Wrong contents", "X.java", String.valueOf(builder)); >+ } catch (IOException e) { >+ e.printStackTrace(); >+ } >+ // check that the .class file exist for X >+ assertTrue("delete failed", inputFile.delete()); >+ assertTrue("delete failed", dir.delete()); >+ } >+} >#P org.eclipse.jdt.compiler.tool >Index: src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java,v >retrieving revision 1.12 >diff -u -r1.12 EclipseFileManager.java >--- src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java 9 Oct 2009 13:01:17 -0000 1.12 >+++ src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java 3 Feb 2010 20:31:45 -0000 >@@ -148,25 +148,19 @@ > if (File.separatorChar == '/') { > if (!path.endsWith(normalizedPackageName)) return; > } else if (!path.endsWith(normalizedPackageName.replace('/', File.separatorChar))) return; >- File[] files = currentFile.listFiles(); >- if (files != null) { >- // this was a directory >- for (File f : files) { >- if (f.isDirectory() && recurse) { >- collectAllMatchingFiles(file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector); >- } else { >- final Kind kind = getKind(f); >- if (kinds.contains(kind)) { >- collector.add(new EclipseFileObject(normalizedPackageName + currentFile.getName(), currentFile.toURI(), kind, this.charset)); >- } >- } >- } >- } >- // currentFile is not a directory >- // check if it matches the criteria >- final Kind kind = getKind(file); >- if (kinds.contains(kind)) { >- collector.add(new EclipseFileObject(normalizedPackageName + currentFile.getName(), currentFile.toURI(), kind, this.charset)); >+ File[] files = currentFile.listFiles(); >+ if (files != null) { >+ // this was a directory >+ for (File f : files) { >+ if (f.isDirectory() && recurse) { >+ collectAllMatchingFiles(file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector); >+ } else { >+ final Kind kind = getKind(f); >+ if (kinds.contains(kind)) { >+ collector.add(new EclipseFileObject(normalizedPackageName + f.getName(), f.toURI(), kind, this.charset)); >+ } >+ } >+ } > } > } else { > Archive archive = this.getArchive(file); >@@ -181,10 +175,10 @@ > ArrayList<String> types = archive.getTypes(packageName); > if (types != null) { > for (String typeName : types) { >- final Kind kind = getKind(getExtension(typeName)); >- if (kinds.contains(kind)) { >- collector.add(archive.getArchiveFileObject(packageName + typeName, this.charset)); >- } >+ final Kind kind = getKind(getExtension(typeName)); >+ if (kinds.contains(kind)) { >+ collector.add(archive.getArchiveFileObject(packageName + typeName, this.charset)); >+ } > } > } > } >@@ -193,10 +187,10 @@ > ArrayList<String> types = archive.getTypes(key); > if (types != null) { > for (String typeName : types) { >- final Kind kind = getKind(typeName); >- if (kinds.contains(kind)) { >- collector.add(archive.getArchiveFileObject(normalizedPackageName + typeName, this.charset)); >- } >+ final Kind kind = getKind(typeName); >+ if (kinds.contains(kind)) { >+ collector.add(archive.getArchiveFileObject(normalizedPackageName + typeName, this.charset)); >+ } > } > } > } >#P org.eclipse.jdt.compiler.tool.tests >Index: src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java,v >retrieving revision 1.21 >diff -u -r1.21 CompilerToolTests.java >--- src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java 4 Jan 2010 19:24:56 -0000 1.21 >+++ src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java 3 Feb 2010 20:31:46 -0000 >@@ -19,13 +19,17 @@ > import java.io.StringWriter; > import java.nio.charset.Charset; > import java.util.ArrayList; >+import java.util.HashSet; >+import java.util.Iterator; > import java.util.List; > import java.util.Locale; > import java.util.ServiceLoader; >+import java.util.Set; > > import javax.tools.FileObject; > import javax.tools.ForwardingJavaFileManager; > import javax.tools.JavaCompiler; >+import javax.tools.JavaFileManager; > import javax.tools.JavaFileObject; > import javax.tools.StandardJavaFileManager; > import javax.tools.StandardLocation; >@@ -51,6 +55,8 @@ > public static TestSuite suite() { > TestSuite suite = new TestSuite(); > suite.addTest(new CompilerToolTests("testInitializeJavaCompiler")); >+ suite.addTest(new CompilerToolTests("testFileManager")); >+ suite.addTest(new CompilerToolTests("testFileManager2")); > suite.addTest(new CompilerToolTests("testCheckOptions")); > suite.addTest(new CompilerToolTests("testCompilerOneClassWithSystemCompiler")); > // suite.addTest(new CompilerToolTests("testCompilerOneClassWithSystemCompiler2")); >@@ -682,6 +688,136 @@ > assertTrue("delete failed", inputFile.delete()); > } > >+ public void testFileManager() { >+ String tmpFolder = System.getProperty("java.io.tmpdir"); >+ File dir = new File(tmpFolder, "src" + System.currentTimeMillis()); >+ dir.mkdirs(); >+ File inputFile = new File(dir, "X.java"); >+ BufferedWriter writer = null; >+ try { >+ writer = new BufferedWriter(new FileWriter(inputFile)); >+ writer.write("public class X {}"); >+ writer.flush(); >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } finally { >+ if (writer != null) { >+ try { >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } >+ } >+ } >+ try { >+ //JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler(); >+ StandardJavaFileManager fileManager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); >+ >+ List<File> fins = new ArrayList<File>(); >+ fins.add(dir); >+ >+ JavaFileManager.Location sourceLoc = javax.tools.StandardLocation.SOURCE_PATH; >+ fileManager.setLocation(sourceLoc, fins); >+ >+ Set<JavaFileObject.Kind> fileTypes = new HashSet<JavaFileObject.Kind>(); >+ fileTypes.add(JavaFileObject.Kind.SOURCE); >+ >+ Iterable<? extends JavaFileObject> compilationUnits = fileManager.list(sourceLoc, "", fileTypes, true); >+ >+ Iterator<? extends JavaFileObject> it = compilationUnits.iterator(); >+ StringBuilder builder = new StringBuilder(); >+ while (it.hasNext()) { >+ JavaFileObject next = it.next(); >+ String name = next.getName(); >+ name = name.replace('\\', '/'); >+ int lastIndexOf = name.lastIndexOf('/'); >+ builder.append(name.substring(lastIndexOf + 1)); >+ } >+ assertEquals("Wrong contents", "X.java", String.valueOf(builder)); >+ } catch (IOException e) { >+ e.printStackTrace(); >+ } >+ // check that the .class file exist for X >+ assertTrue("delete failed", inputFile.delete()); >+ assertTrue("delete failed", dir.delete()); >+ } >+ public void testFileManager2() { >+ String tmpFolder = System.getProperty("java.io.tmpdir"); >+ File dir = new File(tmpFolder, "src" + System.currentTimeMillis()); >+ dir.mkdirs(); >+ File dir2 = new File(dir, "src2"); >+ dir2.mkdirs(); >+ File inputFile = new File(dir, "X.java"); >+ BufferedWriter writer = null; >+ try { >+ writer = new BufferedWriter(new FileWriter(inputFile)); >+ writer.write("public class X {}"); >+ writer.flush(); >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } finally { >+ if (writer != null) { >+ try { >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } >+ } >+ } >+ File inputFile2 = new File(dir2, "X2.java"); >+ writer = null; >+ try { >+ writer = new BufferedWriter(new FileWriter(inputFile2)); >+ writer.write("public class X2 {}"); >+ writer.flush(); >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } finally { >+ if (writer != null) { >+ try { >+ writer.close(); >+ } catch (IOException e) { >+ // ignore >+ } >+ } >+ } >+ try { >+ //JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler(); >+ StandardJavaFileManager fileManager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); >+ >+ List<File> fins = new ArrayList<File>(); >+ fins.add(dir); >+ >+ JavaFileManager.Location sourceLoc = javax.tools.StandardLocation.SOURCE_PATH; >+ fileManager.setLocation(sourceLoc, fins); >+ >+ Set<JavaFileObject.Kind> fileTypes = new HashSet<JavaFileObject.Kind>(); >+ fileTypes.add(JavaFileObject.Kind.SOURCE); >+ >+ Iterable<? extends JavaFileObject> compilationUnits = fileManager.list(sourceLoc, "", fileTypes, true); >+ >+ Iterator<? extends JavaFileObject> it = compilationUnits.iterator(); >+ StringBuilder builder = new StringBuilder(); >+ while (it.hasNext()) { >+ JavaFileObject next = it.next(); >+ String name = next.getName(); >+ name = name.replace('\\', '/'); >+ int lastIndexOf = name.lastIndexOf('/'); >+ builder.append(name.substring(lastIndexOf + 1)); >+ } >+ assertEquals("Wrong contents", "X2.javaX.java", String.valueOf(builder)); >+ } catch (IOException e) { >+ e.printStackTrace(); >+ } >+ // check that the .class file exist for X >+ assertTrue("delete failed", inputFile2.delete()); >+ assertTrue("delete failed", dir2.delete()); >+ assertTrue("delete failed", inputFile.delete()); >+ assertTrue("delete failed", dir.delete()); >+ } > /* > * Clean up the compiler > */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 301562
: 158095