commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r766378 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/java/org/apache/commons/runtime/io/ main/native/ main/native/include/ main/native/os/unix/ test/org/apache/commons/runtime/
Date Sat, 18 Apr 2009 19:43:51 GMT
Author: mturk
Date: Sat Apr 18 19:43:51 2009
New Revision: 766378

URL: http://svn.apache.org/viewvc?rev=766378&view=rev
Log:
Add File skeleton

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java  
(with props)
    commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c   (with props)
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java   (with
props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java?rev=766378&r1=766377&r2=766378&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
Sat Apr 18 19:43:51 2009
@@ -42,7 +42,7 @@
     static {
         instance = new Properties();
         if (instance != null) {
-            CPU_CACHE_TTL                   = getLong("cpu.cache.ttl");
+            CPU_CACHE_TTL                   = getL("cpu.cache.ttl");
         }
     }
 
@@ -98,7 +98,7 @@
 
     private static int getI(String key)
     {
-        return getInt(key, 0);
+        return getI(key, 0);
     }
 
     private static String getS(String key)

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=766378&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Sat
Apr 18 19:43:51 2009
@@ -0,0 +1,38 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.commons.runtime.io;
+
+/** File extends the {@code java.io.File} object.
+ */
+
+public class File extends java.io.File {
+
+    private static native int ftype0(String pathname);
+
+    /**
+     * Create new File.
+     */
+    public File(String pathname)
+    {
+        super(pathname);
+    }
+
+    public FileType getFileType()
+    {
+        return FileType.valueOf(ftype0(getPath()));
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=766378&r1=766377&r2=766378&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Sat Apr 18 19:43:51 2009
@@ -76,18 +76,22 @@
 	$(SRCDIR)/shared/version.$(OBJ)
 
 LINUX_OBJS= \
+	$(SRCDIR)/os/unix/file.$(OBJ) \
 	$(SRCDIR)/os/unix/main.$(OBJ) \
 	$(SRCDIR)/os/linux/os.$(OBJ)
 
 SOLARIS_OBJS= \
+	$(SRCDIR)/os/unix/file.$(OBJ) \
 	$(SRCDIR)/os/unix/main.$(OBJ) \
 	$(SRCDIR)/os/solaris/os.$(OBJ)
 
 DARWIN_OBJS= \
+	$(SRCDIR)/os/unix/file.$(OBJ) \
 	$(SRCDIR)/os/unix/main.$(OBJ) \
 	$(SRCDIR)/os/darwin/os.$(OBJ)
 
 HPUX_OBJS= \
+	$(SRCDIR)/os/unix/file.$(OBJ) \
 	$(SRCDIR)/os/unix/main.$(OBJ) \
 	$(SRCDIR)/os/hpux/os.$(OBJ)
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=766378&r1=766377&r2=766378&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Sat Apr 18 19:43:51 2009
@@ -211,6 +211,8 @@
 typedef  unsigned __int64   acr_uint64_t;
 typedef  __int64            acr_off_t;
 typedef  int                acr_socklen_t;
+/* API char type on windows is always WCHAR */
+typedef  wchar_t            acr_pchar_t;
 #else
 typedef  ssize_t            acr_ssize_t;
 typedef  long long          acr_int64_t;
@@ -221,6 +223,8 @@
 typedef  int64_t            acr_off_t;
 #endif
 typedef  socklen_t          acr_socklen_t;
+/* API char type on POSIX is always char (UTF-8) */
+typedef  char               acr_pchar_t;
 #endif
 
 #if CC_SIZEOF_VOIDP == 8

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h?rev=766378&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h Sat Apr 18 19:43:51 2009
@@ -0,0 +1,56 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#ifndef _ACR_FILE_H
+#define _ACR_FILE_H
+
+#include "acr.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file acr_file.h
+ * @brief
+ *
+ * ACR File functions
+ *
+ */
+
+#define ACR_FT_NOFILE     0    /**< no file type determined */
+#define ACR_FT_REG        1    /**< a regular file */
+#define ACR_FT_DIR        2    /**< a directory */
+#define ACR_FT_CHR        3    /**< a character device */
+#define ACR_FT_BLK        4    /**< a block device */
+#define ACR_FT_PIPE       5    /**< a FIFO / pipe */
+#define ACR_FT_LNK        6    /**< a symbolic link */
+#define ACR_FT_SOCK       7    /**< a [unix domain] socket */
+#define ACR_FT_UNKFILE  127    /**< a file of some other unknown type */
+
+/** Get FileType
+ * @param env JNI environment to use. If NULL no exception will be thrown
+ *            if stat fails.
+ * @param fname File name for which to get the type.
+ * @return One of the ACR_FT_* types or -1 of error
+ */
+ACR_DECLARE(int) ACR_FileTypeGet(JNIEnv *_E, const acr_pchar_t *fname);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ACR_FILE_H */

Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h?rev=766378&r1=766377&r2=766378&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_private.h Sat Apr 18 19:43:51
2009
@@ -35,6 +35,7 @@
 #define ACR_JNI_EXPORT_DECLARE(RT, CL, MN)  \
     JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_##CL##_##MN
 
+
 /* ACR_ALIGN() is only to be used to align on a power of 2 boundary */
 #define ACR_ALIGN(size, boundary) \
     (((size) + ((boundary) - 1)) & ~((boundary) - 1))

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=766378&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Sat Apr 18 19:43:51 2009
@@ -0,0 +1,117 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 "acr.h"
+#include "acr_private.h"
+#include "acr_error.h"
+#include "acr_file.h"
+
+/**
+ * Posix file functions
+ *
+ */
+
+#if defined(_LARGEFILE64_SOURCE)
+#define stat(f,b) stat64(f,b)
+#define lstat(f,b) lstat64(f,b)
+#define fstat(f,b) fstat64(f,b)
+#define lseek(f,o,w) lseek64(f,o,w)
+#define ftruncate(f,l) ftruncate64(f,l)
+typedef struct stat64 struct_stat;
+#else
+typedef struct stat struct_stat;
+#endif
+
+ACR_DECLARE(int) ACR_FileTypeGet(JNIEnv *_E, const char *fname)
+{
+    struct_stat info;
+
+    if (stat(fname, &info) == 0) {
+        int type;
+
+        switch (info.st_mode & S_IFMT) {
+            case S_IFREG:
+                type = ACR_FT_REG;  break;
+            case S_IFDIR:
+                type = ACR_FT_DIR;  break;
+            case S_IFLNK:
+                type = ACR_FT_LNK;  break;
+            case S_IFCHR:
+                type = ACR_FT_CHR;  break;
+            case S_IFBLK:
+                type = ACR_FT_BLK;  break;
+#if defined(S_IFFIFO)
+            case S_IFFIFO:
+                type = ACR_FT_PIPE; break;
+#endif
+#if defined(S_IFSOCK)
+            case S_IFSOCK:
+                type = ACR_FT_SOCK; break;
+#endif
+
+            default:
+        	/* Work around missing S_IFxxx values above
+             * for Linux et al.
+             */
+#if !defined(S_IFFIFO) && defined(S_ISFIFO)
+            	if (S_ISFIFO(info.st_mode)) {
+                    type = ACR_FT_PIPE;
+            	} else
+#endif
+#if !defined(S_IFSOCK) && defined(S_ISSOCK)
+            	if (S_ISSOCK(info.st_mode)) {
+                    type = ACR_FT_SOCK;
+        	    } else
+#endif
+                type = ACR_FT_UNKFILE;
+            break;
+        }
+        return type;
+    }
+    else if (_E) {
+#if !defined(ENOENT) || !defined(ENOTDIR)
+#error ENOENT || ENOTDIR not defined; please see the
+#error comments at this line in the source for a workaround.
+        /*
+         * If ENOENT || ENOTDIR is not defined in one of the your OS's
+         * include files, APR cannot report a good reason why the stat()
+         * of the file failed; there are cases where it can fail even though
+         * the file exists.  This opens holes in Apache, for example, because
+         * it becomes possible for someone to get a directory listing of a 
+         * directory even though there is an index (eg. index.html) file in 
+         * it.  If you do not have a problem with this, delete the above 
+         * #error lines and start the compile again.  If you need to do this,
+         * please submit a bug report to http://www.apache.org/bug_report.html
+         * letting us know that you needed to do this.  Please be sure to 
+         * include the operating system you are using.
+         */
+#endif
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, errno);
+    }
+    return -1;
+}
+
+ACR_JNI_EXPORT_DECLARE(int, io_File, ftype0)(ACR_JNISTDARGS, jstring pathname)
+{
+    int type;
+    CSTR_DECLARE(pathname);
+
+    UNREFERENCED_O;
+    type = ACR_FileTypeGet(_E, J2S(pathname));
+    CSTR_RELEASE(pathname);
+
+    return type;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java?rev=766378&r1=766377&r2=766378&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestAll.java Sat Apr
18 19:43:51 2009
@@ -35,6 +35,7 @@
         suite.addTest(TestOS.suite());
         suite.addTest(TestDirectByteBuffer.suite());
         suite.addTest(TestPrivate.suite());
+        suite.addTest(TestFile.suite());
         return suite;
     }
 

Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java?rev=766378&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (added)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Sat Apr
18 19:43:51 2009
@@ -0,0 +1,54 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.commons.runtime;
+
+import org.apache.commons.runtime.io.*;
+import junit.framework.*;
+
+/**
+ * File Test.
+ *
+ */
+public class TestFile extends TestCase
+{
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(TestFile.class);
+        return suite;
+    }
+
+    protected void setUp()
+        throws Exception
+    {
+        System.loadLibrary("acr");
+    }
+
+    public void testFileType()
+        throws Exception
+    {
+        File f;
+        if (OS.IS_UNIX)
+            f = new File("/tmp");
+        else
+            f = new File("C:\\Program Files");
+
+        FileType t = f.getFileType();
+        assertEquals("Type", FileType.DIR, t);
+    }
+
+
+}

Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message