langtools/test/tools/javac/processing/filer/TestGetResource2.java
changeset 6720 f16f91662ad8
parent 6573 6bad8be140fc
child 14963 974d4423c999
equal deleted inserted replaced
6719:1ce993f87850 6720:f16f91662ad8
     1 /*
     1 /*
     2  * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2010, 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.
    22  */
    22  */
    23 
    23 
    24 /* @test
    24 /* @test
    25  * @bug 6929404
    25  * @bug 6929404
    26  * @summary Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
    26  * @summary Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
       
    27  * @library ../../lib
    27  */
    28  */
    28 
    29 
    29 import java.io.*;
    30 import java.io.*;
    30 import java.security.*;
    31 import java.security.*;
    31 import java.util.*;
    32 import java.util.*;
   112 
   113 
   113         if (errors > 0)
   114         if (errors > 0)
   114             throw new Exception(errors + " errors occurred");
   115             throw new Exception(errors + " errors occurred");
   115     }
   116     }
   116 
   117 
   117     @SupportedAnnotationTypes("*")
   118     static class AnnoProc extends JavacTestingAbstractProcessor {
   118     static class AnnoProc extends AbstractProcessor {
       
   119 
   119 
   120         public @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   120         public @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
   121             if (roundEnv.processingOver()) {
   121             if (roundEnv.processingOver()) {
   122                 return false;
   122                 return false;
   123             }
   123             }
   124 
   124 
   125             try {
   125             try {
   126                 FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "resources", "file.txt");
   126                 FileObject resource = filer.getResource(StandardLocation.SOURCE_PATH, "resources", "file.txt");
   127                 try {
   127                 try {
   128                     resource.openInputStream().close();
   128                     resource.openInputStream().close();
   129                     processingEnv.getMessager().printMessage(Kind.NOTE, "found: " + resource.toUri());
   129                     messager.printMessage(Kind.NOTE, "found: " + resource.toUri());
   130                     return true;
   130                     return true;
   131                 } catch (IOException x) {
   131                 } catch (IOException x) {
   132                     processingEnv.getMessager().printMessage(Kind.ERROR, "could not read: " + resource.toUri());
   132                     messager.printMessage(Kind.ERROR, "could not read: " + resource.toUri());
   133                     x.printStackTrace();
   133                     x.printStackTrace();
   134                 }
   134                 }
   135             } catch (IOException x) {
   135             } catch (IOException x) {
   136                 processingEnv.getMessager().printMessage(Kind.ERROR, "did not find resource");
   136                 messager.printMessage(Kind.ERROR, "did not find resource");
   137                 x.printStackTrace();
   137                 x.printStackTrace();
   138             }
   138             }
   139 
   139 
   140             return false;
   140             return false;
   141         }
   141         }
   142 
   142 
   143         @Override
       
   144         public SourceVersion getSupportedSourceVersion() {
       
   145             return SourceVersion.latest();
       
   146         }
       
   147     }
   143     }
   148 
   144 
   149     private File write(File dir, String path, String contents) throws IOException {
   145     private File write(File dir, String path, String contents) throws IOException {
   150         File f = new File(dir, path);
   146         File f = new File(dir, path);
   151         f.getParentFile().mkdirs();
   147         f.getParentFile().mkdirs();