Search in sources :

Example 1 with JqassistantPlugin

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;
}
Also used : ClasspathRuleSource(com.buschmais.jqassistant.core.rule.api.source.ClasspathRuleSource) RuleSource(com.buschmais.jqassistant.core.rule.api.source.RuleSource) JqassistantPlugin(com.buschmais.jqassistant.core.plugin.schema.v1.JqassistantPlugin) ClasspathRuleSource(com.buschmais.jqassistant.core.rule.api.source.ClasspathRuleSource) ArrayList(java.util.ArrayList) RulesType(com.buschmais.jqassistant.core.plugin.schema.v1.RulesType)

Example 2 with JqassistantPlugin

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;
}
Also used : ScopeType(com.buschmais.jqassistant.core.plugin.schema.v1.ScopeType) Scope(com.buschmais.jqassistant.core.scanner.api.Scope) HashMap(java.util.HashMap) JqassistantPlugin(com.buschmais.jqassistant.core.plugin.schema.v1.JqassistantPlugin)

Example 3 with JqassistantPlugin

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;
}
Also used : PluginRepositoryException(com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException) JqassistantPlugin(org.jqassistant.schema.plugin.v1.JqassistantPlugin) URL(java.net.URL)

Example 4 with JqassistantPlugin

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);
            }
        }
    }
}
Also used : IdClassType(org.jqassistant.schema.plugin.v1.IdClassType) PluginRepositoryException(com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException) RuleParserPlugin(com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin) JqassistantPlugin(org.jqassistant.schema.plugin.v1.JqassistantPlugin) IdClassListType(org.jqassistant.schema.plugin.v1.IdClassListType) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException)

Example 5 with JqassistantPlugin

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);
}
Also used : JqassistantPlugin(org.jqassistant.schema.plugin.v1.JqassistantPlugin) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Aggregations

JqassistantPlugin (org.jqassistant.schema.plugin.v1.JqassistantPlugin)12 IdClassListType (org.jqassistant.schema.plugin.v1.IdClassListType)5 Test (org.junit.jupiter.api.Test)5 PluginRepositoryException (com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException)3 JqassistantPlugin (com.buschmais.jqassistant.core.plugin.schema.v1.JqassistantPlugin)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3 IdClassType (org.jqassistant.schema.plugin.v1.IdClassType)3 AnalyzerPluginRepository (com.buschmais.jqassistant.core.analysis.spi.AnalyzerPluginRepository)2 PluginConfigurationReader (com.buschmais.jqassistant.core.plugin.api.PluginConfigurationReader)2 PluginInfo (com.buschmais.jqassistant.core.plugin.api.PluginInfo)2 PluginRepository (com.buschmais.jqassistant.core.plugin.api.PluginRepository)2 Scope (com.buschmais.jqassistant.core.scanner.api.Scope)2 ScannerPluginRepository (com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 RuleInterpreterPlugin (com.buschmais.jqassistant.core.analysis.api.RuleInterpreterPlugin)1 IdClassType (com.buschmais.jqassistant.core.plugin.schema.v1.IdClassType)1 ReportType (com.buschmais.jqassistant.core.plugin.schema.v1.ReportType)1 RulesType (com.buschmais.jqassistant.core.plugin.schema.v1.RulesType)1 ScopeType (com.buschmais.jqassistant.core.plugin.schema.v1.ScopeType)1