@Test public void badFormatYamlGroupIdNoVersion() throws URISyntaxException { File pluginYmlFile = new File(this.getClass().getResource("PluginListParserTest/badformat2.yaml").toURI()); assertThatThrownBy(() -> pluginList.parsePluginYamlFile(pluginYmlFile)) .isInstanceOf(PluginInputException.class); }
public List<Plugin> parsePluginYamlFile(File pluginYamlFile) { List<Plugin> pluginsFromYaml = new ArrayList<>(); if (fileExists(pluginYamlFile)) { try (InputStream inputStream = new FileInputStream(pluginYamlFile)) { Plugins plugins = MAPPER.readValue(inputStream, Plugins.class); for (PluginInfo pluginInfo : plugins.getPlugins()) { String name = pluginInfo.getArtifactId(); if (StringUtils.isEmpty(name)) { throw new PluginInputException("ArtifactId is required"); } String groupId = pluginInfo.getGroupId(); Source pluginSource = pluginInfo.getSource(); Plugin plugin; if (pluginSource == null && StringUtils.isNotEmpty(groupId)) { throw new PluginInputException("Version must be input for " + name); } else if (pluginSource == null) { plugin = new Plugin(name, "latest", null, null); } else { String version = pluginSource.getVersion(); if (StringUtils.isNotEmpty(groupId) && version == null) { throw new PluginInputException("Version must be input for " + name); } if (version == null) { version = "latest"; } String url = pluginSource.getUrl(); if (!isURL(url)) { url = null; } plugin = new Plugin(name, version, url, groupId); } pluginsFromYaml.add(plugin); } } catch (IOException e) { System.out.println("Unable to open " + pluginsFromYaml); e.printStackTrace(); } } return pluginsFromYaml; }
PluginListParser { public List<Plugin> parsePluginYamlFile(File pluginYamlFile) { List<Plugin> pluginsFromYaml = new ArrayList<>(); if (fileExists(pluginYamlFile)) { try (InputStream inputStream = new FileInputStream(pluginYamlFile)) { Plugins plugins = MAPPER.readValue(inputStream, Plugins.class); for (PluginInfo pluginInfo : plugins.getPlugins()) { String name = pluginInfo.getArtifactId(); if (StringUtils.isEmpty(name)) { throw new PluginInputException("ArtifactId is required"); } String groupId = pluginInfo.getGroupId(); Source pluginSource = pluginInfo.getSource(); Plugin plugin; if (pluginSource == null && StringUtils.isNotEmpty(groupId)) { throw new PluginInputException("Version must be input for " + name); } else if (pluginSource == null) { plugin = new Plugin(name, "latest", null, null); } else { String version = pluginSource.getVersion(); if (StringUtils.isNotEmpty(groupId) && version == null) { throw new PluginInputException("Version must be input for " + name); } if (version == null) { version = "latest"; } String url = pluginSource.getUrl(); if (!isURL(url)) { url = null; } plugin = new Plugin(name, version, url, groupId); } pluginsFromYaml.add(plugin); } } catch (IOException e) { System.out.println("Unable to open " + pluginsFromYaml); e.printStackTrace(); } } return pluginsFromYaml; } }
PluginListParser { public List<Plugin> parsePluginYamlFile(File pluginYamlFile) { List<Plugin> pluginsFromYaml = new ArrayList<>(); if (fileExists(pluginYamlFile)) { try (InputStream inputStream = new FileInputStream(pluginYamlFile)) { Plugins plugins = MAPPER.readValue(inputStream, Plugins.class); for (PluginInfo pluginInfo : plugins.getPlugins()) { String name = pluginInfo.getArtifactId(); if (StringUtils.isEmpty(name)) { throw new PluginInputException("ArtifactId is required"); } String groupId = pluginInfo.getGroupId(); Source pluginSource = pluginInfo.getSource(); Plugin plugin; if (pluginSource == null && StringUtils.isNotEmpty(groupId)) { throw new PluginInputException("Version must be input for " + name); } else if (pluginSource == null) { plugin = new Plugin(name, "latest", null, null); } else { String version = pluginSource.getVersion(); if (StringUtils.isNotEmpty(groupId) && version == null) { throw new PluginInputException("Version must be input for " + name); } if (version == null) { version = "latest"; } String url = pluginSource.getUrl(); if (!isURL(url)) { url = null; } plugin = new Plugin(name, version, url, groupId); } pluginsFromYaml.add(plugin); } } catch (IOException e) { System.out.println("Unable to open " + pluginsFromYaml); e.printStackTrace(); } } return pluginsFromYaml; } PluginListParser(boolean verbose); }
PluginListParser { public List<Plugin> parsePluginYamlFile(File pluginYamlFile) { List<Plugin> pluginsFromYaml = new ArrayList<>(); if (fileExists(pluginYamlFile)) { try (InputStream inputStream = new FileInputStream(pluginYamlFile)) { Plugins plugins = MAPPER.readValue(inputStream, Plugins.class); for (PluginInfo pluginInfo : plugins.getPlugins()) { String name = pluginInfo.getArtifactId(); if (StringUtils.isEmpty(name)) { throw new PluginInputException("ArtifactId is required"); } String groupId = pluginInfo.getGroupId(); Source pluginSource = pluginInfo.getSource(); Plugin plugin; if (pluginSource == null && StringUtils.isNotEmpty(groupId)) { throw new PluginInputException("Version must be input for " + name); } else if (pluginSource == null) { plugin = new Plugin(name, "latest", null, null); } else { String version = pluginSource.getVersion(); if (StringUtils.isNotEmpty(groupId) && version == null) { throw new PluginInputException("Version must be input for " + name); } if (version == null) { version = "latest"; } String url = pluginSource.getUrl(); if (!isURL(url)) { url = null; } plugin = new Plugin(name, version, url, groupId); } pluginsFromYaml.add(plugin); } } catch (IOException e) { System.out.println("Unable to open " + pluginsFromYaml); e.printStackTrace(); } } return pluginsFromYaml; } PluginListParser(boolean verbose); List<Plugin> parsePluginsFromCliOption(String[] plugins); List<Plugin> parsePluginTxtFile(File pluginTxtFile); List<Plugin> parsePluginYamlFile(File pluginYamlFile); boolean fileExists(File pluginFile); static boolean isURL(String url); }
PluginListParser { public List<Plugin> parsePluginYamlFile(File pluginYamlFile) { List<Plugin> pluginsFromYaml = new ArrayList<>(); if (fileExists(pluginYamlFile)) { try (InputStream inputStream = new FileInputStream(pluginYamlFile)) { Plugins plugins = MAPPER.readValue(inputStream, Plugins.class); for (PluginInfo pluginInfo : plugins.getPlugins()) { String name = pluginInfo.getArtifactId(); if (StringUtils.isEmpty(name)) { throw new PluginInputException("ArtifactId is required"); } String groupId = pluginInfo.getGroupId(); Source pluginSource = pluginInfo.getSource(); Plugin plugin; if (pluginSource == null && StringUtils.isNotEmpty(groupId)) { throw new PluginInputException("Version must be input for " + name); } else if (pluginSource == null) { plugin = new Plugin(name, "latest", null, null); } else { String version = pluginSource.getVersion(); if (StringUtils.isNotEmpty(groupId) && version == null) { throw new PluginInputException("Version must be input for " + name); } if (version == null) { version = "latest"; } String url = pluginSource.getUrl(); if (!isURL(url)) { url = null; } plugin = new Plugin(name, version, url, groupId); } pluginsFromYaml.add(plugin); } } catch (IOException e) { System.out.println("Unable to open " + pluginsFromYaml); e.printStackTrace(); } } return pluginsFromYaml; } PluginListParser(boolean verbose); List<Plugin> parsePluginsFromCliOption(String[] plugins); List<Plugin> parsePluginTxtFile(File pluginTxtFile); List<Plugin> parsePluginYamlFile(File pluginYamlFile); boolean fileExists(File pluginFile); static boolean isURL(String url);  }