langtools/test/lib/combo/tools/javac/combo/JavacTemplateTestBase.java
changeset 27388 d694da45bd7a
parent 19931 f82b95ab8015
child 34752 9c262a013456
equal deleted inserted replaced
27387:54142fc27e8a 27388:d694da45bd7a
     1 /*
     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   243         return compile(classpaths, files, generate);
   243         return compile(classpaths, files, generate);
   244     }
   244     }
   245 
   245 
   246     private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
   246     private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
   247         JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
   247         JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
   248         StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null);
   248         try (StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null)) {
   249         if (classpaths.size() > 0)
   249             if (classpaths.size() > 0)
   250             fm.setLocation(StandardLocation.CLASS_PATH, classpaths);
   250                 fm.setLocation(StandardLocation.CLASS_PATH, classpaths);
   251         JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files);
   251             JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files);
   252         if (generate) {
   252             if (generate) {
   253             File destDir = new File(root, Integer.toString(counter.incrementAndGet()));
   253                 File destDir = new File(root, Integer.toString(counter.incrementAndGet()));
   254             // @@@ Assert that this directory didn't exist, or start counter at max+1
   254                 // @@@ Assert that this directory didn't exist, or start counter at max+1
   255             destDir.mkdirs();
   255                 destDir.mkdirs();
   256             fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
   256                 fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
   257             ct.generate();
   257                 ct.generate();
   258             return destDir;
   258                 return destDir;
   259         }
   259             }
   260         else {
   260             else {
   261             ct.analyze();
   261                 ct.analyze();
   262             return nullDir;
   262                 return nullDir;
       
   263             }
   263         }
   264         }
   264     }
   265     }
   265 
   266 
   266     /** Load the given class using the provided list of class paths */
   267     /** Load the given class using the provided list of class paths */
   267     protected Class<?> loadClass(String className, File... destDirs) {
   268     protected Class<?> loadClass(String className, File... destDirs) {