PluginParser extends Parser<T> { @Override protected void parse(T type) { var plugin = environment.resolver.any(type, Plugin.class); environment.mappings.put("main", stringify(type)); var name = plugin.name().isEmpty() ? environment.project.name : plugin.name(); if (!matcher.reset(name).matches()) { environment.error(type, format(name, "is not a valid plugin name", "should contain only alphanumeric characters and \"_\"")); } environment.mappings.put("name", name); var version = plugin.version().isEmpty() ? environment.project.version : plugin.version(); if (!VERSIONING.matcher(version).matches()) { environment.warn(type, format(version, "may be malformed", "version should follow SemVer, https: } environment.mappings.put("version", version); } PluginParser(Environment<T> environment); static PluginParser<Class<?>> type(Environment<Class<?>> environment); static PluginParser<Element> element(Environment<Element> environment, Elements elements, Types types);  }
@Test void parse() { parser.parse(PluginParserTest.class); verify(environment, times(0)).error(any(), any()); verify(environment, times(0)).warn(any(), any()); assertEquals(PluginParserTest.class.getName(), environment.mappings.get("main")); assertEquals("name1", environment.mappings.get("name")); assertEquals("1.0.0", environment.mappings.get("version")); }
@Test void parse_errors() { parser.parse(Errors.class); verify(environment).error(Errors.class, "\"a !\" is not a valid plugin name, should contain only alphanumeric characters and \"_\""); verify(environment).warn(Errors.class, "\"1\" may be malformed, version should follow SemVer, https: }
@Test void parse_empty() { parser.parse(Empty.class); verify(environment, times(0)).error(any(), any()); verify(environment, times(0)).warn(any(), any()); assertEquals("project_name", environment.mappings.get("name")); assertEquals("1.0.0", environment.mappings.get("version")); }