langtools/test/tools/javac/processing/filer/TestGetResource2.java
author jjg
Tue, 24 Aug 2010 15:09:21 -0700
changeset 6573 6bad8be140fc
child 6720 f16f91662ad8
permissions -rw-r--r--
6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6573
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     1
/*
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     2
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     4
 *
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     8
 *
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    13
 * accompanied this code).
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    14
 *
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    18
 *
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    21
 * questions.
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    22
 */
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    23
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    24
/* @test
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    25
 * @bug 6929404
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    26
 * @summary Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    27
 */
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    28
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    29
import java.io.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    30
import java.security.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    31
import java.util.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    32
import javax.annotation.processing.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    33
import javax.lang.model.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    34
import javax.lang.model.element.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    35
import javax.tools.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    36
import javax.tools.Diagnostic.Kind;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    37
import javax.tools.JavaCompiler.CompilationTask;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    38
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    39
public class TestGetResource2 {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    40
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    42
        new TestGetResource2().run();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    43
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    44
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    45
    void run() throws Exception {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    46
        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    47
        CodeSource cs = javac.getClass().getProtectionDomain().getCodeSource();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    48
        if (cs == null) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    49
            System.err.println("got compiler from " +
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    50
                ClassLoader.getSystemResource(javac.getClass().getName().replace(".", "/")+".class"));
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    51
        } else {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    52
            System.err.println("got compiler from " + cs.getLocation());
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    53
        }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    54
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    55
        testSingleSourceDir(javac);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    56
        testCompositeSourcePath(javac);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    57
        testMissingResource(javac);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    58
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    59
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    60
    private void testSingleSourceDir(JavaCompiler javac) throws Exception {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    61
        System.err.println("testSingleSourceDir");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    62
        File tmpdir = new File("testSingleSourceDir");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    63
        File srcdir = new File(tmpdir, "src");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    64
        File destdir = new File(tmpdir, "dest");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    65
        write(srcdir, "pkg/X.java", "package pkg; class X {}");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    66
        write(srcdir, "resources/file.txt", "hello");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    67
        destdir.mkdirs();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    68
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    69
        CompilationTask task = javac.getTask(null, null, null,
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    70
                Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()),
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    71
                Collections.singleton("pkg.X"), null);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    72
        task.setProcessors(Collections.singleton(new AnnoProc()));
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    73
        boolean result = task.call();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    74
        System.err.println("javac result with single source dir: " + result);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    75
        expect(result, true);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    76
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    77
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    78
    private void testCompositeSourcePath(JavaCompiler javac) throws Exception {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    79
        System.err.println("testCompositeSearchPath");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    80
        File tmpdir = new File("testCompositeSourcePath");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    81
        File srcdir = new File(tmpdir, "src");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    82
        File rsrcdir = new File(tmpdir, "rsrc");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    83
        File destdir = new File(tmpdir, "dest");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    84
        write(srcdir, "pkg/X.java", "package pkg; class X {}");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    85
        write(rsrcdir, "resources/file.txt", "hello");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    86
        destdir.mkdirs();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    87
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    88
        CompilationTask task = javac.getTask(null, null, null,
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    89
                Arrays.asList("-sourcepath", srcdir + File.pathSeparator + rsrcdir, "-d", destdir.toString()),
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    90
                Collections.singleton("pkg.X"), null);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    91
        task.setProcessors(Collections.singleton(new AnnoProc()));
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    92
        boolean result = task.call();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    93
        System.err.println("javac result with composite source path: " + result);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    94
        expect(result, true);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    95
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    96
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    97
    private void testMissingResource(JavaCompiler javac) throws Exception {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    98
        System.err.println("testMissingResource");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    99
        File tmpdir = new File("testMissingResource");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   100
        File srcdir = new File(tmpdir, "src");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   101
        File destdir = new File(tmpdir, "dest");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   102
        write(srcdir, "pkg/X.java", "package pkg; class X {}");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   103
        destdir.mkdirs();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   104
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   105
        CompilationTask task = javac.getTask(null, null, null,
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   106
                Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()),
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   107
                Collections.singleton("pkg.X"), null);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   108
        task.setProcessors(Collections.singleton(new AnnoProc()));
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   109
        boolean result = task.call();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   110
        System.err.println("javac result when missing resource: " + result);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   111
        expect(result, false);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   112
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   113
        if (errors > 0)
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   114
            throw new Exception(errors + " errors occurred");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   115
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   116
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   117
    @SupportedAnnotationTypes("*")
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   118
    static class AnnoProc extends AbstractProcessor {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   119
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   120
        public @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   121
            if (roundEnv.processingOver()) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   122
                return false;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   123
            }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   124
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   125
            try {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   126
                FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "resources", "file.txt");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   127
                try {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   128
                    resource.openInputStream().close();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   129
                    processingEnv.getMessager().printMessage(Kind.NOTE, "found: " + resource.toUri());
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   130
                    return true;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   131
                } catch (IOException x) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   132
                    processingEnv.getMessager().printMessage(Kind.ERROR, "could not read: " + resource.toUri());
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   133
                    x.printStackTrace();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   134
                }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   135
            } catch (IOException x) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   136
                processingEnv.getMessager().printMessage(Kind.ERROR, "did not find resource");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   137
                x.printStackTrace();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   138
            }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   139
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   140
            return false;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   141
        }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   142
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   143
        @Override
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   144
        public SourceVersion getSupportedSourceVersion() {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   145
            return SourceVersion.latest();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   146
        }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   147
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   148
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   149
    private File write(File dir, String path, String contents) throws IOException {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   150
        File f = new File(dir, path);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   151
        f.getParentFile().mkdirs();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   152
        Writer w = new FileWriter(f);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   153
        try {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   154
            w.write(contents);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   155
        } finally {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   156
            w.close();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   157
        }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   158
        return f;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   159
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   160
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   161
    void expect(boolean val, boolean expect) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   162
        if (val != expect)
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   163
            error("Unexpected value: " + val + "; expected: " + expect);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   164
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   165
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   166
    void error(String msg) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   167
        System.err.println(msg);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   168
        errors++;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   169
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   170
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   171
    int errors = 0;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   172
}