Search in sources :

Example 1 with RuleParserPlugin

use of com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin in project jqa-core-framework by buschmais.

the class RuleParser method parse.

private void parse(RuleSource source, RuleSetBuilder ruleSetBuilder) throws RuleException {
    for (RuleParserPlugin ruleParserPlugin : ruleParserPlugins) {
        if (ruleParserPlugin.accepts(source)) {
            logger.debug("Parsing rule source with id '{}' using '{}'.", source.getId(), ruleParserPlugin);
            ruleParserPlugin.parse(source, ruleSetBuilder);
            return;
        }
    }
    logger.debug("Rule source with id '{}' has not been accepted by any rule parser.", source.getId());
}
Also used : RuleParserPlugin(com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin)

Example 2 with RuleParserPlugin

use of com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin in project jqa-core-framework by buschmais.

the class XmlRuleParserPluginTest method testReadUrlSource.

@Test
void testReadUrlSource() throws Exception {
    RuleSetBuilder ruleSetBuilder = RuleSetBuilder.newInstance();
    URL url = getClass().getResource("/test-concepts.xml");
    RuleParserPlugin reader = new XmlRuleParserPlugin();
    reader.initialize();
    reader.configure(RuleConfiguration.builder().build());
    UrlRuleSource ruleSource = new UrlRuleSource(url);
    assertThat(reader.accepts(ruleSource), equalTo(true));
    reader.parse(ruleSource, ruleSetBuilder);
    RuleSet ruleSet = ruleSetBuilder.getRuleSet();
    assertThat(ruleSet.getConceptBucket().size(), equalTo(1));
    assertThat(ruleSet.getConstraintBucket().size(), equalTo(1));
    assertThat(ruleSet.getConceptBucket().getIds(), contains("java:Throwable"));
    assertThat(ruleSet.getConstraintBucket().getIds(), contains("example:ConstructorOfDateMustNotBeUsed"));
    assertThat(ruleSet.getGroupsBucket().size(), equalTo(1));
    Group group = ruleSet.getGroupsBucket().getById("default");
    assertThat(group.getId(), equalTo("default"));
}
Also used : RuleParserPlugin(com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin) XmlRuleParserPlugin(com.buschmais.jqassistant.core.rule.impl.reader.XmlRuleParserPlugin) XmlRuleParserPlugin(com.buschmais.jqassistant.core.rule.impl.reader.XmlRuleParserPlugin) UrlRuleSource(com.buschmais.jqassistant.core.rule.api.source.UrlRuleSource) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 3 with RuleParserPlugin

use of com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin 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 4 with RuleParserPlugin

use of com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin in project jqa-core-framework by buschmais.

the class RuleSetTestHelper method getDefaultRuleParserPlugins.

public static List<RuleParserPlugin> getDefaultRuleParserPlugins(RuleConfiguration ruleConfiguration) throws RuleException {
    List<RuleParserPlugin> ruleParserPlugins = asList(new AsciidocRuleParserPlugin(), new XmlRuleParserPlugin(), new YamlRuleParserPlugin());
    for (RuleParserPlugin ruleParserPlugin : ruleParserPlugins) {
        ruleParserPlugin.initialize();
        ruleParserPlugin.configure(ruleConfiguration);
    }
    return ruleParserPlugins;
}
Also used : RuleParserPlugin(com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin) YamlRuleParserPlugin(com.buschmais.jqassistant.core.rule.impl.reader.YamlRuleParserPlugin) AsciidocRuleParserPlugin(com.buschmais.jqassistant.core.rule.impl.reader.AsciidocRuleParserPlugin) XmlRuleParserPlugin(com.buschmais.jqassistant.core.rule.impl.reader.XmlRuleParserPlugin) YamlRuleParserPlugin(com.buschmais.jqassistant.core.rule.impl.reader.YamlRuleParserPlugin) XmlRuleParserPlugin(com.buschmais.jqassistant.core.rule.impl.reader.XmlRuleParserPlugin) AsciidocRuleParserPlugin(com.buschmais.jqassistant.core.rule.impl.reader.AsciidocRuleParserPlugin)

Aggregations

RuleParserPlugin (com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin)4 XmlRuleParserPlugin (com.buschmais.jqassistant.core.rule.impl.reader.XmlRuleParserPlugin)2 PluginRepositoryException (com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException)1 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)1 UrlRuleSource (com.buschmais.jqassistant.core.rule.api.source.UrlRuleSource)1 AsciidocRuleParserPlugin (com.buschmais.jqassistant.core.rule.impl.reader.AsciidocRuleParserPlugin)1 YamlRuleParserPlugin (com.buschmais.jqassistant.core.rule.impl.reader.YamlRuleParserPlugin)1 URL (java.net.URL)1 IdClassListType (org.jqassistant.schema.plugin.v1.IdClassListType)1 IdClassType (org.jqassistant.schema.plugin.v1.IdClassType)1 JqassistantPlugin (org.jqassistant.schema.plugin.v1.JqassistantPlugin)1 Test (org.junit.jupiter.api.Test)1