8196425: tools/javac/modules/AnnotationProcessing.java failed
authorjjg
Thu, 21 Jun 2018 13:29:44 -0700
changeset 50704 1a3f1cf62456
parent 50703 0486d7749b8d
child 50705 08c77757320c
8196425: tools/javac/modules/AnnotationProcessing.java failed Reviewed-by: jlahoda
test/langtools/tools/javac/modules/AnnotationProcessing.java
--- a/test/langtools/tools/javac/modules/AnnotationProcessing.java	Thu Jun 21 20:52:52 2018 +0200
+++ b/test/langtools/tools/javac/modules/AnnotationProcessing.java	Thu Jun 21 13:29:44 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, 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
@@ -568,7 +568,7 @@
                             "--module-source-path", moduleSrc.toString());
                 assertFileExists(classes, "m1x", "api1", "Impl.class");
 
-                Files.delete(m1.resolve("test").resolve("Test.java"));
+                deleteFile(m1.resolve("test").resolve("Test.java"));
 
                 //resource class output:
                 runCompiler(base,
@@ -623,7 +623,7 @@
             assertFileExists(classes, "m1x", pack, "Pass.class");
             assertFileNotExists(classes, "m2x", pack, "Pass.class");
 
-            Files.delete(m1.resolve("test").resolve("Test.java"));
+            deleteFile(m1.resolve("test").resolve("Test.java"));
 
             runCompiler(base,
                         moduleSrc,
@@ -694,6 +694,36 @@
         }
     }
 
+    private void deleteFile(Path file) throws IOException {
+        long startTime = System.currentTimeMillis();
+
+        do {
+            Files.delete(file);
+            if (!Files.exists(file)) {
+                return;
+            }
+            System.err.println("!! File not deleted !!");
+            System.gc(); // allow finalizers and cleaners to run
+            try {
+                Thread.sleep(RETRY_DELETE_MILLIS);
+            } catch (InterruptedException e) {
+                throw new IOException("Interrupted while deleting " + file, e);
+            }
+        } while ((System.currentTimeMillis() - startTime) <= MAX_RETRY_DELETE_MILLIS);
+
+        throw new IOException("Can't delete " + file);
+    }
+
+
+    private static final int RETRY_DELETE_MILLIS;
+    private static final int MAX_RETRY_DELETE_MILLIS;
+
+    static {
+        boolean isWindows = System.getProperty("os.name").startsWith("Windows");
+        RETRY_DELETE_MILLIS = isWindows ? 500 : 0;
+        MAX_RETRY_DELETE_MILLIS = isWindows ? 15 * 1000 : 0;
+    }
+
     public static abstract class GeneratingAP extends AbstractProcessor {
 
         public void createSource(CreateFileObject file, String name, String content) {
@@ -842,7 +872,7 @@
                                 options);
                     assertFileExists(classes, modulePath, "impl", "Impl.class");
 
-                    Files.delete(m1.resolve("test").resolve("Test.java"));
+                    deleteFile(m1.resolve("test").resolve("Test.java"));
 
                     //resource class output:
                     runCompiler(base,
@@ -869,7 +899,7 @@
                     "expectFilerException(() -> filer.getResource(StandardLocation.SOURCE_PATH, \"m1x/impl\", \"resource\"))",
                     "-sourcepath", m1.toString());
 
-        Files.delete(m1.resolve("impl").resolve("resource"));
+        deleteFile(m1.resolve("impl").resolve("resource"));
 
         //can read resources from the system module path if module name given:
         runCompiler(base,
@@ -930,7 +960,7 @@
                         "-sourcepath", m1.toString());
         }
 
-        Files.delete(m1.resolve("module-info.java"));
+        deleteFile(m1.resolve("module-info.java"));
         tb.writeJavaFiles(m1,
                           "package test; class Test { }");