< prev index next >

langtools/test/tools/sjavac/OptionDecoding.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2015, 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 8035063 8054465
  27  * @summary Tests decoding of String[] into Options.
  28  *
  29  * @modules jdk.compiler/com.sun.tools.sjavac
  30  *          jdk.compiler/com.sun.tools.sjavac.client

  31  *          jdk.compiler/com.sun.tools.sjavac.options
  32  * @build Wrapper
  33  * @run main Wrapper OptionDecoding
  34  */
  35 
  36 import static util.OptionTestUtil.assertEquals;
  37 import static util.OptionTestUtil.checkFilesFound;
  38 
  39 import java.io.File;
  40 import java.io.IOException;
  41 import java.nio.file.Files;
  42 import java.nio.file.Path;
  43 import java.nio.file.Paths;
  44 import java.util.ArrayList;
  45 import java.util.Arrays;
  46 import java.util.Collections;
  47 import java.util.HashMap;
  48 import java.util.List;
  49 import java.util.Map;
  50 


 130     // Test server configuration options
 131     static void testServerConf() {
 132         Options options = Options.parseArgs("--server:someServerConfiguration");
 133         assertEquals("someServerConfiguration", options.getServerConf());
 134         assertEquals(false, options.startServerFlag());
 135 
 136         options = Options.parseArgs("--startserver:someServerConfiguration");
 137         assertEquals("someServerConfiguration", options.getServerConf());
 138         assertEquals(true, options.startServerFlag());
 139     }
 140 
 141     // Test input paths
 142     static void testSearchPaths() {
 143         List<String> i, x, iF, xF;
 144         i = x = iF = xF = new ArrayList<>();
 145 
 146         SourceLocation dir1 = new SourceLocation(Paths.get("dir1"), i, x);
 147         SourceLocation dir2 = new SourceLocation(Paths.get("dir2"), i, x);
 148         String dir1_PS_dir2 = "dir1" + File.pathSeparator + "dir2";
 149 
 150         Options options = Options.parseArgs("-sourcepath", dir1_PS_dir2);
 151         assertEquals(options.getSourceSearchPaths(), Arrays.asList(dir1, dir2));
 152 
 153         options = Options.parseArgs("-modulepath", dir1_PS_dir2);
 154         assertEquals(options.getModuleSearchPaths(), Arrays.asList(dir1, dir2));
 155 
 156         options = Options.parseArgs("-classpath", dir1_PS_dir2);
 157         assertEquals(options.getClassSearchPath(), Arrays.asList(dir1, dir2));
 158     }
 159 
 160     // Test -tr option
 161     static void testTranslationRules() {
 162         Class<?> cls = com.sun.tools.sjavac.CompileJavaPackages.class;
 163 
 164         Options options = Options.parseArgs(
 165                 "-tr", ".exa=" + cls.getName(),
 166                 "-tr", ".exb=" + cls.getName(),
 167                 "-copy", ".html");
 168 
 169         assertEquals(cls, options.getTranslationRules().get(".exa").getClass());
 170         assertEquals(cls, options.getTranslationRules().get(".exb").getClass());
 171         assertEquals(CopyFile.class, options.getTranslationRules().get(".html").getClass());
 172     }
 173 }
   1 /*
   2  * Copyright (c) 2014, 2016, 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 8035063 8054465
  27  * @summary Tests decoding of String[] into Options.
  28  *
  29  * @modules jdk.compiler/com.sun.tools.sjavac
  30  *          jdk.compiler/com.sun.tools.sjavac.client
  31  *          jdk.compiler/com.sun.tools.sjavac.comp
  32  *          jdk.compiler/com.sun.tools.sjavac.options
  33  * @build Wrapper
  34  * @run main Wrapper OptionDecoding
  35  */
  36 
  37 import static util.OptionTestUtil.assertEquals;
  38 import static util.OptionTestUtil.checkFilesFound;
  39 
  40 import java.io.File;
  41 import java.io.IOException;
  42 import java.nio.file.Files;
  43 import java.nio.file.Path;
  44 import java.nio.file.Paths;
  45 import java.util.ArrayList;
  46 import java.util.Arrays;
  47 import java.util.Collections;
  48 import java.util.HashMap;
  49 import java.util.List;
  50 import java.util.Map;
  51 


 131     // Test server configuration options
 132     static void testServerConf() {
 133         Options options = Options.parseArgs("--server:someServerConfiguration");
 134         assertEquals("someServerConfiguration", options.getServerConf());
 135         assertEquals(false, options.startServerFlag());
 136 
 137         options = Options.parseArgs("--startserver:someServerConfiguration");
 138         assertEquals("someServerConfiguration", options.getServerConf());
 139         assertEquals(true, options.startServerFlag());
 140     }
 141 
 142     // Test input paths
 143     static void testSearchPaths() {
 144         List<String> i, x, iF, xF;
 145         i = x = iF = xF = new ArrayList<>();
 146 
 147         SourceLocation dir1 = new SourceLocation(Paths.get("dir1"), i, x);
 148         SourceLocation dir2 = new SourceLocation(Paths.get("dir2"), i, x);
 149         String dir1_PS_dir2 = "dir1" + File.pathSeparator + "dir2";
 150 
 151         Options options = Options.parseArgs("--source-path", dir1_PS_dir2);
 152         assertEquals(options.getSourceSearchPaths(), Arrays.asList(dir1, dir2));
 153 
 154         options = Options.parseArgs("--module-path", dir1_PS_dir2);
 155         assertEquals(options.getModuleSearchPaths(), Arrays.asList(dir1, dir2));
 156 
 157         options = Options.parseArgs("--class-path", dir1_PS_dir2);
 158         assertEquals(options.getClassSearchPath(), Arrays.asList(dir1, dir2));
 159     }
 160 
 161     // Test -tr option
 162     static void testTranslationRules() {
 163         Class<?> cls = com.sun.tools.sjavac.CompileJavaPackages.class;
 164 
 165         Options options = Options.parseArgs(
 166                 "-tr", ".exa=" + cls.getName(),
 167                 "-tr", ".exb=" + cls.getName(),
 168                 "-copy", ".html");
 169 
 170         assertEquals(cls, options.getTranslationRules().get(".exa").getClass());
 171         assertEquals(cls, options.getTranslationRules().get(".exb").getClass());
 172         assertEquals(CopyFile.class, options.getTranslationRules().get(".html").getClass());
 173     }
 174 }
< prev index next >