test/tools/javadoc/api/basic/GetTask_FileManagerTest.java

changeset 1413
bdcef2ef52d2
child 2010
64328fe5e4a6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javadoc/api/basic/GetTask_FileManagerTest.java	Thu Nov 15 23:07:24 2012 -0800
     1.3 @@ -0,0 +1,111 @@
     1.4 +/*
     1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 6493690
    1.30 + * @summary javadoc should have a javax.tools.Tool service provider
    1.31 + * @build APITest
    1.32 + * @run main GetTask_FileManagerTest
    1.33 + */
    1.34 +
    1.35 +import java.io.IOException;
    1.36 +import java.nio.file.Path;
    1.37 +import java.util.Arrays;
    1.38 +import java.util.Set;
    1.39 +
    1.40 +import javax.tools.DocumentationTool;
    1.41 +import javax.tools.DocumentationTool.DocumentationTask;
    1.42 +import javax.tools.JavaFileObject;
    1.43 +import javax.tools.JavaFileObject.Kind;
    1.44 +import javax.tools.ToolProvider;
    1.45 +
    1.46 +import com.sun.tools.javac.nio.JavacPathFileManager;
    1.47 +import com.sun.tools.javac.nio.PathFileManager;
    1.48 +import com.sun.tools.javac.util.Context;
    1.49 +
    1.50 +/**
    1.51 + * Tests for DocumentationTool.getTask  fileManager  parameter.
    1.52 + */
    1.53 +public class GetTask_FileManagerTest extends APITest {
    1.54 +    public static void main(String... args) throws Exception {
    1.55 +        new GetTask_FileManagerTest().run();
    1.56 +    }
    1.57 +
    1.58 +    /**
    1.59 +     * Verify that an alternate file manager can be specified:
    1.60 +     * in this case, a PathFileManager.
    1.61 +     */
    1.62 +    @Test
    1.63 +    public void testFileManager() throws Exception {
    1.64 +        JavaFileObject srcFile = createSimpleJavaFileObject();
    1.65 +        DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    1.66 +        PathFileManager fm = new JavacPathFileManager(new Context(), false, null);
    1.67 +        Path outDir = getOutDir().toPath();
    1.68 +        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    1.69 +        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    1.70 +        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
    1.71 +        if (t.call()) {
    1.72 +            System.err.println("task succeeded");
    1.73 +            checkFiles(outDir, standardExpectFiles);
    1.74 +        } else {
    1.75 +            throw new Exception("task failed");
    1.76 +        }
    1.77 +    }
    1.78 +
    1.79 +    /**
    1.80 +     * Verify that exceptions from a bad file manager are thrown as expected.
    1.81 +     */
    1.82 +    @Test
    1.83 +    public void testBadFileManager() throws Exception {
    1.84 +        JavaFileObject srcFile = createSimpleJavaFileObject();
    1.85 +        DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    1.86 +        PathFileManager fm = new JavacPathFileManager(new Context(), false, null) {
    1.87 +            @Override
    1.88 +            public Iterable<JavaFileObject> list(Location location,
    1.89 +                    String packageName,
    1.90 +                    Set<Kind> kinds,
    1.91 +                    boolean recurse)
    1.92 +                    throws IOException {
    1.93 +                throw new UnexpectedError();
    1.94 +            }
    1.95 +        };
    1.96 +        Path outDir = getOutDir().toPath();
    1.97 +        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    1.98 +        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    1.99 +        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
   1.100 +        try {
   1.101 +            t.call();
   1.102 +            error("call completed without exception");
   1.103 +        } catch (RuntimeException e) {
   1.104 +            Throwable c = e.getCause();
   1.105 +            if (c.getClass() == UnexpectedError.class)
   1.106 +                System.err.println("exception caught as expected: " + c);
   1.107 +            else
   1.108 +                throw e;
   1.109 +        }
   1.110 +    }
   1.111 +
   1.112 +    public static class UnexpectedError extends Error { }
   1.113 +
   1.114 +}

mercurial