8010511: Tests are creating files in /tmp
Reviewed-by: darcy
This commit is contained in:
parent
84a50dc114
commit
18f48ab46b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,6 +23,8 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6558476
|
||||
* @summary com/sun/tools/javac/Main.compile don't release file handles on return
|
||||
* @run main/othervm -Xmx512m -Xms512m T6558476
|
||||
*/
|
||||
|
||||
@ -70,8 +72,7 @@ public class T6558476 {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
File javaHomeDir = new File(System.getProperty("java.home"));
|
||||
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
|
||||
File outputDir = new File(tmpDir, "outputDir" + new Random().nextInt(65536));
|
||||
File outputDir = new File("outputDir" + new Random().nextInt(65536));
|
||||
outputDir.mkdir();
|
||||
outputDir.deleteOnExit();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -39,7 +39,7 @@ public class T6900149 {
|
||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
StandardJavaFileManager fm =
|
||||
compiler.getStandardFileManager(null, null, null);
|
||||
File emptyFile = File.createTempFile("Empty", ".java");
|
||||
File emptyFile = createTempFile("Empty.java");
|
||||
File[] files = new File[] { emptyFile, emptyFile };
|
||||
CompilationTask task = compiler.getTask(null, fm, diag,
|
||||
null, null, fm.getJavaFileObjects(files));
|
||||
@ -47,4 +47,10 @@ public class T6900149 {
|
||||
throw new AssertionError("compilation failed");
|
||||
}
|
||||
}
|
||||
|
||||
private static File createTempFile(String path) throws IOException {
|
||||
File f = new File(path);
|
||||
try (FileWriter out = new FileWriter(f)) { }
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -34,6 +34,8 @@
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -53,7 +55,27 @@ public class CheckExamples {
|
||||
* Standard entry point.
|
||||
*/
|
||||
public static void main(String... args) throws Exception {
|
||||
new CheckExamples().run();
|
||||
boolean jtreg = (System.getProperty("test.src") != null);
|
||||
Path tmpDir;
|
||||
boolean deleteOnExit;
|
||||
if (jtreg) {
|
||||
// use standard jtreg scratch directory: the current directory
|
||||
tmpDir = Paths.get(System.getProperty("user.dir"));
|
||||
deleteOnExit = false;
|
||||
} else {
|
||||
tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")),
|
||||
CheckExamples.class.getName());
|
||||
deleteOnExit = true;
|
||||
}
|
||||
Example.setTempDir(tmpDir.toFile());
|
||||
|
||||
try {
|
||||
new CheckExamples().run();
|
||||
} finally {
|
||||
if (deleteOnExit) {
|
||||
clean(tmpDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,6 +212,25 @@ public class CheckExamples {
|
||||
|
||||
int errors;
|
||||
|
||||
/**
|
||||
* Clean the contents of a directory.
|
||||
*/
|
||||
static void clean(Path dir) throws IOException {
|
||||
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Files.delete(file);
|
||||
return super.visitFile(file, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
if (exc == null) Files.delete(dir);
|
||||
return super.postVisitDirectory(dir, exc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static class Counts {
|
||||
static String[] prefixes = {
|
||||
"compiler.err.",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -33,7 +33,8 @@
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -56,16 +57,18 @@ import java.util.regex.Pattern;
|
||||
public class RunExamples {
|
||||
public static void main(String... args) throws Exception {
|
||||
jtreg = (System.getProperty("test.src") != null);
|
||||
File tmpDir;
|
||||
Path tmpDir;
|
||||
boolean deleteOnExit;
|
||||
if (jtreg) {
|
||||
// use standard jtreg scratch directory: the current directory
|
||||
tmpDir = new File(System.getProperty("user.dir"));
|
||||
tmpDir = Paths.get(System.getProperty("user.dir"));
|
||||
deleteOnExit = false;
|
||||
} else {
|
||||
tmpDir = new File(System.getProperty("java.io.tmpdir"),
|
||||
RunExamples.class.getName()
|
||||
+ (new SimpleDateFormat("yyMMddHHmmss")).format(new Date()));
|
||||
tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")),
|
||||
RunExamples.class.getName());
|
||||
deleteOnExit = true;
|
||||
}
|
||||
Example.setTempDir(tmpDir);
|
||||
Example.setTempDir(tmpDir.toFile());
|
||||
|
||||
RunExamples r = new RunExamples();
|
||||
|
||||
@ -73,15 +76,8 @@ public class RunExamples {
|
||||
if (r.run(args))
|
||||
return;
|
||||
} finally {
|
||||
/* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the
|
||||
* jtreg scratch directory, which is the current directory.
|
||||
* In case someone is faking jtreg mode, make sure to only
|
||||
* clean tmpDir when it is reasonable to do so.
|
||||
*/
|
||||
if (tmpDir.isDirectory() &&
|
||||
tmpDir.getName().startsWith(RunExamples.class.getName())) {
|
||||
if (clean(tmpDir))
|
||||
tmpDir.delete();
|
||||
if (deleteOnExit) {
|
||||
clean(tmpDir);
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,14 +199,20 @@ public class RunExamples {
|
||||
/**
|
||||
* Clean the contents of a directory.
|
||||
*/
|
||||
static boolean clean(File dir) {
|
||||
boolean ok = true;
|
||||
for (File f: dir.listFiles()) {
|
||||
if (f.isDirectory())
|
||||
ok &= clean(f);
|
||||
ok &= f.delete();
|
||||
}
|
||||
return ok;
|
||||
static void clean(Path dir) throws IOException {
|
||||
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Files.delete(file);
|
||||
return super.visitFile(file, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||
if (exc == null) Files.delete(dir);
|
||||
return super.postVisitDirectory(dir, exc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static abstract class Runner {
|
||||
|
Loading…
x
Reference in New Issue
Block a user