commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject commons-io git commit: IO-514: Remove org.apache.commons.io.Java7Support
Date Wed, 09 Nov 2016 22:33:06 GMT
Repository: commons-io
Updated Branches:
  refs/heads/master 948e0271b -> 9d432121e


IO-514: Remove org.apache.commons.io.Java7Support


Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/9d432121
Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/9d432121
Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/9d432121

Branch: refs/heads/master
Commit: 9d432121e1c60557da3e159252a88885944e5f00
Parents: 948e027
Author: Pascal Schumacher <pascalschumacher@gmx.net>
Authored: Sat Nov 5 22:29:56 2016 +0100
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Wed Nov 9 23:32:59 2016 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                         |   3 +
 .../java/org/apache/commons/io/FileUtils.java   |  55 +-----
 .../org/apache/commons/io/Java7Support.java     | 184 -------------------
 .../org/apache/commons/io/Java7SupportTest.java |  57 ------
 4 files changed, 5 insertions(+), 294 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-io/blob/9d432121/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index bf04ff1..27e77a9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -83,6 +83,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action issue="IO-519" dev="jochen" type="add">
         Add MessageDigestCalculatingInputStream
       </action>
+      <action issue="IO-514" dev="pschumacher" type="remove">
+        Remove org.apache.commons.io.Java7Support
+      </action>
     </release>
     <release version="2.5" date="2016-04-22" description="New features and bug fixes.">
       <action issue="IO-492" dev="ggregory" type="fix" due-to="Santiago Castro">

http://git-wip-us.apache.org/repos/asf/commons-io/blob/9d432121/src/main/java/org/apache/commons/io/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index 652f3f2..5b2d60a 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -34,6 +34,7 @@ import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
@@ -3029,61 +3030,9 @@ public class FileUtils {
      * @since 2.0
      */
     public static boolean isSymlink(final File file) throws IOException {
-        if ( Java7Support.isAtLeastJava7() )
-        {
-            return Java7Support.isSymLink( file );
-        }
-
         if (file == null) {
             throw new NullPointerException("File must not be null");
         }
-        if (FilenameUtils.isSystemWindows()) {
-            return false;
-        }
-        File fileInCanonicalDir = null;
-        if (file.getParent() == null) {
-            fileInCanonicalDir = file;
-        } else {
-            final File canonicalDir = file.getParentFile().getCanonicalFile();
-            fileInCanonicalDir = new File(canonicalDir, file.getName());
-        }
-
-        if (fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile()))
{
-            return isBrokenSymlink(file);
-        } else {
-            return true;
-        }
-    }
-
-    /**
-     * Determines if the specified file is possibly a broken symbolic link.
-     *
-     * @param file the file to check
-
-     * @return true if the file is a Symbolic Link
-     * @throws IOException if an IO error occurs while checking the file
-     */
-    private static boolean isBrokenSymlink(final File file) throws IOException {
-        // if file exists then if it is a symlink it's not broken
-        if (file.exists()) {
-            return false;
-        }
-        // a broken symlink will show up in the list of files of its parent directory
-        final File canon = file.getCanonicalFile();
-        File parentDir = canon.getParentFile();
-        if (parentDir == null || !parentDir.exists()) {
-            return false;
-        }
-
-        // is it worthwhile to create a FileFilterUtil method for this?
-        // is it worthwhile to create an "identity"  IOFileFilter for this?
-        File[] fileInDir = parentDir.listFiles(
-                new FileFilter() {
-                    public boolean accept(File aFile) {
-                        return aFile.equals(canon);
-                    }
-                }
-        );
-        return fileInDir != null && fileInDir.length > 0;
+        return Files.isSymbolicLink(file.toPath());
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-io/blob/9d432121/src/main/java/org/apache/commons/io/Java7Support.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/io/Java7Support.java b/src/main/java/org/apache/commons/io/Java7Support.java
deleted file mode 100644
index 911aa98..0000000
--- a/src/main/java/org/apache/commons/io/Java7Support.java
+++ /dev/null
@@ -1,184 +0,0 @@
-package org.apache.commons.io;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * Java7 feature detection and reflection based feature access.
- * <p/>
- * Taken from maven-shared-utils, only for private usage until we go full java7
- */
-class Java7Support {
-
-    private static final boolean IS_JAVA7;
-
-    private static Method isSymbolicLink;
-
-    private static Method delete;
-
-    private static Method toPath;
-
-    private static Method exists;
-
-    private static Method toFile;
-
-    private static Method readSymlink;
-
-    private static Method createSymlink;
-
-    private static Object emptyLinkOpts;
-
-    private static Object emptyFileAttributes;
-
-    static {
-        boolean isJava7x = true;
-        try {
-            ClassLoader cl = Thread.currentThread().getContextClassLoader();
-            Class<?> files = cl.loadClass("java.nio.file.Files");
-            Class<?> path = cl.loadClass("java.nio.file.Path");
-            Class<?> fa = cl.loadClass("java.nio.file.attribute.FileAttribute");
-            Class<?> linkOption = cl.loadClass("java.nio.file.LinkOption");
-            isSymbolicLink = files.getMethod("isSymbolicLink", path);
-            delete = files.getMethod("delete", path);
-            readSymlink = files.getMethod("readSymbolicLink", path);
-
-            emptyFileAttributes = Array.newInstance(fa, 0);
-            createSymlink = files.getMethod("createSymbolicLink", path, path, emptyFileAttributes.getClass());
-            emptyLinkOpts = Array.newInstance(linkOption, 0);
-            exists = files.getMethod("exists", path, emptyLinkOpts.getClass());
-            toPath = File.class.getMethod("toPath");
-            toFile = path.getMethod("toFile");
-        } catch (ClassNotFoundException | NoSuchMethodException e) {
-            isJava7x = false;
-        }
-        IS_JAVA7 = isJava7x;
-    }
-
-    /**
-     * Invokes java7 isSymbolicLink
-     * @param file The file to check
-     * @return true if the file is a symbolic link
-     */
-    public static boolean isSymLink(File file) {
-        try {
-            Object path = toPath.invoke(file);
-            Boolean result = (Boolean) isSymbolicLink.invoke(null, path);
-            return result.booleanValue();
-        } catch (IllegalAccessException | InvocationTargetException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Reads the target of a symbolic link
-     * @param symlink The symlink to read
-     * @return The location the symlink is pointing to
-     * @throws IOException Upon failure
-     */
-
-    public static File readSymbolicLink(File symlink)
-            throws IOException {
-        try {
-            Object path = toPath.invoke(symlink);
-            Object resultPath = readSymlink.invoke(null, path);
-            return (File) toFile.invoke(resultPath);
-        } catch (IllegalAccessException | InvocationTargetException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-
-    /**
-     * Indicates if a symlunk target exists
-     * @param file The symlink file
-     * @return true if the target exists
-     * @throws IOException upon error
-     */
-    private static boolean exists(File file)
-            throws IOException {
-        try {
-            Object path = toPath.invoke(file);
-            final Boolean result = (Boolean) exists.invoke(null, path, emptyLinkOpts);
-            return result.booleanValue();
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException(e);
-        } catch (InvocationTargetException e) {
-            throw (RuntimeException) e.getTargetException();
-        }
-
-    }
-
-    /**
-     * Creates a symbolic link
-     * @param symlink The symlink to create
-     * @param target Where it should point
-     * @return The newly created symlink
-     * @throws IOException upon error
-     */
-    public static File createSymbolicLink(File symlink, File target)
-            throws IOException {
-        try {
-            if (!exists(symlink)) {
-                Object link = toPath.invoke(symlink);
-                Object path = createSymlink.invoke(null, link, toPath.invoke(target), emptyFileAttributes);
-                return (File) toFile.invoke(path);
-            }
-            return symlink;
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException(e);
-        } catch (InvocationTargetException e) {
-            final Throwable targetException = e.getTargetException();
-            throw (IOException) targetException;
-        }
-
-    }
-
-    /**
-     * Performs a nio delete
-     *
-     * @param file the file to delete
-     * @throws IOException Upon error
-     */
-    public static void delete(File file)
-            throws IOException {
-        try {
-            Object path = toPath.invoke(file);
-            delete.invoke(null, path);
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException(e);
-        } catch (InvocationTargetException e) {
-            throw (IOException) e.getTargetException();
-        }
-    }
-
-    /**
-     * Indicates if the current vm has java7 lubrary support
-     * @return true if java7 library support
-     */
-    public static boolean isAtLeastJava7() {
-        return IS_JAVA7;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-io/blob/9d432121/src/test/java/org/apache/commons/io/Java7SupportTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/Java7SupportTest.java b/src/test/java/org/apache/commons/io/Java7SupportTest.java
deleted file mode 100644
index bafed45..0000000
--- a/src/test/java/org/apache/commons/io/Java7SupportTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.apache.commons.io;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-import java.io.File;
-import java.util.Locale;
-
-import org.junit.Assume;
-import org.junit.Test;
-
-public class Java7SupportTest {
-    @Test
-    public void testIsSymLink()
-            throws Exception {
-
-        File file = new File(".");
-        if (Java7Support.isAtLeastJava7()) {
-            assertFalse(Java7Support.isSymLink(file));
-        }
-    }
-
-    @Test
-    public void createAndReadSymlink()
-            throws Exception {
-
-        Assume.assumeFalse(System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"));
-
-        File file = new File("target/fzz");
-        if (Java7Support.isAtLeastJava7()) {
-            Java7Support.createSymbolicLink(file, new File("../target"));
-
-            final File file1 = Java7Support.readSymbolicLink(file);
-            assertEquals("target", file1.getName());
-            Java7Support.delete(file);
-        }
-    }
-
-}


Mime
View raw message