Package org.apache.tools.ant.util

Examples of org.apache.tools.ant.util.FileUtils


        File canfil = new File(canstr);

        // rename the resource, thus breaking the link
        String parentStr = canfil.getParent();
        File parentDir = new File(parentStr);
        FileUtils fu = FileUtils.newFileUtils();
        File temp = fu.createTempFile("symlink", ".tmp", parentDir);
        temp.deleteOnExit();
        try {
            try {
                fu.rename(canfil, temp);
            } catch (IOException e) {
                throw new IOException("Couldn't rename resource when "
                                      + "attempting to delete " + linkfil);
            }

            // delete the (now) broken link
            if (!linkfil.delete()) {
                throw new IOException("Couldn't delete symlink: " + linkfil
                                      + " (was it a real file? is this not a "
                                      + "UNIX system?)");
            }
        } finally {
            // return the resource to its original name.
            try {
                fu.rename(temp, canfil);
            } catch (IOException e) {
                throw new IOException("Couldn't return resource " + temp
                                      + " to its original name: " + canstr
                                      + "\n THE RESOURCE'S NAME ON DISK HAS "
                                      + "BEEN CHANGED BY THIS ERROR!\n");
View Full Code Here


            enumLinks = linksFiles.elements();

            File parentNext, next;
            String nameParentNext;
            FileUtils fu = FileUtils.newFileUtils();
            Vector removals = new Vector();
            while (enumLinks.hasMoreElements()) {
                next = (File) enumLinks.nextElement();
                nameParentNext = next.getParent();

                parentNext = new File(nameParentNext);
                try {
                    if (!fu.isSymbolicLink(parentNext, next.getName())) {
                        removals.addElement(next);
                    }
                } catch (IOException ioe) {
                    handleError("Failed checking " + next
                                + " for symbolic link. FileSet skipped.");
View Full Code Here

        File executableFile = getProject().resolveFile(exec);
        if (executableFile.exists()) {
            return executableFile.getAbsolutePath();
        }

        FileUtils fileUtils = FileUtils.newFileUtils();
        // now try to resolve against the dir if given
        if (dir != null) {
            executableFile = fileUtils.resolveFile(dir, exec);
            if (executableFile.exists()) {
                return executableFile.getAbsolutePath();
            }
        }

        // couldn't find it - must be on path
        if (searchPath) {
            Vector env = Execute.getProcEnvironment();
            Enumeration e = env.elements();
            Path p = null;
            while (e.hasMoreElements()) {
                String line = (String) e.nextElement();
                if (line.startsWith("PATH=") || line.startsWith("Path=")) {
                    p = new Path(getProject(), line.substring(5));
                    break;
                }
            }

            if (p != null) {
                String[] dirs = p.list();
                for (int i = 0; i < dirs.length; i++) {
                    executableFile = fileUtils.resolveFile(new File(dirs[i]),
                                                           exec);
                    if (executableFile.exists()) {
                        return executableFile.getAbsolutePath();
                    }
                }
View Full Code Here

                    }
                    // not the requested type
                    return false;
                }

                FileUtils fileUtils = FileUtils.newFileUtils();
                File parent = fileUtils.getParentFile(path);
                // **   full-pathname specified == parent dir of path in list
                if (parent != null && parent.exists()
                    && file.equals(parent.getAbsolutePath())) {
                    if (type == null) {
                        log("Found: " + parent, Project.MSG_VERBOSE);
                        return true;
                    } else if (type.isDir()) {
                        log("Found directory: " + parent, Project.MSG_VERBOSE);
                        return true;
                    }
                    // not the requested type
                    return false;
                }

                // **   simple name specified   == path in list + name
                if (path.exists() && path.isDirectory()) {
                    if (checkFile(new File(path, file),
                                  file + " in " + path)) {
                        return true;
                    }
                }

                // **   simple name specified   == parent dir + name
                if (parent != null && parent.exists()) {
                    if (checkFile(new File(parent, file),
                                  file + " in " + parent)) {
                        return true;
                    }
                }

                // **   simple name specified   == parent of parent dir + name
                if (parent != null) {
                    File grandParent = fileUtils.getParentFile(parent);
                    if (grandParent != null && grandParent.exists()) {
                        if (checkFile(new File(grandParent, file),
                                      file + " in " + grandParent)) {
                            return true;
                        }
View Full Code Here

        executeTarget("testFilterReaderTailLinesSkip");
        File expected = getProject().resolveFile(
            "expected/head-tail.tailLinesSkip.test");
        File result = getProject().resolveFile(
            "result/head-tail.filterReaderTailLinesSkip.test");
        FileUtils fu = FileUtils.newFileUtils();
        assertTrue("testFilterReaderTailLinesSkip: Result not like expected",
                   fu.contentEquals(expected, result));
    }
View Full Code Here

    public void testHeadTail() throws IOException {
        executeTarget("testHeadTail");
        File expected = getProject().resolveFile("expected/head-tail.headtail.test");
        File result = getProject().resolveFile("result/head-tail.headtail.test");
        FileUtils fu = FileUtils.newFileUtils();
        assertTrue("testHeadTail: Result not like expected", fu.contentEquals(expected, result));
    }
View Full Code Here

    public void testRunSuccessWithFailOnError() {
        executeTarget("testRunSuccessWithFailOnError");
    }

    public void testSpawn() {
        FileUtils fileutils  = FileUtils.newFileUtils();
        File logFile = fileutils.createTempFile("spawn","log", project.getBaseDir());
        // this is guaranteed by FileUtils#createTempFile
        assertTrue("log file not existing", !logFile.exists());
        project.setProperty("logFile", logFile.getAbsolutePath());
        project.setProperty("timeToWait", Long.toString(TIME_TO_WAIT));
        project.executeTarget("testSpawn");
View Full Code Here

    public void tearDown() {
        executeTarget("cleanup");
    }

    public void testRealTest() throws java.io.IOException {
        FileUtils fileUtils = FileUtils.newFileUtils();
        executeTarget("realTest");
        assertTrue("File content mismatch after bunzip2",
            fileUtils.contentEquals(project.resolveFile("expected/asf-logo-huge.tar"),
                                    project.resolveFile("asf-logo-huge.tar")));
    }
View Full Code Here

        assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
                                           project.resolveFile("asf-logo.gif")));
    }

    public void testTestGzipTarTask() throws java.io.IOException {
        FileUtils fileUtils = FileUtils.newFileUtils();
        executeTarget("testGzipTarTask");
        assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
                                           project.resolveFile("asf-logo.gif")));
    }
View Full Code Here

        assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
                                           project.resolveFile("asf-logo.gif")));
    }

    public void testTestBzip2TarTask() throws java.io.IOException {
        FileUtils fileUtils = FileUtils.newFileUtils();
        executeTarget("testBzip2TarTask");
        assertTrue(fileUtils.contentEquals(project.resolveFile("../asf-logo.gif"),
                                           project.resolveFile("asf-logo.gif")));
    }
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.util.FileUtils

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.