test/tools/javac/api/lib/ToolTester.java

changeset 1733
e39669aea0bd
parent 554
9d9f26857129
child 2525
2eb010b6cb22
     1.1 --- a/test/tools/javac/api/lib/ToolTester.java	Fri May 10 14:31:42 2013 -0700
     1.2 +++ b/test/tools/javac/api/lib/ToolTester.java	Sun May 12 18:18:54 2013 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -24,7 +24,7 @@
    1.11  import java.io.File;
    1.12  import java.io.IOException;
    1.13  import java.nio.charset.Charset;
    1.14 -import java.util.Arrays;
    1.15 +import java.util.*;
    1.16  import javax.tools.*;
    1.17  
    1.18  import static javax.tools.StandardLocation.CLASS_PATH;
    1.19 @@ -34,6 +34,8 @@
    1.20  public class ToolTester {
    1.21      public final File test_src     = new File(System.getProperty("test.src", "."));
    1.22      public final File test_classes = new File(System.getProperty("test.classes", "."));
    1.23 +    public final List<File> test_class_path = pathToFiles(System.getProperty("test.class.path"),
    1.24 +                                     Arrays.asList(test_classes));
    1.25      public final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    1.26      public final StandardJavaFileManager fm = getFileManager(tool, null, null);
    1.27      public JavaCompiler.CompilationTask task = null;
    1.28 @@ -43,11 +45,36 @@
    1.29          StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, encoding);
    1.30          try {
    1.31              fm.setLocation(SOURCE_PATH,  Arrays.asList(test_src));
    1.32 -            fm.setLocation(CLASS_PATH,   Arrays.asList(test_classes));
    1.33 +            fm.setLocation(CLASS_PATH,   test_class_path);
    1.34              fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
    1.35          } catch (IOException e) {
    1.36              throw new AssertionError(e);
    1.37          }
    1.38          return fm;
    1.39      }
    1.40 +
    1.41 +    protected List<File> pathToFiles(String path, List<File> defaultPath) {
    1.42 +        List<File> files = new ArrayList<>();
    1.43 +        for (String f: path.split(File.pathSeparator)) {
    1.44 +            if (f.isEmpty())
    1.45 +                continue;
    1.46 +            File file = new File(f);
    1.47 +            if (file.exists())
    1.48 +                files.add(file);
    1.49 +        }
    1.50 +        if (files.isEmpty())
    1.51 +            files.addAll(defaultPath);
    1.52 +        return files;
    1.53 +    }
    1.54 +
    1.55 +    protected <T> List<T> join(List<T> a, List<T> b) {
    1.56 +        if (a.isEmpty())
    1.57 +            return b;
    1.58 +        if (b.isEmpty())
    1.59 +            return a;
    1.60 +        List<T> result = new ArrayList<>();
    1.61 +        result.addAll(a);
    1.62 +        result.addAll(b);
    1.63 +        return result;
    1.64 +    }
    1.65  }

mercurial