< prev index next >

test/jdk/tools/launcher/SourceMode.java

Print this page




   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 8192920 8204588
  27  * @summary Test source mode
  28  * @modules jdk.compiler jdk.jlink
  29  * @run main SourceMode
  30  */
  31 
  32 
  33 import java.io.IOException;
  34 import java.io.PrintStream;
  35 import java.nio.file.Files;
  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.nio.file.attribute.PosixFilePermission;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.HashMap;
  42 import java.util.List;
  43 import java.util.Map;
  44 import java.util.Set;
  45 import java.util.spi.ToolProvider;
  46 


 230     void testClassNamedJava() throws IOException {
 231         starting("testClassNamedJava");
 232         Path base = Files.createDirectories(Paths.get("testClassNamedJava"));
 233         Path src = Files.createDirectories(base.resolve("src"));
 234         Path srcfile = src.resolve("java.java");
 235         createFile(srcfile, List.of(
 236                 "package HelloWorld;",
 237                 "class java {",
 238                 "    public static void main(String... args) {",
 239                 "        System.out.println(HelloWorld.java.class.getName());",
 240                 "    }",
 241                 "}"
 242         ));
 243         Path classes = base.resolve("classes");
 244         compile("-d", classes.toString(), srcfile.toString());
 245         TestResult tr =
 246             doExec(javaCmd, "-cp", classes.toString(), "HelloWorld.java");
 247         if (!tr.isOK())
 248             error(tr, "Command failed");
 249         if (!tr.contains("HelloWorld.java"))

























 250             error(tr, "Expected output not found");
 251         show(tr);
 252     }
 253 
 254     // java --source
 255     @Test
 256     void testSourceNoArg() throws IOException {
 257         starting("testSourceNoArg");
 258         TestResult tr = doExec(javaCmd, "--source");
 259         if (tr.isOK())
 260             error(tr, "Command succeeded unexpectedly");
 261         if (!tr.contains("--source requires source version"))
 262             error(tr, "Expected output not found");
 263         show(tr);
 264     }
 265 
 266     // java --source N -jar simple.jar
 267     @Test
 268     void testSourceJarConflict() throws IOException {
 269         starting("testSourceJarConflict");




   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 8192920 8204588 8210275
  27  * @summary Test source mode
  28  * @modules jdk.compiler jdk.jlink
  29  * @run main SourceMode
  30  */
  31 
  32 
  33 import java.io.IOException;
  34 import java.io.PrintStream;
  35 import java.nio.file.Files;
  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.nio.file.attribute.PosixFilePermission;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.HashMap;
  42 import java.util.List;
  43 import java.util.Map;
  44 import java.util.Set;
  45 import java.util.spi.ToolProvider;
  46 


 230     void testClassNamedJava() throws IOException {
 231         starting("testClassNamedJava");
 232         Path base = Files.createDirectories(Paths.get("testClassNamedJava"));
 233         Path src = Files.createDirectories(base.resolve("src"));
 234         Path srcfile = src.resolve("java.java");
 235         createFile(srcfile, List.of(
 236                 "package HelloWorld;",
 237                 "class java {",
 238                 "    public static void main(String... args) {",
 239                 "        System.out.println(HelloWorld.java.class.getName());",
 240                 "    }",
 241                 "}"
 242         ));
 243         Path classes = base.resolve("classes");
 244         compile("-d", classes.toString(), srcfile.toString());
 245         TestResult tr =
 246             doExec(javaCmd, "-cp", classes.toString(), "HelloWorld.java");
 247         if (!tr.isOK())
 248             error(tr, "Command failed");
 249         if (!tr.contains("HelloWorld.java"))
 250             error(tr, "Expected output not found");
 251         show(tr);
 252     }
 253 
 254     // java --source N -cp ... HelloWorld 
 255     @Test
 256     void testSourceClasspath() throws IOException {
 257         starting("testSourceClasspath");
 258         Path base = Files.createDirectories(Paths.get("testSourceClasspath"));
 259         Path src = Files.createDirectories(base.resolve("src"));
 260         Path srcfile = src.resolve("java.java");
 261         createFile(srcfile, List.of(
 262                 "class HelloWorld {",
 263                 "    public static void main(String... args) {",
 264                 "        System.out.println(\"Hello World\");",
 265                 "    }",
 266                 "}"
 267         ));
 268         Path classes = base.resolve("classes");
 269         compile("-d", classes.toString(), srcfile.toString());
 270         TestResult tr =
 271             doExec(javaCmd, "--source", thisVersion, "-cp", classes.toString(), "HelloWorld");
 272         if (tr.isOK())
 273             error(tr, "Command succeeded unexpectedly");
 274         if (!tr.contains("file not found: HelloWorld"))
 275             error(tr, "Expected output not found");
 276         show(tr);
 277     }
 278 
 279     // java --source
 280     @Test
 281     void testSourceNoArg() throws IOException {
 282         starting("testSourceNoArg");
 283         TestResult tr = doExec(javaCmd, "--source");
 284         if (tr.isOK())
 285             error(tr, "Command succeeded unexpectedly");
 286         if (!tr.contains("--source requires source version"))
 287             error(tr, "Expected output not found");
 288         show(tr);
 289     }
 290 
 291     // java --source N -jar simple.jar
 292     @Test
 293     void testSourceJarConflict() throws IOException {
 294         starting("testSourceJarConflict");


< prev index next >