8180887: move FileUtils to top level testlibrary

Reviewed-by: psandoz
This commit is contained in:
Igor Ignatyev 2017-05-30 15:05:33 -07:00
parent 4f2e94d65a
commit c85d273e7d
29 changed files with 84 additions and 333 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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
@ -25,7 +25,7 @@
* @test * @test
* @bug 7130985 * @bug 7130985
* @summary Four helper classes missing in Sun JDK * @summary Four helper classes missing in Sun JDK
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @build jdk.testlibrary.* * @build jdk.testlibrary.*
* @modules java.corba * @modules java.corba
* @run main CorbaExceptionsCompileTest * @run main CorbaExceptionsCompileTest
@ -35,12 +35,12 @@ import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.rmi.RemoteException;
import org.omg.CORBA.ORBPackage.InvalidName; import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA.TypeCodePackage.BadKind;
import org.omg.CORBA.TypeCodePackage.Bounds; import org.omg.CORBA.TypeCodePackage.Bounds;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import jdk.testlibrary.JDKToolLauncher; import jdk.testlibrary.JDKToolLauncher;
public class CorbaExceptionsCompileTest implements CorbaExceptionsTest { public class CorbaExceptionsCompileTest implements CorbaExceptionsTest {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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
@ -26,8 +26,7 @@
* @bug 8071474 * @bug 8071474
* @summary Better failure atomicity for default read object. * @summary Better failure atomicity for default read object.
* @modules jdk.compiler * @modules jdk.compiler
* @library /lib/testlibrary * @library /test/lib
* @build jdk.testlibrary.FileUtils
* @compile FailureAtomicity.java SerialRef.java * @compile FailureAtomicity.java SerialRef.java
* @run main failureAtomicity.FailureAtomicity * @run main failureAtomicity.FailureAtomicity
*/ */
@ -59,7 +58,7 @@ import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager; import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation; import javax.tools.StandardLocation;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class FailureAtomicity { public class FailureAtomicity {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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
@ -29,7 +29,7 @@ import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import static jdk.testlibrary.ProcessTools.*; import static jdk.testlibrary.ProcessTools.*;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -40,9 +40,9 @@ import static org.testng.Assert.assertTrue;
* @test * @test
* @bug 8087335 * @bug 8087335
* @summary Tests for Class.forName(Module,String) * @summary Tests for Class.forName(Module,String)
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @modules jdk.compiler * @modules jdk.compiler
* @build TestDriver CompilerUtils jdk.testlibrary.ProcessTools jdk.testlibrary.FileUtils TestMain TestLayer * @build TestDriver CompilerUtils jdk.testlibrary.ProcessTools TestMain TestLayer
* @run testng TestDriver * @run testng TestDriver
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2017, 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
@ -24,7 +24,7 @@
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.nio.file.Files; import java.nio.file.Files;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import static java.nio.file.StandardCopyOption.*; import static java.nio.file.StandardCopyOption.*;
public class Common { public class Common {

View File

@ -24,9 +24,9 @@
/** /**
* @test * @test
* @bug 6899919 * @bug 6899919
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @modules jdk.compiler * @modules jdk.compiler
* @build jdk.testlibrary.FileUtils JarUtils CompilerUtils * @build JarUtils CompilerUtils
* @run main/othervm GetResourceAsStream * @run main/othervm GetResourceAsStream
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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
@ -26,7 +26,7 @@
* @modules jdk.incubator.httpclient * @modules jdk.incubator.httpclient
* java.logging * java.logging
* jdk.httpserver * jdk.httpserver
* @library /lib/testlibrary/ * @library /lib/testlibrary/ /test/lib
* @compile ../../../com/sun/net/httpserver/LogFilter.java * @compile ../../../com/sun/net/httpserver/LogFilter.java
* @compile ../../../com/sun/net/httpserver/FileServerHandler.java * @compile ../../../com/sun/net/httpserver/FileServerHandler.java
* @build LightWeightHttpServer * @build LightWeightHttpServer
@ -52,7 +52,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.function.Supplier; import java.util.function.Supplier;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import static java.nio.charset.StandardCharsets.*; import static java.nio.charset.StandardCharsets.*;
import static java.nio.file.StandardOpenOption.*; import static java.nio.file.StandardOpenOption.*;
import static jdk.incubator.http.HttpRequest.BodyProcessor.*; import static jdk.incubator.http.HttpRequest.BodyProcessor.*;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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
@ -45,7 +45,7 @@ import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager; import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation; import javax.tools.StandardLocation;
import javax.tools.ToolProvider; import javax.tools.ToolProvider;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import jdk.testlibrary.JDKToolFinder; import jdk.testlibrary.JDKToolFinder;
import static java.lang.String.format; import static java.lang.String.format;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
@ -55,8 +55,8 @@ import static java.util.Arrays.asList;
* @bug 8064924 * @bug 8064924
* @modules jdk.compiler * @modules jdk.compiler
* @summary Basic test for URLStreamHandlerProvider * @summary Basic test for URLStreamHandlerProvider
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @build jdk.testlibrary.FileUtils jdk.testlibrary.JDKToolFinder * @build jdk.testlibrary.JDKToolFinder
* @compile Basic.java Child.java * @compile Basic.java Child.java
* @run main Basic * @run main Basic
*/ */

View File

@ -25,9 +25,7 @@
* @bug 4313887 6873621 6979526 7006126 7020517 * @bug 4313887 6873621 6979526 7006126 7020517
* @summary Unit test for java.nio.file.FileStore * @summary Unit test for java.nio.file.FileStore
* @key intermittent * @key intermittent
* @library .. * @library .. /test/lib
* @library .. /lib/testlibrary
* @build jdk.testlibrary.FileUtils
* @run main Basic * @run main Basic
*/ */
@ -35,8 +33,8 @@ import java.nio.file.*;
import java.nio.file.attribute.*; import java.nio.file.attribute.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.*;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class Basic { public class Basic {

View File

@ -24,8 +24,7 @@
/* @test /* @test
* @bug 4313887 6838333 8132497 * @bug 4313887 6838333 8132497
* @summary Unit test for java.nio.file.FileSystem * @summary Unit test for java.nio.file.FileSystem
* @library .. /lib/testlibrary * @library .. /test/lib
* @build jdk.testlibrary.FileUtils
* @run main/othervm Basic * @run main/othervm Basic
*/ */
@ -41,7 +40,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.ProviderNotFoundException; import java.nio.file.ProviderNotFoundException;
import java.util.HashMap; import java.util.HashMap;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
/** /**
* Simple sanity checks for java.nio.file.FileSystem * Simple sanity checks for java.nio.file.FileSystem

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, 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
@ -28,8 +28,7 @@
* "java.util.logging.FileHandler.maxLocks" which will be present in * "java.util.logging.FileHandler.maxLocks" which will be present in
* "logging.properties" file with default value of 100. This property can be * "logging.properties" file with default value of 100. This property can be
* overriden by specifying this property in the custom config file. * overriden by specifying this property in the custom config file.
* @library /lib/testlibrary * @library /test/lib
* @build jdk.testlibrary.FileUtils
* @author rpatil * @author rpatil
* @run main/othervm FileHandlerMaxLocksTest * @run main/othervm FileHandlerMaxLocksTest
*/ */
@ -40,7 +39,7 @@ import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class FileHandlerMaxLocksTest { public class FileHandlerMaxLocksTest {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2017, 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
@ -24,8 +24,7 @@
/* @test /* @test
* @bug 8038491 * @bug 8038491
* @summary Crash in ZipFile.read() when ZipFileInputStream is shared between threads * @summary Crash in ZipFile.read() when ZipFileInputStream is shared between threads
* @library /lib/testlibrary * @library /test/lib
* @build jdk.testlibrary.FileUtils
* @run main MultiThreadedReadTest * @run main MultiThreadedReadTest
* @key randomness * @key randomness
*/ */
@ -38,7 +37,7 @@ import java.util.Random;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class MultiThreadedReadTest extends Thread { public class MultiThreadedReadTest extends Thread {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2017, 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
@ -24,15 +24,14 @@
/** /**
* @test * @test
* @bug 6374379 * @bug 6374379
* @library ../../../../lib/testlibrary * @library /test/lib
* @summary Verify that we can read zip file names > 255 chars long * @summary Verify that we can read zip file names > 255 chars long
*/ */
import java.io.*; import java.io.*;
import java.util.jar.*; import java.util.jar.*;
import java.util.zip.*;
import java.util.Stack; import java.util.Stack;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class ReadLongZipFileName { public class ReadLongZipFileName {
private static String entryName = "testFile.txt";; private static String entryName = "testFile.txt";;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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
@ -24,8 +24,7 @@
/* @test /* @test
* @bug 6907252 * @bug 6907252
* @summary ZipFileInputStream Not Thread-Safe * @summary ZipFileInputStream Not Thread-Safe
* @library /lib/testlibrary * @library /test/lib
* @build jdk.testlibrary.*
* @run main ZipEntryFreeTest * @run main ZipEntryFreeTest
*/ */
@ -35,7 +34,7 @@ import java.util.Random;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.zip.*; import java.util.zip.*;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class ZipEntryFreeTest extends Thread { public class ZipEntryFreeTest extends Thread {

View File

@ -25,9 +25,8 @@
* @test * @test
* @bug 8163798 * @bug 8163798
* @summary basic tests for multi-release jar versioned streams * @summary basic tests for multi-release jar versioned streams
* @library /lib/testlibrary * @library /test/lib
* @modules jdk.jartool/sun.tools.jar java.base/jdk.internal.util.jar * @modules jdk.jartool/sun.tools.jar java.base/jdk.internal.util.jar
* @build jdk.testlibrary.FileUtils
* @run testng TestVersionedStream * @run testng TestVersionedStream
*/ */
@ -57,7 +56,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class TestVersionedStream { public class TestVersionedStream {
private final Path userdir; private final Path userdir;

View File

@ -25,7 +25,7 @@
* @test * @test
* @bug 8170859 * @bug 8170859
* @summary Basic test for incubator modules in jmods and images * @summary Basic test for incubator modules in jmods and images
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @key intermittent * @key intermittent
* @modules jdk.compiler jdk.jartool jdk.jlink * @modules jdk.compiler jdk.jartool jdk.jlink
* @build CompilerUtils * @build CompilerUtils
@ -39,14 +39,13 @@ import java.io.PrintStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.spi.ToolProvider; import java.util.spi.ToolProvider;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -1,230 +0,0 @@
/*
* Copyright (c) 2017, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.testlibrary;
import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Common library for various test file utility functions.
*/
public final class FileUtils {
private static final boolean isWindows =
System.getProperty("os.name").startsWith("Windows");
private static final int RETRY_DELETE_MILLIS = isWindows ? 500 : 0;
private static final int MAX_RETRY_DELETE_TIMES = isWindows ? 15 : 0;
/**
* Deletes a file, retrying if necessary.
*
* @param path the file to delete
*
* @throws NoSuchFileException
* if the file does not exist (optional specific exception)
* @throws DirectoryNotEmptyException
* if the file is a directory and could not otherwise be deleted
* because the directory is not empty (optional specific exception)
* @throws IOException
* if an I/O error occurs
*/
public static void deleteFileWithRetry(Path path)
throws IOException
{
try {
deleteFileWithRetry0(path);
} catch (InterruptedException x) {
throw new IOException("Interrupted while deleting.", x);
}
}
/**
* Deletes a file, retrying if necessary.
* No exception thrown if file doesn't exist.
*
* @param path the file to delete
*
* @throws NoSuchFileException
* if the file does not exist (optional specific exception)
* @throws DirectoryNotEmptyException
* if the file is a directory and could not otherwise be deleted
* because the directory is not empty (optional specific exception)
* @throws IOException
* if an I/O error occurs
*/
public static void deleteFileIfExistsWithRetry(Path path)
throws IOException
{
try {
if(Files.exists(path))
deleteFileWithRetry0(path);
} catch (InterruptedException x) {
throw new IOException("Interrupted while deleting.", x);
}
}
private static void deleteFileWithRetry0(Path path)
throws IOException, InterruptedException
{
int times = 0;
IOException ioe = null;
while (true) {
try {
Files.delete(path);
while (Files.exists(path)) {
times++;
if (times > MAX_RETRY_DELETE_TIMES)
throw new IOException("File still exists after " + times + " waits.");
Thread.sleep(RETRY_DELETE_MILLIS);
}
break;
} catch (NoSuchFileException | DirectoryNotEmptyException x) {
throw x;
} catch (IOException x) {
// Backoff/retry in case another process is accessing the file
times++;
if (ioe == null)
ioe = x;
else
ioe.addSuppressed(x);
if (times > MAX_RETRY_DELETE_TIMES)
throw ioe;
Thread.sleep(RETRY_DELETE_MILLIS);
}
}
}
/**
* Deletes a directory and its subdirectories, retrying if necessary.
*
* @param dir the directory to delete
*
* @throws IOException
* If an I/O error occurs. Any such exceptions are caught
* internally. If only one is caught, then it is re-thrown.
* If more than one exception is caught, then the second and
* following exceptions are added as suppressed exceptions of the
* first one caught, which is then re-thrown.
*/
public static void deleteFileTreeWithRetry(Path dir)
throws IOException
{
IOException ioe = null;
final List<IOException> excs = deleteFileTreeUnchecked(dir);
if (!excs.isEmpty()) {
ioe = excs.remove(0);
for (IOException x : excs)
ioe.addSuppressed(x);
}
if (ioe != null)
throw ioe;
}
public static List<IOException> deleteFileTreeUnchecked(Path dir) {
final List<IOException> excs = new ArrayList<>();
try {
java.nio.file.Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
try {
deleteFileWithRetry0(file);
} catch (IOException x) {
excs.add(x);
} catch (InterruptedException x) {
excs.add(new IOException("Interrupted while deleting.", x));
return FileVisitResult.TERMINATE;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
try {
deleteFileWithRetry0(dir);
} catch (IOException x) {
excs.add(x);
} catch (InterruptedException x) {
excs.add(new IOException("Interrupted while deleting.", x));
return FileVisitResult.TERMINATE;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
excs.add(exc);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException x) {
excs.add(x);
}
return excs;
}
/**
* Checks whether all file systems are accessible. This is performed
* by checking free disk space on all mounted file systems via a
* separate, spawned process. File systems are considered to be
* accessible if this process completes successfully before a given
* fixed duration has elapsed.
*
* @implNote On Unix this executes the {@code df} command in a separate
* process and on Windows always returns {@code true}.
*/
public static boolean areFileSystemsAccessible() throws IOException {
boolean areFileSystemsAccessible = true;
if (!isWindows) {
// try to check whether 'df' hangs
System.out.println("\n--- df output ---");
System.out.flush();
Process proc = new ProcessBuilder("df").inheritIO().start();
try {
proc.waitFor(90, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {
}
try {
int exitValue = proc.exitValue();
if (exitValue != 0) {
System.err.printf("df process exited with %d != 0%n",
exitValue);
areFileSystemsAccessible = false;
}
} catch (IllegalThreadStateException ignored) {
System.err.println("df command apparently hung");
areFileSystemsAccessible = false;
}
}
return areFileSystemsAccessible;
}
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, 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
@ -28,9 +28,8 @@
* options with/without a --release option. Some input files are * options with/without a --release option. Some input files are
* duplicates that sometimes cause exceptions and other times do not, * duplicates that sometimes cause exceptions and other times do not,
* demonstrating identical behavior to JDK 8 jar tool. * demonstrating identical behavior to JDK 8 jar tool.
* @library /lib/testlibrary * @library /test/lib
* @modules jdk.jartool * @modules jdk.jartool
* @build jdk.testlibrary.FileUtils
* @run testng InputFilesTest * @run testng InputFilesTest
*/ */
@ -51,7 +50,7 @@ import java.util.spi.ToolProvider;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.zip.ZipException; import java.util.zip.ZipException;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class InputFilesTest { public class InputFilesTest {
private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar") private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, 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
@ -27,9 +27,8 @@
* @summary test that both old style command line options and new gnu style * @summary test that both old style command line options and new gnu style
* command line options work with the --release option whether or * command line options work with the --release option whether or
* not the --release option is preceded by a file name. * not the --release option is preceded by a file name.
* @library /lib/testlibrary * @library /test/lib
* @modules jdk.jartool/sun.tools.jar * @modules jdk.jartool/sun.tools.jar
* @build jdk.testlibrary.FileUtils
* @run testng ReleaseBeforeFiles * @run testng ReleaseBeforeFiles
*/ */
@ -46,7 +45,7 @@ import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class ReleaseBeforeFiles { public class ReleaseBeforeFiles {
private Runnable onCompletion; private Runnable onCompletion;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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
@ -35,7 +35,7 @@ import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import jdk.testlibrary.JDKToolFinder; import jdk.testlibrary.JDKToolFinder;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -49,8 +49,8 @@ import static org.testng.Assert.assertTrue;
/* /*
* @test * @test
* @bug 8170952 * @bug 8170952
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @build jdk.testlibrary.FileUtils jdk.testlibrary.JDKToolFinder * @build jdk.testlibrary.JDKToolFinder
* @run testng CLICompatibility * @run testng CLICompatibility
* @summary Basic test for compatibility of CLI options * @summary Basic test for compatibility of CLI options
*/ */

View File

@ -29,8 +29,7 @@
* @modules java.base/jdk.internal.module * @modules java.base/jdk.internal.module
* jdk.compiler * jdk.compiler
* jdk.jartool * jdk.jartool
* @library /lib/testlibrary * @library /test/lib
* @build jdk.testlibrary.FileUtils
* @run testng Basic * @run testng Basic
*/ */
@ -57,7 +56,7 @@ import java.util.stream.Stream;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import jdk.internal.module.ModuleInfoExtender; import jdk.internal.module.ModuleInfoExtender;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class Basic { public class Basic {
private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar") private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")

View File

@ -25,7 +25,6 @@ import java.io.*;
import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*; import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
@ -36,7 +35,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import jdk.testlibrary.JDKToolFinder; import jdk.testlibrary.JDKToolFinder;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
@ -48,10 +47,10 @@ import static java.lang.System.out;
/* /*
* @test * @test
* @bug 8167328 8171830 8165640 8174248 8176772 * @bug 8167328 8171830 8165640 8174248 8176772
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @modules jdk.compiler * @modules jdk.compiler
* jdk.jartool * jdk.jartool
* @build jdk.testlibrary.FileUtils jdk.testlibrary.JDKToolFinder * @build jdk.testlibrary.JDKToolFinder
* @compile Basic.java * @compile Basic.java
* @run testng Basic * @run testng Basic
* @summary Tests for plain Modular jars & Multi-Release Modular jars * @summary Tests for plain Modular jars & Multi-Release Modular jars

View File

@ -24,18 +24,16 @@
/* /*
* @test * @test
* @summary Tests for API validator. * @summary Tests for API validator.
* @library /test/lib /lib/testlibrary * @library /test/lib
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* jdk.compiler * jdk.compiler
* jdk.jartool * jdk.jartool
* @build jdk.test.lib.JDKToolFinder jdk.test.lib.Utils jdk.test.lib.process.*
* @build jdk.testlibrary.FileUtils
* @build MRTestBase * @build MRTestBase
* @run testng/timeout=1200 ApiValidatorTest * @run testng/timeout=1200 ApiValidatorTest
*/ */
import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.OutputAnalyzer;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
@ -421,4 +419,5 @@ public class ApiValidatorTest extends MRTestBase {
javac(classes, sourceFiles); javac(classes, sourceFiles);
} }
} }

View File

@ -23,19 +23,17 @@
/* /*
* @test * @test
* @library /test/lib /lib/testlibrary * @library /test/lib
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* jdk.compiler * jdk.compiler
* jdk.jartool * jdk.jartool
* @build jdk.test.lib.JDKToolFinder jdk.test.lib.Utils jdk.test.lib.process.*
* @build jdk.testlibrary.FileUtils
* @build MRTestBase * @build MRTestBase
* @run testng Basic * @run testng Basic
*/ */
import static org.testng.Assert.*; import static org.testng.Assert.*;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import org.testng.annotations.*; import org.testng.annotations.*;
import java.io.File; import java.io.File;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2017, 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
@ -29,7 +29,7 @@ import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import static jdk.testlibrary.ProcessTools.*; import static jdk.testlibrary.ProcessTools.*;
@ -39,9 +39,9 @@ import static org.testng.Assert.*;
/** /**
* @test * @test
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @modules jdk.compiler jdk.jlink * @modules jdk.compiler jdk.jlink
* @build CompiledVersionTest CompilerUtils jdk.testlibrary.FileUtils jdk.testlibrary.ProcessTools * @build CompiledVersionTest CompilerUtils jdk.testlibrary.ProcessTools
* @run testng CompiledVersionTest * @run testng CompiledVersionTest
*/ */

View File

@ -23,7 +23,6 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.module.ModuleDescriptor;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -33,7 +32,7 @@ import java.util.spi.ToolProvider;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import static jdk.testlibrary.ProcessTools.*; import static jdk.testlibrary.ProcessTools.*;
@ -44,11 +43,11 @@ import static org.testng.Assert.*;
/** /**
* @test * @test
* @bug 8142968 8173381 8174740 * @bug 8142968 8173381 8174740
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @modules jdk.compiler jdk.jlink * @modules jdk.compiler jdk.jlink
* @modules java.base/jdk.internal.module * @modules java.base/jdk.internal.module
* @modules java.base/jdk.internal.org.objectweb.asm * @modules java.base/jdk.internal.org.objectweb.asm
* @build ModuleTargetHelper UserModuleTest CompilerUtils jdk.testlibrary.FileUtils jdk.testlibrary.ProcessTools * @build ModuleTargetHelper UserModuleTest CompilerUtils jdk.testlibrary.ProcessTools
* @run testng UserModuleTest * @run testng UserModuleTest
*/ */

View File

@ -1,5 +1,5 @@
/** /**
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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,10 +23,10 @@
/* /*
* @test * @test
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @modules jdk.compiler * @modules jdk.compiler
* jdk.jlink * jdk.jlink
* @build jdk.testlibrary.FileUtils CompilerUtils * @build CompilerUtils
* @run testng JmodNegativeTest * @run testng JmodNegativeTest
* @summary Negative tests for jmod * @summary Negative tests for jmod
*/ */
@ -41,7 +41,7 @@ import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.spi.ToolProvider; import java.util.spi.ToolProvider;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -1,5 +1,5 @@
/** /**
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2017, 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
@ -25,10 +25,10 @@
* @test * @test
* @bug 8142968 8166568 8166286 8170618 8168149 * @bug 8142968 8166568 8166286 8170618 8168149
* @summary Basic test for jmod * @summary Basic test for jmod
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @modules jdk.compiler * @modules jdk.compiler
* jdk.jlink * jdk.jlink
* @build jdk.testlibrary.FileUtils CompilerUtils * @build CompilerUtils
* @run testng/othervm -Djava.io.tmpdir=. JmodTest * @run testng/othervm -Djava.io.tmpdir=. JmodTest
*/ */
@ -40,9 +40,8 @@ import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.spi.ToolProvider; import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -24,16 +24,16 @@
/** /**
* @test * @test
* @bug 8167063 * @bug 8167063
* @library /lib/testlibrary * @library /test/lib
* @build jdk.testlibrary.FileUtils
* @run main LauncherMessageTest * @run main LauncherMessageTest
* @summary LauncherHelper should not throw JNI error for LinkageError * @summary LauncherHelper should not throw JNI error for LinkageError
*/ */
import java.io.File; import java.io.File;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
public class LauncherMessageTest { public class LauncherMessageTest {

View File

@ -25,7 +25,7 @@
* @test * @test
* @bug 8157068 8177844 * @bug 8157068 8177844
* @summary Patch java.base and user module with ModuleHashes attribute * @summary Patch java.base and user module with ModuleHashes attribute
* @library /lib/testlibrary * @library /lib/testlibrary /test/lib
* @modules jdk.compiler * @modules jdk.compiler
* @build CompilerUtils * @build CompilerUtils
* @run testng PatchSystemModules * @run testng PatchSystemModules
@ -39,7 +39,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.testlibrary.FileUtils; import jdk.test.lib.util.FileUtils;
import jdk.testlibrary.JDKToolFinder; import jdk.testlibrary.JDKToolFinder;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;