# HG changeset patch # User andrew # Date 1313488347 -3600 # Node ID 8317cb1976d6339f0c05933425742d277b15bdf8 # Parent 49d52dd99f97e94a9b66539e891bc7a7ccb61568 Support building using system GIO (USE_SYSTEM_GIO, GIO_CFLAGS, GIO_LIBS) diff -r 49d52dd99f97 -r 8317cb1976d6 make/java/nio/Makefile --- a/make/java/nio/Makefile Mon Aug 15 15:53:02 2011 +0100 +++ b/make/java/nio/Makefile Tue Aug 16 10:52:27 2011 +0100 @@ -241,6 +241,11 @@ UnixCopyFile.c \ UnixNativeDispatcher.c +ifndef USE_SYSTEM_GIO +FILES_c += \ + gio_fp.c +endif + FILES_export += \ sun/nio/ch/EPoll.java \ sun/nio/ch/EPollArrayWrapper.java \ @@ -255,7 +260,7 @@ sun/nio/fs/LinuxWatchService.java \ sun/nio/fs/UnixCopyFile.java \ sun/nio/fs/UnixNativeDispatcher.java - + FILES_gen += \ sun/nio/fs/UnixConstants.java endif # PLATFORM = linux @@ -267,6 +272,10 @@ vpath %.c $(PLATFORM_SRC)/native/sun/nio/ch vpath %.c $(SHARE_SRC)/native/sun/nio/ch +ifndef USE_SYSTEM_GIO + vpath %.c $(PLATFORM_SRC)/native/sun/nio/fs/glib2 +endif + # # Various variables # @@ -291,9 +300,17 @@ $(OBJDIR)/../../../java.lang/java/$(OBJDIRNAME)/io_util.obj \ $(OBJDIR)/../../../java.lang/java/$(OBJDIRNAME)/FileDescriptor_md.obj endif + ifeq ($(PLATFORM), linux) OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -lnet -lpthread -ldl +ifdef USE_SYSTEM_GIO + OTHER_LDLIBS += $(GIO_LIBS) + OTHER_INCLUDES += $(GIO_CFLAGS) -DUSE_SYSTEM_GIO +else + OTHER_INCLUDES += -I$(PLATFORM_SRC)/native/sun/nio/fs/glib2 endif +endif + ifeq ($(PLATFORM), solaris) OTHER_LDLIBS += $(JVMLIB) $(LIBSOCKET) -lposix4 -ldl -lsendfile \ -L$(LIBDIR)/$(LIBARCH) -ljava -lnet diff -r 49d52dd99f97 -r 8317cb1976d6 src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c --- a/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c Mon Aug 15 15:53:02 2011 +0100 +++ b/src/solaris/native/sun/nio/fs/GnomeFileTypeDetector.c Tue Aug 16 10:52:27 2011 +0100 @@ -29,7 +29,6 @@ #include "jlong.h" #include -#include #include #ifdef __solaris__ @@ -40,34 +39,11 @@ #include #endif -/* 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; +#include -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; - +#ifndef USE_SYSTEM_GIO +#include +#endif /* Definitions for GNOME VFS */ @@ -80,51 +56,22 @@ static gnome_vfs_init_function gnome_vfs_init; static gnome_vfs_mime_type_from_name_function gnome_vfs_mime_type_from_name; - #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"); + jboolean ret; - 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"); - +#ifdef USE_SYSTEM_GIO + ret = JNI_TRUE; +#else + ret = init(); +#endif - 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; + g_type_init (); + return ret; } JNIEXPORT jbyteArray JNICALL @@ -136,11 +83,11 @@ GFileInfo* gfileinfo; jbyteArray result = NULL; - gfile = (*g_file_new_for_path)(path); - gfileinfo = (*g_file_query_info)(gfile, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + 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); + const char* mime = g_file_info_get_content_type (gfileinfo); if (mime != NULL) { jsize len = strlen(mime); result = (*env)->NewByteArray(env, len); @@ -148,9 +95,9 @@ (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)mime); } } - (*g_object_unref)(gfileinfo); + g_object_unref (gfileinfo); } - (*g_object_unref)(gfile); + g_object_unref (gfile); return result; } diff -r 49d52dd99f97 -r 8317cb1976d6 src/solaris/native/sun/nio/fs/glib2/gio/gio.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/solaris/native/sun/nio/fs/glib2/gio/gio.h Tue Aug 16 10:52:27 2011 +0100 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2008, 2009, 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. + */ + +/* Definitions for GIO */ + +#ifndef __GIO_H__ +#define __GIO_H__ + +#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 (*type_init_func)(void); +typedef void (*object_unref_func)(gpointer object); +typedef GFile* (*file_new_for_path_func)(const char* path); +typedef GFileInfo* (*file_query_info_func)(GFile *file, + const char *attributes, GFileQueryInfoFlags flags, + GCancellable *cancellable, GError **error); +typedef char* (*file_info_get_content_type_func)(GFileInfo *info); + +#endif diff -r 49d52dd99f97 -r 8317cb1976d6 src/solaris/native/sun/nio/fs/glib2/gio_fp.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/solaris/native/sun/nio/fs/glib2/gio_fp.c Tue Aug 16 10:52:27 2011 +0100 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008, 2009, 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 +#include + +#include "gio_fp.h" + +type_init_func type_init; +object_unref_func object_unref; +file_new_for_path_func file_new_for_path; +file_query_info_func file_query_info; +file_info_get_content_type_func file_info_get_content_type; + +jboolean init() +{ + 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; + } + } + + type_init = (type_init_func)dlsym(gio_handle, "g_type_init"); + (*g_type_init)(); + + object_unref = (object_unref_func)dlsym(gio_handle, "g_object_unref"); + + file_new_for_path = + (file_new_for_path_func)dlsym(gio_handle, "g_file_new_for_path"); + + file_query_info = + (file_query_info_func)dlsym(gio_handle, "g_file_query_info"); + + file_info_get_content_type = (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; + } + + return JNI_TRUE; +} diff -r 49d52dd99f97 -r 8317cb1976d6 src/solaris/native/sun/nio/fs/glib2/gio_fp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/solaris/native/sun/nio/fs/glib2/gio_fp.h Tue Aug 16 10:52:27 2011 +0100 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2008, 2009, 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. + */ + +#ifndef __GIO_FP_H__ +#define __GIO_FP_H__ + +#include + +extern type_init_func type_init; +extern object_unref_func object_unref; +extern file_new_for_path_func file_new_for_path; +extern file_query_info_func file_query_info; +extern file_info_get_content_type_func file_info_get_content_type; + +#define g_type_init (*type_init) +#define g_object_unref (*object_unref) +#define g_file_new_for_path (*file_new_for_path) +#define g_file_query_info (*file_query_info) +#define g_file_info_get_content_type (*file_info_get_content_type) + +jboolean init(); + +#endif