8133987: (fs) Rename GnomeFileTypeDetector to GioFileTypeDetector
Summary: Rename class and associated native file as indicated and fix some related comments in the source and test.
Reviewed-by: alanb
--- a/jdk/make/lib/NioLibraries.gmk Fri Aug 28 07:55:45 2015 -0700
+++ b/jdk/make/lib/NioLibraries.gmk Fri Aug 28 10:46:43 2015 -0700
@@ -47,7 +47,7 @@
ifeq ($(OPENJDK_TARGET_OS), macosx)
BUILD_LIBNIO_MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libnio/mapfile-$(OPENJDK_TARGET_OS)
BUILD_LIBNIO_EXFILES += \
- GnomeFileTypeDetector.c \
+ GioFileTypeDetector.c \
#
endif
--- a/jdk/make/mapfiles/libnio/mapfile-linux Fri Aug 28 07:55:45 2015 -0700
+++ b/jdk/make/mapfiles/libnio/mapfile-linux Fri Aug 28 10:46:43 2015 -0700
@@ -135,8 +135,8 @@
Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_accept0;
Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs;
Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect;
- Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio;
- Java_sun_nio_fs_GnomeFileTypeDetector_probeGio;
+ Java_sun_nio_fs_GioFileTypeDetector_initializeGio;
+ Java_sun_nio_fs_GioFileTypeDetector_probeGio;
Java_sun_nio_fs_MagicFileTypeDetector_initialize0;
Java_sun_nio_fs_MagicFileTypeDetector_probe0;
Java_sun_nio_fs_LinuxWatchService_eventSize;
--- a/jdk/make/mapfiles/libnio/mapfile-solaris Fri Aug 28 07:55:45 2015 -0700
+++ b/jdk/make/mapfiles/libnio/mapfile-solaris Fri Aug 28 10:46:43 2015 -0700
@@ -130,8 +130,8 @@
Java_sun_nio_ch_SolarisEventPort_port_1get;
Java_sun_nio_ch_SolarisEventPort_port_1getn;
Java_sun_nio_ch_SolarisEventPort_port_1send;
- Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio;
- Java_sun_nio_fs_GnomeFileTypeDetector_probeGio;
+ Java_sun_nio_fs_GioFileTypeDetector_initializeGio;
+ Java_sun_nio_fs_GioFileTypeDetector_probeGio;
Java_sun_nio_fs_UnixNativeDispatcher_init;
Java_sun_nio_fs_UnixNativeDispatcher_getcwd;
Java_sun_nio_fs_UnixNativeDispatcher_strerror;
--- a/jdk/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java Fri Aug 28 07:55:45 2015 -0700
+++ b/jdk/src/java.base/linux/classes/sun/nio/fs/LinuxFileSystemProvider.java Fri Aug 28 10:46:43 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -106,7 +106,7 @@
new GetPropertyAction("user.home")), ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types");
- return chain(new GnomeFileTypeDetector(),
+ return chain(new GioFileTypeDetector(),
new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes),
new MagicFileTypeDetector());
--- a/jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java Fri Aug 28 07:55:45 2015 -0700
+++ b/jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java Fri Aug 28 10:46:43 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -89,7 +89,7 @@
new GetPropertyAction("user.home")), ".mime.types");
Path etcMimeTypes = Paths.get("/etc/mime.types");
- return chain(new GnomeFileTypeDetector(),
+ return chain(new GioFileTypeDetector(),
new MimeTypesFileTypeDetector(userMimeTypes),
new MimeTypesFileTypeDetector(etcMimeTypes));
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/unix/classes/sun/nio/fs/GioFileTypeDetector.java Fri Aug 28 10:46:43 2015 -0700
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.nio.fs;
+
+import java.nio.file.Path;
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * File type detector that uses the GNOME I/O library to guess the
+ * MIME type of a file.
+ */
+
+public class GioFileTypeDetector
+ extends AbstractFileTypeDetector
+{
+ // true if GIO is available
+ private final boolean gioAvailable;
+
+ public GioFileTypeDetector() {
+ gioAvailable = initializeGio();
+ }
+
+ @Override
+ public String implProbeContentType(Path obj) throws IOException {
+ if (!gioAvailable)
+ return null;
+ if (!(obj instanceof UnixPath))
+ return null;
+
+ UnixPath path = (UnixPath)obj;
+ NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
+ try {
+ // GIO may access file so need permission check
+ path.checkRead();
+ byte[] type = probeGio(buffer.address());
+ return (type == null) ? null : Util.toString(type);
+ } finally {
+ buffer.release();
+ }
+
+ }
+
+ // GIO
+ private static native boolean initializeGio();
+ //
+ // The probeGIO() method is synchronized to avert potential problems
+ // such as crashes due to a suspected lack of thread safety in GIO.
+ //
+ private static synchronized native byte[] probeGio(long pathAddress);
+
+ static {
+ AccessController.doPrivileged(new PrivilegedAction<>() {
+ public Void run() {
+ System.loadLibrary("nio");
+ return null;
+ }});
+ }
+}
--- a/jdk/src/java.base/unix/classes/sun/nio/fs/GnomeFileTypeDetector.java Fri Aug 28 07:55:45 2015 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.nio.fs;
-
-import java.nio.file.Path;
-import java.io.IOException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * File type detector that uses the GNOME I/O library to guess the
- * MIME type of a file.
- */
-
-public class GnomeFileTypeDetector
- extends AbstractFileTypeDetector
-{
- // true if GIO is available
- private final boolean gioAvailable;
-
- public GnomeFileTypeDetector() {
- gioAvailable = initializeGio();
- }
-
- @Override
- public String implProbeContentType(Path obj) throws IOException {
- if (!gioAvailable)
- return null;
- if (!(obj instanceof UnixPath))
- return null;
-
- UnixPath path = (UnixPath)obj;
- NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
- try {
- // GIO may access file so need permission check
- path.checkRead();
- byte[] type = probeGio(buffer.address());
- return (type == null) ? null : Util.toString(type);
- } finally {
- buffer.release();
- }
-
- }
-
- // GIO
- private static native boolean initializeGio();
- private static synchronized native byte[] probeGio(long pathAddress);
-
- static {
- AccessController.doPrivileged(new PrivilegedAction<>() {
- public Void run() {
- System.loadLibrary("nio");
- return null;
- }});
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/unix/native/libnio/fs/GioFileTypeDetector.c Fri Aug 28 10:46:43 2015 -0700
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "jni.h"
+#include "jni_util.h"
+#include "jvm.h"
+#include "jlong.h"
+
+#include <stdlib.h>
+#include <dlfcn.h>
+
+#ifdef __solaris__
+#include <strings.h>
+#endif
+
+#if defined(__linux__)
+#include <string.h>
+#endif
+
+/*
+ * For reference see for example the GFileInfo section at
+ * https://developer.gnome.org/gio/unstable/.
+ */
+
+/* Definitions for GIO */
+
+#define G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "standard::content-type"
+
+typedef void* gpointer;
+typedef struct _GFile GFile;
+typedef struct _GFileInfo GFileInfo;
+typedef struct _GCancellable GCancellable;
+typedef struct _GError GError;
+
+typedef enum {
+ G_FILE_QUERY_INFO_NONE = 0
+} GFileQueryInfoFlags;
+
+typedef void (*g_type_init_func)(void);
+typedef void (*g_object_unref_func)(gpointer object);
+typedef GFile* (*g_file_new_for_path_func)(const char* path);
+typedef GFileInfo* (*g_file_query_info_func)(GFile *file,
+ const char *attributes, GFileQueryInfoFlags flags,
+ GCancellable *cancellable, GError **error);
+typedef char* (*g_file_info_get_content_type_func)(GFileInfo *info);
+
+static g_type_init_func g_type_init;
+static g_object_unref_func g_object_unref;
+static g_file_new_for_path_func g_file_new_for_path;
+static g_file_query_info_func g_file_query_info;
+static g_file_info_get_content_type_func g_file_info_get_content_type;
+
+
+#include "sun_nio_fs_GioFileTypeDetector.h"
+
+
+JNIEXPORT jboolean JNICALL
+Java_sun_nio_fs_GioFileTypeDetector_initializeGio
+ (JNIEnv* env, jclass this)
+{
+ void* gio_handle;
+
+ gio_handle = dlopen("libgio-2.0.so", RTLD_LAZY);
+ if (gio_handle == NULL) {
+ gio_handle = dlopen("libgio-2.0.so.0", RTLD_LAZY);
+ if (gio_handle == NULL) {
+ return JNI_FALSE;
+ }
+ }
+
+ g_type_init = (g_type_init_func)dlsym(gio_handle, "g_type_init");
+ (*g_type_init)();
+
+ g_object_unref = (g_object_unref_func)dlsym(gio_handle, "g_object_unref");
+
+ g_file_new_for_path =
+ (g_file_new_for_path_func)dlsym(gio_handle, "g_file_new_for_path");
+
+ g_file_query_info =
+ (g_file_query_info_func)dlsym(gio_handle, "g_file_query_info");
+
+ g_file_info_get_content_type = (g_file_info_get_content_type_func)
+ dlsym(gio_handle, "g_file_info_get_content_type");
+
+
+ if (g_type_init == NULL ||
+ g_object_unref == NULL ||
+ g_file_new_for_path == NULL ||
+ g_file_query_info == NULL ||
+ g_file_info_get_content_type == NULL)
+ {
+ dlclose(gio_handle);
+ return JNI_FALSE;
+ }
+
+ (*g_type_init)();
+ return JNI_TRUE;
+}
+
+JNIEXPORT jbyteArray JNICALL
+Java_sun_nio_fs_GioFileTypeDetector_probeGio
+ (JNIEnv* env, jclass this, jlong pathAddress)
+{
+ char* path = (char*)jlong_to_ptr(pathAddress);
+ GFile* gfile;
+ GFileInfo* gfileinfo;
+ jbyteArray result = NULL;
+
+ gfile = (*g_file_new_for_path)(path);
+ gfileinfo = (*g_file_query_info)(gfile, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ if (gfileinfo != NULL) {
+ const char* mime = (*g_file_info_get_content_type)(gfileinfo);
+ if (mime != NULL) {
+ jsize len = strlen(mime);
+ result = (*env)->NewByteArray(env, len);
+ if (result != NULL) {
+ (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)mime);
+ }
+ }
+ (*g_object_unref)(gfileinfo);
+ }
+ (*g_object_unref)(gfile);
+
+ return result;
+}
--- a/jdk/src/java.base/unix/native/libnio/fs/GnomeFileTypeDetector.c Fri Aug 28 07:55:45 2015 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include "jni.h"
-#include "jni_util.h"
-#include "jvm.h"
-#include "jlong.h"
-
-#include <stdlib.h>
-#include <dlfcn.h>
-
-#ifdef __solaris__
-#include <strings.h>
-#endif
-
-#if defined(__linux__)
-#include <string.h>
-#endif
-
-/*
- * For reference see for example the GFileInfo section at
- * https://developer.gnome.org/gio/unstable/.
- */
-
-/* Definitions for GIO */
-
-#define G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "standard::content-type"
-
-typedef void* gpointer;
-typedef struct _GFile GFile;
-typedef struct _GFileInfo GFileInfo;
-typedef struct _GCancellable GCancellable;
-typedef struct _GError GError;
-
-typedef enum {
- G_FILE_QUERY_INFO_NONE = 0
-} GFileQueryInfoFlags;
-
-typedef void (*g_type_init_func)(void);
-typedef void (*g_object_unref_func)(gpointer object);
-typedef GFile* (*g_file_new_for_path_func)(const char* path);
-typedef GFileInfo* (*g_file_query_info_func)(GFile *file,
- const char *attributes, GFileQueryInfoFlags flags,
- GCancellable *cancellable, GError **error);
-typedef char* (*g_file_info_get_content_type_func)(GFileInfo *info);
-
-static g_type_init_func g_type_init;
-static g_object_unref_func g_object_unref;
-static g_file_new_for_path_func g_file_new_for_path;
-static g_file_query_info_func g_file_query_info;
-static g_file_info_get_content_type_func g_file_info_get_content_type;
-
-
-#include "sun_nio_fs_GnomeFileTypeDetector.h"
-
-
-JNIEXPORT jboolean JNICALL
-Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio
- (JNIEnv* env, jclass this)
-{
- void* gio_handle;
-
- gio_handle = dlopen("libgio-2.0.so", RTLD_LAZY);
- if (gio_handle == NULL) {
- gio_handle = dlopen("libgio-2.0.so.0", RTLD_LAZY);
- if (gio_handle == NULL) {
- return JNI_FALSE;
- }
- }
-
- g_type_init = (g_type_init_func)dlsym(gio_handle, "g_type_init");
- (*g_type_init)();
-
- g_object_unref = (g_object_unref_func)dlsym(gio_handle, "g_object_unref");
-
- g_file_new_for_path =
- (g_file_new_for_path_func)dlsym(gio_handle, "g_file_new_for_path");
-
- g_file_query_info =
- (g_file_query_info_func)dlsym(gio_handle, "g_file_query_info");
-
- g_file_info_get_content_type = (g_file_info_get_content_type_func)
- dlsym(gio_handle, "g_file_info_get_content_type");
-
-
- if (g_type_init == NULL ||
- g_object_unref == NULL ||
- g_file_new_for_path == NULL ||
- g_file_query_info == NULL ||
- g_file_info_get_content_type == NULL)
- {
- dlclose(gio_handle);
- return JNI_FALSE;
- }
-
- (*g_type_init)();
- return JNI_TRUE;
-}
-
-JNIEXPORT jbyteArray JNICALL
-Java_sun_nio_fs_GnomeFileTypeDetector_probeGio
- (JNIEnv* env, jclass this, jlong pathAddress)
-{
- char* path = (char*)jlong_to_ptr(pathAddress);
- GFile* gfile;
- GFileInfo* gfileinfo;
- jbyteArray result = NULL;
-
- gfile = (*g_file_new_for_path)(path);
- gfileinfo = (*g_file_query_info)(gfile, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- G_FILE_QUERY_INFO_NONE, NULL, NULL);
- if (gfileinfo != NULL) {
- const char* mime = (*g_file_info_get_content_type)(gfileinfo);
- if (mime != NULL) {
- jsize len = strlen(mime);
- result = (*env)->NewByteArray(env, len);
- if (result != NULL) {
- (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)mime);
- }
- }
- (*g_object_unref)(gfileinfo);
- }
- (*g_object_unref)(gfile);
-
- return result;
-}
--- a/jdk/test/java/nio/file/Files/probeContentType/ParallelProbes.java Fri Aug 28 07:55:45 2015 -0700
+++ b/jdk/test/java/nio/file/Files/probeContentType/ParallelProbes.java Fri Aug 28 10:46:43 2015 -0700
@@ -21,17 +21,18 @@
* questions.
*/
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-
/* @test
* @summary Test probing content type simultaneously from multiple threads.
* @requires (os.family == "linux") | (os.family == "solaris")
* @build ParallelProbes SimpleFileTypeDetector
* @run main/othervm ParallelProbes 10
*/
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+
public class ParallelProbes {
private static final int REPEATS = 1000;