diff options
author | Chris McGee | 2012-05-22 20:12:15 +0000 |
---|---|---|
committer | Szymon Brandys | 2012-05-22 20:12:15 +0000 |
commit | 01fff881f9bedd43e7f7c0b2ca6cbcce1abf141a (patch) | |
tree | 397bdbc4e8bfb9b570db6f42affac26a4244b721 | |
parent | 883cadb5ae814fd0799d5e488dc1d58bbe38a5b6 (diff) | |
download | eclipse.platform.resources-01fff881f9bedd43e7f7c0b2ca6cbcce1abf141a.tar.gz eclipse.platform.resources-01fff881f9bedd43e7f7c0b2ca6cbcce1abf141a.tar.xz eclipse.platform.resources-01fff881f9bedd43e7f7c0b2ca6cbcce1abf141a.zip |
bug 375433 - Provide Java 7 NIO2 hooks into eclipse filesystem as av20120522-2012
fallback for cases where there is no native support
4 files changed, 141 insertions, 12 deletions
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileHandler.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileHandler.java new file mode 100644 index 000000000..db601e430 --- /dev/null +++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileHandler.java @@ -0,0 +1,32 @@ +/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.filesystem.local;
+
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.provider.FileInfo;
+
+/**
+ * Native handler that delegates to the LocalFileNatives.
+ */
+public class LocalFileHandler extends NativeHandler {
+
+ public int getSupportedAttributes() {
+ return LocalFileNatives.attributes();
+ }
+
+ public FileInfo fetchFileInfo(String fileName) {
+ return LocalFileNatives.fetchFileInfo(fileName);
+ }
+
+ public boolean putFileInfo(String fileName, IFileInfo info, int options) {
+ return LocalFileNatives.putFileInfo(fileName, info, options);
+ }
+}
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileNativesManager.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileNativesManager.java index aa26a2b12..b0fe41017 100644 --- a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileNativesManager.java +++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileNativesManager.java @@ -12,34 +12,73 @@ package org.eclipse.core.internal.filesystem.local; import org.eclipse.core.filesystem.IFileInfo; import org.eclipse.core.filesystem.provider.FileInfo; +import org.eclipse.core.internal.filesystem.local.unix.UnixFileHandler; import org.eclipse.core.internal.filesystem.local.unix.UnixFileNatives; /** * Dispatches methods backed by native code to the appropriate platform specific - * implementation depending on a library provided by a fragment. + * implementation depending on a library provided by a fragment. Failing this it tries + * to use Java 7 NIO/2 API's (if they are available). */ public class LocalFileNativesManager { + private static final NativeHandler DEFAULT = new NativeHandler() { + public boolean putFileInfo(String fileName, IFileInfo info, int options) { + return false; + } + + public int getSupportedAttributes() { + return 0; + } + + public FileInfo fetchFileInfo(String fileName) { + return new FileInfo(); + } + }; + + private static NativeHandler DELEGATE = DEFAULT; + + static { + if (UnixFileNatives.isUsingNatives()) { + DELEGATE = new UnixFileHandler(); + } else if (LocalFileNatives.isUsingNatives()) { + DELEGATE = new LocalFileHandler(); + } else { + try { + Class c = LocalFileNativesManager.class.getClassLoader().loadClass("org.eclipse.core.internal.filesystem.jdk7.Java7Handler"); //$NON-NLS-1$ + + DELEGATE = (NativeHandler) c.newInstance(); + } catch (ClassNotFoundException e) { + // Class was missing? + // Leave the delegate as default + } catch (LinkageError e) { + // Maybe the bundle was somehow loaded, the class was there but the bytecodes were the wrong version? + // Leave the delegate as default + } catch (IllegalAccessException e) { + // We could not instantiate the object because we have no access + // Leave delegate as default + } catch (InstantiationException e) { + // We could not instantiate the object because of something unexpected + // Leave delegate as default + } catch (ClassCastException e) { + // The handler does not inherit from the correct class + // Leave delegate as default + } + } + } public static int getSupportedAttributes() { - if (UnixFileNatives.isUsingNatives()) - return UnixFileNatives.getSupportedAttributes(); - return LocalFileNatives.attributes(); + return DELEGATE.getSupportedAttributes(); } public static FileInfo fetchFileInfo(String fileName) { - if (UnixFileNatives.isUsingNatives()) - return UnixFileNatives.fetchFileInfo(fileName); - return LocalFileNatives.fetchFileInfo(fileName); + return DELEGATE.fetchFileInfo(fileName); } public static boolean putFileInfo(String fileName, IFileInfo info, int options) { - if (UnixFileNatives.isUsingNatives()) - return UnixFileNatives.putFileInfo(fileName, info, options); - return LocalFileNatives.putFileInfo(fileName, info, options); + return DELEGATE.putFileInfo(fileName, info, options); } public static boolean isUsingNatives() { - return UnixFileNatives.isUsingNatives() || LocalFileNatives.isUsingNatives(); + return DELEGATE != DEFAULT; } - } diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/NativeHandler.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/NativeHandler.java new file mode 100644 index 000000000..e5db794f6 --- /dev/null +++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/NativeHandler.java @@ -0,0 +1,25 @@ +/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.filesystem.local;
+
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.provider.FileInfo;
+
+/**
+ * This delegate provides the interface for native file attribute support.
+ */
+public abstract class NativeHandler {
+ public abstract int getSupportedAttributes();
+
+ public abstract FileInfo fetchFileInfo(String fileName);
+
+ public abstract boolean putFileInfo(String fileName, IFileInfo info, int options);
+}
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileHandler.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileHandler.java new file mode 100644 index 000000000..a7b880270 --- /dev/null +++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileHandler.java @@ -0,0 +1,33 @@ +/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.filesystem.local.unix;
+
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.provider.FileInfo;
+import org.eclipse.core.internal.filesystem.local.NativeHandler;
+
+/**
+ * Native handler that delegates to UnixFileNatives
+ */
+public class UnixFileHandler extends NativeHandler {
+
+ public int getSupportedAttributes() {
+ return UnixFileNatives.getSupportedAttributes();
+ }
+
+ public FileInfo fetchFileInfo(String fileName) {
+ return UnixFileNatives.fetchFileInfo(fileName);
+ }
+
+ public boolean putFileInfo(String fileName, IFileInfo info, int options) {
+ return UnixFileNatives.putFileInfo(fileName, info, options);
+ }
+}
|