langtools/test/tools/javac/processing/filer/TestGetResource2.java
author darcy
Fri, 21 Dec 2012 08:45:43 -0800
changeset 14963 974d4423c999
parent 6720 f16f91662ad8
child 30730 d3ce7619db2c
permissions -rw-r--r--
8005282: Use @library tag with non-relative path for javac tests Reviewed-by: jjg
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
/*
6720
f16f91662ad8 6983738: Use a JavacTestingAbstractProcessor
darcy
parents: 6573
diff changeset
     2
 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
6573
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
14963
974d4423c999 8005282: Use @library tag with non-relative path for javac tests
darcy
parents: 6720
diff changeset
    27
 * @library /tools/javac/lib
6573
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
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    30
import java.io.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    31
import java.security.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    32
import java.util.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    33
import javax.annotation.processing.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    34
import javax.lang.model.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    35
import javax.lang.model.element.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    36
import javax.tools.*;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    37
import javax.tools.Diagnostic.Kind;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    38
import javax.tools.JavaCompiler.CompilationTask;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    39
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    40
public class TestGetResource2 {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    41
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    42
    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
    43
        new TestGetResource2().run();
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
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    46
    void run() throws Exception {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    47
        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    48
        CodeSource cs = javac.getClass().getProtectionDomain().getCodeSource();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    49
        if (cs == null) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    50
            System.err.println("got compiler from " +
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    51
                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
    52
        } else {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    53
            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
    54
        }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    55
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    56
        testSingleSourceDir(javac);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    57
        testCompositeSourcePath(javac);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    58
        testMissingResource(javac);
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
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    61
    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
    62
        System.err.println("testSingleSourceDir");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    63
        File tmpdir = new File("testSingleSourceDir");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    64
        File srcdir = new File(tmpdir, "src");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    65
        File destdir = new File(tmpdir, "dest");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    66
        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
    67
        write(srcdir, "resources/file.txt", "hello");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    68
        destdir.mkdirs();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    69
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    70
        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
    71
                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
    72
                Collections.singleton("pkg.X"), null);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    73
        task.setProcessors(Collections.singleton(new AnnoProc()));
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    74
        boolean result = task.call();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    75
        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
    76
        expect(result, true);
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
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    79
    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
    80
        System.err.println("testCompositeSearchPath");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    81
        File tmpdir = new File("testCompositeSourcePath");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    82
        File srcdir = new File(tmpdir, "src");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    83
        File rsrcdir = new File(tmpdir, "rsrc");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    84
        File destdir = new File(tmpdir, "dest");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    85
        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
    86
        write(rsrcdir, "resources/file.txt", "hello");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    87
        destdir.mkdirs();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    88
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    89
        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
    90
                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
    91
                Collections.singleton("pkg.X"), null);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    92
        task.setProcessors(Collections.singleton(new AnnoProc()));
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    93
        boolean result = task.call();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    94
        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
    95
        expect(result, true);
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
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
    98
    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
    99
        System.err.println("testMissingResource");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   100
        File tmpdir = new File("testMissingResource");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   101
        File srcdir = new File(tmpdir, "src");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   102
        File destdir = new File(tmpdir, "dest");
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   103
        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
   104
        destdir.mkdirs();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   105
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   106
        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
   107
                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
   108
                Collections.singleton("pkg.X"), null);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   109
        task.setProcessors(Collections.singleton(new AnnoProc()));
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   110
        boolean result = task.call();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   111
        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
   112
        expect(result, false);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   113
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   114
        if (errors > 0)
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   115
            throw new Exception(errors + " errors occurred");
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
6720
f16f91662ad8 6983738: Use a JavacTestingAbstractProcessor
darcy
parents: 6573
diff changeset
   118
    static class AnnoProc extends JavacTestingAbstractProcessor {
6573
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 {
6720
f16f91662ad8 6983738: Use a JavacTestingAbstractProcessor
darcy
parents: 6573
diff changeset
   126
                FileObject resource = filer.getResource(StandardLocation.SOURCE_PATH, "resources", "file.txt");
6573
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();
6720
f16f91662ad8 6983738: Use a JavacTestingAbstractProcessor
darcy
parents: 6573
diff changeset
   129
                    messager.printMessage(Kind.NOTE, "found: " + resource.toUri());
6573
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) {
6720
f16f91662ad8 6983738: Use a JavacTestingAbstractProcessor
darcy
parents: 6573
diff changeset
   132
                    messager.printMessage(Kind.ERROR, "could not read: " + resource.toUri());
6573
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) {
6720
f16f91662ad8 6983738: Use a JavacTestingAbstractProcessor
darcy
parents: 6573
diff changeset
   136
                messager.printMessage(Kind.ERROR, "did not find resource");
6573
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
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   144
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   145
    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
   146
        File f = new File(dir, path);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   147
        f.getParentFile().mkdirs();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   148
        Writer w = new FileWriter(f);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   149
        try {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   150
            w.write(contents);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   151
        } finally {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   152
            w.close();
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   153
        }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   154
        return f;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   155
    }
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   156
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   157
    void expect(boolean val, boolean expect) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   158
        if (val != expect)
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   159
            error("Unexpected value: " + val + "; expected: " + expect);
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
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   162
    void error(String msg) {
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   163
        System.err.println(msg);
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   164
        errors++;
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
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   167
    int errors = 0;
6bad8be140fc 6929404: Filer.getResource(SOURCE_PATH, ...) does not work when -sourcepath contains >1 entry
jjg
parents:
diff changeset
   168
}