01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM - Initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.build;
11:
12: import java.lang.reflect.InvocationTargetException;
13: import java.lang.reflect.Method;
14: import org.eclipse.core.runtime.*;
15: import org.osgi.framework.Bundle;
16:
17: public class AntLogAdapter implements ILog {
18: private Object antLog;
19: private Method log;
20:
21: public AntLogAdapter(Object antLog) throws NoSuchMethodException {
22: this .antLog = antLog;
23: try {
24: log = antLog.getClass().getMethod(
25: "log", new Class[] { String.class, int.class }); //$NON-NLS-1$
26: } catch (SecurityException e) {
27: // TODO Auto-generated catch block
28: e.printStackTrace();
29: }
30: }
31:
32: public void addLogListener(ILogListener listener) {
33: throw new UnsupportedOperationException();
34: }
35:
36: public Bundle getBundle() {
37: return BundleHelper.getDefault().getBundle();
38: }
39:
40: public void log(IStatus status) {
41: try {
42: log.invoke(antLog, new Object[] { status.getMessage(),
43: new Integer(mapLogLevels(status.getSeverity())) });
44: IStatus[] nestedStatus = status.getChildren();
45: if (nestedStatus != null) {
46: for (int i = 0; i < nestedStatus.length; i++) {
47: log(nestedStatus[i]);
48: }
49: }
50: } catch (IllegalArgumentException e) {
51: // TODO Auto-generated catch block
52: e.printStackTrace();
53: } catch (IllegalAccessException e) {
54: // TODO Auto-generated catch block
55: e.printStackTrace();
56: } catch (InvocationTargetException e) {
57: // TODO Auto-generated catch block
58: e.printStackTrace();
59: }
60: }
61:
62: private int mapLogLevels(int iStatusLevel) {
63: switch (iStatusLevel) {
64: case IStatus.ERROR:
65: return 0;
66: case IStatus.OK:
67: return 2;
68: case IStatus.INFO:
69: return 2;
70: case IStatus.WARNING:
71: return 1;
72: default:
73: return 1;
74: }
75: }
76:
77: public void removeLogListener(ILogListener listener) {
78: throw new UnsupportedOperationException();
79: }
80:
81: }
|