langtools/test/tools/javadoc/api/basic/GetTask_DocletClassTest.java
changeset 27319 030080f03e4f
parent 14545 2e7bab0639b8
child 30730 d3ce7619db2c
equal deleted inserted replaced
27318:4660a5da7d90 27319:030080f03e4f
     1 /*
     1 /*
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 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.
    68         int key = r.nextInt();
    68         int key = r.nextInt();
    69         JavaFileObject srcFile = createSimpleJavaFileObject(
    69         JavaFileObject srcFile = createSimpleJavaFileObject(
    70                 "pkg/C",
    70                 "pkg/C",
    71                 "package pkg; /** " + key + "*/ public class C { }");
    71                 "package pkg; /** " + key + "*/ public class C { }");
    72         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    72         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    73         StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    73         try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
    74         File outDir = getOutDir();
    74             File outDir = getOutDir();
    75         fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    75             fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    76         Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    76             Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    77         DocumentationTask t = tool.getTask(null, fm, null, TestDoclet.class, null, files);
    77             DocumentationTask t = tool.getTask(null, fm, null, TestDoclet.class, null, files);
    78         if (t.call()) {
    78             if (t.call()) {
    79             System.err.println("task succeeded");
    79                 System.err.println("task succeeded");
    80             if (TestDoclet.lastCaller.equals(String.valueOf(key)))
    80                 if (TestDoclet.lastCaller.equals(String.valueOf(key)))
    81                 System.err.println("found expected key: " + key);
    81                     System.err.println("found expected key: " + key);
    82             else
    82                 else
    83                 error("Expected key not found");
    83                     error("Expected key not found");
    84             checkFiles(outDir, Collections.<String>emptySet());
    84                 checkFiles(outDir, Collections.<String>emptySet());
    85         } else {
    85             } else {
    86             throw new Exception("task failed");
    86                 throw new Exception("task failed");
       
    87             }
    87         }
    88         }
    88     }
    89     }
    89 
    90 
    90     public static class TestDoclet {
    91     public static class TestDoclet {
    91         static String lastCaller;
    92         static String lastCaller;
   113      */
   114      */
   114     @Test
   115     @Test
   115     public void testBadDoclet() throws Exception {
   116     public void testBadDoclet() throws Exception {
   116         JavaFileObject srcFile = createSimpleJavaFileObject();
   117         JavaFileObject srcFile = createSimpleJavaFileObject();
   117         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
   118         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
   118         StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
   119         try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
   119         File outDir = getOutDir();
   120             File outDir = getOutDir();
   120         fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
   121             fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
   121         Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
   122             Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
   122         DocumentationTask t = tool.getTask(null, fm, null, BadDoclet.class, null, files);
   123             DocumentationTask t = tool.getTask(null, fm, null, BadDoclet.class, null, files);
   123         try {
   124             try {
   124             t.call();
   125                 t.call();
   125             error("call completed without exception");
   126                 error("call completed without exception");
   126         } catch (RuntimeException e) {
   127             } catch (RuntimeException e) {
   127             Throwable c = e.getCause();
   128                 Throwable c = e.getCause();
   128             if (c.getClass() == UnexpectedError.class)
   129                 if (c.getClass() == UnexpectedError.class)
   129                 System.err.println("exception caught as expected: " + c);
   130                     System.err.println("exception caught as expected: " + c);
   130             else
   131                 else
   131                 throw e;
   132                     throw e;
       
   133             }
   132         }
   134         }
   133     }
   135     }
   134 
   136 
   135     public static class UnexpectedError extends Error { }
   137     public static class UnexpectedError extends Error { }
   136 
   138