1 11 package org.eclipse.pde.internal.build; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.lang.reflect.Method ; 15 import org.eclipse.core.runtime.*; 16 import org.osgi.framework.Bundle; 17 18 public class AntLogAdapter implements ILog { 19 private Object antLog; 20 private Method log; 21 22 public AntLogAdapter(Object antLog) throws NoSuchMethodException { 23 this.antLog = antLog; 24 try { 25 log = antLog.getClass().getMethod("log", new Class [] { String .class, int.class }); } catch (SecurityException e) { 27 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(), new Integer (mapLogLevels(status.getSeverity()))} ); 43 IStatus[] nestedStatus = status.getChildren(); 44 if (nestedStatus != null) { 45 for (int i = 0; i < nestedStatus.length; i++) { 46 log(nestedStatus[i]); 47 } 48 } 49 } catch (IllegalArgumentException e) { 50 e.printStackTrace(); 52 } catch (IllegalAccessException e) { 53 e.printStackTrace(); 55 } catch (InvocationTargetException e) { 56 e.printStackTrace(); 58 } 59 } 60 61 private int mapLogLevels(int iStatusLevel) { 62 switch (iStatusLevel) { 63 case IStatus.ERROR : 64 return 0; 65 case IStatus.OK: 66 return 2; 67 case IStatus.INFO: 68 return 2; 69 case IStatus.WARNING: 70 return 1; 71 default: 72 return 1; 73 } 74 } 75 76 public void removeLogListener(ILogListener listener) { 77 throw new UnsupportedOperationException (); 78 } 79 80 } 81 | Popular Tags |