< prev index next >

test/jdk/java/net/spi/URLStreamHandlerProvider/Basic.java

Print this page

  1 /*
  2  * Copyright (c) 2015, 2021, 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  */

 28 import java.io.InputStream;
 29 import java.io.InputStreamReader;
 30 import java.io.SequenceInputStream;
 31 import java.io.StringWriter;
 32 import java.io.Writer;
 33 import java.nio.file.Files;
 34 import java.nio.file.Path;
 35 import java.nio.file.Paths;
 36 import java.util.ArrayList;
 37 import java.util.Collection;
 38 import java.util.Collections;
 39 import java.util.List;
 40 import java.util.function.Consumer;
 41 import java.util.stream.Collectors;
 42 import java.util.stream.Stream;
 43 import javax.tools.JavaCompiler;
 44 import javax.tools.JavaFileObject;
 45 import javax.tools.StandardJavaFileManager;
 46 import javax.tools.StandardLocation;
 47 import javax.tools.ToolProvider;


 48 import jdk.test.lib.util.FileUtils;
 49 import jdk.test.lib.JDKToolFinder;
 50 import static java.lang.String.format;
 51 import static java.util.Arrays.asList;
 52 
 53 /*
 54  * @test
 55  * @bug 8064924
 56  * @modules jdk.compiler
 57  * @summary Basic test for URLStreamHandlerProvider
 58  * @library /test/lib
 59  * @build jdk.test.lib.Platform
 60  *        jdk.test.lib.util.FileUtils
 61  *        jdk.test.lib.JDKToolFinder
 62  * @compile Basic.java Child.java
 63  * @run main Basic
 64  */
 65 
 66 public class Basic {
 67 

217                     .map(p -> p.toFile())
218                     .collect(Collectors.toList());
219             Iterable<? extends JavaFileObject> compilationUnits =
220                     fileManager.getJavaFileObjectsFromFiles(files);
221             fileManager.setLocation(StandardLocation.CLASS_OUTPUT, dests);
222             JavaCompiler.CompilationTask task =
223                     compiler.getTask(null, fileManager, null, null, null, compilationUnits);
224             boolean passed = task.call();
225             if (!passed)
226                 throw new RuntimeException("Error compiling " + files);
227         }
228     }
229 
230     static void quickFail(Result r) {
231         if (r.exitValue != 0)
232             throw new RuntimeException(r.output);
233     }
234 
235     static Result java(List<String> sysProps, Collection<Path> classpath,
236                        String classname, String arg) {
237         String java = getJDKTool("java");
238 
239         List<String> commands = new ArrayList<>();
240         commands.add(java);
241         for (String prop : sysProps)
242             commands.add(prop);
243 
244         String cp = classpath.stream()
245                 .map(Path::toString)
246                 .collect(Collectors.joining(File.pathSeparator));
247         commands.add("-cp");
248         commands.add(cp);
249         commands.add(classname);
250         commands.add(arg);
251 
252         return run(new ProcessBuilder(commands));
253     }
254 
255     static Result run(ProcessBuilder pb) {
256         Process p = null;
257         System.out.println("running: " + pb.command());
258         try {
259             p = pb.start();
260         } catch (IOException e) {
261             throw new RuntimeException(
262                     format("Couldn't start process '%s'", pb.command()), e);
263         }
264 
265         String output;
266         try {
267             output = toString(p.getInputStream(), p.getErrorStream());
268         } catch (IOException e) {
269             throw new RuntimeException(
270                     format("Couldn't read process output '%s'", pb.command()), e);
271         }
272 

  1 /*
  2  * Copyright (c) 2015, 2024, 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  */

 28 import java.io.InputStream;
 29 import java.io.InputStreamReader;
 30 import java.io.SequenceInputStream;
 31 import java.io.StringWriter;
 32 import java.io.Writer;
 33 import java.nio.file.Files;
 34 import java.nio.file.Path;
 35 import java.nio.file.Paths;
 36 import java.util.ArrayList;
 37 import java.util.Collection;
 38 import java.util.Collections;
 39 import java.util.List;
 40 import java.util.function.Consumer;
 41 import java.util.stream.Collectors;
 42 import java.util.stream.Stream;
 43 import javax.tools.JavaCompiler;
 44 import javax.tools.JavaFileObject;
 45 import javax.tools.StandardJavaFileManager;
 46 import javax.tools.StandardLocation;
 47 import javax.tools.ToolProvider;
 48 
 49 import jdk.test.lib.process.ProcessTools;
 50 import jdk.test.lib.util.FileUtils;
 51 import jdk.test.lib.JDKToolFinder;
 52 import static java.lang.String.format;
 53 import static java.util.Arrays.asList;
 54 
 55 /*
 56  * @test
 57  * @bug 8064924
 58  * @modules jdk.compiler
 59  * @summary Basic test for URLStreamHandlerProvider
 60  * @library /test/lib
 61  * @build jdk.test.lib.Platform
 62  *        jdk.test.lib.util.FileUtils
 63  *        jdk.test.lib.JDKToolFinder
 64  * @compile Basic.java Child.java
 65  * @run main Basic
 66  */
 67 
 68 public class Basic {
 69 

219                     .map(p -> p.toFile())
220                     .collect(Collectors.toList());
221             Iterable<? extends JavaFileObject> compilationUnits =
222                     fileManager.getJavaFileObjectsFromFiles(files);
223             fileManager.setLocation(StandardLocation.CLASS_OUTPUT, dests);
224             JavaCompiler.CompilationTask task =
225                     compiler.getTask(null, fileManager, null, null, null, compilationUnits);
226             boolean passed = task.call();
227             if (!passed)
228                 throw new RuntimeException("Error compiling " + files);
229         }
230     }
231 
232     static void quickFail(Result r) {
233         if (r.exitValue != 0)
234             throw new RuntimeException(r.output);
235     }
236 
237     static Result java(List<String> sysProps, Collection<Path> classpath,
238                        String classname, String arg) {

239 
240         List<String> commands = new ArrayList<>(sysProps);



241 
242         String cp = classpath.stream()
243                 .map(Path::toString)
244                 .collect(Collectors.joining(File.pathSeparator));
245         commands.add("-cp");
246         commands.add(cp);
247         commands.add(classname);
248         commands.add(arg);
249 
250         return run(ProcessTools.createTestJavaProcessBuilder(commands));
251     }
252 
253     static Result run(ProcessBuilder pb) {
254         Process p = null;
255         System.out.println("running: " + pb.command());
256         try {
257             p = pb.start();
258         } catch (IOException e) {
259             throw new RuntimeException(
260                     format("Couldn't start process '%s'", pb.command()), e);
261         }
262 
263         String output;
264         try {
265             output = toString(p.getInputStream(), p.getErrorStream());
266         } catch (IOException e) {
267             throw new RuntimeException(
268                     format("Couldn't read process output '%s'", pb.command()), e);
269         }
270 
< prev index next >