langtools/test/tools/apt/Basics/CheckAptIsRemovedTest.java
changeset 27579 d1a63c99cdd5
parent 27578 d61af14a5cf7
child 27580 ca12cdda0551
equal deleted inserted replaced
27578:d61af14a5cf7 27579:d1a63c99cdd5
     1 /*
       
     2  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     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
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 4908512 5024825 4957203 4993280 4996963 6174696 6177059 7041249
       
    27  * @summary Make sure apt is removed and doesn't come back
       
    28  * @library /tools/lib
       
    29  * @build ToolBox
       
    30  * @run main CheckAptIsRemovedTest
       
    31  */
       
    32 
       
    33 import java.nio.file.Files;
       
    34 import java.nio.file.Path;
       
    35 import java.nio.file.Paths;
       
    36 
       
    37 // Original test: test/tools/apt/Basics/apt.sh
       
    38 public class CheckAptIsRemovedTest {
       
    39     //I think this class can be let with the imports only and that should be enough for as test's purpose
       
    40     private static final String NullAPFSrc =
       
    41         "import com.sun.mirror.apt.*;\n" +
       
    42         "import com.sun.mirror.declaration.*;\n" +
       
    43         "import com.sun.mirror.type.*;\n" +
       
    44         "import com.sun.mirror.util.*;\n" +
       
    45         "import java.util.Collection;\n" +
       
    46         "import java.util.Set;\n\n" +
       
    47 
       
    48         "public class NullAPF implements AnnotationProcessorFactory {\n" +
       
    49         "    static class NullAP implements AnnotationProcessor {\n" +
       
    50         "        NullAP(AnnotationProcessorEnvironment ape) {}\n" +
       
    51         "        public void process() {return;}\n" +
       
    52         "    }\n\n" +
       
    53 
       
    54         "    static Collection<String> supportedTypes;\n\n" +
       
    55         "    static {\n" +
       
    56         "        String types[] = {\"*\"};\n" +
       
    57         "        supportedTypes = java.util.Arrays.asList(types);\n" +
       
    58         "    }\n\n" +
       
    59 
       
    60         "    public Collection<String> supportedOptions() {\n" +
       
    61         "        return java.util.Collections.emptySet();\n" +
       
    62         "    }\n\n" +
       
    63 
       
    64         "    public Collection<String> supportedAnnotationTypes() {\n" +
       
    65         "        return supportedTypes;\n" +
       
    66         "    }\n\n" +
       
    67 
       
    68         "    public AnnotationProcessor getProcessorFor(" +
       
    69         "        Set<AnnotationTypeDeclaration> atds,\n" +
       
    70         "        AnnotationProcessorEnvironment env) {\n" +
       
    71         "        return new NullAP(env);\n" +
       
    72         "    }\n" +
       
    73         "}";
       
    74 
       
    75     public static void main(String[] args) throws Exception {
       
    76         String testJDK = System.getProperty("test.jdk");
       
    77         Path aptLin = Paths.get(testJDK, "bin", "apt");
       
    78         Path aptWin = Paths.get(testJDK, "bin", "apt.exe");
       
    79 
       
    80         if (Files.exists(aptLin) || Files.exists(aptWin)) {
       
    81             throw new AssertionError("apt executable should not exist");
       
    82         }
       
    83 
       
    84         Path classpath = Paths.get(testJDK, "lib", "tools.jar");
       
    85         ToolBox tb = new ToolBox();
       
    86         tb.new JavacTask()
       
    87                 .classpath(classpath.toString()) // TODO: add overload
       
    88                 .sourcepath(".")
       
    89                 .sources(NullAPFSrc)
       
    90                 .run(ToolBox.Expect.FAIL)
       
    91                 .writeAll();
       
    92     }
       
    93 
       
    94 }