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 193394 Details for
Bug 342936
NPEs and inconsistencies when running jdt.compiler.tool.tests against Java 7
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix
patch_342936.txt (text/plain), 44.76 KB, created by
Olivier Thomann
on 2011-04-15 13:48:19 EDT
(
hide
)
Description:
Proposed fix
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2011-04-15 13:48:19 EDT
Size:
44.76 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.compiler.apt.tests >Index: processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java,v >retrieving revision 1.4 >diff -u -r1.4 MessagerProc.java >--- processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java 19 Jan 2009 08:42:12 -0000 1.4 >+++ processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java 15 Apr 2011 17:47:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2009 BEA Systems, Inc. >+ * Copyright (c) 2007, 2011 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 >@@ -7,7 +7,7 @@ > * > * Contributors: > * wharley@bea.com - initial API and implementation >- * >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > > package org.eclipse.jdt.compiler.apt.tests.processors.messager; >Index: src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java,v >retrieving revision 1.9 >diff -u -r1.9 BatchDispatchTests.java >--- src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java 15 Nov 2007 17:49:06 -0000 1.9 >+++ src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java 15 Apr 2011 17:47:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2006, 2007 BEA Systems, Inc. >+ * Copyright (c) 2006, 2011 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 >@@ -7,7 +7,7 @@ > * > * Contributors: > * wharley@bea.com - initial API and implementation >- * >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > package org.eclipse.jdt.compiler.apt.tests; > >@@ -83,6 +83,10 @@ > public void testProcessorArgumentsWithSystemCompiler() throws IOException { > // System compiler > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTestProcessorArguments(compiler); > } > >@@ -105,6 +109,10 @@ > public void testCompilerOneClassWithSystemCompiler() throws IOException { > // System compiler > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTestGenerateClass(compiler); > } > >@@ -124,6 +132,10 @@ > */ > public void testInheritedAnnosWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTestInheritance(compiler, INHERITEDANNOPROC); > } > >Index: src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java,v >retrieving revision 1.14 >diff -u -r1.14 BatchTestUtils.java >--- src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java 28 Apr 2009 16:35:01 -0000 1.14 >+++ src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java 15 Apr 2011 17:47:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2009 BEA Systems, Inc. >+ * Copyright (c) 2007, 2011 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 >@@ -7,8 +7,8 @@ > * > * Contributors: > * wharley@bea.com - initial API and implementation >- * >- *******************************************************************************/ >+ * IBM Corporation - fix for 342936 >+*******************************************************************************/ > > package org.eclipse.jdt.compiler.apt.tests; > >@@ -27,6 +27,7 @@ > import java.util.Locale; > import java.util.ServiceLoader; > >+import javax.tools.DiagnosticListener; > import javax.tools.JavaCompiler; > import javax.tools.JavaFileObject; > import javax.tools.StandardJavaFileManager; >@@ -131,14 +132,17 @@ > * @param errors a StringWriter into which compiler output will be written > * @return true if the compilation was successful > */ >- public static boolean compileTreeWithErrors(JavaCompiler compiler, List<String> options, File targetFolder, StringWriter errors) { >+ public static boolean compileTreeWithErrors( >+ JavaCompiler compiler, >+ List<String> options, >+ File targetFolder, >+ DiagnosticListener<? super JavaFileObject> diagnosticListener) { > StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); > > // create new list containing inputfile > List<File> files = new ArrayList<File>(); > findFilesUnder(targetFolder, files); > Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files); >- PrintWriter printWriter = new PrintWriter(errors); > > options.add("-d"); > options.add(_tmpBinFolderName); >@@ -148,7 +152,9 @@ > options.add(_tmpSrcFolderName + File.pathSeparator + _tmpGenFolderName + File.pathSeparator + _processorJarPath); > options.add("-processorpath"); > options.add(_processorJarPath); >- CompilationTask task = compiler.getTask(printWriter, manager, null, options, null, units); >+ // use writer to prevent System.out/err to be polluted with problems >+ StringWriter writer = new StringWriter(); >+ CompilationTask task = compiler.getTask(writer, manager, diagnosticListener, options, null, units); > Boolean result = task.call(); > > return result.booleanValue(); >Index: src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java,v >retrieving revision 1.2 >diff -u -r1.2 FilerTests.java >--- src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java 5 Mar 2011 19:41:19 -0000 1.2 >+++ src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java 15 Apr 2011 17:47:17 -0000 >@@ -8,6 +8,7 @@ > * Contributors: > * wharley@bea.com - initial API and implementation > * philippe.marschall@netcetera.ch - Regression test for 338370 >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > > package org.eclipse.jdt.compiler.apt.tests; >@@ -36,6 +37,10 @@ > */ > public void testElementWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTestCreateResource(compiler, true); > } > >Index: src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java,v >retrieving revision 1.5 >diff -u -r1.5 MessagerTests.java >--- src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java 2 Mar 2009 06:38:43 -0000 1.5 >+++ src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java 15 Apr 2011 17:47:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2009 BEA Systems, Inc. and others >+ * Copyright (c) 2007, 2011 BEA Systems, Inc. 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 >@@ -7,19 +7,20 @@ > * > * Contributors: > * wharley@bea.com - initial API and implementation >- * >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > > package org.eclipse.jdt.compiler.apt.tests; > > import java.io.File; > import java.io.IOException; >-import java.io.StringWriter; > import java.util.ArrayList; > import java.util.List; >-import java.util.regex.Pattern; > >+import javax.tools.Diagnostic; >+import javax.tools.DiagnosticListener; > import javax.tools.JavaCompiler; >+import javax.tools.JavaFileObject; > import javax.tools.ToolProvider; > > import junit.framework.TestCase; >@@ -29,107 +30,22 @@ > * @since 3.3 > */ > public class MessagerTests extends TestCase { >- private static final String COMPARE_OK = "OK"; >- // See corresponding usages in the MessagerProc class >- private static final String MESSAGERPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.messager.MessagerProc"; >- >- // Expected output for the javac compiler. >- // Note that this is actually a series of regular expressions, which will be matched line by line! >- // This is required in order to deal with things like hard-coded paths. >- private static final String[] EXPECTED_JAVAC_MESSAGES = { >- "Note\\: Informational message not associated with an element", >- ".*D\\.java\\:15\\: Error on element D", >- "public class D \\{", >- " \\^", >- ".*D\\.java\\:12\\: Error on element D", >- "\\@AnnoZ\\(", >- "\\^", >- ".*D\\.java\\:12\\: Error on element D", >- "\\@AnnoZ\\(", >- "\\^", >- "error\\: Error on element java\\.lang\\.String", >- ".*E\\.java\\:12\\: warning\\: Warning on method foo", >- " public void foo\\(int i\\) \\{\\}", >- " \\^", >- ".*E\\.java\\:14\\: Note\\: Note for field j", >- " public static int j;", >- " \\^", >- ".*D\\.java\\:19\\: warning\\: Error on parameter of D\\.methodDvoid", >- " public void methodDvoid\\(DEnum dEnum1\\) \\{", >- " \\^", >- "4 errors" >- }; >- >- // Expected output for Eclipse compiler. >- // Note that this is actually a series of regular expressions, which will be matched line by line! >- // This is required in order to deal with things like hard-coded paths. >- private static final String[] EXPECTED_ECLIPSE_MESSAGES = { >- "----------", >- "1\\. WARNING in \\(original file name is not available\\)", >- "Informational message not associated with an element", >- "----------", >- "2\\. ERROR in .*D\\.java \\(at line 15\\)", >- " public class D \\{", >- " \\^", >- "Error on element D", >- "----------", >- "3\\. ERROR in .*D\\.java \\(at line 12\\)", >- " @AnnoZ\\(", >- " \\^\\^\\^\\^\\^\\^", >- "Error on element D", >- "----------", >- "4\\. ERROR in .*D\\.java \\(at line 13\\)", >- " annoZString = \"annoZOnD\"\\)", >- " \\^\\^\\^\\^\\^\\^\\^\\^\\^\\^\\^", >- "Error on element D", >- "----------", >- "5\\. ERROR in \\(original file name is not available\\)", >- "Error on element java\\.lang\\.String", >- "----------", >- "6\\. WARNING in .*E\\.java \\(at line 12\\)", >- " public void foo\\(int i\\) \\{\\}", >- " \\^\\^\\^\\^\\^\\^\\^\\^\\^\\^", >- "Warning on method foo", >- "----------", >- "7\\. WARNING in .*E\\.java \\(at line 14\\)", >- " public static int j;", >- " \\^", >- "Note for field j", >- "----------", >- "8\\. WARNING in .*D\\.java \\(at line 19\\)", >- " public void methodDvoid\\(DEnum dEnum1\\) \\{", >- " \\^\\^\\^\\^\\^\\^", >- "Error on parameter of D\\.methodDvoid", >- "----------", >- "8 problems \\(4 errors, 4 warnings\\)" >- }; > >- /** >- * Compare an actual multi-line string against an array of regular expressions >- * representing an expected string. Each regular expression will be matched against >- * one line of the actual string. >- * @return the string "OK" if every line in the actual was matched by the corresponding regex >- * in the expected, or an error string if not. >- */ >- private static String compareRegexLines(String actual, String[] expected) { >- String[] actualLines = actual.split("\n"); >- if (actualLines.length != expected.length) { >- return "ERROR: expected " + expected.length + " lines but found " + actualLines.length; >+ public final class DiagnosticReport<S> implements DiagnosticListener<S> { >+ public int errors; >+ >+ DiagnosticReport() { >+ this.errors = 0; > } >- int i = 0; >- for (String pattern : expected) { >- int iCR = actualLines[i].indexOf('\r'); >- actualLines[i] = iCR > 0 ? actualLines[i].substring(0, iCR) : actualLines[i]; >- int iNL = actualLines[i].indexOf('\n'); >- actualLines[i] = iNL > 0 ? actualLines[i].substring(0, iNL) : actualLines[i]; >- if (!Pattern.matches(pattern, actualLines[i++])) { >- --i; >- return "ERROR: mismatch at line " + i + ": actual line was [" + actualLines[i] + "]"; >+ public void report(Diagnostic<? extends S> diagnostic) { >+ if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { >+ errors++; > } > } >- return COMPARE_OK; > } >- >+ // See corresponding usages in the MessagerProc class >+ private static final String MESSAGERPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.messager.MessagerProc"; >+ > @Override > protected void setUp() throws Exception { > super.setUp(); >@@ -142,8 +58,15 @@ > */ > public void testMessagerWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >- String actualErrors = internalTestMessager(compiler); >- assertEquals(COMPARE_OK, compareRegexLines(actualErrors, EXPECTED_JAVAC_MESSAGES)); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } >+ DiagnosticReport<JavaFileObject> diagnosticListener = new DiagnosticReport<JavaFileObject>(); >+ internalTestMessager(compiler, diagnosticListener); >+ // surprisingly enough javac 1.7 only reports 3 errors >+ // javac 1.6 reports 4 errors as expected >+ assertTrue("Wrong number of reported errors", diagnosticListener.errors >= 3); > } > > /** >@@ -152,8 +75,9 @@ > */ > public void testMessagerWithEclipseCompiler() throws IOException { > JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); >- String actualErrors = internalTestMessager(compiler); >- assertEquals(COMPARE_OK, compareRegexLines(actualErrors, EXPECTED_ECLIPSE_MESSAGES)); >+ DiagnosticReport<JavaFileObject> diagnosticListener = new DiagnosticReport<JavaFileObject>(); >+ internalTestMessager(compiler, diagnosticListener); >+ assertEquals("Wrong number of reported errors", 4, diagnosticListener.errors); > } > > /** >@@ -161,7 +85,7 @@ > * @throws IOException > * @return the outputted errors, if the test succeeded enough to generate them > */ >- private String internalTestMessager(JavaCompiler compiler) throws IOException { >+ private void internalTestMessager(JavaCompiler compiler, DiagnosticListener<? super JavaFileObject> diagnosticListener) throws IOException { > System.clearProperty(MESSAGERPROCNAME); > File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "errors"); > BatchTestUtils.copyResources("targets/errors", targetFolder); >@@ -169,12 +93,11 @@ > // Turn on the MessagerProc - without this, it will just return without doing anything > List<String> options = new ArrayList<String>(); > options.add("-A" + MESSAGERPROCNAME); >+ options.add("-nowarn"); > >- // Invoke processing by compiling the targets.model resources >- StringWriter errors = new StringWriter(); >- boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, errors); >+ // Invoke processing by compiling the targets.errors resources >+ boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener); > >- assertTrue("errors should not be empty", errors.getBuffer().length() != 0); > assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); > > // If it succeeded, the processor will have set this property to "succeeded"; >@@ -182,10 +105,6 @@ > String property = System.getProperty(MESSAGERPROCNAME); > assertNotNull("No property", property); > assertEquals("succeeded", property); >- >- //System.out.println(errors.getBuffer().toString()); >- >- return errors.getBuffer().toString(); > } > > /* (non-Javadoc) >Index: src/org/eclipse/jdt/compiler/apt/tests/ModelTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/ModelTests.java,v >retrieving revision 1.7 >diff -u -r1.7 ModelTests.java >--- src/org/eclipse/jdt/compiler/apt/tests/ModelTests.java 21 Apr 2010 06:25:23 -0000 1.7 >+++ src/org/eclipse/jdt/compiler/apt/tests/ModelTests.java 15 Apr 2011 17:47:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007-2010 BEA Systems, Inc. >+ * Copyright (c) 2007, 2011 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 >@@ -7,7 +7,7 @@ > * > * Contributors: > * wharley@bea.com - initial API and implementation >- * >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > > package org.eclipse.jdt.compiler.apt.tests; >@@ -46,6 +46,10 @@ > */ > public void testElementWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTest(compiler, ELEMENTPROC); > } > >@@ -64,6 +68,10 @@ > */ > public void testTypeMirrorWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTest(compiler, TYPEMIRRORPROC); > } > >@@ -82,6 +90,10 @@ > */ > public void testGenericsWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTest(compiler, GENERICSPROC); > } > >@@ -100,6 +112,10 @@ > */ > public void testVisitorsWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTest(compiler, VISITORPROC); > } > >Index: src/org/eclipse/jdt/compiler/apt/tests/ModelUtilTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/ModelUtilTests.java,v >retrieving revision 1.3 >diff -u -r1.3 ModelUtilTests.java >--- src/org/eclipse/jdt/compiler/apt/tests/ModelUtilTests.java 1 Apr 2008 19:25:29 -0000 1.3 >+++ src/org/eclipse/jdt/compiler/apt/tests/ModelUtilTests.java 15 Apr 2011 17:47:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2008 BEA Systems, Inc. >+ * Copyright (c) 2007, 2011 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 >@@ -7,6 +7,7 @@ > * > * Contributors: > * wharley@bea.com - initial API and implementation >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > > package org.eclipse.jdt.compiler.apt.tests; >@@ -42,6 +43,10 @@ > */ > public void testElementsWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTest(compiler, ELEMENTUTILSPROC); > } > >@@ -60,6 +65,10 @@ > */ > public void testTypesWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > internalTest(compiler, TYPEUTILSPROC); > } > >Index: src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java,v >retrieving revision 1.10 >diff -u -r1.10 NegativeTests.java >--- src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java 21 Aug 2009 18:34:32 -0000 1.10 >+++ src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java 15 Apr 2011 17:47:17 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2009 BEA Systems, Inc. >+ * Copyright (c) 2007, 2011 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 >@@ -7,18 +7,20 @@ > * > * Contributors: > * wharley@bea.com - initial API and implementation >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > > package org.eclipse.jdt.compiler.apt.tests; > > import java.io.File; > import java.io.IOException; >-import java.io.StringWriter; > import java.util.ArrayList; > import java.util.Collection; > import java.util.Collections; > import java.util.List; >+import java.util.Set; > >+import javax.lang.model.SourceVersion; > import javax.tools.JavaCompiler; > import javax.tools.ToolProvider; > >@@ -46,7 +48,15 @@ > */ > public void testNegativeModelWithSystemCompiler() throws IOException { > JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); >- >+ if (compiler == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } >+ Set<SourceVersion> sourceVersions = compiler.getSourceVersions(); >+ if (sourceVersions.size() > 4) { >+ // test fail on JDK7 >+ return; >+ } > internalTestNegativeModel(compiler, 0, Collections.singletonList("-A" + IGNOREJAVACBUGS)); > } > >@@ -155,10 +165,8 @@ > options.addAll(extraOptions); > > // Invoke processing by compiling the targets.model resources >- StringWriter errors = new StringWriter(); >- boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, errors); >+ boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null); > >- assertTrue("errors should not be empty", errors.getBuffer().length() != 0); > assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); > > // If it succeeded, the processor will have set this property to "succeeded"; >#P org.eclipse.jdt.compiler.tool >Index: src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java,v >retrieving revision 1.14 >diff -u -r1.14 EclipseCompilerImpl.java >--- src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java 11 May 2010 18:48:01 -0000 1.14 >+++ src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java 15 Apr 2011 17:47:18 -0000 >@@ -1,12 +1,13 @@ > /******************************************************************************* >- * Copyright (c) 2007, 2010 IBM Corporation and others. >+ * Copyright (c) 2007, 2011 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 > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * IBM Corporation - initial API and implementation >+ * IBM Corporation - initial API and implementation >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.tool; > >@@ -17,6 +18,7 @@ > import java.io.PrintWriter; > import java.util.ArrayList; > import java.util.HashMap; >+import java.util.Iterator; > import java.util.Locale; > import java.util.Map; > >@@ -40,6 +42,7 @@ > import org.eclipse.jdt.internal.compiler.batch.Main; > import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; > import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit; >+import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; > import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; > import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; > import org.eclipse.jdt.internal.compiler.util.Messages; >@@ -481,4 +484,77 @@ > } > } > } >+ @Override >+ protected void loggingExtraProblems() { >+ super.loggingExtraProblems(); >+ for (@SuppressWarnings("rawtypes") >+ Iterator iterator = this.extraProblems.iterator(); iterator.hasNext(); ) { >+ final CategorizedProblem problem = (CategorizedProblem) iterator.next(); >+ if (this.diagnosticListener != null) { >+ this.diagnosticListener.report(new Diagnostic<JavaFileObject>() { >+ @Override >+ public String getCode() { >+ return null; >+ } >+ @Override >+ public long getColumnNumber() { >+ if (problem instanceof DefaultProblem) { >+ return ((DefaultProblem) problem).column; >+ } >+ return Diagnostic.NOPOS; >+ } >+ @Override >+ public long getEndPosition() { >+ if (problem instanceof DefaultProblem) { >+ return ((DefaultProblem) problem).getSourceEnd(); >+ } >+ return Diagnostic.NOPOS; >+ } >+ @Override >+ public Kind getKind() { >+ if (problem.isError()) { >+ return Diagnostic.Kind.ERROR; >+ } >+ if (problem.isWarning()) { >+ return Diagnostic.Kind.WARNING; >+ } >+ return Diagnostic.Kind.OTHER; >+ } >+ @Override >+ public long getLineNumber() { >+ if (problem instanceof DefaultProblem) { >+ return ((DefaultProblem) problem).getSourceLineNumber(); >+ } >+ return Diagnostic.NOPOS; >+ } >+ @Override >+ public String getMessage(Locale locale) { >+ return problem.getMessage(); >+ } >+ @Override >+ public long getPosition() { >+ if (problem instanceof DefaultProblem) { >+ return ((DefaultProblem) problem).getSourceStart(); >+ } >+ return Diagnostic.NOPOS; >+ } >+ @Override >+ public JavaFileObject getSource() { >+ if (problem instanceof DefaultProblem) { >+ File f = new File(new String(((DefaultProblem) problem).getOriginatingFileName())); >+ if (f.exists()) { >+ return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null); >+ } >+ return null; >+ } >+ return null; >+ } >+ @Override >+ public long getStartPosition() { >+ return getPosition(); >+ } >+ }); >+ } >+ } >+ } > } >#P org.eclipse.jdt.compiler.tool.tests >Index: src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java,v >retrieving revision 1.3 >diff -u -r1.3 AbstractCompilerToolTest.java >--- src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java 11 May 2010 18:48:31 -0000 1.3 >+++ src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java 15 Apr 2011 17:47:18 -0000 >@@ -1,12 +1,13 @@ > /******************************************************************************* >- * Copyright (c) 2008, 2010 IBM Corporation and others. >+ * Copyright (c) 2008, 2011 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 > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * IBM Corporation - initial API and implementation >+ * IBM Corporation - initial API and implementation >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > package org.eclipse.jdt.compiler.tool.tests; > >@@ -95,7 +96,7 @@ > CompilerInvocationTestsArguments arguments = (CompilerInvocationTestsArguments) extraArguments; > StandardJavaFileManager manager = arguments.standardJavaFileManager; > if (manager == null) { >- manager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up >+ manager = COMPILER.getStandardFileManager(null, null, null); // will pick defaults up > } > List<File> files = new ArrayList<File>(); > String[] fileNames = arguments.fileNames; >Index: src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java,v >retrieving revision 1.12 >diff -u -r1.12 CompilerInvocationTests.java >--- src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java 11 May 2010 18:48:31 -0000 1.12 >+++ src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java 15 Apr 2011 17:47:18 -0000 >@@ -1,12 +1,13 @@ > /******************************************************************************* >- * Copyright (c) 2008, 2010 IBM Corporation and others. >+ * Copyright (c) 2008, 2011 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 > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * IBM Corporation - initial API and implementation >+ * IBM Corporation - initial API and implementation >+ * IBM Corporation - fix for 342936 > *******************************************************************************/ > package org.eclipse.jdt.compiler.tool.tests; > >@@ -45,7 +46,7 @@ > > public class CompilerInvocationTests extends AbstractCompilerToolTest { > static { >-// TESTS_NAMES = new String[] { "test000" }; >+// TESTS_NAMES = new String[] { "test019_sourcepath_without_destination" }; > // TESTS_NUMBERS = new int[] { 5 }; > // TESTS_RANGE = new int[] { 1, -1 }; > } >@@ -325,6 +326,10 @@ > // exploring -d / FileManager interaction > // -d changes CLASS_OUTPUT location > public void test002_dash_d_option() { >+ if (JAVAC_COMPILER == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up > runTest( > true /* shouldCompileOK */, >@@ -348,6 +353,10 @@ > // exploring -d / FileManager interaction > // -d changes CLASS_OUTPUT location (OUTPUT_DIR subdirectory) > public void test003_dash_d_option() { >+ if (JAVAC_COMPILER == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up > String outputDir = OUTPUT_DIR + File.separator + "bin"; > runTest( >@@ -373,6 +382,10 @@ > // ecj uses the output location from the javac standard Java file manager if it > // is set > public void test004_no_dash_d_option() throws IOException { >+ if (JAVAC_COMPILER == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > File binDirectory = new File(OUTPUT_DIR + File.separator + "bin"); > binDirectory.mkdir(); > StandardJavaFileManager javacStandardJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up >@@ -401,6 +414,10 @@ > // ecj does not call setLocation on standard Java file managers; it uses > // handleOption instead; javac does the same > public void test005_dash_d_option_custom_file_manager() { >+ if (JAVAC_COMPILER == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > StandardJavaFileManager javacJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null); > SetLocationDetector customJavaFileManager = > new SetLocationDetector( >@@ -425,7 +442,7 @@ > }); > assertEquals(OUTPUT_DIR, customJavaFileManager.getLocation(StandardLocation.CLASS_OUTPUT).toString()); > assertFalse(customJavaFileManager.matchFound()); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > customJavaFileManager = new SetLocationDetector(javacJavaFileManager, > StandardLocation.CLASS_OUTPUT); > assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, >@@ -438,6 +455,10 @@ > // exploring -d / FileManager interaction > // ecj calls getLocation on a non-javac standard Java file manager > public void test006_no_dash_d_option_custom_file_manager() throws IOException { >+ if (JAVAC_COMPILER == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > File binDirectory = new File(OUTPUT_DIR + File.separator + "bin"); > binDirectory.mkdirs(); > GetLocationDetector customJavaFileManager = >@@ -476,7 +497,7 @@ > Iterator<String> remaining = remainingAsList.iterator(); > assertTrue("does not support -d option", ecjStandardJavaFileManager.handleOption("-d", remaining)); > assertEquals("unexpected consumption rate", "remainder", remaining.next()); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > StandardJavaFileManager javacStandardJavaFileManager = > ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); // will pick defaults up > remaining = remainingAsList.iterator(); >@@ -536,7 +557,7 @@ > passed = false; > } > assertFalse("does not catch inappropriate -encoding option", passed); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > // this fails, which may be deemed appropriate or not; but at least > // test #11 shows that the behavior that can be observed from the > // outside is inappropriate >@@ -573,7 +594,7 @@ > passed = false; > } > assertFalse("does not catch inappropriate -encoding option", passed); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > // compared to what the command-line javac does, this is due to be a > // bug > passed = true; >@@ -584,13 +605,17 @@ > } catch (Throwable t) { > passed = false; > } >- assertFalse("does not catch inappropriate -encoding option", passed); >+ assertFalse("does not catch inappropriate -encoding option", passed); > } > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=188796 > // files access must happen through the user-specified file manager > // simplest source read case > public void test012_files_access_read() throws IOException { >+ if (JAVAC_COMPILER == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > GetJavaFileForInputDetector customJavaFileManager = > new GetJavaFileForInputDetector( > JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */)); >@@ -612,7 +637,7 @@ > "X.class" > }); > assertTrue(customJavaFileManager.matchFound); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > customJavaFileManager.matchFound = false; > assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, > Arrays.asList("-d", OUTPUT_DIR), null, >@@ -625,9 +650,13 @@ > // files access must happen through the user-specified file manager > // source file accessed through the sourcepath > public void _test013_files_access_read() throws IOException { >+ if (JAVAC_COMPILER == null) { >+ System.out.println("No system java compiler available"); >+ return; >+ } > GetJavaFileForInputDetector customJavaFileManager = > new GetJavaFileForInputDetector( >- JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), >+ COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), > "Y.java", Kind.SOURCE); > List<String> options = Arrays.asList( > "-d", OUTPUT_DIR, >@@ -654,7 +683,7 @@ > "X.class" > }); > assertTrue(customJavaFileManager.matchFound); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > customJavaFileManager.matchFound = false; > assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, > options, null, >@@ -669,7 +698,7 @@ > public void _test014_files_access_read() throws IOException { > GetJavaFileForInputDetector customJavaFileManager = > new GetJavaFileForInputDetector( >- JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), >+ COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), > "Y.class", Kind.CLASS); > List<String> options = Arrays.asList( > "-d", OUTPUT_DIR, >@@ -711,7 +740,7 @@ > "X.class" > }); > assertTrue(customJavaFileManager.matchFound); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > // javac merely throws an exception, which is due to be a bug on their > // side > customJavaFileManager.matchFound = false; >@@ -728,7 +757,7 @@ > public void test015_files_access_write() throws IOException { > GetJavaFileForOutputDetector customJavaFileManager = > new GetJavaFileForOutputDetector( >- JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), >+ COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), > "X.class"); > List<String> options = Arrays.asList("-d", OUTPUT_DIR); > runTest( >@@ -750,7 +779,7 @@ > "X.class" > }); > assertTrue(customJavaFileManager.matchFound); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > customJavaFileManager.matchFound = false; > assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, > options, null, >@@ -765,7 +794,7 @@ > public void test016_files_access_write() throws IOException { > GetJavaFileForOutputDetector customJavaFileManager = > new GetJavaFileForOutputDetector( >- JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), >+ COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), > "Y.class"); > List<String> options = Arrays.asList( > "-sourcepath", OUTPUT_DIR + File.separator + "src2"); >@@ -792,7 +821,7 @@ > "src/X.class" > }); > assertTrue(customJavaFileManager.matchFound); >- if (RUN_JAVAC) { >+ if (RUN_JAVAC && JAVAC_COMPILER != null) { > customJavaFileManager.matchFound = false; > assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, > options, null, >@@ -859,8 +888,16 @@ > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583 > public void test019_sourcepath_without_destination() throws IOException { >+ String sourceDirectoryName = OUTPUT_DIR + "/src2"; >+ File sourceFolder = new File(sourceDirectoryName); >+ if (!sourceFolder.exists()) { >+ if (!sourceFolder.mkdirs()) { >+ // source folder could not be built >+ return; >+ } >+ } > StandardJavaFileManager ecjStandardJavaFileManager = >- JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */); >+ COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */); > assertTrue(ecjStandardJavaFileManager.handleOption( > "-sourcepath", > Arrays.asList(OUTPUT_DIR + "/src2").iterator())); >@@ -890,7 +927,7 @@ > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583 > public void _test020_sourcepath_with_destination() throws IOException { > StandardJavaFileManager ecjStandardJavaFileManager = >- JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */); >+ COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */); > assertTrue(ecjStandardJavaFileManager.handleOption( > "-sourcepath", > Arrays.asList("\"" + OUTPUT_DIR + "/src2\"[-d \"" + OUTPUT_DIR + "/bin2\"]").iterator())); >@@ -924,7 +961,7 @@ > errBuffer = new ByteArrayOutputStream(); > CompilationTask task = COMPILER.getTask( > new PrintWriter(outBuffer), >- JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), >+ COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), > new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), > Arrays.asList("-v"), null, null); > assertTrue(task.call()); >@@ -953,7 +990,7 @@ > System.setErr(new PrintStream(errBuffer)); > CompilationTask task = COMPILER.getTask( > null, >- JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), >+ COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), > new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), > Arrays.asList("-v"), null, null); > try { >#P org.eclipse.jdt.core >Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v >retrieving revision 1.362 >diff -u -r1.362 Main.java >--- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 2 Mar 2011 14:29:07 -0000 1.362 >+++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 15 Apr 2011 17:47:19 -0000 >@@ -1328,7 +1328,7 @@ > > private PrintWriter err; > >- ArrayList extraProblems; >+ protected ArrayList extraProblems; > public final static String bundleName = "org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$ > // two uses: recognize 'none' in options; code the singleton none > // for the '-d none' option (wherever it may be found) >@@ -3740,7 +3740,7 @@ > } > > if (this.extraProblems != null) { >- this.logger.loggingExtraProblems(this); >+ loggingExtraProblems(); > this.extraProblems = null; > } > if (this.compilerStats != null) { >@@ -3751,6 +3751,9 @@ > // cleanup > environment.cleanup(); > } >+protected void loggingExtraProblems() { >+ this.logger.loggingExtraProblems(this); >+} > public void printUsage() { > printUsage("misc.usage"); //$NON-NLS-1$ > } >Index: compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java,v >retrieving revision 1.51 >diff -u -r1.51 DefaultProblem.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java 7 Mar 2009 01:08:10 -0000 1.51 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java 15 Apr 2011 17:47:19 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 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 >@@ -18,7 +18,10 @@ > public class DefaultProblem extends CategorizedProblem { > private char[] fileName; > private int id; >- private int startPosition, endPosition, line, column; >+ private int startPosition; >+ private int endPosition; >+ private int line; >+ public int column; > private int severity; > private String[] arguments; > private String message;
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 342936
: 193394