diff --git a/jdk/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java b/jdk/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java index 47dbc156250..1e93b3203e5 100644 --- a/jdk/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java +++ b/jdk/src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -232,9 +232,11 @@ class LinuxWatchService for (WatchEvent.Modifier modifier: modifiers) { if (modifier == null) return new NullPointerException(); - if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) - continue; // ignore - return new UnsupportedOperationException("Modifier not supported"); + if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) && + !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) && + !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) { + return new UnsupportedOperationException("Modifier not supported"); + } } } diff --git a/jdk/src/java.base/share/classes/module-info.java b/jdk/src/java.base/share/classes/module-info.java index d21c881ee30..67220c9474f 100644 --- a/jdk/src/java.base/share/classes/module-info.java +++ b/jdk/src/java.base/share/classes/module-info.java @@ -216,6 +216,8 @@ module java.base { exports sun.nio.cs to java.desktop, jdk.charsets; + exports sun.nio.fs to + jdk.unsupported; exports sun.reflect.annotation to jdk.compiler; exports sun.reflect.generics.reflectiveObjects to diff --git a/jdk/src/java.base/share/classes/sun/nio/fs/ExtendedOptions.java b/jdk/src/java.base/share/classes/sun/nio/fs/ExtendedOptions.java new file mode 100644 index 00000000000..71ebffc8320 --- /dev/null +++ b/jdk/src/java.base/share/classes/sun/nio/fs/ExtendedOptions.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2016, 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.CopyOption; +import java.nio.file.OpenOption; +import java.nio.file.WatchEvent; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Provides support for handling JDK-specific OpenOption, CopyOption and + * WatchEvent.Modifier types. + */ + +public final class ExtendedOptions { + + // maps InternalOption to ExternalOption + private static final Map, Wrapper> internalToExternal + = new ConcurrentHashMap<>(); + + /** + * Wraps an option or modifier. + */ + private static final class Wrapper { + private final Object option; + private final T param; + + Wrapper(Object option, T param) { + this.option = option; + this.param = param; + } + + T parameter() { + return param; + } + } + + /** + * The internal version of a JDK-specific OpenOption, CopyOption or + * WatchEvent.Modifier. + */ + public static final class InternalOption { + + InternalOption() { } + + private void registerInternal(Object option, T param) { + Wrapper wrapper = new Wrapper(option, param); + internalToExternal.put(this, wrapper); + } + + /** + * Register this internal option as a OpenOption. + */ + public void register(OpenOption option) { + registerInternal(option, null); + } + + /** + * Register this internal option as a CopyOption. + */ + public void register(CopyOption option) { + registerInternal(option, null); + } + + /** + * Register this internal option as a WatchEvent.Modifier. + */ + public void register(WatchEvent.Modifier option) { + registerInternal(option, null); + } + + /** + * Register this internal option as a WatchEvent.Modifier with the + * given parameter. + */ + public void register(WatchEvent.Modifier option, T param) { + registerInternal(option, param); + } + + /** + * Returns true if the given option (or modifier) maps to this internal + * option. + */ + public boolean matches(Object option) { + Wrapper wrapper = internalToExternal.get(this); + if (wrapper == null) + return false; + else + return option == wrapper.option; + } + + /** + * Returns the parameter object associated with this internal option. + */ + @SuppressWarnings("unchecked") + public T parameter() { + Wrapper wrapper = internalToExternal.get(this); + if (wrapper == null) + return null; + else + return (T) wrapper.parameter(); + } + } + + // Internal equivalents of the options and modifiers defined in + // package com.sun.nio.file + + public static final InternalOption INTERRUPTIBLE = new InternalOption<>(); + + public static final InternalOption NOSHARE_READ = new InternalOption<>(); + public static final InternalOption NOSHARE_WRITE = new InternalOption<>(); + public static final InternalOption NOSHARE_DELETE = new InternalOption<>(); + + public static final InternalOption FILE_TREE = new InternalOption<>(); + + public static final InternalOption SENSITIVITY_HIGH = new InternalOption<>(); + public static final InternalOption SENSITIVITY_MEDIUM = new InternalOption<>(); + public static final InternalOption SENSITIVITY_LOW = new InternalOption<>(); +} diff --git a/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java b/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java index 536bfa7accf..13c365894c4 100644 --- a/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java +++ b/jdk/src/java.base/share/classes/sun/nio/fs/PollingWatchService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -25,16 +25,32 @@ package sun.nio.fs; -import java.nio.file.*; -import java.nio.file.attribute.*; +import java.nio.file.ClosedWatchServiceException; +import java.nio.file.DirectoryIteratorException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.NotDirectoryException; +import java.nio.file.Path; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +import java.nio.file.attribute.BasicFileAttributes; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; import java.io.IOException; -import java.util.*; -import java.util.concurrent.*; -import com.sun.nio.file.SensitivityWatchEventModifier; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; /** * Simple WatchService implementation that uses periodic tasks to poll @@ -46,8 +62,7 @@ class PollingWatchService extends AbstractWatchService { // map of registrations - private final Map map = - new HashMap(); + private final Map map = new HashMap<>(); // used to execute the periodic tasks that poll for changes private final ScheduledExecutorService scheduledExecutor; @@ -58,7 +73,7 @@ class PollingWatchService .newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { - Thread t = new Thread(null, r, "FileSystemWatchService", 0, false); + Thread t = new Thread(null, r, "FileSystemWatcher", 0, false); t.setDaemon(true); return t; }}); @@ -74,8 +89,7 @@ class PollingWatchService throws IOException { // check events - CCE will be thrown if there are invalid elements - final Set> eventSet = - new HashSet>(events.length); + final Set> eventSet = new HashSet<>(events.length); for (WatchEvent.Kind event: events) { // standard events if (event == StandardWatchEventKinds.ENTRY_CREATE || @@ -99,17 +113,22 @@ class PollingWatchService if (eventSet.isEmpty()) throw new IllegalArgumentException("No events to register"); - // A modifier may be used to specify the sensitivity level - SensitivityWatchEventModifier sensivity = SensitivityWatchEventModifier.MEDIUM; + // Extended modifiers may be used to specify the sensitivity level + int sensitivity = 10; if (modifiers.length > 0) { for (WatchEvent.Modifier modifier: modifiers) { if (modifier == null) throw new NullPointerException(); - if (modifier instanceof SensitivityWatchEventModifier) { - sensivity = (SensitivityWatchEventModifier)modifier; - continue; + + if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) { + sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter(); + } else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) { + sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter(); + } else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) { + sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter(); + } else { + throw new UnsupportedOperationException("Modifier not supported"); } - throw new UnsupportedOperationException("Modifier not supported"); } } @@ -120,12 +139,12 @@ class PollingWatchService // registration is done in privileged block as it requires the // attributes of the entries in the directory. try { - final SensitivityWatchEventModifier s = sensivity; + int value = sensitivity; return AccessController.doPrivileged( new PrivilegedExceptionAction() { @Override public PollingWatchKey run() throws IOException { - return doPrivilegedRegister(path, eventSet, s); + return doPrivilegedRegister(path, eventSet, value); } }); } catch (PrivilegedActionException pae) { @@ -140,7 +159,7 @@ class PollingWatchService // existing key if already registered private PollingWatchKey doPrivilegedRegister(Path path, Set> events, - SensitivityWatchEventModifier sensivity) + int sensitivityInSeconds) throws IOException { // check file is a directory and get its file key if possible @@ -169,7 +188,7 @@ class PollingWatchService watchKey.disable(); } } - watchKey.enable(events, sensivity.sensitivityValueInSeconds()); + watchKey.enable(events, sensitivityInSeconds); return watchKey; } @@ -178,7 +197,7 @@ class PollingWatchService @Override void implClose() throws IOException { synchronized (map) { - for (Map.Entry entry: map.entrySet()) { + for (Map.Entry entry: map.entrySet()) { PollingWatchKey watchKey = entry.getValue(); watchKey.disable(); watchKey.invalidate(); diff --git a/jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisWatchService.java b/jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisWatchService.java index 7a31d13b3a6..cc077cb8b0f 100644 --- a/jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisWatchService.java +++ b/jdk/src/java.base/solaris/classes/sun/nio/fs/SolarisWatchService.java @@ -272,9 +272,11 @@ class SolarisWatchService for (WatchEvent.Modifier modifier: modifiers) { if (modifier == null) return new NullPointerException(); - if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) - continue; // ignore - return new UnsupportedOperationException("Modifier not supported"); + if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) && + !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) && + !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) { + return new UnsupportedOperationException("Modifier not supported"); + } } } diff --git a/jdk/src/java.base/unix/classes/sun/nio/fs/UnixCopyFile.java b/jdk/src/java.base/unix/classes/sun/nio/fs/UnixCopyFile.java index 7a31ab186a6..34fe5d24526 100644 --- a/jdk/src/java.base/unix/classes/sun/nio/fs/UnixCopyFile.java +++ b/jdk/src/java.base/unix/classes/sun/nio/fs/UnixCopyFile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -25,13 +25,18 @@ package sun.nio.fs; -import java.nio.file.*; import java.io.IOException; +import java.nio.file.AtomicMoveNotSupportedException; +import java.nio.file.CopyOption; +import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.LinkOption; +import java.nio.file.LinkPermission; +import java.nio.file.StandardCopyOption; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import com.sun.nio.file.ExtendedCopyOption; import static sun.nio.fs.UnixNativeDispatcher.*; import static sun.nio.fs.UnixConstants.*; @@ -82,7 +87,7 @@ class UnixCopyFile { flags.failIfUnableToCopyBasic = true; continue; } - if (option == ExtendedCopyOption.INTERRUPTIBLE) { + if (ExtendedOptions.INTERRUPTIBLE.matches(option)) { flags.interruptible = true; continue; } diff --git a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsChannelFactory.java b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsChannelFactory.java index 4a1139a2a73..7af7132bfee 100644 --- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsChannelFactory.java +++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsChannelFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -34,8 +34,6 @@ import java.nio.file.OpenOption; import java.nio.file.StandardOpenOption; import java.util.Set; -import com.sun.nio.file.ExtendedOpenOption; - import jdk.internal.misc.JavaIOFileDescriptorAccess; import jdk.internal.misc.SharedSecrets; import sun.nio.ch.FileChannelImpl; @@ -103,15 +101,6 @@ class WindowsChannelFactory { } continue; } - if (option instanceof ExtendedOpenOption) { - switch ((ExtendedOpenOption)option) { - case NOSHARE_READ : flags.shareRead = false; break; - case NOSHARE_WRITE : flags.shareWrite = false; break; - case NOSHARE_DELETE : flags.shareDelete = false; break; - default: throw new UnsupportedOperationException(); - } - continue; - } if (option == LinkOption.NOFOLLOW_LINKS) { flags.noFollowLinks = true; continue; @@ -120,6 +109,18 @@ class WindowsChannelFactory { flags.openReparsePoint = true; continue; } + if (ExtendedOptions.NOSHARE_READ.matches(option)) { + flags.shareRead = false; + continue; + } + if (ExtendedOptions.NOSHARE_WRITE.matches(option)) { + flags.shareWrite = false; + continue; + } + if (ExtendedOptions.NOSHARE_DELETE.matches(option)) { + flags.shareDelete = false; + continue; + } if (option == null) throw new NullPointerException(); throw new UnsupportedOperationException(); diff --git a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileCopy.java b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileCopy.java index 001f1ba5fb5..c96a699370f 100644 --- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileCopy.java +++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsFileCopy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -28,7 +28,6 @@ package sun.nio.fs; import java.nio.file.*; import java.io.IOException; import java.util.concurrent.ExecutionException; -import com.sun.nio.file.ExtendedCopyOption; import static sun.nio.fs.WindowsNativeDispatcher.*; import static sun.nio.fs.WindowsConstants.*; @@ -67,7 +66,7 @@ class WindowsFileCopy { copyAttributes = true; continue; } - if (option == ExtendedCopyOption.INTERRUPTIBLE) { + if (ExtendedOptions.INTERRUPTIBLE.matches(option)) { interruptible = true; continue; } diff --git a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java index 539bad62190..763f10e6929 100644 --- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java +++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -32,8 +32,6 @@ import java.net.URI; import java.util.*; import java.lang.ref.WeakReference; -import com.sun.nio.file.ExtendedWatchEventModifier; - import static sun.nio.fs.WindowsNativeDispatcher.*; import static sun.nio.fs.WindowsConstants.*; @@ -864,7 +862,7 @@ class WindowsPath implements Path { modifiers = Arrays.copyOf(modifiers, ml); int i=0; while (i < ml) { - if (modifiers[i++] == ExtendedWatchEventModifier.FILE_TREE) { + if (ExtendedOptions.FILE_TREE.matches(modifiers[i++])) { watchSubtree = true; break; } diff --git a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java index 00e68fb785b..d5b82285075 100644 --- a/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java +++ b/jdk/src/java.base/windows/classes/sun/nio/fs/WindowsWatchService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -35,7 +35,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import com.sun.nio.file.ExtendedWatchEventModifier; import jdk.internal.misc.Unsafe; import static sun.nio.fs.WindowsNativeDispatcher.*; @@ -342,14 +341,16 @@ class WindowsWatchService // FILE_TREE modifier allowed for (WatchEvent.Modifier modifier: modifiers) { - if (modifier == ExtendedWatchEventModifier.FILE_TREE) { + if (ExtendedOptions.FILE_TREE.matches(modifier)) { watchSubtree = true; } else { if (modifier == null) return new NullPointerException(); - if (modifier instanceof com.sun.nio.file.SensitivityWatchEventModifier) - continue; // ignore - return new UnsupportedOperationException("Modifier not supported"); + if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) && + !ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) && + !ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) { + return new UnsupportedOperationException("Modifier not supported"); + } } } diff --git a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedCopyOption.java b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedCopyOption.java similarity index 85% rename from jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedCopyOption.java rename to jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedCopyOption.java index 5c49d16151b..56b6dc36bf7 100644 --- a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedCopyOption.java +++ b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedCopyOption.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2016, 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 @@ -26,6 +26,7 @@ package com.sun.nio.file; import java.nio.file.CopyOption; +import sun.nio.fs.ExtendedOptions; /** * Defines extended copy options supported on some platforms @@ -39,5 +40,9 @@ public enum ExtendedCopyOption implements CopyOption { * The copy may be interrupted by the {@link Thread#interrupt interrupt} * method. */ - INTERRUPTIBLE, + INTERRUPTIBLE(ExtendedOptions.INTERRUPTIBLE); + + ExtendedCopyOption(ExtendedOptions.InternalOption option) { + option.register(this); + } } diff --git a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedOpenOption.java b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedOpenOption.java similarity index 82% rename from jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedOpenOption.java rename to jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedOpenOption.java index 28cef93d8bf..74e7ad185b2 100644 --- a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedOpenOption.java +++ b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedOpenOption.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2016, 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 @@ -26,6 +26,7 @@ package com.sun.nio.file; import java.nio.file.OpenOption; +import sun.nio.fs.ExtendedOptions; /** * Defines extended open options supported on some platforms @@ -38,13 +39,17 @@ public enum ExtendedOpenOption implements OpenOption { /** * Prevent operations on the file that request read access. */ - NOSHARE_READ, + NOSHARE_READ(ExtendedOptions.NOSHARE_READ), /** * Prevent operations on the file that request write access. */ - NOSHARE_WRITE, + NOSHARE_WRITE(ExtendedOptions.NOSHARE_WRITE), /** * Prevent operations on the file that request delete access. */ - NOSHARE_DELETE; + NOSHARE_DELETE(ExtendedOptions.NOSHARE_DELETE); + + ExtendedOpenOption(ExtendedOptions.InternalOption option) { + option.register(this); + } } diff --git a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java similarity index 85% rename from jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java rename to jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java index 805386dd1ce..e810ba0a2d7 100644 --- a/jdk/src/java.base/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java +++ b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/ExtendedWatchEventModifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2016, 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 @@ -26,6 +26,7 @@ package com.sun.nio.file; import java.nio.file.WatchEvent.Modifier; +import sun.nio.fs.ExtendedOptions; /** * Defines extended watch event modifiers supported on some platforms @@ -39,5 +40,9 @@ public enum ExtendedWatchEventModifier implements Modifier { /** * Register a file tree instead of a single directory. */ - FILE_TREE, + FILE_TREE(ExtendedOptions.FILE_TREE); + + ExtendedWatchEventModifier(ExtendedOptions.InternalOption option) { + option.register(this); + } } diff --git a/jdk/src/java.base/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java similarity index 80% rename from jdk/src/java.base/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java rename to jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java index cc5066697a8..e7561d90d25 100644 --- a/jdk/src/java.base/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java +++ b/jdk/src/jdk.unsupported/share/classes/com/sun/nio/file/SensitivityWatchEventModifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2016, 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 @@ -26,6 +26,7 @@ package com.sun.nio.file; import java.nio.file.WatchEvent.Modifier; +import sun.nio.fs.ExtendedOptions; /** * Defines the sensitivity levels when registering objects with a @@ -38,15 +39,15 @@ public enum SensitivityWatchEventModifier implements Modifier { /** * High sensitivity. */ - HIGH(2), + HIGH(ExtendedOptions.SENSITIVITY_HIGH, 2), /** * Medium sensitivity. */ - MEDIUM(10), + MEDIUM(ExtendedOptions.SENSITIVITY_MEDIUM, 10), /** * Low sensitivity. */ - LOW(30); + LOW(ExtendedOptions.SENSITIVITY_LOW, 30); /** * Returns the sensitivity in seconds. @@ -56,7 +57,9 @@ public enum SensitivityWatchEventModifier implements Modifier { } private final int sensitivity; - private SensitivityWatchEventModifier(int sensitivity) { + private SensitivityWatchEventModifier(ExtendedOptions.InternalOption option, + int sensitivity) { this.sensitivity = sensitivity; + option.register(this, sensitivity); } } diff --git a/jdk/src/jdk.unsupported/share/classes/module-info.java b/jdk/src/jdk.unsupported/share/classes/module-info.java index a13d3428022..5ad248766ae 100644 --- a/jdk/src/jdk.unsupported/share/classes/module-info.java +++ b/jdk/src/jdk.unsupported/share/classes/module-info.java @@ -26,5 +26,6 @@ module jdk.unsupported { exports sun.misc; exports sun.reflect; + exports com.sun.nio.file; } diff --git a/jdk/test/java/nio/file/Files/InterruptCopy.java b/jdk/test/java/nio/file/Files/InterruptCopy.java index 34ffa0585e8..05bdb4d37c1 100644 --- a/jdk/test/java/nio/file/Files/InterruptCopy.java +++ b/jdk/test/java/nio/file/Files/InterruptCopy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -24,7 +24,7 @@ /* @test * @bug 4313887 6993267 * @summary Unit test for Sun-specific ExtendedCopyOption.INTERRUPTIBLE option - * @modules java.base/com.sun.nio.file + * @modules jdk.unsupported * @library .. */ diff --git a/jdk/test/java/nio/file/Files/SBC.java b/jdk/test/java/nio/file/Files/SBC.java index 584a370f658..8f470b8d9ed 100644 --- a/jdk/test/java/nio/file/Files/SBC.java +++ b/jdk/test/java/nio/file/Files/SBC.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -25,7 +25,7 @@ * @bug 4313887 * @summary Unit test for java.nio.file.Files.newByteChannel * @library .. - * @modules java.base/com.sun.nio.file + * @modules jdk.unsupported */ import java.nio.ByteBuffer; diff --git a/jdk/test/java/nio/file/WatchService/FileTreeModifier.java b/jdk/test/java/nio/file/WatchService/FileTreeModifier.java index ff26a5f5f1e..1648df003a6 100644 --- a/jdk/test/java/nio/file/WatchService/FileTreeModifier.java +++ b/jdk/test/java/nio/file/WatchService/FileTreeModifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -23,9 +23,9 @@ /* @test * @bug 4313887 6838333 - * @summary Sanity test for Sun-specific FILE_TREE watch event modifier + * @summary Sanity test for JDK-specific FILE_TREE watch event modifier * @library .. - * @modules java.base/com.sun.nio.file + * @modules jdk.unsupported */ import java.nio.file.*; diff --git a/jdk/test/java/nio/file/WatchService/SensitivityModifier.java b/jdk/test/java/nio/file/WatchService/SensitivityModifier.java index 6a9f30e8629..f01704a9ba8 100644 --- a/jdk/test/java/nio/file/WatchService/SensitivityModifier.java +++ b/jdk/test/java/nio/file/WatchService/SensitivityModifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -23,8 +23,8 @@ /* @test * @bug 4313887 - * @summary Sanity test for Sun-specific sensitivity level watch event modifier - * @modules java.base/com.sun.nio.file + * @summary Sanity test for JDK-specific sensitivity level watch event modifier + * @modules jdk.unsupported * @library .. * @run main/timeout=240 SensitivityModifier * @key randomness diff --git a/jdk/test/java/nio/file/WatchService/WithSecurityManager.java b/jdk/test/java/nio/file/WatchService/WithSecurityManager.java index 997144d49a3..e165da54fb4 100644 --- a/jdk/test/java/nio/file/WatchService/WithSecurityManager.java +++ b/jdk/test/java/nio/file/WatchService/WithSecurityManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2016, 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 @@ -24,7 +24,7 @@ /* @test * @bug 4313887 * @summary Unit test for Watchable#register's permission checks - * @modules java.base/com.sun.nio.file + * @modules jdk.unsupported * @build WithSecurityManager * @run main/othervm WithSecurityManager denyAll.policy - fail * @run main/othervm WithSecurityManager denyAll.policy tree fail