Search in sources :

Example 1 with Delete

use of org.apache.tools.ant.taskdefs.Delete in project ant by apache.

the class FTPTaskMirrorImpl method getTimeDiff.

/**
 * auto find the time difference between local and remote
 * @param ftp handle to ftp client
 * @return number of millis to add to remote time to make it comparable to local time
 * @since ant 1.6
 */
private long getTimeDiff(FTPClient ftp) {
    long returnValue = 0;
    File tempFile = findFileName(ftp);
    try {
        // create a local temporary file
        FILE_UTILS.createNewFile(tempFile);
        long localTimeStamp = tempFile.lastModified();
        BufferedInputStream instream = new BufferedInputStream(Files.newInputStream(tempFile.toPath()));
        ftp.storeFile(tempFile.getName(), instream);
        instream.close();
        if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
            FTPFile[] ftpFiles = ftp.listFiles(tempFile.getName());
            if (ftpFiles.length == 1) {
                long remoteTimeStamp = ftpFiles[0].getTimestamp().getTime().getTime();
                returnValue = localTimeStamp - remoteTimeStamp;
            }
            ftp.deleteFile(ftpFiles[0].getName());
        }
        // delegate the deletion of the local temp file to the delete task
        // because of race conditions occurring on Windows
        Delete mydelete = new Delete();
        mydelete.bindToOwner(task);
        mydelete.setFile(tempFile.getCanonicalFile());
        mydelete.execute();
    } catch (Exception e) {
        throw new BuildException(e, task.getLocation());
    }
    return returnValue;
}
Also used : Delete(org.apache.tools.ant.taskdefs.Delete) BufferedInputStream(java.io.BufferedInputStream) FTPFile(org.apache.commons.net.ftp.FTPFile) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) FTPFile(org.apache.commons.net.ftp.FTPFile) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 2 with Delete

use of org.apache.tools.ant.taskdefs.Delete in project ant-ivy by apache.

the class IvyDeliverTest method cleanTestDir.

private void cleanTestDir() {
    Delete del = new Delete();
    del.setProject(new Project());
    del.setDir(new File("build/test/deliver"));
    del.execute();
}
Also used : Delete(org.apache.tools.ant.taskdefs.Delete) Project(org.apache.tools.ant.Project) File(java.io.File)

Example 3 with Delete

use of org.apache.tools.ant.taskdefs.Delete in project ant-ivy by apache.

the class IvyDeliverTest method cleanRep.

private void cleanRep() {
    Delete del = new Delete();
    del.setProject(new Project());
    del.setDir(new File("test/repositories/1/apache"));
    del.execute();
}
Also used : Delete(org.apache.tools.ant.taskdefs.Delete) Project(org.apache.tools.ant.Project) File(java.io.File)

Example 4 with Delete

use of org.apache.tools.ant.taskdefs.Delete in project ant-ivy by apache.

the class TestPerformance method cleanRepo.

private void cleanRepo() {
    Delete del = new Delete();
    del.setProject(new Project());
    del.setDir(new File("build/test/perf"));
    del.execute();
}
Also used : Delete(org.apache.tools.ant.taskdefs.Delete) Project(org.apache.tools.ant.Project) File(java.io.File)

Example 5 with Delete

use of org.apache.tools.ant.taskdefs.Delete in project ant-ivy by apache.

the class DefaultRepositoryCacheManagerTest method tearDown.

@After
public void tearDown() {
    IvyContext.popContext();
    Delete del = new Delete();
    del.setProject(new Project());
    del.setDir(cacheManager.getRepositoryCacheRoot());
    del.execute();
}
Also used : Delete(org.apache.tools.ant.taskdefs.Delete) Project(org.apache.tools.ant.Project) After(org.junit.After)

Aggregations

Delete (org.apache.tools.ant.taskdefs.Delete)15 File (java.io.File)12 Project (org.apache.tools.ant.Project)12 IOException (java.io.IOException)3 BuildException (org.apache.tools.ant.BuildException)3 Test (org.junit.Test)3 BufferedInputStream (java.io.BufferedInputStream)2 FTPFile (org.apache.commons.net.ftp.FTPFile)2 FileSet (org.apache.tools.ant.types.FileSet)2 After (org.junit.After)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Permission (java.security.Permission)1 HashSet (java.util.HashSet)1 DefaultLogger (org.apache.tools.ant.DefaultLogger)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 TempFile (org.apache.tools.ant.taskdefs.TempFile)1