changeset 304:b937698bcb0c

Generators: use java.nio.Path to create/resolve directories. This fixes Windows build failures.
author shade
date Tue, 05 Jul 2016 14:42:47 +0300
parents f7369d2f8c41
children 41007cd99ae8
files jcstress-test-gen/src/main/java/org/openjdk/jcstress/TestGenMain.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/GeneratorUtils.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/ResultGenerator.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/TestGenerator.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/Utils.java jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java
diffstat 6 files changed, 34 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/TestGenMain.java	Thu Jun 30 13:38:25 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/TestGenMain.java	Tue Jul 05 14:42:47 2016 +0300
@@ -26,11 +26,11 @@
 
 import org.openjdk.jcstress.generator.TestGenerator;
 
-import java.io.FileNotFoundException;
+import java.io.IOException;
 
 public class TestGenMain {
 
-    public static void main(String[] args) throws FileNotFoundException {
+    public static void main(String[] args) throws IOException {
         if (args.length >= 2) {
             new TestGenerator(args[0], args[1]).run();
         } else {
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/GeneratorUtils.java	Thu Jun 30 13:38:25 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/chapters/GeneratorUtils.java	Tue Jul 05 14:42:47 2016 +0300
@@ -35,8 +35,8 @@
 
 public class GeneratorUtils {
     static void writeOut(String destination, String pkg, String name, String contents) throws IOException {
-        Path dir = Paths.get(destination, pkg.replaceAll("\\.", File.separator));
-        Path file = Paths.get(destination, pkg.replaceAll("\\.", File.separator), name + ".java");
+        Path dir = Paths.get(destination, pkg.split("\\."));
+        Path file = dir.resolve(name + ".java");
         Files.createDirectories(dir);
 
         boolean doWrite = true;
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/ResultGenerator.java	Thu Jun 30 13:38:25 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/ResultGenerator.java	Tue Jul 05 14:42:47 2016 +0300
@@ -24,8 +24,11 @@
  */
 package org.openjdk.jcstress.generator;
 
-import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -55,12 +58,13 @@
         if (!generatedResults.add(name))
             return name;
 
-        String pathname = Utils.ensureDir(srcRoot + "/" + "org.openjdk.jcstress.infra.results.".replaceAll("\\.", "/"));
-
-        PrintWriter pw = null;
+        PrintWriter pw;
         try {
-            pw = new PrintWriter(pathname + "/" + name + ".java");
-        } catch (FileNotFoundException e) {
+            Path dir = Paths.get(srcRoot, "org.openjdk.jcstress.infra.results.".split("\\."));
+            Path file = dir.resolve(name + ".java");
+            Files.createDirectories(dir);
+            pw = new PrintWriter(file.toFile());
+        } catch (IOException e) {
             throw new IllegalStateException(e);
         }
 
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/TestGenerator.java	Thu Jun 30 13:38:25 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/TestGenerator.java	Tue Jul 05 14:42:47 2016 +0300
@@ -24,8 +24,11 @@
  */
 package org.openjdk.jcstress.generator;
 
-import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
@@ -48,11 +51,11 @@
         this.resultGenerator = new ResultGenerator(srcRoot);
     }
 
-    public void run() throws FileNotFoundException {
+    public void run() throws IOException {
         generateMemoryEffects();
     }
 
-    public void generateMemoryEffects() throws FileNotFoundException {
+    public void generateMemoryEffects() throws IOException {
         for (Class<?> varType : Types.SUPPORTED_PRIMITIVES) {
             for (Class<?> guardType : Types.SUPPORTED_PRIMITIVES) {
                 generate(new Types(guardType, varType), new VolatileReadWrite(guardType), "volatile_" + guardType + "_" + varType, "org.openjdk.jcstress.tests.memeffects.basic.volatiles");
@@ -96,12 +99,13 @@
         }
     }
 
-   public void generate(Types types, Primitive prim, String klass, String pkg) throws FileNotFoundException {
+   public void generate(Types types, Primitive prim, String klass, String pkg) throws IOException {
         String resultName = resultGenerator.generateResult(types);
 
-        String pathname = Utils.ensureDir(srcRoot + "/" + pkg.replaceAll("\\.", "/"));
-
-        PrintWriter pw = new PrintWriter(pathname + "/" + klass + ".java");
+        Path dir = Paths.get(srcRoot, pkg.split("\\."));
+        Path file = dir.resolve(klass + ".java");
+        Files.createDirectories(dir);
+        PrintWriter pw = new PrintWriter(file.toFile());
 
         pw.println("package " + pkg +";");
         pw.println();
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/Utils.java	Thu Jun 30 13:38:25 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2005, 2014, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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 org.openjdk.jcstress.generator;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-public class Utils {
-    public static String ensureDir(String path) {
-        File file = new File(path);
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        return file.getAbsolutePath();
-    }
-
-    public static <T> List<List<T>> permutate(List<T> src) {
-        if (src.size() <= 1) {
-            List<List<T>> al = new ArrayList<>();
-            al.add(src);
-            return al;
-        }
-
-        List<List<T>> result = new ArrayList<>();
-        for (int i = 0; i < src.size(); i++) {
-            List<T> copy = new ArrayList<>(src);
-            T el = copy.remove(i);
-
-            for (List<T> perm : permutate(copy)) {
-                List<T> c = new ArrayList<>(perm);
-                c.add(0, el);
-                result.add(c);
-            }
-        }
-
-        return result;
-    }
-
-
-}
--- a/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java	Thu Jun 30 13:38:25 2016 +0300
+++ b/jcstress-test-gen/src/main/java/org/openjdk/jcstress/generator/seqcst/SeqCstTraceGenerator.java	Tue Jul 05 14:42:47 2016 +0300
@@ -26,10 +26,12 @@
 
 import org.openjdk.jcstress.generator.ResultGenerator;
 import org.openjdk.jcstress.generator.TestGenerator;
-import org.openjdk.jcstress.generator.Utils;
 
-import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -168,8 +170,6 @@
     }
 
     private void emit(MultiThread mt, Collection<TraceResult> scResults) {
-        String pathname = Utils.ensureDir(srcDir + "/" + pkg.replaceAll("\\.", "/"));
-
         String klass = mt.canonicalId() + "_Test";
 
         Class[] klasses = new Class[mt.loadCount() + mt.allVariables().size()];
@@ -181,8 +181,11 @@
 
         PrintWriter pw;
         try {
-            pw = new PrintWriter(pathname + "/" + klass + ".java");
-        } catch (FileNotFoundException e) {
+            Path dir = Paths.get(srcDir, pkg.split("\\."));
+            Path file = dir.resolve(klass + ".java");
+            Files.createDirectories(dir);
+            pw = new PrintWriter(file.toFile());
+        } catch (IOException e) {
             throw new IllegalStateException(e);
         }