PluginService extends DeliverableService<Plugin> { String getPluginUrl(Path pluginDir) { Path packageJson = pluginDir.resolve("package.json"); if (packageJson.toFile().isFile()) { Path pluginMain = getPluginProperty(packageJson, "main"); if (pluginMain == null) return null; logger.info("detected plugin <{}> with package.json", pluginDir.getParent().relativize(pluginDir)); return relativeToPlugins(pluginDir, pluginMain).toString(); } Path indexJs = pluginDir.resolve("index.js"); if (indexJs.toFile().isFile()) { logger.info("detected plugin <{}> with index.js", pluginDir.getParent().relativize(pluginDir)); return relativeToPlugins(pluginDir, indexJs).toString(); } return null; } PluginService(); @Inject  PluginService(PropertiesProvider propertiesProvider);  PluginService(Path pluginsDir);  PluginService(Path pluginsDir, InputStream inputStream); String addPlugins(String stringContent, List<String> userProjects); static final String DEFAULT_PLUGIN_REGISTRY_FILENAME; static final String PLUGINS_BASE_URL; }
@Test public void test_get_plugin_url() throws Exception { pluginFolder.newFolder("target_dir", "my_plugin").toPath().resolve("index.js").toFile().createNewFile(); assertThat(new PluginService().getPluginUrl(pluginFolder.getRoot().toPath().resolve("target_dir").resolve("my_plugin"))). isEqualTo("/plugins/my_plugin/index.js"); }
@Test public void test_get_plugin_url_with_subdirectory() throws Exception { pluginFolder.newFolder("target_dir", "my_plugin", "dist").toPath().resolve("main.js").toFile().createNewFile(); Path packageJson = pluginFolder.getRoot().toPath().resolve("target_dir").resolve("my_plugin").resolve("package.json"); Files.write(packageJson, asList("{", "\"main\":\"dist/main.js\"", "}")); assertThat(new PluginService().getPluginUrl(pluginFolder.getRoot().toPath().resolve("target_dir").resolve("my_plugin"))). isEqualTo("/plugins/my_plugin/dist/main.js"); }