aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLazar Kirchev2012-05-09 11:57:24 (EDT)
committerLazar Kirchev2012-05-11 01:59:51 (EDT)
commit2ce5ac7362e7ca3389aadb4643de685b7db00646 (patch)
tree9402af96c1f519ec892af0cad76e8bb83d74e174
parentc9303791491aa30b09518e56fb64a7eb948a8f5f (diff)
downloadrt.equinox.bundles-2ce5ac7362e7ca3389aadb4643de685b7db00646.zip
rt.equinox.bundles-2ce5ac7362e7ca3389aadb4643de685b7db00646.tar.gz
rt.equinox.bundles-2ce5ac7362e7ca3389aadb4643de685b7db00646.tar.bz2
Bug 378969 - [console] close/exit commands are dangerousv20120511-0559
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties5
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java5
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java37
3 files changed, 41 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties
index 64bc484..ad516ea 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2011 IBM Corporation and others.
+# Copyright (c) 2003, 2012 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
@@ -97,3 +97,6 @@ CONSOLE_CANNOT_LIST_DISABLED_NO_PLATFORM_ADMIN_MESSAGE=Cannot list disabled bund
CONSOLE_DISABLED_COUNT_MESSAGE={0} disabled bundle(s) in the system
CONSOLE_DISABLED_BUNDLE_HEADER=Bundle :\t{0} (id={1})
CONSOLE_DISABLED_BUNDLE_REASON=Reason(s):\t{0} (policy={1})
+CONSOLE_STOP_MESSAGE=Really want to stop Equinox? (y/n; default=y)
+CONSOLE_STOP_CONFIRMATION_YES=y
+CONSOLE_STOP_ERROR_READ_CONFIRMATION=Error while reading confirmation
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java
index e0a9d5a..eee8340 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/ConsoleMsg.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 20011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 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
@@ -96,6 +96,9 @@ public class ConsoleMsg extends NLS {
public static String CONSOLE_DISABLED_COUNT_MESSAGE;
public static String CONSOLE_DISABLED_BUNDLE_HEADER;
public static String CONSOLE_DISABLED_BUNDLE_REASON;
+ public static String CONSOLE_STOP_MESSAGE;
+ public static String CONSOLE_STOP_CONFIRMATION_YES;
+ public static String CONSOLE_STOP_ERROR_READ_CONFIRMATION;
public static String STARTLEVEL_FRAMEWORK_ACTIVE_STARTLEVEL;
public static String STARTLEVEL_BUNDLE_STARTLEVEL;
diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java
index 66fd7a6..9e7008e 100755
--- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java
+++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/commands/EquinoxCommandProvider.java
@@ -12,7 +12,11 @@
package org.eclipse.equinox.console.commands;
+import java.io.BufferedReader;
+import java.io.Closeable;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
@@ -185,8 +189,10 @@ public class EquinoxCommandProvider implements SynchronousBundleListener {
*/
@Descriptor(ConsoleMsg.CONSOLE_HELP_EXIT_COMMAND_DESCRIPTION)
public void exit() throws Exception {
- System.out.println();
- System.exit(0);
+ if (confirmStop()) {
+ System.out.println();
+ System.exit(0);
+ }
}
/**
@@ -1169,8 +1175,10 @@ public class EquinoxCommandProvider implements SynchronousBundleListener {
*/
@Descriptor(ConsoleMsg.CONSOLE_HELP_CLOSE_COMMAND_DESCRIPTION)
public void close() throws Exception {
- context.getBundle(0).stop();
- System.exit(0);
+ if (confirmStop()) {
+ context.getBundle(0).stop();
+ System.exit(0);
+ }
}
/**
@@ -2026,5 +2034,26 @@ public class EquinoxCommandProvider implements SynchronousBundleListener {
}
}
+
+ private boolean confirmStop() {
+ System.out.print(ConsoleMsg.CONSOLE_STOP_MESSAGE);
+ System.out.flush();
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+ String reply = null;
+ try {
+ reply = reader.readLine();
+ } catch (IOException e) {
+ System.out.println(ConsoleMsg.CONSOLE_STOP_ERROR_READ_CONFIRMATION);
+ }
+
+ if (reply != null) {
+ if (reply.toLowerCase().startsWith(ConsoleMsg.CONSOLE_STOP_CONFIRMATION_YES) || reply.length() == 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}