akarasulu 2003/11/10 14:27:49
Modified: merlin/util/env/src/java/org/apache/avalon/util/env Env.java
Log:
Code for OS X support.
Revision Changes Path
1.5 +87 -3
avalon/merlin/util/env/src/java/org/apache/avalon/util/env/Env.java
Index: Env.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/util/env/src/java/org/apache/avalon/util/env/Env.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Env.java 7 Nov 2003 20:24:48 -0000 1.4
+++ Env.java 10 Nov 2003 22:27:49 -0000 1.5
@@ -215,6 +215,11 @@
*/
public static String getUserShell() throws EnvAccessException
{
+ if ( -1 != OSNAME.indexOf( "Mac OS X" ) )
+ {
+ return getMacUserShell() ;
+ }
+
if ( isUnix() )
{
return getUnixUserShell() ;
@@ -230,11 +235,90 @@
+ "supported on unrecognized operatings system" ) ) ;
}
-
+
// ------------------------------------------------------------------------
// Private UNIX Shell Operations
// ------------------------------------------------------------------------
+
+ /**
+ * Gets the default login shell used by a mac user.
+ *
+ * @return the Mac user's default shell as referenced by cmd:
+ * 'nidump passwd /'
+ */
+ private static String getMacUserShell() throws EnvAccessException
+ {
+ Process l_proc = null ;
+ BufferedReader l_in = null ;
+
+ if ( null != s_shell )
+ {
+ return s_shell ;
+ }
+
+ try
+ {
+ String l_entry = null ;
+ String [] l_args = { "nidump", "passwd", "/" } ;
+ l_proc = Runtime.getRuntime().exec( l_args ) ;
+ l_in = new BufferedReader(
+ new InputStreamReader( l_proc.getInputStream() ) ) ;
+
+ while ( null != ( l_entry = l_in.readLine() ) )
+ {
+ // Skip entries other than the one for this username
+ if ( ! l_entry.startsWith( USERNAME ) )
+ {
+ continue ;
+ }
+
+ // Get the shell part of the passwd entry
+ int l_index = l_entry.lastIndexOf( ':' ) ;
+
+ if ( l_index == -1 )
+ {
+ throw new EnvAccessException(
+ "passwd database contains malformed user entry for "
+ + USERNAME ) ;
+ }
+
+ s_shell = l_entry.substring( l_index + 1 ) ;
+ return s_shell ;
+ }
+
+ l_proc.waitFor() ;
+ l_in.close() ;
+ }
+ catch( Throwable t )
+ {
+ t.printStackTrace() ;
+ throw new EnvAccessException( t ) ;
+ }
+ finally
+ {
+ if ( l_proc != null )
+ {
+ l_proc.destroy() ;
+ }
+
+ try
+ {
+ if ( null != l_in )
+ {
+ l_in.close() ;
+ }
+ }
+ catch( IOException e )
+ {
+ // do nothing
+ }
+ }
+
+ throw new EnvAccessException( "User " + USERNAME
+ + " does not seem to exist in the passwd database" ) ;
+ }
+
/**
* Gets the default login shell used by a unix user.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]