1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.shared.utils.io; 20 21 import javax.annotation.Nonnull; 22 23 import java.io.File; 24 import java.io.IOException; 25 import java.nio.file.Files; 26 27 /** 28 * Java7 feature detection 29 * 30 * @author Kristian Rosenvold 31 * 32 * @deprecated no longer needed, prefer to use {@link java.nio.file.Files} methods directly. 33 */ 34 @Deprecated 35 public class Java7Support { 36 /** 37 * @param file The file to check for being a symbolic link. 38 * @return true if the file is a symlink false otherwise. 39 */ 40 public static boolean isSymLink(@Nonnull File file) { 41 return Files.isSymbolicLink(file.toPath()); 42 } 43 44 /** 45 * @param symlink The sym link. 46 * @return The file. 47 * @throws IOException in case of error. 48 */ 49 @Nonnull 50 public static File readSymbolicLink(@Nonnull File symlink) throws IOException { 51 return Files.readSymbolicLink(symlink.toPath()).toFile(); 52 } 53 54 /** 55 * @param file The file to check. 56 * @return true if exist false otherwise. 57 * @throws IOException in case of failure. 58 */ 59 public static boolean exists(@Nonnull File file) throws IOException { 60 return Files.exists(file.toPath()); 61 } 62 63 /** 64 * @param symlink The link name. 65 * @param target The target. 66 * @return The linked file. 67 * @throws IOException in case of an error. 68 */ 69 @Nonnull 70 public static File createSymbolicLink(@Nonnull File symlink, @Nonnull File target) throws IOException { 71 return FileUtils.createSymbolicLink(symlink, target); 72 } 73 74 /** 75 * Performs a nio delete 76 * @param file the file to delete 77 * @throws IOException in case of error. 78 */ 79 public static void delete(@Nonnull File file) throws IOException { 80 Files.delete(file.toPath()); 81 } 82 83 /** 84 * @return true in case of Java 7. 85 */ 86 public static boolean isJava7() { 87 return true; 88 } 89 90 /** 91 * @return true in case of Java7 or greater. 92 */ 93 public static boolean isAtLeastJava7() { 94 return true; 95 } 96 }