You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/20 10:20:56 UTC
svn commit: r766612 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/io/ main/native/ main/native/include/
main/native/shared/ main/native/test/ test/org/apache/commons/runtime/
Author: mturk
Date: Mon Apr 20 08:20:56 2009
New Revision: 766612
URL: http://svn.apache.org/viewvc?rev=766612&view=rev
Log:
Add common File object class code
Added:
commons/sandbox/runtime/trunk/src/main/native/shared/fco.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h
commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
Modified: 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=766612&r1=766611&r2=766612&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Mon Apr 20 08:20:56 2009
@@ -165,4 +165,22 @@
return FileType.valueOf(fileType);
}
+ /**
+ * Returns {@code true} if the file denoted by this abstract
+ * pathname is symbolic link.
+ *
+ * @return {@code true} if the file is symbolic link.
+ * @throws IOException If an I/O error occured.
+ * @see FileType
+ */
+ public boolean isSymbolicLink()
+ throws IOException
+ {
+ if (fileType < 0)
+ fileType = ftype0(getPath());
+ // XXX: The value should be obtained directly from
+ // FileType Enum.
+ return fileType == 6;
+ }
+
}
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=766612&r1=766611&r2=766612&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Mon Apr 20 08:20:56 2009
@@ -69,6 +69,7 @@
$(SRCDIR)/shared/descriptor.$(OBJ) \
$(SRCDIR)/shared/dbb.$(OBJ) \
$(SRCDIR)/shared/error.$(OBJ) \
+ $(SRCDIR)/shared/fco.$(OBJ) \
$(SRCDIR)/shared/memory.$(OBJ) \
$(SRCDIR)/shared/pointer.$(OBJ) \
$(SRCDIR)/shared/string.$(OBJ) \
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=766612&r1=766611&r2=766612&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Mon Apr 20 08:20:56 2009
@@ -63,6 +63,7 @@
$(SRCDIR)/shared/descriptor.$(OBJ) \
$(SRCDIR)/shared/dbb.$(OBJ) \
$(SRCDIR)/shared/error.$(OBJ) \
+ $(SRCDIR)/shared/fco.$(OBJ) \
$(SRCDIR)/shared/memory.$(OBJ) \
$(SRCDIR)/shared/pointer.$(OBJ) \
$(SRCDIR)/shared/string.$(OBJ) \
Modified: 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=766612&r1=766611&r2=766612&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_file.h Mon Apr 20 08:20:56 2009
@@ -49,6 +49,15 @@
*/
ACR_DECLARE(int) ACR_FileTypeGet(JNIEnv *_E, const acr_pchar_t *fname);
+/** Create new File object with FileType set.
+ * @param env JNI environment to use. If NULL no exception will be thrown
+ * if stat fails.
+ * @param fname Abstract file name to use.
+ * @param ftype File type.
+ */
+ACR_DECLARE(jobject) ACR_IoFileObjectCreate(JNIEnv *_E, const acr_pchar_t *fname,
+ int ftype);
+
#ifdef __cplusplus
}
#endif
Added: commons/sandbox/runtime/trunk/src/main/native/shared/fco.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/fco.c?rev=766612&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/fco.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/fco.c Mon Apr 20 08:20:56 2009
@@ -0,0 +1,75 @@
+/* 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.
+ */
+
+/*
+ *
+ * @author Mladen Turk
+ */
+
+#include "acr.h"
+#include "acr_private.h"
+#include "acr_error.h"
+#include "acr_string.h"
+#include "acr_clazz.h"
+#include "acr_file.h"
+
+/**
+ * Common File object
+ */
+
+J_DECLARE_CLAZZ = {
+ NULL,
+ NULL,
+ ACR_CLASS_PATH "io/File"
+};
+
+J_DECLARE_M_ID(0000) = {
+ NULL,
+ "<init>",
+ "(Ljava/lang/String;I)V"
+};
+
+
+ACR_CLASS_LDEF(io_File)
+{
+ int rv;
+
+ if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+ return rv;
+ J_LOAD_METHOD(0000);
+
+ return ACR_SUCCESS;
+}
+
+ACR_CLASS_UDEF(io_File)
+{
+ ACR_UnloadClass(_E, &_clazzn);
+}
+
+
+ACR_DECLARE(jobject) ACR_IoFileObjectCreate(JNIEnv *_E, const acr_pchar_t *fname,
+ int ftype)
+{
+ if (_clazzn.i && _m0000n.i) {
+ jstring path = CSTR_TO_JSTRING(fname);
+ return (*_E)->NewObject(_E, _clazzn.i, _m0000n.i,
+ path, ftype);
+ }
+ else {
+ ACR_SET_OS_ERROR(ACR_ECLASSNOTFOUND);
+ return NULL;
+ }
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/shared/fco.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=766612&r1=766611&r2=766612&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Mon Apr 20 08:20:56 2009
@@ -25,6 +25,7 @@
#include "acr_clazz.h"
#include "acr_pointer.h"
#include "acr_descriptor.h"
+#include "acr_file.h"
/**
@@ -303,3 +304,27 @@
{
return ACR_NewCoreFileObjectU(_E, "/tmp/foo");
}
+
+ACR_CLASS_LDEC(io_File);
+
+ACR_JNI_EXPORT_DECLARE(jint, TestFile, ftest00)(ACR_JNISTDARGS, jint d)
+{
+ ACR_CLASS_LRUN(io_File);
+ return 0;
+}
+
+ACR_JNI_EXPORT_DECLARE(jobject, TestFile, ftest01)(ACR_JNISTDARGS, jstring f, jint t)
+{
+ jobject rv = NULL;
+#ifdef _WIN32
+ WITH_WSTR(f) {
+ rv = ACR_IoFileObjectCreate(_E, J2W(f), t);
+ } END_WITH_WSTR(f);
+#else
+ WITH_CSTR(f) {
+ rv = ACR_IoFileObjectCreate(_E, J2S(f), t);
+ } END_WITH_CSTR(f);
+#endif
+
+ return rv;
+}
Modified: 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=766612&r1=766611&r2=766612&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Mon Apr 20 08:20:56 2009
@@ -26,6 +26,9 @@
public class TestFile extends TestCase
{
+ private static native int ftest00(int d);
+ private static native File ftest01(String fname, int t);
+
public static Test suite() {
TestSuite suite = new TestSuite(TestFile.class);
return suite;
@@ -37,6 +40,13 @@
System.loadLibrary("acr");
}
+ public void testFileClassLoad()
+ throws Exception
+ {
+ int i = ftest00(0);
+ assertEquals("Value", 0, i);
+ }
+
public void testFileType()
throws Exception
{
@@ -50,5 +60,12 @@
assertEquals("Type", FileType.DIR, t);
}
+ public void testFileTypeCreated()
+ throws Exception
+ {
+ File f = ftest01("foo", 4);
+ FileType t = f.getFileType();
+ assertEquals("Type", FileType.BLK, t);
+ }
}