Bug 228320 Console's log command should support multiple LogReaderServices
diff --git a/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMessages.properties b/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMessages.properties
index 3d2d7f4..3da8647 100644
--- a/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMessages.properties
+++ b/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMessages.properties
@@ -54,7 +54,6 @@
 CONSOLE_HELP_BUNDLES_COMMAND_DESCRIPTION=display details for all installed bundles
 CONSOLE_HELP_BUNDLE_COMMAND_DESCRIPTION=display details for the specified bundle(s)
 CONSOLE_HELP_HEADERS_COMMAND_DESCRIPTION=print bundle headers
-CONSOLE_HELP_LOG_COMMAND_DESCRIPTION=display log entries
 CONSOLE_HELP_EXTRAS_HEADER=Extras
 CONSOLE_HELP_EXEC_COMMAND_DESCRIPTION=execute a command in a separate process and wait
 CONSOLE_HELP_FORK_COMMAND_DESCRIPTION=execute a command in a separate process
@@ -94,11 +93,6 @@
 CONSOLE_IMPORTED_PACKAGES_MESSAGE=Imported packages
 CONSOLE_EXPORTED_REMOVAL_PENDING_MESSAGE=[exported(removal pending)]
 CONSOLE_EXPORTED_MESSAGE=[exported]
-CONSOLE_DEBUG_MESSAGE=Debug
-CONSOLE_INFO_MESSAGE=Info
-CONSOLE_WARNING_MESSAGE=Warn
-CONSOLE_ERROR_MESSAGE=Error
-CONSOLE_LOGSERVICE_NOT_REGISTERED_MESSAGE=The LogReaderService is not registered.
 CONSOLE_TOTAL_MEMORY_MESSAGE=Total memory:
 CONSOLE_FREE_MEMORY_BEFORE_GARBAGE_COLLECTION_MESSAGE=Free memory before GC:
 CONSOLE_FREE_MEMORY_AFTER_GARBAGE_COLLECTION_MESSAGE=Free memory after GC:
diff --git a/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMsg.java b/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMsg.java
index d4491b3..fc8287b 100644
--- a/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMsg.java
+++ b/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/ConsoleMsg.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
+ * Copyright (c) 2004, 2009 IBM Corporation 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
@@ -68,7 +68,6 @@
 	public static String CONSOLE_HELP_IDLOCATION_ARGUMENT_DESCRIPTION;
 	public static String CONSOLE_HELP_BUNDLE_COMMAND_DESCRIPTION;
 	public static String CONSOLE_HELP_HEADERS_COMMAND_DESCRIPTION;
-	public static String CONSOLE_HELP_LOG_COMMAND_DESCRIPTION;
 	public static String CONSOLE_HELP_EXTRAS_HEADER;
 	public static String CONSOLE_HELP_COMMAND_ARGUMENT_DESCRIPTION;
 	public static String CONSOLE_HELP_GETPROP_COMMAND_DESCRIPTION;
@@ -126,11 +125,6 @@
 	public static String CONSOLE_PROVIDED_MESSAGE;
 	public static String CONSOLE_REQUIRED_BUNDLES_MESSAGE;
 	public static String CONSOLE_NO_REQUIRED_BUNDLES_MESSAGE;
-	public static String CONSOLE_DEBUG_MESSAGE;
-	public static String CONSOLE_INFO_MESSAGE;
-	public static String CONSOLE_WARNING_MESSAGE;
-	public static String CONSOLE_ERROR_MESSAGE;
-	public static String CONSOLE_LOGSERVICE_NOT_REGISTERED_MESSAGE;
 	public static String CONSOLE_TOTAL_MEMORY_MESSAGE;
 	public static String CONSOLE_FREE_MEMORY_BEFORE_GARBAGE_COLLECTION_MESSAGE;
 	public static String CONSOLE_FREE_MEMORY_AFTER_GARBAGE_COLLECTION_MESSAGE;
diff --git a/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java b/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java
index 420fc19..d92117b 100644
--- a/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java
+++ b/bundles/org.eclipse.osgi/console/src/org/eclipse/osgi/framework/internal/core/FrameworkCommandProvider.java
@@ -13,7 +13,6 @@
 
 import java.io.*;
 import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.net.URL;
 import java.security.ProtectionDomain;
 import java.util.*;
@@ -25,6 +24,7 @@
 import org.eclipse.osgi.util.NLS;
 import org.osgi.framework.*;
 import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
+import org.osgi.service.condpermadmin.ConditionalPermissionUpdate;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.packageadmin.RequiredBundle;
 
@@ -60,8 +60,6 @@
  ss - display installed bundles (short status)
  status - display installed bundles and registered services
  threads - display threads and thread groups
- ---Log Commands---
- log {(<id>|<location>)} - display log entries
  ---Extras---
  exec <command> - execute a command in a separate process and wait
  fork <command> - execute a command in a separate process
@@ -156,7 +154,6 @@
 		addCommand("bundles", ConsoleMsg.CONSOLE_HELP_STATE_ARGUMENT_DESCRIPTION, ConsoleMsg.CONSOLE_HELP_BUNDLES_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
 		addCommand("bundle", ConsoleMsg.CONSOLE_HELP_IDLOCATION_ARGUMENT_DESCRIPTION, ConsoleMsg.CONSOLE_HELP_BUNDLE_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
 		addCommand("headers", ConsoleMsg.CONSOLE_HELP_IDLOCATION_ARGUMENT_DESCRIPTION, ConsoleMsg.CONSOLE_HELP_HEADERS_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
-		addCommand("log", ConsoleMsg.CONSOLE_HELP_IDLOCATION_ARGUMENT_DESCRIPTION, ConsoleMsg.CONSOLE_HELP_LOG_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
 		addHeader(ConsoleMsg.CONSOLE_HELP_EXTRAS_HEADER, help);
 		addCommand("exec", ConsoleMsg.CONSOLE_HELP_COMMAND_ARGUMENT_DESCRIPTION, ConsoleMsg.CONSOLE_HELP_EXEC_COMMAND_DESCRIPTION, help); //$NON-NLS-1$ 
 		addCommand("fork", ConsoleMsg.CONSOLE_HELP_COMMAND_ARGUMENT_DESCRIPTION, ConsoleMsg.CONSOLE_HELP_FORK_COMMAND_DESCRIPTION, help); //$NON-NLS-1$
@@ -824,7 +821,7 @@
 							PackageAdmin packageAdmin = (PackageAdmin) context.getService(packageAdminRef);
 							if (packageAdmin != null) {
 								intp.print("  "); //$NON-NLS-1$
-								if ((packageAdmin.getBundleType(bundle) & PackageAdminImpl.BUNDLE_TYPE_FRAGMENT) > 0) {
+								if ((packageAdmin.getBundleType(bundle) & PackageAdmin.BUNDLE_TYPE_FRAGMENT) > 0) {
 									org.osgi.framework.Bundle[] hosts = packageAdmin.getHosts(bundle);
 									if (hosts != null) {
 										intp.println(ConsoleMsg.CONSOLE_HOST_MESSAGE);
@@ -952,130 +949,6 @@
 	}
 
 	/**
-	 *  Handle the log command's abbreviation.  Invoke _log()
-	 *
-	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
-	 */
-	public void _l(CommandInterpreter intp) throws Exception {
-		_log(intp);
-	}
-
-	/**
-	 *  Handle the log command.  Display log entries.
-	 *
-	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
-	 */
-	public void _log(CommandInterpreter intp) throws Exception {
-		long logid = -1;
-		String token = intp.nextArgument();
-		if (token != null) {
-			AbstractBundle bundle = getBundleFromToken(intp, token, false);
-
-			if (bundle == null) {
-				try {
-					logid = Long.parseLong(token);
-				} catch (NumberFormatException e) {
-					return;
-				}
-			} else {
-				logid = bundle.getBundleId();
-			}
-		}
-
-		org.osgi.framework.ServiceReference logreaderRef = context.getServiceReference("org.osgi.service.log.LogReaderService"); //$NON-NLS-1$
-		if (logreaderRef != null) {
-			Object logreader = context.getService(logreaderRef);
-			if (logreader != null) {
-				try {
-					Enumeration logs = (Enumeration) (logreader.getClass().getMethod("getLog", null).invoke(logreader, null)); //$NON-NLS-1$
-					ArrayList entriesList = new ArrayList();
-					while (logs.hasMoreElements())
-						entriesList.add(0, logs.nextElement());
-					Object[] entries = entriesList.toArray();
-					if (entries.length == 0)
-						return;
-					Class clazz = entries[0].getClass();
-					Method getBundle = clazz.getMethod("getBundle", null); //$NON-NLS-1$
-					Method getLevel = clazz.getMethod("getLevel", null); //$NON-NLS-1$
-					Method getMessage = clazz.getMethod("getMessage", null); //$NON-NLS-1$
-					Method getServiceReference = clazz.getMethod("getServiceReference", null); //$NON-NLS-1$
-					Method getException = clazz.getMethod("getException", null); //$NON-NLS-1$
-
-					for (int i = 0; i < entries.length; i++) {
-						Object logentry = entries[i];
-						AbstractBundle bundle = (AbstractBundle) getBundle.invoke(logentry, null);
-
-						if ((logid == -1) || ((bundle != null) && (logid == bundle.getBundleId()))) {
-							Integer level = (Integer) getLevel.invoke(logentry, null);
-							switch (level.intValue()) {
-								case 4 :
-									intp.print(">"); //$NON-NLS-1$
-									intp.print(ConsoleMsg.CONSOLE_DEBUG_MESSAGE);
-									intp.print(" "); //$NON-NLS-1$
-									break;
-								case 3 :
-									intp.print(">"); //$NON-NLS-1$
-									intp.print(ConsoleMsg.CONSOLE_INFO_MESSAGE);
-									intp.print(" "); //$NON-NLS-1$
-									break;
-								case 2 :
-									intp.print(">"); //$NON-NLS-1$
-									intp.print(ConsoleMsg.CONSOLE_WARNING_MESSAGE);
-									intp.print(" "); //$NON-NLS-1$
-									break;
-								case 1 :
-									intp.print(">"); //$NON-NLS-1$
-									intp.print(ConsoleMsg.CONSOLE_ERROR_MESSAGE);
-									intp.print(" "); //$NON-NLS-1$
-									break;
-								default :
-									intp.print(">"); //$NON-NLS-1$
-									intp.print(level);
-									intp.print(" "); //$NON-NLS-1$
-									break;
-							}
-
-							if (bundle != null) {
-								intp.print("["); //$NON-NLS-1$
-								intp.print(new Long(bundle.getBundleId()));
-								intp.print("] "); //$NON-NLS-1$
-							}
-
-							intp.print(getMessage.invoke(logentry, null));
-							intp.print(" "); //$NON-NLS-1$
-
-							ServiceReference svcref = (ServiceReference) getServiceReference.invoke(logentry, null);
-							if (svcref != null) {
-								intp.print("{"); //$NON-NLS-1$
-								intp.print(Constants.SERVICE_ID);
-								intp.print("="); //$NON-NLS-1$
-								intp.print(svcref.getProperty(Constants.SERVICE_ID).toString());
-								intp.println("}"); //$NON-NLS-1$
-							} else {
-								if (bundle != null) {
-									intp.println(bundle.getLocation());
-								} else {
-									intp.println();
-								}
-							}
-
-							Throwable t = (Throwable) getException.invoke(logentry, null);
-							if (t != null) {
-								intp.printStackTrace(t);
-							}
-						}
-					}
-				} finally {
-					context.ungetService(logreaderRef);
-				}
-				return;
-			}
-		}
-
-		intp.println(ConsoleMsg.CONSOLE_LOGSERVICE_NOT_REGISTERED_MESSAGE);
-	}
-
-	/**
 	 *  Handle the gc command.  Perform a garbage collection.
 	 *
 	 *  @param intp A CommandInterpreter object containing the command and it's arguments.
@@ -1142,6 +1015,9 @@
 			if (permLocations != null)
 				for (int i = 0; i < permLocations.length; i++)
 					securityAdmin.setPermissions(permLocations[i], null);
+			ConditionalPermissionUpdate update = securityAdmin.newConditionalPermissionUpdate();
+			update.getConditionalPermissionInfos().clear();
+			update.commit();
 		}
 		// clear the permissions from conditional permission admin
 		if (securityAdmin != null)