Search in sources :

Example 11 with JqassistantPlugin

use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.

the class PluginRepositoryImplTest method allPluginsKnownToThePluginReaderFormThePluginOverview.

@Test
void allPluginsKnownToThePluginReaderFormThePluginOverview() {
    PluginConfigurationReader pluginConfigurationReader = Mockito.mock(PluginConfigurationReader.class);
    JqassistantPlugin pluginA = Mockito.mock(JqassistantPlugin.class);
    JqassistantPlugin pluginB = Mockito.mock(JqassistantPlugin.class);
    JqassistantPlugin pluginC = Mockito.mock(JqassistantPlugin.class);
    doReturn("jqa.a").when(pluginA).getId();
    doReturn("A").when(pluginA).getName();
    doReturn("jqa.b").when(pluginB).getId();
    doReturn("B").when(pluginB).getName();
    doReturn("jqa.c").when(pluginC).getId();
    doReturn("C").when(pluginC).getName();
    doReturn(Arrays.asList(pluginA, pluginB, pluginC)).when(pluginConfigurationReader).getPlugins();
    doReturn(PluginRepositoryImplTest.class.getClassLoader()).when(pluginConfigurationReader).getClassLoader();
    PluginRepository pluginRepository = new PluginRepositoryImpl(pluginConfigurationReader);
    pluginRepository.initialize();
    Collection<PluginInfo> overview = pluginRepository.getPluginOverview();
    assertThat(overview).hasSize(3);
    assertThat(overview).anyMatch(info -> info.getName().equals("A") && info.getId().equals("jqa.a"));
    assertThat(overview).anyMatch(info -> info.getName().equals("B") && info.getId().equals("jqa.b"));
    assertThat(overview).anyMatch(info -> info.getName().equals("C") && info.getId().equals("jqa.c"));
}
Also used : PluginConfigurationReader(com.buschmais.jqassistant.core.plugin.api.PluginConfigurationReader) JqassistantPlugin(org.jqassistant.schema.plugin.v1.JqassistantPlugin) ScannerPluginRepository(com.buschmais.jqassistant.core.scanner.spi.ScannerPluginRepository) AnalyzerPluginRepository(com.buschmais.jqassistant.core.analysis.spi.AnalyzerPluginRepository) PluginRepository(com.buschmais.jqassistant.core.plugin.api.PluginRepository) PluginInfo(com.buschmais.jqassistant.core.plugin.api.PluginInfo) Test(org.junit.jupiter.api.Test)

Example 12 with JqassistantPlugin

use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.

the class AnalyzerPluginRepositoryImpl method initialize.

@Override
public void initialize() {
    for (JqassistantPlugin plugin : plugins) {
        IdClassListType reportTypes = plugin.getReport();
        initializeReportPlugins(reportTypes);
        initializeRuleInterpreterPlugins(plugin);
    }
}
Also used : JqassistantPlugin(org.jqassistant.schema.plugin.v1.JqassistantPlugin) IdClassListType(org.jqassistant.schema.plugin.v1.IdClassListType)

Example 13 with JqassistantPlugin

use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.

the class AnalyzerPluginRepositoryImpl method initializeRuleInterpreterPlugins.

private void initializeRuleInterpreterPlugins(JqassistantPlugin plugin) {
    IdClassListType ruleInterpreters = plugin.getRuleInterpreter();
    if (ruleInterpreters != null) {
        for (IdClassType pluginType : ruleInterpreters.getClazz()) {
            RuleInterpreterPlugin ruleInterpreterPlugin = createInstance(pluginType.getValue());
            ruleInterpreterPlugin.initialize();
            for (String language : ruleInterpreterPlugin.getLanguages()) {
                Collection<RuleInterpreterPlugin> plugins = ruleInterpreterPlugins.get(language.toLowerCase());
                if (plugins == null) {
                    plugins = new ArrayList<>();
                    ruleInterpreterPlugins.put(language.toLowerCase(), plugins);
                }
                plugins.add(ruleInterpreterPlugin);
            }
        }
    }
}
Also used : IdClassType(org.jqassistant.schema.plugin.v1.IdClassType) IdClassListType(org.jqassistant.schema.plugin.v1.IdClassListType) RuleInterpreterPlugin(com.buschmais.jqassistant.core.analysis.api.RuleInterpreterPlugin)

Example 14 with JqassistantPlugin

use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.

the class PluginIdGenerator method apply.

@Override
public JqassistantPlugin apply(JqassistantPlugin plugin) {
    if (StringUtils.isBlank(plugin.getId())) {
        String name = plugin.getName().toLowerCase();
        IntUnaryOperator replacer = i -> (Character.isWhitespace(i)) ? UNDERSCORE : i;
        StringBuilder generate = new StringBuilder();
        for (int index = 0; index < name.length(); index++) {
            int updated = replacer.applyAsInt(name.charAt(index));
            int lastChar = getLastChar(generate);
            if (!(updated == UNDERSCORE && lastChar == UNDERSCORE)) {
                generate.appendCodePoint(updated);
            }
        }
        plugin.setId(generate.toString());
        LOGGER.debug("Assigned generated plugin id '{}' to plugin named '{}'", plugin.getName(), plugin.getId());
    }
    return plugin;
}
Also used : JqassistantPlugin(org.jqassistant.schema.plugin.v1.JqassistantPlugin) Logger(org.slf4j.Logger) IntUnaryOperator(java.util.function.IntUnaryOperator) LoggerFactory(org.slf4j.LoggerFactory) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) IntUnaryOperator(java.util.function.IntUnaryOperator)

Example 15 with JqassistantPlugin

use of org.jqassistant.schema.plugin.v1.JqassistantPlugin in project jqa-core-framework by buschmais.

the class ScannerPluginRepositoryImpl method getScopes.

private Map<String, Scope> getScopes(List<JqassistantPlugin> plugins) {
    Map<String, Scope> scopes = new HashMap<>();
    for (JqassistantPlugin plugin : plugins) {
        ClassListType scopeTypes = plugin.getScope();
        if (scopeTypes != null) {
            for (String scopePluginName : scopeTypes.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 : Scope(com.buschmais.jqassistant.core.scanner.api.Scope) HashMap(java.util.HashMap) JqassistantPlugin(org.jqassistant.schema.plugin.v1.JqassistantPlugin) IdClassListType(org.jqassistant.schema.plugin.v1.IdClassListType) ClassListType(org.jqassistant.schema.plugin.v1.ClassListType)

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