Extensions implements Closeable { public Map<String, BaseCommand<? extends BaseArgs>> getCommands() throws Exception { return _getCommands(null); } Extensions(ClassLoader classLoader); static Collection<String> getCommandNames(Collection<Class<? extends BaseArgs>> argsClass); static String[] sortArgs(Map<String, BaseCommand<? extends BaseArgs>> commands, String[] args); @Override void close(); Map<String, BaseCommand<? extends BaseArgs>> getCommands(); Map<String, BaseCommand<? extends BaseArgs>> getCommands(String profileName); Path getTemplatesPath();  }
@Test public void testLoadCommandsBuiltIn() throws Exception { ClassLoader classLoader = _extensionsClassLoaderSupplier.get(); try (Extensions extensions = new Extensions(classLoader)) { Map<String, BaseCommand<? extends BaseArgs>> commands = extensions.getCommands(); List<BaseCommand<? extends BaseArgs>> values = commands.values( ).stream( ).distinct( ).collect( Collectors.toList() ); Assert.assertNotNull(values); Assert.assertEquals(values.toString(), _BUILT_IN_COMMANDS_COUNT, values.size()); } }
@Test public void testLoadCommandsWithCustomExtension() throws Exception { _setupTestExtensions(); ClassLoader classLoader = _extensionsClassLoaderSupplier.get(); try (Extensions extensions = new Extensions(classLoader)) { Map<String, BaseCommand<? extends BaseArgs>> commands = extensions.getCommands(); List<BaseCommand<? extends BaseArgs>> values = commands.values( ).stream( ).distinct( ).collect( Collectors.toList() ); Assert.assertNotNull(values); Assert.assertEquals(values.toString(), _BUILT_IN_COMMANDS_COUNT + 1, values.size()); } }
@Test public void testLoadCommandsWithCustomExtensionInWorkspace() throws Exception { _setupTestExtensions(); File workspaceDir = temporaryFolder.newFolder("build", "test", "workspace"); String[] args = { "--base", workspaceDir.getPath(), "init", "-P", "foo", "-v", BladeTest.PRODUCT_VERSION_PORTAL_73 }; TestUtil.runBlade(_rootDir, _extensionsDir, args); BladeSettings settings = _bladeTest.getBladeSettings(); settings.setProfileName("foo"); ClassLoader classLoader = _extensionsClassLoaderSupplier.get(); try (Extensions extensions = new Extensions(classLoader)) { Map<String, BaseCommand<? extends BaseArgs>> commands = extensions.getCommands("foo"); List<BaseCommand<? extends BaseArgs>> values = commands.values( ).stream( ).distinct( ).collect( Collectors.toList() ); Assert.assertNotNull(values); Assert.assertEquals(values.toString(), _BUILT_IN_COMMANDS_COUNT + 2, values.size()); } }