mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
8010511: Tests are creating files in /tmp
Reviewed-by: darcy
This commit is contained in:
parent
84a50dc114
commit
18f48ab46b
4 changed files with 82 additions and 32 deletions
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
|
* @bug 6558476
|
||||||
|
* @summary com/sun/tools/javac/Main.compile don't release file handles on return
|
||||||
* @run main/othervm -Xmx512m -Xms512m T6558476
|
* @run main/othervm -Xmx512m -Xms512m T6558476
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -70,8 +72,7 @@ public class T6558476 {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
File javaHomeDir = new File(System.getProperty("java.home"));
|
File javaHomeDir = new File(System.getProperty("java.home"));
|
||||||
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
|
File outputDir = new File("outputDir" + new Random().nextInt(65536));
|
||||||
File outputDir = new File(tmpDir, "outputDir" + new Random().nextInt(65536));
|
|
||||||
outputDir.mkdir();
|
outputDir.mkdir();
|
||||||
outputDir.deleteOnExit();
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -39,7 +39,7 @@ public class T6900149 {
|
||||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||||
StandardJavaFileManager fm =
|
StandardJavaFileManager fm =
|
||||||
compiler.getStandardFileManager(null, null, null);
|
compiler.getStandardFileManager(null, null, null);
|
||||||
File emptyFile = File.createTempFile("Empty", ".java");
|
File emptyFile = createTempFile("Empty.java");
|
||||||
File[] files = new File[] { emptyFile, emptyFile };
|
File[] files = new File[] { emptyFile, emptyFile };
|
||||||
CompilationTask task = compiler.getTask(null, fm, diag,
|
CompilationTask task = compiler.getTask(null, fm, diag,
|
||||||
null, null, fm.getJavaFileObjects(files));
|
null, null, fm.getJavaFileObjects(files));
|
||||||
|
@ -47,4 +47,10 @@ public class T6900149 {
|
||||||
throw new AssertionError("compilation failed");
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -34,6 +34,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +55,27 @@ public class CheckExamples {
|
||||||
* Standard entry point.
|
* Standard entry point.
|
||||||
*/
|
*/
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
|
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();
|
new CheckExamples().run();
|
||||||
|
} finally {
|
||||||
|
if (deleteOnExit) {
|
||||||
|
clean(tmpDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,6 +212,25 @@ public class CheckExamples {
|
||||||
|
|
||||||
int errors;
|
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 class Counts {
|
||||||
static String[] prefixes = {
|
static String[] prefixes = {
|
||||||
"compiler.err.",
|
"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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -33,7 +33,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.text.SimpleDateFormat;
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -56,16 +57,18 @@ import java.util.regex.Pattern;
|
||||||
public class RunExamples {
|
public class RunExamples {
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
jtreg = (System.getProperty("test.src") != null);
|
jtreg = (System.getProperty("test.src") != null);
|
||||||
File tmpDir;
|
Path tmpDir;
|
||||||
|
boolean deleteOnExit;
|
||||||
if (jtreg) {
|
if (jtreg) {
|
||||||
// use standard jtreg scratch directory: the current directory
|
// 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 {
|
} else {
|
||||||
tmpDir = new File(System.getProperty("java.io.tmpdir"),
|
tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")),
|
||||||
RunExamples.class.getName()
|
RunExamples.class.getName());
|
||||||
+ (new SimpleDateFormat("yyMMddHHmmss")).format(new Date()));
|
deleteOnExit = true;
|
||||||
}
|
}
|
||||||
Example.setTempDir(tmpDir);
|
Example.setTempDir(tmpDir.toFile());
|
||||||
|
|
||||||
RunExamples r = new RunExamples();
|
RunExamples r = new RunExamples();
|
||||||
|
|
||||||
|
@ -73,15 +76,8 @@ public class RunExamples {
|
||||||
if (r.run(args))
|
if (r.run(args))
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
/* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the
|
if (deleteOnExit) {
|
||||||
* jtreg scratch directory, which is the current directory.
|
clean(tmpDir);
|
||||||
* 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,14 +199,20 @@ public class RunExamples {
|
||||||
/**
|
/**
|
||||||
* Clean the contents of a directory.
|
* Clean the contents of a directory.
|
||||||
*/
|
*/
|
||||||
static boolean clean(File dir) {
|
static void clean(Path dir) throws IOException {
|
||||||
boolean ok = true;
|
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
|
||||||
for (File f: dir.listFiles()) {
|
@Override
|
||||||
if (f.isDirectory())
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
ok &= clean(f);
|
Files.delete(file);
|
||||||
ok &= f.delete();
|
return super.visitFile(file, attrs);
|
||||||
}
|
}
|
||||||
return ok;
|
|
||||||
|
@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 {
|
static abstract class Runner {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue