Repository: embulk/embulk
Issue: "embulk new" command not work in windows 

I have executed command in windows 10 x64

> E:\\work> embulk new java-file-output onefile

```
2018-07-18 10:41:05.724 +0900: Embulk v0.9.7
Creating embulk-output-onefile/
java.lang.UnsupportedOperationException
        at sun.nio.fs.WindowsFileSystemProvider.readAttributes(Unknown Source)
        at java.nio.file.Files.readAttributes(Unknown Source)
        at java.nio.file.Files.getPosixFilePermissions(Unknown Source)
        at org.embulk.cli.EmbulkNew.setExecutable(EmbulkNew.java:390)
        at org.embulk.cli.EmbulkNew.newPlugin(EmbulkNew.java:169)
        at org.embulk.cli.EmbulkRun.runSubcommand(EmbulkRun.java:338)
        at org.embulk.cli.EmbulkRun.run(EmbulkRun.java:91)
        at org.embulk.cli.Main.main(Main.java:26)
Failed. Removing the directory created.
```

I have executed same command in cent os6, then success. but not work in windows PC.
JDK version is 1.8.0_171.



Changed files:
embulk-core/src/main/java/org/embulk/cli/EmbulkMigrate.java
embulk-core/src/main/java/org/embulk/cli/EmbulkNew.java
embulk-core/src/main/java/org/embulk/cli/EmbulkSelfUpdate.java

diff --git a/embulk-core/src/main/java/org/embulk/cli/EmbulkMigrate.java b/embulk-core/src/main/java/org/embulk/cli/EmbulkMigrate.java
index 8064276d..8a5c152b 100644
--- a/embulk-core/src/main/java/org/embulk/cli/EmbulkMigrate.java
+++ b/embulk-core/src/main/java/org/embulk/cli/EmbulkMigrate.java
@@ -4,6 +4,7 @@ import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.FileSystem;
 import java.nio.file.FileSystems;
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
@@ -87,7 +88,7 @@ public class EmbulkMigrate {
         if (migrator.match("gradle/wrapper/gradle-wrapper.properties", GRADLE_VERSION_IN_WRAPPER)) {
             // gradle < 4.1
             migrator.copy("org/embulk/plugin/template/java/gradlew", "gradlew");
-            migrator.setExecutable("gradlew");
+            migrator.setExecutableIfAvailable("gradlew");
             migrator.copy("org/embulk/plugin/template/java/gradle/wrapper/gradle-wrapper.properties",
                           "gradle/wrapper/gradle-wrapper.properties");
             migrator.copy("org/embulk/plugin/template/java/gradle/wrapper/gradle-wrapper.jar",
@@ -381,14 +382,18 @@ public class EmbulkMigrate {
             }
         }
 
-        private void setExecutable(String targetFileName) throws IOException {
+        private void setExecutableIfAvailable(final String targetFileName) throws IOException {
             final Path targetPath = this.basePath.resolve(targetFileName);
-            final Set<PosixFilePermission> permissions =
-                    new HashSet<PosixFilePermission>(Files.getPosixFilePermissions(targetPath));
-            permissions.add(PosixFilePermission.OWNER_EXECUTE);
-            permissions.add(PosixFilePermission.GROUP_EXECUTE);
-            permissions.add(PosixFilePermission.OTHERS_EXECUTE);
-            Files.setPosixFilePermissions(targetPath, permissions);
+            final FileSystem fileSystem = targetPath.getFileSystem();
+            if (fileSystem.supportedFileAttributeViews().contains("posix")) {
+                // NTFS does not support PosixFilePermissions, for example.
+                final Set<PosixFilePermission> permissions =
+                        new HashSet<PosixFilePermission>(Files.getPosixFilePermissions(targetPath));
+                permissions.add(PosixFilePermission.OWNER_EXECUTE);
+                permissions.add(PosixFilePermission.GROUP_EXECUTE);
+                permissions.add(PosixFilePermission.OTHERS_EXECUTE);
+                Files.setPosixFilePermissions(targetPath, permissions);
+            }
         }
 
         private final Path basePath;
diff --git a/embulk-core/src/main/java/org/embulk/cli/EmbulkNew.java b/embulk-core/src/main/java/org/embulk/cli/EmbulkNew.java
index 4317cf1c..82b0cbbf 100644
--- a/embulk-core/src/main/java/org/embulk/cli/EmbulkNew.java
+++ b/embulk-core/src/main/java/org/embulk/cli/EmbulkNew.java
@@ -7,6 +7,7 @@ import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.FileSystem;
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -166,7 +167,7 @@ public class EmbulkNew {
                     copy("org/embulk/plugin/template/java/gradle/wrapper/gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.properties");
                     copy("org/embulk/plugin/template/java/gradlew.bat", "gradlew.bat");
                     copy("org/embulk/plugin/template/java/gradlew", "gradlew");
-                    setExecutable("gradlew");
+                    setExecutableIfAvailable("gradlew");
                     copy("org/embulk/plugin/template/java/config/checkstyle/checkstyle.xml", "config/checkstyle/checkstyle.xml");
                     copy("org/embulk/plugin/template/java/config/checkstyle/default.xml", "config/checkstyle/default.xml");
                     copyTemplated("org/embulk/plugin/template/java/build.gradle.vm",
@@ -384,14 +385,18 @@ public class EmbulkNew {
         }
     }
 
-    private void setExecutable(String targetFileName) throws IOException {
+    private void setExecutableIfAvailable(final String targetFileName) throws IOException {
         final Path targetPath = this.pluginBasePath.resolve(targetFileName);
-        final Set<PosixFilePermission> permissions =
-                new HashSet<PosixFilePermission>(Files.getPosixFilePermissions(targetPath));
-        permissions.add(PosixFilePermission.OWNER_EXECUTE);
-        permissions.add(PosixFilePermission.GROUP_EXECUTE);
-        permissions.add(PosixFilePermission.OTHERS_EXECUTE);
-        Files.setPosixFilePermissions(targetPath, permissions);
+        final FileSystem fileSystem = targetPath.getFileSystem();
+        if (fileSystem.supportedFileAttributeViews().contains("posix")) {
+            // NTFS does not support PosixFilePermissions, for example.
+            final Set<PosixFilePermission> permissions =
+                    new HashSet<PosixFilePermission>(Files.getPosixFilePermissions(targetPath));
+            permissions.add(PosixFilePermission.OWNER_EXECUTE);
+            permissions.add(PosixFilePermission.GROUP_EXECUTE);
+            permissions.add(PosixFilePermission.OTHERS_EXECUTE);
+            Files.setPosixFilePermissions(targetPath, permissions);
+        }
     }
 
     private final Path basePath;
diff --git a/embulk-core/src/main/java/org/embulk/cli/EmbulkSelfUpdate.java b/embulk-core/src/main/java/org/embulk/cli/EmbulkSelfUpdate.java
index 537cb834..58c5c49d 100644
--- a/embulk-core/src/main/java/org/embulk/cli/EmbulkSelfUpdate.java
+++ b/embulk-core/src/main/java/org/embulk/cli/EmbulkSelfUpdate.java
@@ -7,6 +7,7 @@ import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.nio.file.FileSystem;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -88,7 +89,10 @@ public class EmbulkSelfUpdate {
                 InputStream input = connection.getInputStream();
                 // TODO(dmikurube): Confirm if it is okay to replace a temp file created by Files.createTempFile.
                 Files.copy(input, jarPathTemp, StandardCopyOption.REPLACE_EXISTING);
-                Files.setPosixFilePermissions(jarPathTemp, Files.getPosixFilePermissions(jarPathJava));
+                final FileSystem fileSystem = jarPathTemp.getFileSystem();
+                if (fileSystem.supportedFileAttributeViews().contains("posix")) {
+                    Files.setPosixFilePermissions(jarPathTemp, Files.getPosixFilePermissions(jarPathJava));
+                }
             } finally {
                 connection.disconnect();
             }