changeset 225:e7bdce583a72

Test generator should only overwrite when differences are detected.
author shade
date Fri, 06 May 2016 14:18:33 +0300
parents d0c6cd011ea0
children 586f4a89c984
files jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter0aTestGenerator.java
diffstat 1 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter0aTestGenerator.java	Fri May 06 14:10:34 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/Chapter0aTestGenerator.java	Fri May 06 14:18:33 2016 +0300
@@ -33,6 +33,7 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.*;
+import java.util.stream.Collectors;
 
 public class Chapter0aTestGenerator {
 
@@ -185,7 +186,24 @@
         Path dir = Paths.get(destination, pkg.replaceAll("\\.", File.separator));
         Path file = Paths.get(destination, pkg.replaceAll("\\.", File.separator), name + ".java");
         Files.createDirectories(dir);
-        Files.write(file, Arrays.asList(contents), Charset.defaultCharset());
+
+        boolean doWrite = true;
+        try {
+            List<String> l = Files.readAllLines(file);
+            String exists = l.stream().collect(Collectors.joining(System.lineSeparator()));
+            if (contents.equals(exists)) {
+                doWrite = false;
+            }
+        } catch (IOException e) {
+            // Moving on...
+        }
+
+        if (doWrite) {
+            System.out.println("Generating: " + file);
+            Files.write(file, Arrays.asList(contents), Charset.defaultCharset());
+        } else {
+            System.out.println("Skip, no modifications: " + file);
+        }
     }
 
     private static String readFromResource(String name) throws IOException {