|
From: <cr...@us...> - 2009-02-14 05:22:32
|
Revision: 5021
http://jnode.svn.sourceforge.net/jnode/?rev=5021&view=rev
Author: crawley
Date: 2009-02-14 05:22:25 +0000 (Sat, 14 Feb 2009)
Log Message:
-----------
Implemented a 'printenv' command to print the environment variables.
(Currently does nothing useful, but some day you will be able to set
environment variables using the bjorne interpreter, etc.)
Modified Paths:
--------------
trunk/core/src/classpath/vm/gnu/java/security/action/GetPropertiesAction.java
trunk/shell/descriptors/org.jnode.shell.command.xml
trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java
Added Paths:
-----------
trunk/core/src/classpath/vm/gnu/java/security/action/GetEnvAction.java
trunk/shell/src/shell/org/jnode/shell/command/PrintEnvCommand.java
Added: trunk/core/src/classpath/vm/gnu/java/security/action/GetEnvAction.java
===================================================================
--- trunk/core/src/classpath/vm/gnu/java/security/action/GetEnvAction.java (rev 0)
+++ trunk/core/src/classpath/vm/gnu/java/security/action/GetEnvAction.java 2009-02-14 05:22:25 UTC (rev 5021)
@@ -0,0 +1,41 @@
+/*
+ * $Id: GetPropertiesAction.java 4973 2009-02-02 07:52:47Z lsantha $
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package gnu.java.security.action;
+
+import java.security.PrivilegedAction;
+import java.util.Map;
+import java.util.Properties;
+
+
+/**
+ * Utility class for getting the map containing the environment variables in a privileged action.
+ *
+ * @author cr...@jn...
+ */
+public class GetEnvAction implements PrivilegedAction<Map<String, String>> {
+
+ /**
+ * @see java.security.PrivilegedAction#run()
+ */
+ public Map<String, String> run() {
+ return System.getenv();
+ }
+}
Modified: trunk/core/src/classpath/vm/gnu/java/security/action/GetPropertiesAction.java
===================================================================
--- trunk/core/src/classpath/vm/gnu/java/security/action/GetPropertiesAction.java 2009-02-13 07:58:01 UTC (rev 5020)
+++ trunk/core/src/classpath/vm/gnu/java/security/action/GetPropertiesAction.java 2009-02-14 05:22:25 UTC (rev 5021)
@@ -21,9 +21,11 @@
package gnu.java.security.action;
import java.security.PrivilegedAction;
+import java.util.Map;
import java.util.Properties;
+
/**
* Utility class for getting all system properties in a privileged action.
*
@@ -37,4 +39,4 @@
public Properties run() {
return System.getProperties();
}
-}
+}
\ No newline at end of file
Modified: trunk/shell/descriptors/org.jnode.shell.command.xml
===================================================================
--- trunk/shell/descriptors/org.jnode.shell.command.xml 2009-02-13 07:58:01 UTC (rev 5020)
+++ trunk/shell/descriptors/org.jnode.shell.command.xml 2009-02-14 05:22:25 UTC (rev 5021)
@@ -42,6 +42,7 @@
<alias name="namespace" class="org.jnode.shell.command.NamespaceCommand"/>
<alias name="onheap" class="org.jnode.shell.command.OnHeapCommand"/>
<alias name="page" class="org.jnode.shell.command.PageCommand"/>
+ <alias name="printenv" class="org.jnode.shell.command.PrintEnvCommand"/>
<alias name="run" class="org.jnode.shell.command.RunCommand"/>
<alias name="set" class="org.jnode.shell.command.SetCommand"/>
<alias name="sleep" class="org.jnode.shell.command.SleepCommand"/>
@@ -250,6 +251,7 @@
<empty description="Filter standard input a page (screen) at a time"/>
<argument argLabel="file" description="Output the file a page (screen) at a time"/>
</syntax>
+ <syntax alias="env" description="Print the environment variables"/>
<syntax alias="run" description="Run a command file">
<argument argLabel="file"/>
</syntax>
Modified: trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java 2009-02-13 07:58:01 UTC (rev 5020)
+++ trunk/shell/src/shell/org/jnode/shell/command/EnvCommand.java 2009-02-14 05:22:25 UTC (rev 5021)
@@ -34,6 +34,7 @@
* @author epr
*/
public class EnvCommand extends AbstractCommand {
+ // FIXME ... this class and the corresponding alias are incorrectly named
public EnvCommand() {
super("Print the system properties");
Added: trunk/shell/src/shell/org/jnode/shell/command/PrintEnvCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/PrintEnvCommand.java (rev 0)
+++ trunk/shell/src/shell/org/jnode/shell/command/PrintEnvCommand.java 2009-02-14 05:22:25 UTC (rev 5021)
@@ -0,0 +1,60 @@
+/*
+ * $Id: EnvCommand.java 4977 2009-02-02 09:09:41Z lsantha $
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.shell.command;
+
+import gnu.java.security.action.GetEnvAction;
+
+import java.io.PrintWriter;
+import java.security.AccessController;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.jnode.shell.AbstractCommand;
+
+/**
+ * This command prints the current environment variables. A regular JNode command
+ * cannot set environment variables because the Java APIs do not allow this. Environment
+ * variable setting is accomplished by the shell / interpreter and builtin commands, it at all.
+ *
+ * @author cr...@jn...
+ */
+public class PrintEnvCommand extends AbstractCommand {
+
+ public PrintEnvCommand() {
+ super("Print the current environment variables");
+ }
+
+ public static void main(String[] args) throws Exception {
+ new PrintEnvCommand().execute(args);
+ }
+
+ /**
+ * Execute this command
+ */
+ public void execute() throws Exception {
+ final Map<String, String> env = (Map<String, String>) AccessController.doPrivileged(new GetEnvAction());
+ final TreeMap<String, String> sortedEnv = new TreeMap<String, String>(env);
+ final PrintWriter out = getOutput().getPrintWriter();
+ for (Map.Entry<String, String> entry : sortedEnv.entrySet()) {
+ out.println(entry.getKey() + '=' + entry.getValue());
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|