harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r431560 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main: java/org/apache/harmony/luni/platform/ native/luni/linux/ native/luni/shared/ native/luni/windows/
Date Tue, 15 Aug 2006 09:19:58 GMT
Author: pyang
Date: Tue Aug 15 02:19:57 2006
New Revision: 431560

URL: http://svn.apache.org/viewvc?rev=431560&view=rev
Log:
patch applied for HARMONY-1155 ([classlib][luni]implement get environment for 5.0)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/hyenv.c
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/hyenv.h
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyenv.c
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/makefile
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java?rev=431560&r1=431559&r2=431560&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
Tue Aug 15 02:19:57 2006
@@ -15,38 +15,50 @@
 
 package org.apache.harmony.luni.platform;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
  * Environment
- *  
  */
 public class Environment {
 
+	private static Map<String, String> envMap = new HashMap<String, String>();
+
+	static {
+        byte[] bytes = getEnvBytes();
+        if (bytes != null) {
+            String[] envStrings = new String(bytes).split("\0");
+            for (int i = 0; i < envStrings.length; i++) {
+                int separator = envStrings[i].indexOf("=");
+                envMap.put(envStrings[i].substring(0, separator), envStrings[i]
+                        .substring(separator + 1));
+            }
+        }
+	}
+
 	/**
-	 * Returns a Map of the current environment variables, containing
-         * key and value pairs.
-         * 
-         * @return a Map containing the environment variables and their
-         *         values
+	 * Returns a Map of the current environment variables, containing key and
+	 * value pairs.
 	 * 
-	 * TODO: Implement
+	 * @return a Map containing the environment variables and their values
 	 */
-	public static Map<String,String> getenv() {
-		throw new org.apache.harmony.luni.util.NotYetImplementedException("getenv is not implemented");
+	public static Map<String, String> getenv() {
+		return envMap;
 	}
-	
+
 	/**
-	 * Returns a String containing the value of the specified name
-	 * environment variable
+	 * Returns a String containing the value of the specified name environment
+	 * variable
 	 * 
-	 * @param name - the environment variable to get the value of
+	 * @param name -
+	 *            the environment variable to get the value of
 	 * 
-         * @return the value of the environment variable specified
-         * 
-         * TODO: Implement
+	 * @return the value of the environment variable specified
 	 */
 	public static String getenv(String name) {
-		throw new org.apache.harmony.luni.util.NotYetImplementedException("getenv is not implemented");
+		return envMap.get(name);
 	}
+
+	private static native byte[] getEnvBytes();
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/hyenv.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/hyenv.c?rev=431560&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/hyenv.c
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/hyenv.c
Tue Aug 15 02:19:57 2006
@@ -0,0 +1,37 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <string.h>
+#include <unistd.h>
+#include "hyenv.h"
+
+JNIEXPORT jbyteArray JNICALL Java_org_apache_harmony_luni_platform_Environment_getEnvBytes
+  (JNIEnv *env, jclass obj){
+  jstring returnvar;
+  char* var;
+  extern char** environ;
+  jbyteArray byteArray;
+  int bufsize=0,i=0,start=0,len=0;
+  for(i=0;*(environ+i);i++){
+    bufsize+=strlen(environ[i])+1;
+  }
+  byteArray = (*env)->NewByteArray(env,bufsize);
+  for(i=0;*(environ+i);i++){
+      len=strlen(environ[i])+1;
+      (*env)->SetByteArrayRegion(env,byteArray, start, len, environ[i]);
+      start+=len;
+  }
+  return byteArray;
+}
+

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp?rev=431560&r1=431559&r2=431560&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/libhyluni.exp
Tue Aug 15 02:19:57 2006
@@ -222,5 +222,6 @@
 		Java_org_apache_harmony_luni_platform_OSNetworkSystem_setInetAddressImpl;
         Java_org_apache_harmony_luni_platform_OSNetworkSystem_isReachableByICMPImpl;
         Java_org_apache_harmony_luni_platform_OSNetworkSystem_inheritedChannelImpl;
+	Java_org_apache_harmony_luni_platform_Environment_getEnvBytes;
 	local : *;
 };

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/makefile
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/makefile?rev=431560&r1=431559&r2=431560&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/makefile
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/makefile
Tue Aug 15 02:19:57 2006
@@ -1,4 +1,4 @@
-# Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+# Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
 # 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@
 	$(SHAREDSUB)filedesc.o $(SHAREDSUB)timezone.o \
 	$(SHAREDSUB)OSFileSystem.o OSFileSystemLinux32.o \
 	OSMemory.o OSMemoryLinux32.o $(SHAREDSUB)OSNetworkSystem.o \
-	OSNetworkSystemLinux.o
+	OSNetworkSystemLinux.o hyenv.o
 
 MDLLIBFILES = \
 	$(LIBPATH)libhycommon.a $(DLLPATH)libhysig.so $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib.so
\

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/hyenv.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/hyenv.h?rev=431560&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/hyenv.h
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/hyenv.h
Tue Aug 15 02:19:57 2006
@@ -0,0 +1,35 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <jni.h>
+
+
+#ifndef _Included_org_apache_harmony_luni_platform_Environment
+#define _Included_org_apache_harmony_luni_platform_Environment
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class:     org_apache_harmony_luni_platform_Environment
+ * Method:    getEnvBytes
+ * Signature: ()[B
+ */
+JNIEXPORT jbyteArray JNICALL Java_org_apache_harmony_luni_platform_Environment_getEnvBytes
+  (JNIEnv *, jclass);
+
+#ifdef __cplusplus
+}
+#endif
+#endif

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyenv.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyenv.c?rev=431560&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyenv.c
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyenv.c
Tue Aug 15 02:19:57 2006
@@ -0,0 +1,40 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <windows.h>
+#include "hyenv.h"
+
+
+JNIEXPORT jbyteArray JNICALL Java_org_apache_harmony_luni_platform_Environment_getEnvBytes
+  (JNIEnv *env, jclass obj){ 
+  jsize len =0;
+  jbyte *buffer;
+  LPTSTR lpszVars;
+  LPVOID lpvEnv;
+  jbyteArray byteArray;
+  lpvEnv = GetEnvironmentStrings();
+  if (lpvEnv == NULL){
+    return NULL;
+  }
+  lpszVars = (LPTSTR)lpvEnv;
+  buffer = lpszVars;
+  while(*lpszVars){
+    len += strlen(lpszVars)+1;
+	lpszVars += strlen(lpszVars)+1;
+  }
+  byteArray = (*env)->NewByteArray(env,len);
+  (*env)->SetByteArrayRegion(env,byteArray, 0, len, buffer);
+  FreeEnvironmentStrings((LPTCH)lpvEnv);
+  return byteArray;
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def?rev=431560&r1=431559&r2=431560&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/hyluni.def
Tue Aug 15 02:19:57 2006
@@ -215,3 +215,4 @@
 	Java_org_apache_harmony_luni_util_NumberConverter_bigIntDigitGeneratorInstImpl
 	Java_org_apache_harmony_luni_platform_OSNetworkSystem_isReachableByICMPImpl
 	Java_org_apache_harmony_luni_platform_OSNetworkSystem_inheritedChannelImpl
+	Java_org_apache_harmony_luni_platform_Environment_getEnvBytes
\ No newline at end of file

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile?rev=431560&r1=431559&r2=431560&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile
Tue Aug 15 02:19:57 2006
@@ -34,7 +34,7 @@
   $(SHAREDSUB)process.obj $(SHAREDSUB)bigint.obj $(SHAREDSUB)osc.obj \
   $(SHAREDSUB)socket.obj $(SHAREDSUB)inetadds.obj \
   $(SHAREDSUB)filedesc.obj $(SHAREDSUB)timezone.obj \
-  OSFileSystemWin32.obj \
+  OSFileSystemWin32.obj hyenv.obj\
   $(SHAREDSUB)OSFileSystem.obj OSMemoryWin32.obj OSMemory.obj \
   $(SHAREDSUB)OSNetworkSystem.obj OSNetworkSystemWin32.obj
 



Mime
View raw message