use of org.apache.tools.ant.taskdefs.Delete in project ant by apache.
the class FTP 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();
boolean success = FTPReply.isPositiveCompletion(ftp.getReplyCode());
if (success) {
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(this);
mydelete.setFile(tempFile.getCanonicalFile());
mydelete.execute();
} catch (Exception e) {
throw new BuildException(e, getLocation());
}
return returnValue;
}
use of org.apache.tools.ant.taskdefs.Delete in project ant by apache.
the class AggregateTransformer method transform.
/**
* transformation
* @throws BuildException exception if something goes wrong with the transformation.
*/
public void transform() throws BuildException {
checkOptions();
Project project = task.getProject();
TempFile tempFileTask = new TempFile();
tempFileTask.bindToOwner(task);
xsltTask.setXslResource(getStylesheet());
// acrobatic cast.
xsltTask.setIn(((XMLResultAggregator) task).getDestinationFile());
File outputFile;
if (FRAMES.equals(format)) {
// NOSONAR
String tempFileProperty = getClass().getName() + String.valueOf(counter++);
File tmp = FILE_UTILS.resolveFile(project.getBaseDir(), project.getProperty("java.io.tmpdir"));
tempFileTask.setDestDir(tmp);
tempFileTask.setProperty(tempFileProperty);
tempFileTask.execute();
outputFile = new File(project.getProperty(tempFileProperty));
} else {
outputFile = new File(toDir, "junit-noframes.html");
}
xsltTask.setOut(outputFile);
XSLTProcess.Param paramx = xsltTask.createParam();
paramx.setProject(task.getProject());
paramx.setName("output.dir");
paramx.setExpression(toDir.getAbsolutePath());
configureForRedirectExtension();
final long t0 = System.currentTimeMillis();
try {
xsltTask.execute();
} catch (Exception e) {
throw new BuildException("Errors while applying transformations: " + e.getMessage(), e);
}
final long dt = System.currentTimeMillis() - t0;
task.log("Transform time: " + dt + "ms");
if (format.equals(FRAMES)) {
Delete delete = new Delete();
delete.bindToOwner(task);
delete.setFile(outputFile);
delete.execute();
}
}
use of org.apache.tools.ant.taskdefs.Delete in project ant by apache.
the class XMLResultAggregatorTest method testFrames.
@Test
public void testFrames() throws Exception {
// For now, skip this test on JDK 6 (and below); see below for why:
try {
Class.forName("java.nio.file.Files");
} catch (ClassNotFoundException x) {
Assume.assumeNoException("Skip test on JDK 6 and below", x);
}
final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest");
if (d.exists()) {
new Delete() {
{
removeDir(d);
}
};
// is there no utility method for this?
}
assertTrue(d.getAbsolutePath(), d.mkdir());
File xml = new File(d, "x.xml");
PrintWriter pw = new PrintWriter(new FileOutputStream(xml));
try {
pw.println("<testsuite errors='0' failures='0' name='my.UnitTest' tests='1'>");
pw.println(" <testcase classname='my.UnitTest' name='testSomething'/>");
pw.println("</testsuite>");
pw.flush();
} finally {
pw.close();
}
XMLResultAggregator task = new XMLResultAggregator();
task.setTodir(d);
Project project = new Project();
DefaultLogger logger = new DefaultLogger();
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);
logger.setMessageOutputLevel(Project.MSG_INFO);
project.addBuildListener(logger);
project.init();
task.setProject(project);
AggregateTransformer report = task.createReport();
report.setTodir(d);
FileSet fs = new FileSet();
fs.setFile(xml);
task.addFileSet(fs);
/* getResourceAsStream override unnecessary on JDK 7.
* Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD:
Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
public InputStream getResourceAsStream(String name) {
if (name.startsWith("META-INF/services/")) {
return new ByteArrayInputStream(new byte[0]);
}
return super.getResourceAsStream(name);
}
});
*/
// Use the JRE's Xerces, not lib/optional/xerces.jar:
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent());
// Tickle #51668:
System.setSecurityManager(new SecurityManager() {
public void checkPermission(Permission perm) {
}
});
task.execute();
assertTrue(new File(d, "index.html").isFile());
}
use of org.apache.tools.ant.taskdefs.Delete in project egit by eclipse.
the class SmartImportWizardTest method test.
@Test
public void test() throws Exception {
try {
new URL("https://git.eclipse.org/r/").openConnection();
} catch (Exception ex) {
Assume.assumeNoException("Internet access is required for that test", ex);
}
Set<IProject> initialProjects = new HashSet<>(Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()));
Set<IProject> newProjects = null;
bot.menu("File").menu("Import...").click();
expandAndWait(bot.tree().getTreeItem("Git")).select("Projects from Git (with smart import)");
bot.button("Next >").click();
bot.tree().select("Clone URI");
bot.button("Next >").click();
bot.text().setText("https://git.eclipse.org/r/jgit/jgit");
bot.button("Next >").click();
// Time to fetch branch info
waitForButtonEnabled("Next >", 30);
bot.button("Deselect All").click();
bot.tree().getTreeItem("master").check();
bot.button("Next >").click();
Path tmpDir = Files.createTempDirectory(getClass().getName());
try {
bot.text().setText(tmpDir.toString());
bot.button("Next >").click();
// Time to clone repo
waitForButtonEnabled("Finish", 180);
bot.button("Finish").click();
Job.getJobManager().join(SmartImportJob.class, new NullProgressMonitor());
newProjects = new HashSet<>(Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()));
newProjects.removeAll(initialProjects);
Assert.assertTrue("There should be more than one project imported with jgit...", newProjects.size() > 1);
IProject someProject = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.jgit.ui");
Assert.assertTrue("Project not found", someProject.exists());
} finally {
// clean up
if (newProjects != null) {
for (IProject p : newProjects) {
p.delete(true, new NullProgressMonitor());
}
}
Delete deleteTask = new Delete();
deleteTask.setDir(tmpDir.toFile());
deleteTask.execute();
}
}
use of org.apache.tools.ant.taskdefs.Delete in project ant-ivy by apache.
the class RetrieveTest method tearDown.
@After
public void tearDown() {
TestHelper.cleanCache();
Delete del = new Delete();
del.setProject(new Project());
del.setDir(new File("build/test/retrieve"));
del.execute();
}
Aggregations