View | Details | Raw Unified | Return to bug 97998 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/builder/ImageBuilderInternalException.java (-10 lines)
Lines 25-40 Link Here
25
	this.coreException = e;
25
	this.coreException = e;
26
}
26
}
27
27
28
public String getLocalizedMessage() {
29
	IStatus status = this.coreException.getStatus();
30
	if (status.isMultiStatus()) {
31
		IStatus[] children = status.getChildren();
32
		if (children != null && children.length > 0)
33
		    return children[0].getMessage();
34
	}
35
    return this.coreException.getLocalizedMessage();
36
}
37
38
public CoreException getThrowable() {
28
public CoreException getThrowable() {
39
	return coreException;
29
	return coreException;
40
}
30
}
(-)model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java (-29 / +26 lines)
Lines 209-236 Link Here
209
		}
209
		}
210
	} catch (CoreException e) {
210
	} catch (CoreException e) {
211
		Util.log(e, "JavaBuilder handling CoreException while building: " + currentProject.getName()); //$NON-NLS-1$
211
		Util.log(e, "JavaBuilder handling CoreException while building: " + currentProject.getName()); //$NON-NLS-1$
212
		IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
212
		createInconsistentBuildMarker(e);
213
		marker.setAttributes(
214
			new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID},
215
			new Object[] {
216
				Messages.bind(Messages.build_inconsistentProject, e.getLocalizedMessage()),
217
				new Integer(IMarker.SEVERITY_ERROR),
218
				new Integer(CategorizedProblem.CAT_BUILDPATH),
219
				JavaBuilder.SOURCE_ID
220
			}
221
		);
222
	} catch (ImageBuilderInternalException e) {
213
	} catch (ImageBuilderInternalException e) {
223
		Util.log(e.getThrowable(), "JavaBuilder handling ImageBuilderInternalException while building: " + currentProject.getName()); //$NON-NLS-1$
214
		Util.log(e.getThrowable(), "JavaBuilder handling ImageBuilderInternalException while building: " + currentProject.getName()); //$NON-NLS-1$
224
		IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
215
		createInconsistentBuildMarker(e.coreException);
225
		marker.setAttributes(
226
			new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID},
227
			new Object[] {
228
				Messages.bind(Messages.build_inconsistentProject, e.getLocalizedMessage()),
229
				new Integer(IMarker.SEVERITY_ERROR),
230
				new Integer(CategorizedProblem.CAT_BUILDPATH),
231
				JavaBuilder.SOURCE_ID
232
			}
233
		);
234
	} catch (MissingSourceFileException e) {
216
	} catch (MissingSourceFileException e) {
235
		// do not log this exception since its thrown to handle aborted compiles because of missing source files
217
		// do not log this exception since its thrown to handle aborted compiles because of missing source files
236
		if (DEBUG)
218
		if (DEBUG)
Lines 306-320 Link Here
306
		new BatchImageBuilder(this, false).cleanOutputFolders(false);
288
		new BatchImageBuilder(this, false).cleanOutputFolders(false);
307
	} catch (CoreException e) {
289
	} catch (CoreException e) {
308
		Util.log(e, "JavaBuilder handling CoreException while cleaning: " + currentProject.getName()); //$NON-NLS-1$
290
		Util.log(e, "JavaBuilder handling CoreException while cleaning: " + currentProject.getName()); //$NON-NLS-1$
309
		IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
291
		createInconsistentBuildMarker(e);
310
		marker.setAttributes(
311
			new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IMarker.SOURCE_ID},
312
			new Object[] {
313
				Messages.bind(Messages.build_inconsistentProject, e.getLocalizedMessage()),
314
				new Integer(IMarker.SEVERITY_ERROR),
315
				JavaBuilder.SOURCE_ID
316
			}
317
		);
318
	} finally {
292
	} finally {
319
		notifier.done();
293
		notifier.done();
320
		cleanup();
294
		cleanup();
Lines 324-329 Link Here
324
			+ " @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$
298
			+ " @ " + new Date(System.currentTimeMillis())); //$NON-NLS-1$
325
}
299
}
326
300
301
private void createInconsistentBuildMarker(CoreException coreException) throws CoreException {
302
	String message = null;
303
	IStatus status = coreException.getStatus();
304
 	if (status.isMultiStatus()) {
305
 		IStatus[] children = status.getChildren();
306
 		if (children != null && children.length > 0)
307
 		    message = children[0].getMessage();
308
 	}
309
 	if (message == null)
310
 		message = coreException.getMessage();
311
312
	IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
313
	marker.setAttributes(
314
		new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID},
315
		new Object[] {
316
			Messages.bind(Messages.build_inconsistentProject, message),
317
			new Integer(IMarker.SEVERITY_ERROR),
318
			new Integer(CategorizedProblem.CAT_BUILDPATH),
319
			JavaBuilder.SOURCE_ID
320
		}
321
	);
322
}
323
327
private void cleanup() {
324
private void cleanup() {
328
	this.participants = null;
325
	this.participants = null;
329
	this.nameEnvironment = null;
326
	this.nameEnvironment = null;
(-)src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java (+56 lines)
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.builder;
11
package org.eclipse.jdt.core.tests.builder;
12
12
13
import java.io.File;
14
import java.io.IOException;
15
13
import junit.framework.*;
16
import junit.framework.*;
14
17
15
import org.eclipse.core.resources.IMarker;
18
import org.eclipse.core.resources.IMarker;
19
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.core.compiler.CategorizedProblem;
22
import org.eclipse.jdt.core.compiler.CategorizedProblem;
Lines 193-196 Link Here
193
		new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR));
197
		new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR));
194
	assertEquals(JavaBuilder.SOURCE_ID, prob1[0].getSourceId());
198
	assertEquals(JavaBuilder.SOURCE_ID, prob1[0].getSourceId());
195
}
199
}
200
201
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97998
202
// Improving the error message in case of a read-only file in output
203
// directory. Beware: this test only works under Linux - execution on other
204
// platforms always succeeds, but the result is not significant.
205
public void test0105() throws JavaModelException, CoreException, IOException {
206
	if ("Linux".equals(System.getProperty("os.name"))) {
207
		IPath projectPath = env.addProject("P");
208
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
209
		IPath root = env.getPackageFragmentRootPath(projectPath, "");
210
		IPath outputFolderPath = env.getOutputLocation(projectPath);
211
		File outputFolder = env.getWorkspaceRootPath().append(outputFolderPath).toFile();
212
		env.addClass(root, "p1", 
213
				"X",
214
				"package p1;\n" +
215
				"public class X {\n" +
216
				"}\n"
217
			);
218
		try {
219
			fullBuild(projectPath);
220
			expectingNoProblems();
221
			outputFolder.setReadOnly();
222
			// outputFolder.setReadable(false);
223
			// PREMATURE no appropriate solution for Windows/NTFS/JDK 1.4
224
			cleanBuild();
225
			expectingOnlySpecificProblemFor(env.getWorkspaceRootPath(), 
226
					new Problem("", 
227
						"The project was not built due to \"Could not delete \'" + 
228
						env.getWorkspaceRootPath() + "/P/bin/.classpath\'.\". " + 
229
						"Fix the problem, then try refreshing this project and building " +
230
						"it since it may be inconsistent", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR));
231
		} finally {
232
			// waiting for JDK 6: outputFolder.setWritable(true); -- workaround:
233
			try {
234
				Runtime.getRuntime().exec("chmod -R a+w " + outputFolder.getAbsolutePath()).waitFor();
235
			} catch (InterruptedException e) {
236
				// go ahead
237
			}
238
		}
239
		try {
240
			cleanBuild();
241
			expectingNoProblems();
242
		} catch (Throwable t) {
243
			try {
244
				Runtime.getRuntime().exec("chmod -R a+w " + outputFolder.getAbsolutePath()).waitFor();
245
			} catch (InterruptedException ie) {
246
				// go ahead
247
			}
248
			fail(t.getMessage());
249
		}
250
	}
251
}
196
}
252
}

Return to bug 97998