/** * <p>Checks whether the parent of this file is a symbolic link.</p> * * <p>For java versions prior to 7 It doesn't really test for symbolic links but whether the canonical and absolute * paths of the file are identical - this may lead to false positives on some platforms.</p> * * @param parent the parent directory of the file to test * @param name the name of the file to test. * @return true if it's a symbolic link * @throws java.io.IOException . * @since Ant 1.5 */ public boolean isParentSymbolicLink( File parent, String name ) throws IOException { if ( Java7Detector.isJava7() ) { return NioFiles.isSymbolicLink( parent ); } File resolvedParent = new File( parent.getCanonicalPath() ); File toTest = new File( resolvedParent, name ); return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() ); } }
/** * Deletes a file. * * @param fileName The path of the file to delete. */ public static void fileDelete( String fileName ) { File file = new File( fileName ); if ( Java7Detector.isJava7() ) { try { NioFiles.deleteIfExists( file ); } catch ( IOException e ) { throw new RuntimeException( e ); } } else { file.delete(); } }
/** * <p>Checks whether a given file is a symbolic link.</p> * * <p>It doesn't really test for symbolic links but whether the canonical and absolute paths of the file are identical * - this may lead to false positives on some platforms. * </p> * * @param parent the parent directory of the file to test * @param name the name of the file to test. * @return true if it's a symbolic link * @throws java.io.IOException . * @since Ant 1.5 */ public boolean isSymbolicLink( File parent, String name ) throws IOException { if ( Java7Detector.isJava7() ) { return NioFiles.isSymbolicLink( new File( parent, name ) ); } File resolvedParent = new File( parent.getCanonicalPath() ); File toTest = new File( resolvedParent, name ); return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() ); }
private static void doCopyFile( File source, File destination ) throws IOException { // offload to operating system if supported if ( Java7Detector.isJava7() ) { doCopyFileUsingNewIO( source, destination ); } else { doCopyFileUsingLegacyIO( source, destination ); } }
/** * Creates a number of directories, as delivered from DirectoryScanner * * @param sourceBase The basedir used for the directory scan * @param dirs The getIncludedDirs from the dirscanner * @param destination The base dir of the output structure */ public static void mkDirs( final File sourceBase, String[] dirs, final File destination ) throws IOException { for ( String dir : dirs ) { File src = new File( sourceBase, dir ); File dst = new File( destination, dir ); if ( Java7Detector.isJava7() && NioFiles.isSymbolicLink( src ) ) { File target = NioFiles.readSymbolicLink( src ); NioFiles.createSymbolicLink( dst, target ); } else { dst.mkdirs(); } } }