< prev index next >

test/tools/jlink/bindservices/SuggestProviders.java

Print this page




 154 
 155         assertTrue(output.containsAll(expected));
 156     }
 157 
 158     @Test
 159     public void noSuggestProviders() throws Throwable {
 160         if (!hasJmods()) return;
 161 
 162         List<String> output =
 163             JLink.run("--module-path", MODULE_PATH,
 164                       "--add-modules", "m1",
 165                       "--bind-services",
 166                       "--limit-modules", "m1,m2,m3,java.base",
 167                       "--suggest-providers").output();
 168 
 169         String expected = "--bind-services option is specified. No additional providers suggested.";
 170         assertTrue(output.contains(expected));
 171 
 172     }
 173 




































 174     static class JLink {
 175         static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
 176             .orElseThrow(() ->
 177                 new RuntimeException("jlink tool not found")
 178             );
 179 
 180         static JLink run(String... options) {
 181             JLink jlink = new JLink();
 182             assertTrue(jlink.execute(options) == 0);
 183             return jlink;
 184         }
 185 
 186         final List<String> output = new ArrayList<>();
 187         private int execute(String... options) {
 188             System.out.println("jlink " +
 189                 Stream.of(options).collect(Collectors.joining(" ")));
 190 
 191             StringWriter writer = new StringWriter();
 192             PrintWriter pw = new PrintWriter(writer);
 193             int rc = JLINK_TOOL.run(pw, pw, options);


 154 
 155         assertTrue(output.containsAll(expected));
 156     }
 157 
 158     @Test
 159     public void noSuggestProviders() throws Throwable {
 160         if (!hasJmods()) return;
 161 
 162         List<String> output =
 163             JLink.run("--module-path", MODULE_PATH,
 164                       "--add-modules", "m1",
 165                       "--bind-services",
 166                       "--limit-modules", "m1,m2,m3,java.base",
 167                       "--suggest-providers").output();
 168 
 169         String expected = "--bind-services option is specified. No additional providers suggested.";
 170         assertTrue(output.contains(expected));
 171 
 172     }
 173 
 174     @Test
 175     public void suggestNotProvider() throws Throwable {
 176         if (!hasJmods()) return;
 177 
 178         List<String> output =
 179                 JLink.run("--module-path", MODULE_PATH,
 180                         "--add-modules", "m1",
 181                         "--suggest-providers",
 182                         "java.util.List").output();
 183 
 184         System.out.println(output);
 185         List<String> expected = List.of(
 186                 "Services specified in --suggest-providers not used: java.util.List"
 187         );
 188 
 189         assertTrue(output.containsAll(expected));
 190     }
 191 
 192     @Test
 193     public void noOneUsesProvider() throws Throwable {
 194         if (!hasJmods()) return;
 195 
 196         List<String> output =
 197                 JLink.run("--module-path", MODULE_PATH,
 198                         "--add-modules", "m4",
 199                         "--suggest-providers",
 200                         "p4.Impl").output();
 201 
 202         System.out.println(output);
 203         List<String> expected = List.of(
 204                 "Services specified in --suggest-providers not used: p4.Impl"
 205         );
 206 
 207         assertTrue(output.containsAll(expected));
 208     }
 209     
 210     static class JLink {
 211         static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink")
 212             .orElseThrow(() ->
 213                 new RuntimeException("jlink tool not found")
 214             );
 215 
 216         static JLink run(String... options) {
 217             JLink jlink = new JLink();
 218             assertTrue(jlink.execute(options) == 0);
 219             return jlink;
 220         }
 221 
 222         final List<String> output = new ArrayList<>();
 223         private int execute(String... options) {
 224             System.out.println("jlink " +
 225                 Stream.of(options).collect(Collectors.joining(" ")));
 226 
 227             StringWriter writer = new StringWriter();
 228             PrintWriter pw = new PrintWriter(writer);
 229             int rc = JLINK_TOOL.run(pw, pw, options);
< prev index next >