Author: mturk Date: Thu Oct 22 10:41:00 2009 New Revision: 828647 URL: http://svn.apache.org/viewvc?rev=828647&view=rev Log: Always return Path object instead string representing path
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java Thu Oct 22 10:41:00 2009 @@ -157,7 +157,7 @@ throw new IOException(Status.describe(rc)); } - private static native String tmpdir0(String path, String prefix) + private static native Path tmpdir0(String path, String prefix) throws IOException, SecurityException; /** @@ -176,8 +176,8 @@ public static File createTemp(Path path, String prefix) throws IOException, SecurityException { - String tmp = tmpdir0(path.toString(), prefix); - return new File(tmp, FileType.DIR); + Path tmp = tmpdir0(path.toString(), prefix); + return new File(tmp.toString(), FileType.DIR); } /** @@ -194,12 +194,12 @@ public static File createTemp(String prefix) throws IOException, SecurityException { - String tmp = tmpdir0(null, prefix); - return new File(tmp, FileType.DIR); + Path tmp = tmpdir0(null, prefix); + return new File(tmp.toString(), FileType.DIR); } - private static Path tmpDir; - private static native String tmpdir1(String paths); + private static Path tmpDir; + private static native Path tmpdir1(String paths); /** * Get system temporary directory path. * @@ -213,36 +213,27 @@ public synchronized static Path getTempPath(String searchPath) throws SecurityException { - String dir = tmpdir1(searchPath); - if (dir == null) + tmpDir = tmpdir1(searchPath); + if (tmpDir == null) throw new SecurityException(); - tmpDir = new Path(dir); return tmpDir; } - public static native String cur0() + public static native Path getcwd0() throws IOException; public static Path getCurrentPath() throws IOException { - return new Path(cur0()); + return getcwd0(); } - public static native int cwd0(String path) + public static native int chdir0(String path) throws IOException; public static void setCurrentPath(Path path) throws IOException { - int rc = cwd0(path.toString()); - if (rc != 0) { - throw new IOException(Status.describe(rc)); - } - } - public static void setCurrentPath(String path) - throws IOException - { - int rc = cwd0(path); + int rc = chdir0(path.toString()); if (rc != 0) { throw new IOException(Status.describe(rc)); } Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java Thu Oct 22 10:41:00 2009 @@ -115,10 +115,14 @@ * Normalized Path */ private String path; + private int type; - private Path() - throws NullPointerException, IOException + /* Created from native. + */ + private Path(int type, String path) { + this.type = type; + this.path = path; } /** * Creates a new {...@code Path} instance from a {...@code parent} pathname Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h Thu Oct 22 10:41:00 2009 @@ -31,6 +31,8 @@ * */ +ACR_DECLARE(jobject) ACR_NewPathObject(JNIEnv *env, int type, + const acr_pchar_t *fpath); #ifdef __cplusplus } Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c Thu Oct 22 10:41:00 2009 @@ -22,7 +22,7 @@ #include "acr_string.h" #include "acr_descriptor.h" #include "acr_file.h" -#include "acr_port.h" +#include "acr_fileio.h" #include <sys/types.h> #include <dirent.h> @@ -233,7 +233,7 @@ return rc; } -ACR_IO_EXPORT_DECLARE(jstring, Directory, tmpdir0)(ACR_JNISTDARGS, jstring path, +ACR_IO_EXPORT_DECLARE(jobject, Directory, tmpdir0)(ACR_JNISTDARGS, jstring path, jstring prefix) { int rc = 0; @@ -256,13 +256,13 @@ return NULL; } else { - jstring rv = ACR_NewJavaStringA(_E, tmpd); + jstring rv = ACR_NewPathObject(_E, ACR_FT_DIR, tmpd); x_free(tmpd); return rv; } } -ACR_IO_EXPORT_DECLARE(jstring, Directory, tmpdir1)(ACR_JNISTDARGS, +ACR_IO_EXPORT_DECLARE(jobject, Directory, tmpdir1)(ACR_JNISTDARGS, jstring paths) { const char *tmpd = NULL; @@ -273,12 +273,12 @@ tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2S(paths)); } END_WITH_CSTR(paths); if (tmpd) - return ACR_NewJavaStringA(_E, tmpd); + return ACR_NewPathObject(_E, ACR_FT_DIR, tmpd); else return NULL; } -ACR_IO_EXPORT_DECLARE(jstring, Directory, getcwd0)(ACR_JNISTDARGS) +ACR_IO_EXPORT_DECLARE(jobject, Directory, getcwd0)(ACR_JNISTDARGS) { size_t l; char path[PATH_MAX]; @@ -290,7 +290,7 @@ l = strlen(path); if (l > 1 && path[l - 1] == '/') path[l - 1] = '\0'; - return ACR_NewJavaStringA(_E, path); + return ACR_NewPathObject(_E, ACR_FT_DIR, path); } ACR_IO_EXPORT_DECLARE(jint, Directory, chdir0)(ACR_JNISTDARGS, jstring path) Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/finfo.c Thu Oct 22 10:41:00 2009 @@ -24,6 +24,7 @@ #include "acr_string.h" #include "acr_users.h" #include "acr_file.h" +#include "acr_fileio.h" /** * Posix file info functions @@ -169,7 +170,7 @@ { jstring name; if ((name = ACR_NewJavaStringA(_E, fname))) - return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001)); + return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), name); else return NULL; } @@ -178,7 +179,7 @@ { jstring name; if ((name = ACR_NewJavaStringW(_E, fname))) - return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001)); + return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), name); else return NULL; } Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/path.c Thu Oct 22 10:41:00 2009 @@ -18,11 +18,12 @@ #include "acr_private.h" #include "acr_arch.h" #include "acr_port.h" +#include "acr_clazz.h" #include "acr_error.h" #include "acr_string.h" #include "acr_descriptor.h" #include "acr_file.h" -#include "acr_port.h" +#include "acr_fileio.h" /** * Posix file path functions @@ -169,6 +170,43 @@ } } +J_DECLARE_CLAZZ = { + NULL, + NULL, + ACR_IO_CLASS_PATH "Path" +}; + +J_DECLARE_M_ID(0000) = { + NULL, + "<init>", + "(ILjava/lang/String;)V" +}; + +ACR_CLASS_LDEF(io_Path) +{ + int rv; + + if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS) + return rv; + J_LOAD_METHOD(0000); + + return ACR_SUCCESS; +} + +ACR_CLASS_UDEF(io_Path) +{ + ACR_UnloadClass(_E, &_clazzn); +} + +ACR_DECLARE(jobject) ACR_NewPathObject(JNIEnv *_E, int type, const char *fpath) +{ + jstring path; + if ((path = ACR_NewJavaStringA(_E, fpath))) + return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), type, path); + else + return NULL; +} + ACR_IO_EXPORT_DECLARE(void, Path, init0)(ACR_JNISTDARGS, jintArray p) { Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c Thu Oct 22 10:41:00 2009 @@ -6,7 +6,7 @@ #include "acr_string.h" #include "acr_descriptor.h" #include "acr_file.h" -#include "acr_port.h" +#include "acr_fileio.h" /** * Windows directory functions @@ -103,6 +103,7 @@ for (;;) { if (!readdir_r(dir, &ds, &dp)) { if (dp) { + if (*(dp->d_name) == '.' && (*(dp->d_name + 1) == '\0' || (*(dp->d_name + 1) == '.' && *(dp->d_name + 2) == '\0'))) { @@ -221,7 +222,7 @@ return rc; } -ACR_IO_EXPORT_DECLARE(jstring, Directory, tmpdir0)(ACR_JNISTDARGS, jstring path, +ACR_IO_EXPORT_DECLARE(jobject, Directory, tmpdir0)(ACR_JNISTDARGS, jstring path, jstring prefix) { int rc = 0; @@ -244,13 +245,13 @@ return NULL; } else { - jstring rv = ACR_NewJavaStringW(_E, tmpd); + jstring rv = ACR_NewPathObject(_E, ACR_FT_DIR, tmpd); x_free(tmpd); return rv; } } -ACR_IO_EXPORT_DECLARE(jstring, Directory, tmpdir1)(ACR_JNISTDARGS, +ACR_IO_EXPORT_DECLARE(jobject, Directory, tmpdir1)(ACR_JNISTDARGS, jstring paths) { const wchar_t *tmpd = NULL; @@ -261,12 +262,12 @@ tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2W(paths)); } END_WITH_WPATH(paths); if (tmpd) - return ACR_NewJavaStringW(_E, tmpd); + return ACR_NewPathObject(_E, ACR_FT_DIR, tmpd); else return NULL; } -ACR_IO_EXPORT_DECLARE(jstring, Directory, getcwd0)(ACR_JNISTDARGS) +ACR_IO_EXPORT_DECLARE(jobject, Directory, getcwd0)(ACR_JNISTDARGS) { DWORD l; wchar_t path[ACR_HBUFF_SIZ]; @@ -292,7 +293,7 @@ ACR_THROW_IO_IF_ERR(ACR_EOVERFLOW); return NULL; } - return acr_NewJavaNativePathW(_E, rcwd); + return ACR_NewPathObject(_E, ACR_FT_DIR, rcwd); } ACR_IO_EXPORT_DECLARE(jint, Directory, chdir0)(ACR_JNISTDARGS, jstring path) Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/finfo.c Thu Oct 22 10:41:00 2009 @@ -25,6 +25,7 @@ #include "acr_string.h" #include "acr_users.h" #include "acr_file.h" +#include "acr_fileio.h" /** * Windows file info functions @@ -168,7 +169,7 @@ { jstring name; if ((name = ACR_NewJavaStringU(_E, fname))) - return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001)); + return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), name); else return NULL; } @@ -177,7 +178,7 @@ { jstring name; if ((name = ACR_NewJavaStringW(_E, fname))) - return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001)); + return (*_E)->NewObject(_E, _clazzn.i, J4MID(0001), name); else return NULL; } Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c Thu Oct 22 10:41:00 2009 @@ -18,12 +18,14 @@ #include "acr_private.h" #define ACR_WANT_LATE_DLL #include "acr_arch.h" +#include "acr_clazz.h" #include "acr_error.h" #include "acr_memory.h" #include "acr_port.h" #include "acr_string.h" #include "acr_descriptor.h" #include "acr_file.h" +#include "acr_fileio.h" #include <direct.h> /* For _getdrive() */ /** @@ -302,6 +304,42 @@ return r; } +J_DECLARE_CLAZZ = { + NULL, + NULL, + ACR_IO_CLASS_PATH "Path" +}; + +J_DECLARE_M_ID(0000) = { + NULL, + "<init>", + "(ILjava/lang/String;)V" +}; + +ACR_CLASS_LDEF(io_Path) +{ + int rv; + + if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS) + return rv; + J_LOAD_METHOD(0000); + + return ACR_SUCCESS; +} + +ACR_CLASS_UDEF(io_Path) +{ + ACR_UnloadClass(_E, &_clazzn); +} + +ACR_DECLARE(jobject) ACR_NewPathObject(JNIEnv *_E, int type, const wchar_t *fpath) +{ + jstring path; + if ((path = acr_NewJavaNativePathW(_E, fpath))) + return (*_E)->NewObject(_E, _clazzn.i, J4MID(0000), type, path); + else + return NULL; +} ACR_IO_EXPORT_DECLARE(void, Path, init0)(ACR_JNISTDARGS, jintArray p) Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=828647&r1=828646&r2=828647&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Thu Oct 22 10:41:00 2009 @@ -388,6 +388,7 @@ ACR_CLASS_LDEC(io_File); ACR_CLASS_LDEC(io_FileInfo); ACR_CLASS_LDEC(io_MemoryMapProvider); +ACR_CLASS_LDEC(io_Path); ACR_DECLARE(int) ACR_LoadRuntimeClasses(JNIEnv *_E) { @@ -406,6 +407,7 @@ ACR_CLASS_LRUN(io_File); ACR_CLASS_LRUN(io_FileInfo); ACR_CLASS_LRUN(io_MemoryMapProvider); + ACR_CLASS_LRUN(io_Path); #ifdef WIN32 #endif @@ -430,6 +432,7 @@ ACR_CLASS_URUN(io_File); ACR_CLASS_URUN(io_FileInfo); ACR_CLASS_URUN(io_MemoryMapProvider); + ACR_CLASS_URUN(io_Path); #ifdef WIN32 #endif