use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.
the class RulePluginRepositoryImpl method getRuleSources.
private List<RuleSource> getRuleSources(List<JqassistantPlugin> plugins) {
List<RuleSource> sources = new ArrayList<>();
for (JqassistantPlugin plugin : plugins) {
RulesType rulesType = plugin.getRules();
if (rulesType != null) {
for (String resource : rulesType.getResource()) {
String resourceName = RULE_RESOURCE_PATH + resource;
sources.add(new ClasspathRuleSource(classLoader, resourceName));
}
}
}
return sources;
}
use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.
the class ScopePluginRepositoryImpl method getScopes.
private Map<String, Scope> getScopes(List<JqassistantPlugin> plugins) throws PluginRepositoryException {
Map<String, Scope> scopes = new HashMap<>();
for (JqassistantPlugin plugin : plugins) {
ScopeType scopeType = plugin.getScope();
if (scopeType != null) {
for (String scopePluginName : scopeType.getClazz()) {
Class<? extends Enum<?>> type = getType(scopePluginName);
for (Enum enumConstant : type.getEnumConstants()) {
Scope scope = (Scope) enumConstant;
String scopeName = scope.getPrefix() + ":" + scope.getName();
scopes.put(scopeName.toLowerCase(), scope);
}
}
}
}
return scopes;
}
use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.
the class PluginConfigurationReaderImpl method getPlugins.
/**
* Returns an {@link Iterable} over all plugins which can be resolved from the
* current classpath.
*
* @return The plugins which can be resolved from the current classpath.
*/
@Override
public List<JqassistantPlugin> getPlugins() {
if (this.plugins == null) {
LOGGER.info("Scanning for jQAssistant plugins...");
PluginIdGenerator idGenerator = new PluginIdGenerator();
TreeSet<String> ids = new TreeSet<>();
Enumeration<URL> resources = getPluginClassLoaderResources();
this.plugins = new ArrayList<>();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
LOGGER.debug("Reading plugin descriptor from '{}'.", url);
JqassistantPlugin plugin = idGenerator.apply(readPlugin(url));
if (ids.contains(plugin.getId())) {
JqassistantPlugin loadedPlugin = plugins.stream().filter(p -> p.getId().equals(plugin.getId())).findFirst().get();
String message = format("Unable to load plugin '%s' with id '%s', as the same id is used by " + "plugin '%s'", plugin.getName(), plugin.getId(), loadedPlugin.getName());
LOGGER.error(message);
throw new PluginRepositoryException(message);
}
LOGGER.info("Loaded plugin '{}' with id '{}'", plugin.getName(), plugin.getId());
ids.add(plugin.getId());
plugins.add(plugin);
}
}
return plugins;
}
use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.
the class RulePluginRepositoryImpl method initialize.
@Override
public void initialize() {
for (JqassistantPlugin plugin : plugins) {
IdClassListType ruleParsers = plugin.getRuleParser();
if (ruleParsers != null) {
for (IdClassType pluginType : ruleParsers.getClazz()) {
RuleParserPlugin ruleParserPlugin = createInstance(pluginType.getValue());
try {
ruleParserPlugin.initialize();
} catch (RuleException e) {
throw new PluginRepositoryException("Cannot initialize plugin " + ruleParserPlugin, e);
}
ruleParserPlugins.add(ruleParserPlugin);
}
}
}
}
use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.
the class PluginConfigurationReaderImplTest method twoPluginsWithDifferentIdCanBeLoaded.
@Test
void twoPluginsWithDifferentIdCanBeLoaded() throws Exception {
List<URL> urls = Arrays.asList(new URL("file://1"), new URL("file://2"));
Enumeration<URL> enumerationOfUrls = Iterators.asEnumeration(urls.iterator());
PluginConfigurationReaderImpl reader = Mockito.mock(PluginConfigurationReaderImpl.class);
JqassistantPlugin plugin1 = Mockito.mock(JqassistantPlugin.class);
JqassistantPlugin plugin2 = Mockito.mock(JqassistantPlugin.class);
Mockito.doReturn("Plugin A").when(plugin1).getName();
Mockito.doReturn("plugin_a").when(plugin1).getId();
Mockito.doReturn("Plugin B").when(plugin2).getName();
Mockito.doReturn("plugin_b").when(plugin2).getId();
Mockito.doReturn(plugin1).doReturn(plugin2).when(reader).readPlugin(Mockito.any(URL.class));
Mockito.doReturn(enumerationOfUrls).when(reader).getPluginClassLoaderResources();
Mockito.doCallRealMethod().when(reader).getPlugins();
Assertions.assertThat(reader.getPlugins()).hasSize(2).containsAnyOf(plugin1, plugin2);
}
Aggregations