< prev index next >

jdk/test/java/util/ServiceLoader/modules/ServicesTest.java

Print this page




  88             Path src = SRC_DIR.resolve(dir);
  89             assertTrue(CompilerUtils.compile(src, CLASSES_DIR));
  90         }
  91 
  92         // copy resources
  93         for (String rn : RESOURCES) {
  94             Path file = Paths.get(rn.replace('/', File.separatorChar));
  95             Path source = SRC_DIR.resolve(file);
  96 
  97             // drop directory to get a target of classes/META-INF/...
  98             Path target = CLASSES_DIR.resolve(file.subpath(1, file.getNameCount()));
  99 
 100             Files.createDirectories(target.getParent());
 101             Files.copy(source, target);
 102         }
 103 
 104     }
 105 
 106 
 107     /**
 108      * Run test with -modulepath.
 109      *
 110      * BananaScriptEngine should be found.
 111      */
 112     public void runWithModulePath() throws Exception {
 113         int exitValue
 114             = executeTestJava("-mp", MODS_DIR.toString(),
 115                               "-m", "test/test.Main",
 116                               "BananaScriptEngine")
 117                 .outputTo(System.out)
 118                 .errorTo(System.out)
 119                 .getExitValue();
 120 
 121         assertTrue(exitValue == 0);
 122     }
 123 
 124 
 125     /**
 126      * Run test with -modulepath and -classpath.
 127      *
 128      * Both BananaScriptEngine and PearScriptEngine should be found
 129      */
 130     public void runWithModulePathAndClassPath() throws Exception {
 131         int exitValue
 132             = executeTestJava("-mp", MODS_DIR.toString(),
 133                               "-cp", CLASSES_DIR.toString(),
 134                               "-m", "test/test.Main",
 135                               "BananaScriptEngine", "PearScriptEngine")
 136                 .outputTo(System.out)
 137                 .errorTo(System.out)
 138                 .getExitValue();
 139 
 140         assertTrue(exitValue == 0);
 141     }
 142 
 143 
 144     /**
 145      * Exercise ServiceLoader.load(Layer, Class).
 146      */
 147     public void testWithCustomLayer() throws Exception {
 148 
 149         ServiceLoader<ScriptEngineFactory> sl;
 150 
 151         // BananaScriptEngine should not be in the boot Layer
 152         sl = ServiceLoader.load(Layer.boot(), ScriptEngineFactory.class);




  88             Path src = SRC_DIR.resolve(dir);
  89             assertTrue(CompilerUtils.compile(src, CLASSES_DIR));
  90         }
  91 
  92         // copy resources
  93         for (String rn : RESOURCES) {
  94             Path file = Paths.get(rn.replace('/', File.separatorChar));
  95             Path source = SRC_DIR.resolve(file);
  96 
  97             // drop directory to get a target of classes/META-INF/...
  98             Path target = CLASSES_DIR.resolve(file.subpath(1, file.getNameCount()));
  99 
 100             Files.createDirectories(target.getParent());
 101             Files.copy(source, target);
 102         }
 103 
 104     }
 105 
 106 
 107     /**
 108      * Run test with --module-path.
 109      *
 110      * BananaScriptEngine should be found.
 111      */
 112     public void runWithModulePath() throws Exception {
 113         int exitValue
 114             = executeTestJava("--module-path", MODS_DIR.toString(),
 115                               "-m", "test/test.Main",
 116                               "BananaScriptEngine")
 117                 .outputTo(System.out)
 118                 .errorTo(System.out)
 119                 .getExitValue();
 120 
 121         assertTrue(exitValue == 0);
 122     }
 123 
 124 
 125     /**
 126      * Run test with --module-path and -classpath.
 127      *
 128      * Both BananaScriptEngine and PearScriptEngine should be found
 129      */
 130     public void runWithModulePathAndClassPath() throws Exception {
 131         int exitValue
 132             = executeTestJava("--module-path", MODS_DIR.toString(),
 133                               "-cp", CLASSES_DIR.toString(),
 134                               "-m", "test/test.Main",
 135                               "BananaScriptEngine", "PearScriptEngine")
 136                 .outputTo(System.out)
 137                 .errorTo(System.out)
 138                 .getExitValue();
 139 
 140         assertTrue(exitValue == 0);
 141     }
 142 
 143 
 144     /**
 145      * Exercise ServiceLoader.load(Layer, Class).
 146      */
 147     public void testWithCustomLayer() throws Exception {
 148 
 149         ServiceLoader<ScriptEngineFactory> sl;
 150 
 151         // BananaScriptEngine should not be in the boot Layer
 152         sl = ServiceLoader.load(Layer.boot(), ScriptEngineFactory.class);


< prev index next >