Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6802f700941b6d7bfb55fbbc1ce8c4837bcf9e9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*******************************************************************************
 * Copyright (c) 2007 Symbian Software Limited 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:
 * Bala Torati (Symbian) - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.templateengine;

import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.List;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

public class TemplateEngineUtil {

	public static void log(Throwable t) {
		if (t == null) {
			return;
		}
		if (t instanceof InvocationTargetException) {
			t = ((InvocationTargetException) t).getTargetException();
		}
		if (t instanceof CoreException) {
			ResourcesPlugin.getPlugin().getLog().log(((CoreException) t).getStatus());
		} if (t instanceof ProcessFailureException) {
			do {
				List/*<IStatus>*/ statuses = ((ProcessFailureException) t).getStatuses();
				if (statuses != null) {
					for(Iterator i = statuses.iterator(); i.hasNext(); ) {
						IStatus status = (IStatus) i.next();
						ResourcesPlugin.getPlugin().getLog().log(status);
					}
				}
				t = t.getCause();
			} while (t != null && t instanceof ProcessFailureException);
		} else {
			ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.OK, t.getMessage() == null ? t.toString() : t.getMessage() , t));
		}
	}

}

Back to the top