langtools/test/tools/javac/ClassPathTest/ClassPathTest.java
changeset 16549 1bdeedb5446c
parent 16304 475504933a2d
child 26100 bb7dd001d190
equal deleted inserted replaced
16548:d55a654e2751 16549:1bdeedb5446c
    29  * @build ToolBox
    29  * @build ToolBox
    30  * @run main ClassPathTest
    30  * @run main ClassPathTest
    31  */
    31  */
    32 
    32 
    33 import java.nio.file.Paths;
    33 import java.nio.file.Paths;
       
    34 import java.util.ArrayList;
       
    35 import java.util.Arrays;
       
    36 import java.util.List;
    34 import java.util.Map;
    37 import java.util.Map;
    35 import java.util.TreeMap;
    38 import java.util.TreeMap;
    36 import com.sun.tools.javac.util.ArrayUtils;
       
    37 
    39 
    38 //original test: test/tools/javac/ClassPathTest/ClassPathTest.sh
    40 //original test: test/tools/javac/ClassPathTest/ClassPathTest.sh
    39 public class ClassPathTest {
    41 public class ClassPathTest {
    40 
    42 
    41     private static final String ClassPathTest1Src =
    43     private static final String ClassPathTest1Src =
    90                 barPkgClassPathTestAux2Src);
    92                 barPkgClassPathTestAux2Src);
    91         ToolBox.createJavaFileFromSource(pkgClassPathTestAux3Src);
    93         ToolBox.createJavaFileFromSource(pkgClassPathTestAux3Src);
    92     }
    94     }
    93 
    95 
    94     void checkCompileCommands() throws Exception {
    96     void checkCompileCommands() throws Exception {
    95         String[] mainArgs = ToolBox.getJavacBin();
       
    96 
       
    97 //        Without the -cp . parameter the command will fail seems like when called
    97 //        Without the -cp . parameter the command will fail seems like when called
    98 //        from the command line, the current dir is added to the classpath
    98 //        from the command line, the current dir is added to the classpath
    99 //        automatically but this is not happening when called using ProcessBuilder
    99 //        automatically but this is not happening when called using ProcessBuilder
   100 
   100 
   101 //        testJavac success ClassPathTest3.java
   101 //        testJavac success ClassPathTest3.java
   102         String[] commonArgs = ArrayUtils.concatOpen(mainArgs, "-cp", ".");
   102         List<String> mainArgs = new ArrayList<>();
       
   103         mainArgs.add(ToolBox.javacBinary.toString());
       
   104         if (ToolBox.testToolVMOpts != null) {
       
   105             mainArgs.addAll(ToolBox.testToolVMOpts);
       
   106         }
   103 
   107 
   104         ToolBox.AnyToolArgs successParams =
   108         List<String> commonArgs = new ArrayList<>();
   105                 new ToolBox.AnyToolArgs()
   109         commonArgs.addAll(mainArgs);
   106                 .setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest3.java"));
   110         commonArgs.addAll(Arrays.asList("-cp", "."));
       
   111 
       
   112         ToolBox.AnyToolArgs successParams = new ToolBox.AnyToolArgs()
       
   113                 .appendArgs(commonArgs)
       
   114                 .appendArgs("ClassPathTest3.java");
   107         ToolBox.executeCommand(successParams);
   115         ToolBox.executeCommand(successParams);
   108 
   116 
   109 //        testJavac failure ClassPathTest1.java
   117 //        testJavac failure ClassPathTest1.java
   110         ToolBox.AnyToolArgs failParams =
   118         ToolBox.AnyToolArgs failParams =
   111                 new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
   119                 new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
   112                 .setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest1.java"));
   120                 .appendArgs(commonArgs)
       
   121                 .appendArgs("ClassPathTest1.java");
   113         ToolBox.executeCommand(failParams);
   122         ToolBox.executeCommand(failParams);
   114 
   123 
   115 //        This is done inside the executeCommand method
   124 //        This is done inside the executeCommand method
   116 //        CLASSPATH=bar; export CLASSPATH
   125 //        CLASSPATH=bar; export CLASSPATH
   117 
   126 
   118         Map<String, String> extVars = new TreeMap<>();
   127         Map<String, String> extVars = new TreeMap<>();
   119         extVars.put("CLASSPATH", "bar");
   128         extVars.put("CLASSPATH", "bar");
   120 
   129 
   121 //        testJavac success ClassPathTest2.java
   130 //        testJavac success ClassPathTest2.java
   122         successParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest2.java")).set(extVars);
   131         successParams = new ToolBox.AnyToolArgs()
       
   132                 .appendArgs(mainArgs)
       
   133                 .appendArgs("ClassPathTest2.java")
       
   134                 .set(extVars);
   123         ToolBox.executeCommand(successParams);
   135         ToolBox.executeCommand(successParams);
   124 
   136 
   125 //        testJavac failure ClassPathTest1.java
   137 //        testJavac failure ClassPathTest1.java
   126         failParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest1.java")).set(extVars);
   138         failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
       
   139                 .appendArgs(mainArgs)
       
   140                 .appendArgs("ClassPathTest1.java")
       
   141                 .set(extVars);
   127         ToolBox.executeCommand(failParams);
   142         ToolBox.executeCommand(failParams);
   128 
   143 
   129 //        testJavac failure ClassPathTest3.java
   144 //        testJavac failure ClassPathTest3.java
   130         failParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest3.java"));
   145         failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
       
   146                 .appendArgs(mainArgs)
       
   147                 .appendArgs("ClassPathTest3.java")
       
   148                 .set(extVars);
   131         ToolBox.executeCommand(failParams);
   149         ToolBox.executeCommand(failParams);
   132 
   150 
   133 //        testJavac success -classpath foo ClassPathTest1.java
   151 //        testJavac success -classpath foo ClassPathTest1.java
   134 
   152 
   135         commonArgs = ArrayUtils.concatOpen(mainArgs, "-cp", "foo");
   153         commonArgs.clear();
   136         successParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest1.java"));
   154         commonArgs.addAll(mainArgs);
       
   155         commonArgs.addAll(Arrays.asList("-cp", "foo"));
       
   156 
       
   157         successParams = new ToolBox.AnyToolArgs()
       
   158                 .appendArgs(commonArgs)
       
   159                 .appendArgs("ClassPathTest1.java")
       
   160                 .set(extVars);
   137         ToolBox.executeCommand(successParams);
   161         ToolBox.executeCommand(successParams);
   138 
   162 
   139 //        testJavac failure -classpath foo ClassPathTest2.java
   163 //        testJavac failure -classpath foo ClassPathTest2.java
   140         failParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest2.java"));
   164         failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
       
   165                 .appendArgs(commonArgs)
       
   166                 .appendArgs("ClassPathTest2.java")
       
   167                 .set(extVars);
   141         ToolBox.executeCommand(failParams);
   168         ToolBox.executeCommand(failParams);
   142 
   169 
   143 //        testJavac failure -classpath foo ClassPathTest3.java
   170 //        testJavac failure -classpath foo ClassPathTest3.java
   144         failParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest3.java"));
   171         failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
       
   172                 .appendArgs(commonArgs)
       
   173                 .appendArgs("ClassPathTest3.java")
       
   174                 .set(extVars);
   145         ToolBox.executeCommand(failParams);
   175         ToolBox.executeCommand(failParams);
   146     }
   176     }
   147 
   177 
   148 }
   178 }