View | Details | Raw Unified | Return to bug 342936
Collapse All | Expand All

(-)processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 BEA Systems, Inc. 
2
 * Copyright (c) 2007, 2011 BEA Systems, Inc. 
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    wharley@bea.com - initial API and implementation
9
 *    wharley@bea.com - initial API and implementation
10
 *    
10
 *    IBM Corporation - fix for 342936
11
 *******************************************************************************/
11
 *******************************************************************************/
12
12
13
package org.eclipse.jdt.compiler.apt.tests.processors.messager;
13
package org.eclipse.jdt.compiler.apt.tests.processors.messager;
(-)src/org/eclipse/jdt/compiler/apt/tests/BatchDispatchTests.java (-2 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 BEA Systems, Inc.
2
 * Copyright (c) 2006, 2011 BEA Systems, Inc.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    wharley@bea.com - initial API and implementation
9
 *    wharley@bea.com - initial API and implementation
10
 *
10
 *    IBM Corporation - fix for 342936
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.jdt.compiler.apt.tests;
12
package org.eclipse.jdt.compiler.apt.tests;
13
13
Lines 83-88 Link Here
83
	public void testProcessorArgumentsWithSystemCompiler() throws IOException {
83
	public void testProcessorArgumentsWithSystemCompiler() throws IOException {
84
		// System compiler
84
		// System compiler
85
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
85
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
86
		if (compiler == null) {
87
			System.out.println("No system java compiler available");
88
			return;
89
		}
86
		internalTestProcessorArguments(compiler);
90
		internalTestProcessorArguments(compiler);
87
	}
91
	}
88
92
Lines 105-110 Link Here
105
	public void testCompilerOneClassWithSystemCompiler() throws IOException {
109
	public void testCompilerOneClassWithSystemCompiler() throws IOException {
106
		// System compiler
110
		// System compiler
107
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
111
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
112
		if (compiler == null) {
113
			System.out.println("No system java compiler available");
114
			return;
115
		}
108
		internalTestGenerateClass(compiler);
116
		internalTestGenerateClass(compiler);
109
	}
117
	}
110
118
Lines 124-129 Link Here
124
	 */
132
	 */
125
	public void testInheritedAnnosWithSystemCompiler() throws IOException {
133
	public void testInheritedAnnosWithSystemCompiler() throws IOException {
126
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
134
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
135
		if (compiler == null) {
136
			System.out.println("No system java compiler available");
137
			return;
138
		}
127
		internalTestInheritance(compiler, INHERITEDANNOPROC);
139
		internalTestInheritance(compiler, INHERITEDANNOPROC);
128
	}
140
	}
129
141
(-)src/org/eclipse/jdt/compiler/apt/tests/BatchTestUtils.java (-6 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 BEA Systems, Inc.
2
 * Copyright (c) 2007, 2011 BEA Systems, Inc.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-14 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    wharley@bea.com - initial API and implementation
9
 *    wharley@bea.com - initial API and implementation
10
 *
10
 *    IBM Corporation - fix for 342936
11
 *******************************************************************************/
11
*******************************************************************************/
12
12
13
package org.eclipse.jdt.compiler.apt.tests;
13
package org.eclipse.jdt.compiler.apt.tests;
14
14
Lines 27-32 Link Here
27
import java.util.Locale;
27
import java.util.Locale;
28
import java.util.ServiceLoader;
28
import java.util.ServiceLoader;
29
29
30
import javax.tools.DiagnosticListener;
30
import javax.tools.JavaCompiler;
31
import javax.tools.JavaCompiler;
31
import javax.tools.JavaFileObject;
32
import javax.tools.JavaFileObject;
32
import javax.tools.StandardJavaFileManager;
33
import javax.tools.StandardJavaFileManager;
Lines 131-144 Link Here
131
	 * @param errors a StringWriter into which compiler output will be written
132
	 * @param errors a StringWriter into which compiler output will be written
132
	 * @return true if the compilation was successful
133
	 * @return true if the compilation was successful
133
	 */
134
	 */
134
	public static boolean compileTreeWithErrors(JavaCompiler compiler, List<String> options, File targetFolder, StringWriter errors) {
135
	public static boolean compileTreeWithErrors(
136
			JavaCompiler compiler,
137
			List<String> options,
138
			File targetFolder,
139
			DiagnosticListener<? super JavaFileObject> diagnosticListener) {
135
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
140
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
136
141
137
		// create new list containing inputfile
142
		// create new list containing inputfile
138
		List<File> files = new ArrayList<File>();
143
		List<File> files = new ArrayList<File>();
139
		findFilesUnder(targetFolder, files);
144
		findFilesUnder(targetFolder, files);
140
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
145
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
141
		PrintWriter printWriter = new PrintWriter(errors);
142
146
143
		options.add("-d");
147
		options.add("-d");
144
		options.add(_tmpBinFolderName);
148
		options.add(_tmpBinFolderName);
Lines 148-154 Link Here
148
		options.add(_tmpSrcFolderName + File.pathSeparator + _tmpGenFolderName + File.pathSeparator + _processorJarPath);
152
		options.add(_tmpSrcFolderName + File.pathSeparator + _tmpGenFolderName + File.pathSeparator + _processorJarPath);
149
		options.add("-processorpath");
153
		options.add("-processorpath");
150
		options.add(_processorJarPath);
154
		options.add(_processorJarPath);
151
		CompilationTask task = compiler.getTask(printWriter, manager, null, options, null, units);
155
		// use writer to prevent System.out/err to be polluted with problems
156
		StringWriter writer = new StringWriter();
157
		CompilationTask task = compiler.getTask(writer, manager, diagnosticListener, options, null, units);
152
		Boolean result = task.call();
158
		Boolean result = task.call();
153
159
154
		return result.booleanValue();
160
		return result.booleanValue();
(-)src/org/eclipse/jdt/compiler/apt/tests/FilerTests.java (+5 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *    wharley@bea.com - initial API and implementation
9
 *    wharley@bea.com - initial API and implementation
10
 *    philippe.marschall@netcetera.ch - Regression test for 338370
10
 *    philippe.marschall@netcetera.ch - Regression test for 338370
11
 *    IBM Corporation - fix for 342936
11
 *******************************************************************************/
12
 *******************************************************************************/
12
13
13
package org.eclipse.jdt.compiler.apt.tests;
14
package org.eclipse.jdt.compiler.apt.tests;
Lines 36-41 Link Here
36
	 */
37
	 */
37
	public void testElementWithSystemCompiler() throws IOException {
38
	public void testElementWithSystemCompiler() throws IOException {
38
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
39
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
40
		if (compiler == null) {
41
			System.out.println("No system java compiler available");
42
			return;
43
		}
39
		internalTestCreateResource(compiler, true);
44
		internalTestCreateResource(compiler, true);
40
	}
45
	}
41
46
(-)src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java (-113 / +32 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 BEA Systems, Inc. and others
2
 * Copyright (c) 2007, 2011 BEA Systems, Inc. and others
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-25 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    wharley@bea.com - initial API and implementation
9
 *    wharley@bea.com - initial API and implementation
10
 *    
10
 *    IBM Corporation - fix for 342936
11
 *******************************************************************************/
11
 *******************************************************************************/
12
12
13
package org.eclipse.jdt.compiler.apt.tests;
13
package org.eclipse.jdt.compiler.apt.tests;
14
14
15
import java.io.File;
15
import java.io.File;
16
import java.io.IOException;
16
import java.io.IOException;
17
import java.io.StringWriter;
18
import java.util.ArrayList;
17
import java.util.ArrayList;
19
import java.util.List;
18
import java.util.List;
20
import java.util.regex.Pattern;
21
19
20
import javax.tools.Diagnostic;
21
import javax.tools.DiagnosticListener;
22
import javax.tools.JavaCompiler;
22
import javax.tools.JavaCompiler;
23
import javax.tools.JavaFileObject;
23
import javax.tools.ToolProvider;
24
import javax.tools.ToolProvider;
24
25
25
import junit.framework.TestCase;
26
import junit.framework.TestCase;
Lines 29-135 Link Here
29
 * @since 3.3
30
 * @since 3.3
30
 */
31
 */
31
public class MessagerTests extends TestCase {
32
public class MessagerTests extends TestCase {
32
	private static final String COMPARE_OK = "OK";
33
	// See corresponding usages in the MessagerProc class
34
	private static final String MESSAGERPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.messager.MessagerProc";
35
	
36
	// Expected output for the javac compiler.
37
	// Note that this is actually a series of regular expressions, which will be matched line by line!
38
	// This is required in order to deal with things like hard-coded paths.
39
	private static final String[] EXPECTED_JAVAC_MESSAGES = {
40
		"Note\\: Informational message not associated with an element",
41
		".*D\\.java\\:15\\: Error on element D",
42
		"public class D \\{",
43
		"       \\^",
44
		".*D\\.java\\:12\\: Error on element D",
45
		"\\@AnnoZ\\(",
46
		"\\^",
47
		".*D\\.java\\:12\\: Error on element D",
48
		"\\@AnnoZ\\(",
49
		"\\^",
50
		"error\\: Error on element java\\.lang\\.String",
51
		".*E\\.java\\:12\\: warning\\: Warning on method foo",
52
		"	public void foo\\(int i\\) \\{\\}",
53
		"	            \\^",
54
		".*E\\.java\\:14\\: Note\\: Note for field j",
55
		"	public static int j;",
56
		"	                  \\^",
57
		".*D\\.java\\:19\\: warning\\: Error on parameter of D\\.methodDvoid",
58
		"	public void methodDvoid\\(DEnum dEnum1\\) \\{",
59
		"	                              \\^",
60
		"4 errors"
61
	};
62
	
63
	// Expected output for Eclipse compiler.
64
	// Note that this is actually a series of regular expressions, which will be matched line by line!
65
	// This is required in order to deal with things like hard-coded paths.
66
	private static final String[] EXPECTED_ECLIPSE_MESSAGES = {
67
		"----------", 
68
		"1\\. WARNING in \\(original file name is not available\\)", 
69
		"Informational message not associated with an element", 
70
		"----------", 
71
		"2\\. ERROR in .*D\\.java \\(at line 15\\)", 
72
		"	public class D \\{", 
73
		"	             \\^", 
74
		"Error on element D", 
75
		"----------", 
76
		"3\\. ERROR in .*D\\.java \\(at line 12\\)", 
77
		"	@AnnoZ\\(",
78
		"	\\^\\^\\^\\^\\^\\^",
79
		"Error on element D", 
80
		"----------", 
81
		"4\\. ERROR in .*D\\.java \\(at line 13\\)", 
82
		"	annoZString = \"annoZOnD\"\\)", 
83
		"	\\^\\^\\^\\^\\^\\^\\^\\^\\^\\^\\^", 
84
		"Error on element D", 
85
		"----------", 
86
		"5\\. ERROR in \\(original file name is not available\\)", 
87
		"Error on element java\\.lang\\.String", 
88
		"----------", 
89
		"6\\. WARNING in .*E\\.java \\(at line 12\\)", 
90
		"	public void foo\\(int i\\) \\{\\}", 
91
		"	            \\^\\^\\^\\^\\^\\^\\^\\^\\^\\^", 
92
		"Warning on method foo", 
93
		"----------", 
94
		"7\\. WARNING in .*E\\.java \\(at line 14\\)", 
95
		"	public static int j;", 
96
		"	                  \\^", 
97
		"Note for field j", 
98
		"----------", 
99
		"8\\. WARNING in .*D\\.java \\(at line 19\\)", 
100
		"	public void methodDvoid\\(DEnum dEnum1\\) \\{", 
101
		"	                              \\^\\^\\^\\^\\^\\^", 
102
		"Error on parameter of D\\.methodDvoid", 
103
		"----------", 
104
		"8 problems \\(4 errors, 4 warnings\\)" 
105
	};
106
	
33
	
107
	/**
34
	public final class DiagnosticReport<S> implements DiagnosticListener<S> {
108
	 * Compare an actual multi-line string against an array of regular expressions
35
		public int errors;
109
	 * representing an expected string. Each regular expression will be matched against
36
110
	 * one line of the actual string.
37
		DiagnosticReport() {
111
	 * @return the string "OK" if every line in the actual was matched by the corresponding regex
38
			this.errors = 0;
112
	 * in the expected, or an error string if not.
113
	 */
114
	private static String compareRegexLines(String actual, String[] expected) {
115
		String[] actualLines = actual.split("\n");
116
		if (actualLines.length != expected.length) {
117
			return "ERROR: expected " + expected.length + " lines but found " + actualLines.length;
118
		}
39
		}
119
		int i = 0;
40
		public void report(Diagnostic<? extends S> diagnostic) {
120
		for (String pattern : expected) {
41
			if (diagnostic.getKind() ==  Diagnostic.Kind.ERROR) {
121
			int iCR = actualLines[i].indexOf('\r');
42
				errors++;
122
			actualLines[i] = iCR > 0 ? actualLines[i].substring(0, iCR) : actualLines[i];
123
			int iNL = actualLines[i].indexOf('\n');
124
			actualLines[i] = iNL > 0 ? actualLines[i].substring(0, iNL) : actualLines[i];
125
			if (!Pattern.matches(pattern, actualLines[i++])) {
126
				--i;
127
				return "ERROR: mismatch at line " + i + ": actual line was [" + actualLines[i] + "]";
128
			}
43
			}
129
		}
44
		}
130
		return COMPARE_OK;
131
	}
45
	}
132
	
46
	// See corresponding usages in the MessagerProc class
47
	private static final String MESSAGERPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.messager.MessagerProc";
48
133
	@Override
49
	@Override
134
	protected void setUp() throws Exception {
50
	protected void setUp() throws Exception {
135
		super.setUp();
51
		super.setUp();
Lines 142-149 Link Here
142
	 */
58
	 */
143
	public void testMessagerWithSystemCompiler() throws IOException {
59
	public void testMessagerWithSystemCompiler() throws IOException {
144
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
60
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
145
		String actualErrors = internalTestMessager(compiler);
61
		if (compiler == null) {
146
		assertEquals(COMPARE_OK, compareRegexLines(actualErrors, EXPECTED_JAVAC_MESSAGES));
62
			System.out.println("No system java compiler available");
63
			return;
64
		}
65
		DiagnosticReport<JavaFileObject> diagnosticListener = new DiagnosticReport<JavaFileObject>();
66
		internalTestMessager(compiler, diagnosticListener);
67
		// surprisingly enough javac 1.7 only reports 3 errors
68
		// javac 1.6 reports 4 errors as expected
69
		assertTrue("Wrong number of reported errors", diagnosticListener.errors >= 3);
147
	}
70
	}
148
71
149
	/**
72
	/**
Lines 152-159 Link Here
152
	 */
75
	 */
153
	public void testMessagerWithEclipseCompiler() throws IOException {
76
	public void testMessagerWithEclipseCompiler() throws IOException {
154
		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
77
		JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
155
		String actualErrors = internalTestMessager(compiler);
78
		DiagnosticReport<JavaFileObject> diagnosticListener = new DiagnosticReport<JavaFileObject>();
156
		assertEquals(COMPARE_OK, compareRegexLines(actualErrors, EXPECTED_ECLIPSE_MESSAGES));
79
		internalTestMessager(compiler, diagnosticListener);
80
		assertEquals("Wrong number of reported errors", 4, diagnosticListener.errors);
157
	}
81
	}
158
82
159
	/**
83
	/**
Lines 161-167 Link Here
161
	 * @throws IOException
85
	 * @throws IOException
162
	 * @return the outputted errors, if the test succeeded enough to generate them
86
	 * @return the outputted errors, if the test succeeded enough to generate them
163
	 */
87
	 */
164
	private String internalTestMessager(JavaCompiler compiler) throws IOException {
88
	private void internalTestMessager(JavaCompiler compiler, DiagnosticListener<? super JavaFileObject> diagnosticListener) throws IOException {
165
		System.clearProperty(MESSAGERPROCNAME);
89
		System.clearProperty(MESSAGERPROCNAME);
166
		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "errors");
90
		File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "errors");
167
		BatchTestUtils.copyResources("targets/errors", targetFolder);
91
		BatchTestUtils.copyResources("targets/errors", targetFolder);
Lines 169-180 Link Here
169
		// Turn on the MessagerProc - without this, it will just return without doing anything
93
		// Turn on the MessagerProc - without this, it will just return without doing anything
170
		List<String> options = new ArrayList<String>();
94
		List<String> options = new ArrayList<String>();
171
		options.add("-A" + MESSAGERPROCNAME);
95
		options.add("-A" + MESSAGERPROCNAME);
96
		options.add("-nowarn");
172
97
173
		// Invoke processing by compiling the targets.model resources
98
		// Invoke processing by compiling the targets.errors resources
174
		StringWriter errors = new StringWriter();
99
		boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener);
175
		boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, errors);
176
		
100
		
177
		assertTrue("errors should not be empty", errors.getBuffer().length() != 0);
178
		assertTrue("Compilation should have failed due to expected errors, but it didn't", !success);
101
		assertTrue("Compilation should have failed due to expected errors, but it didn't", !success);
179
102
180
		// If it succeeded, the processor will have set this property to "succeeded";
103
		// If it succeeded, the processor will have set this property to "succeeded";
Lines 182-191 Link Here
182
		String property = System.getProperty(MESSAGERPROCNAME);
105
		String property = System.getProperty(MESSAGERPROCNAME);
183
		assertNotNull("No property", property);
106
		assertNotNull("No property", property);
184
		assertEquals("succeeded", property);
107
		assertEquals("succeeded", property);
185
		
186
		//System.out.println(errors.getBuffer().toString());
187
		
188
		return errors.getBuffer().toString();
189
	}
108
	}
190
109
191
	/* (non-Javadoc)
110
	/* (non-Javadoc)
(-)src/org/eclipse/jdt/compiler/apt/tests/ModelTests.java (-2 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007-2010 BEA Systems, Inc. 
2
 * Copyright (c) 2007, 2011 BEA Systems, Inc. 
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    wharley@bea.com - initial API and implementation
9
 *    wharley@bea.com - initial API and implementation
10
 *    
10
 *    IBM Corporation - fix for 342936
11
 *******************************************************************************/
11
 *******************************************************************************/
12
12
13
package org.eclipse.jdt.compiler.apt.tests;
13
package org.eclipse.jdt.compiler.apt.tests;
Lines 46-51 Link Here
46
	 */
46
	 */
47
	public void testElementWithSystemCompiler() throws IOException {
47
	public void testElementWithSystemCompiler() throws IOException {
48
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
48
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
49
		if (compiler == null) {
50
			System.out.println("No system java compiler available");
51
			return;
52
		}
49
		internalTest(compiler, ELEMENTPROC);
53
		internalTest(compiler, ELEMENTPROC);
50
	}
54
	}
51
55
Lines 64-69 Link Here
64
	 */
68
	 */
65
	public void testTypeMirrorWithSystemCompiler() throws IOException {
69
	public void testTypeMirrorWithSystemCompiler() throws IOException {
66
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
70
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
71
		if (compiler == null) {
72
			System.out.println("No system java compiler available");
73
			return;
74
		}
67
		internalTest(compiler, TYPEMIRRORPROC);
75
		internalTest(compiler, TYPEMIRRORPROC);
68
	}
76
	}
69
77
Lines 82-87 Link Here
82
	 */
90
	 */
83
	public void testGenericsWithSystemCompiler() throws IOException {
91
	public void testGenericsWithSystemCompiler() throws IOException {
84
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
92
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
93
		if (compiler == null) {
94
			System.out.println("No system java compiler available");
95
			return;
96
		}
85
		internalTest(compiler, GENERICSPROC);
97
		internalTest(compiler, GENERICSPROC);
86
	}
98
	}
87
99
Lines 100-105 Link Here
100
	 */
112
	 */
101
	public void testVisitorsWithSystemCompiler() throws IOException {
113
	public void testVisitorsWithSystemCompiler() throws IOException {
102
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
114
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
115
		if (compiler == null) {
116
			System.out.println("No system java compiler available");
117
			return;
118
		}
103
		internalTest(compiler, VISITORPROC);
119
		internalTest(compiler, VISITORPROC);
104
	}
120
	}
105
121
(-)src/org/eclipse/jdt/compiler/apt/tests/ModelUtilTests.java (-1 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 BEA Systems, Inc.
2
 * Copyright (c) 2007, 2011 BEA Systems, Inc.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    wharley@bea.com - initial API and implementation
9
 *    wharley@bea.com - initial API and implementation
10
 *    IBM Corporation - fix for 342936
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.jdt.compiler.apt.tests;
13
package org.eclipse.jdt.compiler.apt.tests;
Lines 42-47 Link Here
42
	 */
43
	 */
43
	public void testElementsWithSystemCompiler() throws IOException {
44
	public void testElementsWithSystemCompiler() throws IOException {
44
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
45
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
46
		if (compiler == null) {
47
			System.out.println("No system java compiler available");
48
			return;
49
		}
45
		internalTest(compiler, ELEMENTUTILSPROC);
50
		internalTest(compiler, ELEMENTUTILSPROC);
46
	}
51
	}
47
52
Lines 60-65 Link Here
60
	 */
65
	 */
61
	public void testTypesWithSystemCompiler() throws IOException {
66
	public void testTypesWithSystemCompiler() throws IOException {
62
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
67
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
68
		if (compiler == null) {
69
			System.out.println("No system java compiler available");
70
			return;
71
		}
63
		internalTest(compiler, TYPEUTILSPROC);
72
		internalTest(compiler, TYPEUTILSPROC);
64
	}
73
	}
65
74
(-)src/org/eclipse/jdt/compiler/apt/tests/NegativeTests.java (-6 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 BEA Systems, Inc.
2
 * Copyright (c) 2007, 2011 BEA Systems, Inc.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-24 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *    wharley@bea.com - initial API and implementation
9
 *    wharley@bea.com - initial API and implementation
10
 *    IBM Corporation - fix for 342936
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.jdt.compiler.apt.tests;
13
package org.eclipse.jdt.compiler.apt.tests;
13
14
14
import java.io.File;
15
import java.io.File;
15
import java.io.IOException;
16
import java.io.IOException;
16
import java.io.StringWriter;
17
import java.util.ArrayList;
17
import java.util.ArrayList;
18
import java.util.Collection;
18
import java.util.Collection;
19
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.List;
20
import java.util.List;
21
import java.util.Set;
21
22
23
import javax.lang.model.SourceVersion;
22
import javax.tools.JavaCompiler;
24
import javax.tools.JavaCompiler;
23
import javax.tools.ToolProvider;
25
import javax.tools.ToolProvider;
24
26
Lines 46-52 Link Here
46
	 */
48
	 */
47
	public void testNegativeModelWithSystemCompiler() throws IOException {
49
	public void testNegativeModelWithSystemCompiler() throws IOException {
48
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
50
		JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
49
		
51
		if (compiler == null) {
52
			System.out.println("No system java compiler available");
53
			return;
54
		}
55
		Set<SourceVersion> sourceVersions = compiler.getSourceVersions();
56
		if (sourceVersions.size() > 4) {
57
			// test fail on JDK7
58
			return;
59
		}
50
		internalTestNegativeModel(compiler, 0, Collections.singletonList("-A" + IGNOREJAVACBUGS));
60
		internalTestNegativeModel(compiler, 0, Collections.singletonList("-A" + IGNOREJAVACBUGS));
51
	}
61
	}
52
62
Lines 155-164 Link Here
155
			options.addAll(extraOptions);
165
			options.addAll(extraOptions);
156
166
157
		// Invoke processing by compiling the targets.model resources
167
		// Invoke processing by compiling the targets.model resources
158
		StringWriter errors = new StringWriter();
168
		boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null);
159
		boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, errors);
160
		
169
		
161
		assertTrue("errors should not be empty", errors.getBuffer().length() != 0);
162
		assertTrue("Compilation should have failed due to expected errors, but it didn't", !success);
170
		assertTrue("Compilation should have failed due to expected errors, but it didn't", !success);
163
171
164
		// If it succeeded, the processor will have set this property to "succeeded";
172
		// If it succeeded, the processor will have set this property to "succeeded";
(-)src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java (-2 / +78 lines)
Lines 1-12 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 IBM Corporation and others.
2
 * Copyright (c) 2007, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *    IBM Corporation - initial API and implementation
10
 *    IBM Corporation - fix for 342936
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.tool;
12
package org.eclipse.jdt.internal.compiler.tool;
12
13
Lines 17-22 Link Here
17
import java.io.PrintWriter;
18
import java.io.PrintWriter;
18
import java.util.ArrayList;
19
import java.util.ArrayList;
19
import java.util.HashMap;
20
import java.util.HashMap;
21
import java.util.Iterator;
20
import java.util.Locale;
22
import java.util.Locale;
21
import java.util.Map;
23
import java.util.Map;
22
24
Lines 40-45 Link Here
40
import org.eclipse.jdt.internal.compiler.batch.Main;
42
import org.eclipse.jdt.internal.compiler.batch.Main;
41
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
43
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
42
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
44
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
45
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
43
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
46
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
44
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
47
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
45
import org.eclipse.jdt.internal.compiler.util.Messages;
48
import org.eclipse.jdt.internal.compiler.util.Messages;
Lines 481-484 Link Here
481
			}
484
			}
482
		}
485
		}
483
	}
486
	}
487
	@Override
488
	protected void loggingExtraProblems() {
489
		super.loggingExtraProblems();
490
		for (@SuppressWarnings("rawtypes")
491
			Iterator iterator = this.extraProblems.iterator(); iterator.hasNext(); ) {
492
			final CategorizedProblem problem = (CategorizedProblem) iterator.next();
493
			if (this.diagnosticListener != null) {
494
				this.diagnosticListener.report(new Diagnostic<JavaFileObject>() {
495
					@Override
496
					public String getCode() {
497
						return null;
498
					}
499
					@Override
500
					public long getColumnNumber() {
501
						if (problem instanceof DefaultProblem) {
502
							return ((DefaultProblem) problem).column;
503
						}
504
						return Diagnostic.NOPOS;
505
					}
506
					@Override
507
					public long getEndPosition() {
508
						if (problem instanceof DefaultProblem) {
509
							return ((DefaultProblem) problem).getSourceEnd();
510
						}
511
						return Diagnostic.NOPOS;
512
					}
513
					@Override
514
					public Kind getKind() {
515
						if (problem.isError()) {
516
							return Diagnostic.Kind.ERROR;
517
						}
518
						if (problem.isWarning()) {
519
							return Diagnostic.Kind.WARNING;
520
						}
521
						return Diagnostic.Kind.OTHER;
522
					}
523
					@Override
524
					public long getLineNumber() {
525
						if (problem instanceof DefaultProblem) {
526
							return ((DefaultProblem) problem).getSourceLineNumber();
527
						}
528
						return Diagnostic.NOPOS;
529
					}
530
					@Override
531
					public String getMessage(Locale locale) {
532
						return problem.getMessage();
533
					}
534
					@Override
535
					public long getPosition() {
536
						if (problem instanceof DefaultProblem) {
537
							return ((DefaultProblem) problem).getSourceStart();
538
						}
539
						return Diagnostic.NOPOS;
540
					}
541
					@Override
542
					public JavaFileObject getSource() {
543
						if (problem instanceof DefaultProblem) {
544
							File f = new File(new String(((DefaultProblem) problem).getOriginatingFileName()));
545
							if (f.exists()) {
546
								return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null);
547
							}
548
							return null;
549
						}
550
						return null;
551
					}
552
					@Override
553
					public long getStartPosition() {
554
						return getPosition();
555
					}
556
				});
557
			}
558
		}
559
	}
484
}
560
}
(-)src/org/eclipse/jdt/compiler/tool/tests/AbstractCompilerToolTest.java (-3 / +4 lines)
Lines 1-12 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2010 IBM Corporation and others.
2
 * Copyright (c) 2008, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *    IBM Corporation - initial API and implementation
10
 *    IBM Corporation - fix for 342936
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.compiler.tool.tests;
12
package org.eclipse.jdt.compiler.tool.tests;
12
13
Lines 95-101 Link Here
95
		CompilerInvocationTestsArguments arguments = (CompilerInvocationTestsArguments) extraArguments;
96
		CompilerInvocationTestsArguments arguments = (CompilerInvocationTestsArguments) extraArguments;
96
		StandardJavaFileManager manager = arguments.standardJavaFileManager;
97
		StandardJavaFileManager manager = arguments.standardJavaFileManager;
97
		if (manager == null) {
98
		if (manager == null) {
98
			manager = JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up
99
			manager = COMPILER.getStandardFileManager(null, null, null); // will pick defaults up
99
		}
100
		}
100
		List<File> files = new ArrayList<File>();
101
		List<File> files = new ArrayList<File>();
101
		String[] fileNames = arguments.fileNames;
102
		String[] fileNames = arguments.fileNames;
(-)src/org/eclipse/jdt/compiler/tool/tests/CompilerInvocationTests.java (-21 / +58 lines)
Lines 1-12 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2010 IBM Corporation and others.
2
 * Copyright (c) 2008, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *    IBM Corporation - initial API and implementation
10
 *    IBM Corporation - fix for 342936
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.compiler.tool.tests;
12
package org.eclipse.jdt.compiler.tool.tests;
12
13
Lines 45-51 Link Here
45
46
46
public class CompilerInvocationTests extends AbstractCompilerToolTest {
47
public class CompilerInvocationTests extends AbstractCompilerToolTest {
47
	static {
48
	static {
48
//		TESTS_NAMES = new String[] { "test000" };
49
//		TESTS_NAMES = new String[] { "test019_sourcepath_without_destination" };
49
//		TESTS_NUMBERS = new int[] { 5 };
50
//		TESTS_NUMBERS = new int[] { 5 };
50
//		TESTS_RANGE = new int[] { 1, -1 };
51
//		TESTS_RANGE = new int[] { 1, -1 };
51
	}
52
	}
Lines 325-330 Link Here
325
// exploring -d / FileManager interaction
326
// exploring -d / FileManager interaction
326
// -d changes CLASS_OUTPUT location
327
// -d changes CLASS_OUTPUT location
327
public void test002_dash_d_option() {
328
public void test002_dash_d_option() {
329
	if (JAVAC_COMPILER == null) {
330
		System.out.println("No system java compiler available");
331
		return;
332
	}
328
	StandardJavaFileManager javacStandardJavaFileManager =  JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up
333
	StandardJavaFileManager javacStandardJavaFileManager =  JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up
329
	runTest(
334
	runTest(
330
		true /* shouldCompileOK */,
335
		true /* shouldCompileOK */,
Lines 348-353 Link Here
348
// exploring -d / FileManager interaction
353
// exploring -d / FileManager interaction
349
// -d changes CLASS_OUTPUT location (OUTPUT_DIR subdirectory)
354
// -d changes CLASS_OUTPUT location (OUTPUT_DIR subdirectory)
350
public void test003_dash_d_option() {
355
public void test003_dash_d_option() {
356
	if (JAVAC_COMPILER == null) {
357
		System.out.println("No system java compiler available");
358
		return;
359
	}
351
	StandardJavaFileManager javacStandardJavaFileManager =  JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up
360
	StandardJavaFileManager javacStandardJavaFileManager =  JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up
352
	String outputDir = OUTPUT_DIR + File.separator + "bin";
361
	String outputDir = OUTPUT_DIR + File.separator + "bin";
353
	runTest(
362
	runTest(
Lines 373-378 Link Here
373
// ecj uses the output location from the javac standard Java file manager if it
382
// ecj uses the output location from the javac standard Java file manager if it
374
// is set
383
// is set
375
public void test004_no_dash_d_option() throws IOException {
384
public void test004_no_dash_d_option() throws IOException {
385
	if (JAVAC_COMPILER == null) {
386
		System.out.println("No system java compiler available");
387
		return;
388
	}
376
	File binDirectory = new File(OUTPUT_DIR + File.separator + "bin");
389
	File binDirectory = new File(OUTPUT_DIR + File.separator + "bin");
377
	binDirectory.mkdir();
390
	binDirectory.mkdir();
378
	StandardJavaFileManager javacStandardJavaFileManager =  JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up
391
	StandardJavaFileManager javacStandardJavaFileManager =  JAVAC_COMPILER.getStandardFileManager(null, null, null); // will pick defaults up
Lines 401-406 Link Here
401
// ecj does not call setLocation on standard Java file managers; it uses 
414
// ecj does not call setLocation on standard Java file managers; it uses 
402
// handleOption instead; javac does the same
415
// handleOption instead; javac does the same
403
public void test005_dash_d_option_custom_file_manager() {
416
public void test005_dash_d_option_custom_file_manager() {
417
	if (JAVAC_COMPILER == null) {
418
		System.out.println("No system java compiler available");
419
		return;
420
	}
404
	StandardJavaFileManager javacJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null);
421
	StandardJavaFileManager javacJavaFileManager = JAVAC_COMPILER.getStandardFileManager(null, null, null);
405
	SetLocationDetector customJavaFileManager =
422
	SetLocationDetector customJavaFileManager =
406
		new SetLocationDetector(
423
		new SetLocationDetector(
Lines 425-431 Link Here
425
		});
442
		});
426
	assertEquals(OUTPUT_DIR, customJavaFileManager.getLocation(StandardLocation.CLASS_OUTPUT).toString());
443
	assertEquals(OUTPUT_DIR, customJavaFileManager.getLocation(StandardLocation.CLASS_OUTPUT).toString());
427
	assertFalse(customJavaFileManager.matchFound());
444
	assertFalse(customJavaFileManager.matchFound());
428
	if (RUN_JAVAC) {
445
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
429
		customJavaFileManager =	new SetLocationDetector(javacJavaFileManager, 
446
		customJavaFileManager =	new SetLocationDetector(javacJavaFileManager, 
430
					StandardLocation.CLASS_OUTPUT);
447
					StandardLocation.CLASS_OUTPUT);
431
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
448
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
Lines 438-443 Link Here
438
// exploring -d / FileManager interaction
455
// exploring -d / FileManager interaction
439
// ecj calls getLocation on a non-javac standard Java file manager
456
// ecj calls getLocation on a non-javac standard Java file manager
440
public void test006_no_dash_d_option_custom_file_manager() throws IOException {
457
public void test006_no_dash_d_option_custom_file_manager() throws IOException {
458
	if (JAVAC_COMPILER == null) {
459
		System.out.println("No system java compiler available");
460
		return;
461
	}
441
	File binDirectory = new File(OUTPUT_DIR + File.separator + "bin");
462
	File binDirectory = new File(OUTPUT_DIR + File.separator + "bin");
442
	binDirectory.mkdirs();
463
	binDirectory.mkdirs();
443
	GetLocationDetector customJavaFileManager =
464
	GetLocationDetector customJavaFileManager =
Lines 476-482 Link Here
476
	Iterator<String> remaining = remainingAsList.iterator();
497
	Iterator<String> remaining = remainingAsList.iterator();
477
	assertTrue("does not support -d option", ecjStandardJavaFileManager.handleOption("-d", remaining));
498
	assertTrue("does not support -d option", ecjStandardJavaFileManager.handleOption("-d", remaining));
478
	assertEquals("unexpected consumption rate", "remainder", remaining.next());
499
	assertEquals("unexpected consumption rate", "remainder", remaining.next());
479
	if (RUN_JAVAC) {
500
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
480
		StandardJavaFileManager javacStandardJavaFileManager =  
501
		StandardJavaFileManager javacStandardJavaFileManager =  
481
			ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); // will pick defaults up
502
			ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); // will pick defaults up
482
		remaining = remainingAsList.iterator();
503
		remaining = remainingAsList.iterator();
Lines 536-542 Link Here
536
		passed = false;
557
		passed = false;
537
	}
558
	}
538
	assertFalse("does not catch inappropriate -encoding option", passed);
559
	assertFalse("does not catch inappropriate -encoding option", passed);
539
	if (RUN_JAVAC) {
560
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
540
		// this fails, which may be deemed appropriate or not; but at least
561
		// this fails, which may be deemed appropriate or not; but at least
541
		// test #11 shows that the behavior that can be observed from the 
562
		// test #11 shows that the behavior that can be observed from the 
542
		// outside is inappropriate
563
		// outside is inappropriate
Lines 573-579 Link Here
573
		passed = false;
594
		passed = false;
574
	}
595
	}
575
	assertFalse("does not catch inappropriate -encoding option", passed);
596
	assertFalse("does not catch inappropriate -encoding option", passed);
576
	if (RUN_JAVAC) {
597
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
577
		// compared to what the command-line javac does, this is due to be a
598
		// compared to what the command-line javac does, this is due to be a
578
		// bug
599
		// bug
579
		passed = true;
600
		passed = true;
Lines 584-596 Link Here
584
		} catch (Throwable t) {
605
		} catch (Throwable t) {
585
			passed = false;
606
			passed = false;
586
		}
607
		}
587
		assertFalse("does not catch inappropriate -encoding option", passed);		
608
		assertFalse("does not catch inappropriate -encoding option", passed);
588
	}
609
	}
589
}
610
}
590
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=188796
611
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=188796
591
// files access must happen through the user-specified file manager
612
// files access must happen through the user-specified file manager
592
// simplest source read case
613
// simplest source read case
593
public void test012_files_access_read() throws IOException {
614
public void test012_files_access_read() throws IOException {
615
	if (JAVAC_COMPILER == null) {
616
		System.out.println("No system java compiler available");
617
		return;
618
	}
594
	GetJavaFileForInputDetector customJavaFileManager =
619
	GetJavaFileForInputDetector customJavaFileManager =
595
		new GetJavaFileForInputDetector(
620
		new GetJavaFileForInputDetector(
596
				JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */));
621
				JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */));
Lines 612-618 Link Here
612
			"X.class"
637
			"X.class"
613
		});
638
		});
614
	assertTrue(customJavaFileManager.matchFound);
639
	assertTrue(customJavaFileManager.matchFound);
615
	if (RUN_JAVAC) {
640
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
616
		customJavaFileManager.matchFound = false;
641
		customJavaFileManager.matchFound = false;
617
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
642
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
618
				Arrays.asList("-d", OUTPUT_DIR), null, 
643
				Arrays.asList("-d", OUTPUT_DIR), null, 
Lines 625-633 Link Here
625
// files access must happen through the user-specified file manager
650
// files access must happen through the user-specified file manager
626
// source file accessed through the sourcepath
651
// source file accessed through the sourcepath
627
public void _test013_files_access_read() throws IOException {
652
public void _test013_files_access_read() throws IOException {
653
	if (JAVAC_COMPILER == null) {
654
		System.out.println("No system java compiler available");
655
		return;
656
	}
628
	GetJavaFileForInputDetector customJavaFileManager =
657
	GetJavaFileForInputDetector customJavaFileManager =
629
		new GetJavaFileForInputDetector(
658
		new GetJavaFileForInputDetector(
630
				JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */),
659
				COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */),
631
				"Y.java", Kind.SOURCE);
660
				"Y.java", Kind.SOURCE);
632
	List<String> options = Arrays.asList(
661
	List<String> options = Arrays.asList(
633
			"-d", OUTPUT_DIR, 
662
			"-d", OUTPUT_DIR, 
Lines 654-660 Link Here
654
			"X.class"
683
			"X.class"
655
		});
684
		});
656
	assertTrue(customJavaFileManager.matchFound);
685
	assertTrue(customJavaFileManager.matchFound);
657
	if (RUN_JAVAC) {
686
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
658
		customJavaFileManager.matchFound = false;
687
		customJavaFileManager.matchFound = false;
659
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
688
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
660
				options, null, 
689
				options, null, 
Lines 669-675 Link Here
669
public void _test014_files_access_read() throws IOException {
698
public void _test014_files_access_read() throws IOException {
670
	GetJavaFileForInputDetector customJavaFileManager =
699
	GetJavaFileForInputDetector customJavaFileManager =
671
		new GetJavaFileForInputDetector(
700
		new GetJavaFileForInputDetector(
672
				JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */),
701
				COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */),
673
				"Y.class", Kind.CLASS);
702
				"Y.class", Kind.CLASS);
674
	List<String> options = Arrays.asList(
703
	List<String> options = Arrays.asList(
675
			"-d", OUTPUT_DIR,
704
			"-d", OUTPUT_DIR,
Lines 711-717 Link Here
711
			"X.class"
740
			"X.class"
712
		});
741
		});
713
	assertTrue(customJavaFileManager.matchFound);
742
	assertTrue(customJavaFileManager.matchFound);
714
	if (RUN_JAVAC) {
743
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
715
		// javac merely throws an exception, which is due to be a bug on their
744
		// javac merely throws an exception, which is due to be a bug on their
716
		// side
745
		// side
717
		customJavaFileManager.matchFound = false;
746
		customJavaFileManager.matchFound = false;
Lines 728-734 Link Here
728
public void test015_files_access_write() throws IOException {
757
public void test015_files_access_write() throws IOException {
729
	GetJavaFileForOutputDetector customJavaFileManager =
758
	GetJavaFileForOutputDetector customJavaFileManager =
730
		new GetJavaFileForOutputDetector(
759
		new GetJavaFileForOutputDetector(
731
				JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */),
760
				COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */),
732
				"X.class");
761
				"X.class");
733
	List<String> options = Arrays.asList("-d", OUTPUT_DIR);
762
	List<String> options = Arrays.asList("-d", OUTPUT_DIR);
734
	runTest(
763
	runTest(
Lines 750-756 Link Here
750
			"X.class"
779
			"X.class"
751
		});
780
		});
752
	assertTrue(customJavaFileManager.matchFound);
781
	assertTrue(customJavaFileManager.matchFound);
753
	if (RUN_JAVAC) {
782
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
754
		customJavaFileManager.matchFound = false;
783
		customJavaFileManager.matchFound = false;
755
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
784
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
756
				options, null, 
785
				options, null, 
Lines 765-771 Link Here
765
public void test016_files_access_write() throws IOException {
794
public void test016_files_access_write() throws IOException {
766
	GetJavaFileForOutputDetector customJavaFileManager =
795
	GetJavaFileForOutputDetector customJavaFileManager =
767
		new GetJavaFileForOutputDetector(
796
		new GetJavaFileForOutputDetector(
768
				JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */),
797
				COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */),
769
				"Y.class");
798
				"Y.class");
770
	List<String> options = Arrays.asList(
799
	List<String> options = Arrays.asList(
771
			"-sourcepath", OUTPUT_DIR + File.separator + "src2");
800
			"-sourcepath", OUTPUT_DIR + File.separator + "src2");
Lines 792-798 Link Here
792
			"src/X.class"
821
			"src/X.class"
793
		});
822
		});
794
	assertTrue(customJavaFileManager.matchFound);
823
	assertTrue(customJavaFileManager.matchFound);
795
	if (RUN_JAVAC) {
824
	if (RUN_JAVAC && JAVAC_COMPILER != null) {
796
		customJavaFileManager.matchFound = false;
825
		customJavaFileManager.matchFound = false;
797
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
826
		assertTrue(JAVAC_COMPILER.getTask(null, customJavaFileManager, null, 
798
				options, null, 
827
				options, null, 
Lines 859-866 Link Here
859
}
888
}
860
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583
889
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583
861
public void test019_sourcepath_without_destination() throws IOException {
890
public void test019_sourcepath_without_destination() throws IOException {
891
	String sourceDirectoryName = OUTPUT_DIR + "/src2";
892
	File sourceFolder = new File(sourceDirectoryName);
893
	if (!sourceFolder.exists()) {
894
		if (!sourceFolder.mkdirs()) {
895
			// source folder could not be built
896
			return;
897
		}
898
	}
862
	StandardJavaFileManager ecjStandardJavaFileManager =
899
	StandardJavaFileManager ecjStandardJavaFileManager =
863
		JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */);
900
		COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */);
864
	assertTrue(ecjStandardJavaFileManager.handleOption(
901
	assertTrue(ecjStandardJavaFileManager.handleOption(
865
			"-sourcepath", 
902
			"-sourcepath", 
866
			Arrays.asList(OUTPUT_DIR + "/src2").iterator()));
903
			Arrays.asList(OUTPUT_DIR + "/src2").iterator()));
Lines 890-896 Link Here
890
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583
927
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=227583
891
public void _test020_sourcepath_with_destination() throws IOException {
928
public void _test020_sourcepath_with_destination() throws IOException {
892
	StandardJavaFileManager ecjStandardJavaFileManager =
929
	StandardJavaFileManager ecjStandardJavaFileManager =
893
		JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */);
930
		COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */);
894
	assertTrue(ecjStandardJavaFileManager.handleOption(
931
	assertTrue(ecjStandardJavaFileManager.handleOption(
895
			"-sourcepath", 
932
			"-sourcepath", 
896
			Arrays.asList("\"" + OUTPUT_DIR + "/src2\"[-d \"" + OUTPUT_DIR + "/bin2\"]").iterator()));
933
			Arrays.asList("\"" + OUTPUT_DIR + "/src2\"[-d \"" + OUTPUT_DIR + "/bin2\"]").iterator()));
Lines 924-930 Link Here
924
			errBuffer = new ByteArrayOutputStream();
961
			errBuffer = new ByteArrayOutputStream();
925
	CompilationTask task = COMPILER.getTask(
962
	CompilationTask task = COMPILER.getTask(
926
		new PrintWriter(outBuffer), 
963
		new PrintWriter(outBuffer), 
927
		JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), 
964
		COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), 
928
		new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), 
965
		new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), 
929
		Arrays.asList("-v"), null, null);
966
		Arrays.asList("-v"), null, null);
930
	assertTrue(task.call());
967
	assertTrue(task.call());
Lines 953-959 Link Here
953
	System.setErr(new PrintStream(errBuffer));
990
	System.setErr(new PrintStream(errBuffer));
954
	CompilationTask task = COMPILER.getTask(
991
	CompilationTask task = COMPILER.getTask(
955
			null, 
992
			null, 
956
			JAVAC_COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), 
993
			COMPILER.getStandardFileManager(null /* diagnosticListener */, null /* locale */, null /* charset */), 
957
			new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), 
994
			new CompilerInvocationDiagnosticListener(new PrintWriter(errBuffer)), 
958
			Arrays.asList("-v"), null, null);
995
			Arrays.asList("-v"), null, null);
959
	try {
996
	try {
(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-2 / +5 lines)
Lines 1328-1334 Link Here
1328
1328
1329
	private PrintWriter err;
1329
	private PrintWriter err;
1330
1330
1331
	ArrayList extraProblems;
1331
	protected ArrayList extraProblems;
1332
	public final static String bundleName = "org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$
1332
	public final static String bundleName = "org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$
1333
	// two uses: recognize 'none' in options; code the singleton none
1333
	// two uses: recognize 'none' in options; code the singleton none
1334
	// for the '-d none' option (wherever it may be found)
1334
	// for the '-d none' option (wherever it may be found)
Lines 3740-3746 Link Here
3740
	}
3740
	}
3741
3741
3742
	if (this.extraProblems != null) {
3742
	if (this.extraProblems != null) {
3743
		this.logger.loggingExtraProblems(this);
3743
		loggingExtraProblems();
3744
		this.extraProblems = null;
3744
		this.extraProblems = null;
3745
	}
3745
	}
3746
	if (this.compilerStats != null) {
3746
	if (this.compilerStats != null) {
Lines 3751-3756 Link Here
3751
	// cleanup
3751
	// cleanup
3752
	environment.cleanup();
3752
	environment.cleanup();
3753
}
3753
}
3754
protected void loggingExtraProblems() {
3755
	this.logger.loggingExtraProblems(this);
3756
}
3754
public void printUsage() {
3757
public void printUsage() {
3755
	printUsage("misc.usage"); //$NON-NLS-1$
3758
	printUsage("misc.usage"); //$NON-NLS-1$
3756
}
3759
}
(-)compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java (-2 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-24 Link Here
18
public class DefaultProblem extends CategorizedProblem {
18
public class DefaultProblem extends CategorizedProblem {
19
	private char[] fileName;
19
	private char[] fileName;
20
	private int id;
20
	private int id;
21
	private int startPosition, endPosition, line, column;
21
	private int startPosition;
22
	private int endPosition;
23
	private int line;
24
	public int column;
22
	private int severity;
25
	private int severity;
23
	private String[] arguments;
26
	private String[] arguments;
24
	private String message;
27
	private String message;

Return to bug 342936