Search in sources :

Example 1 with RuleSource

use of com.buschmais.jqassistant.core.rule.api.source.RuleSource in project jqa-core-framework by buschmais.

the class XmlRuleSetReader method read.

@Override
public void read(List<? extends RuleSource> sources, RuleSetBuilder ruleSetBuilder) throws RuleException {
    for (RuleSource ruleSource : sources) {
        if (ruleSource.isType(RuleSource.Type.XML)) {
            List<JqassistantRules> rules = readXmlSource(ruleSource);
            convert(rules, ruleSource, ruleSetBuilder);
        }
    }
}
Also used : RuleSource(com.buschmais.jqassistant.core.rule.api.source.RuleSource)

Example 2 with RuleSource

use of com.buschmais.jqassistant.core.rule.api.source.RuleSource in project jqa-core-framework by buschmais.

the class RuleSetBuilderTest method duplicateRules.

@Test
public void duplicateRules() throws RuleException {
    RuleSource ruleSource = new FileRuleSource(new File("test.xml"));
    // Concepts
    Concept concept1 = Concept.Builder.newConcept().id("test").ruleSource(ruleSource).get();
    Concept concept2 = Concept.Builder.newConcept().id("test").ruleSource(ruleSource).get();
    RuleSetBuilder builder = RuleSetBuilder.newInstance();
    builder.addConcept(concept1);
    try {
        builder.addConcept(concept2);
        Assert.fail("Expecting an exception");
    } catch (RuleException e) {
    }
    // Constraints
    Constraint constraint1 = Constraint.Builder.newConstraint().id("test").ruleSource(ruleSource).get();
    Constraint constraint2 = Constraint.Builder.newConstraint().id("test").ruleSource(ruleSource).get();
    builder.addConstraint(constraint1);
    try {
        builder.addConstraint(constraint2);
        Assert.fail("Expecting an exception");
    } catch (RuleException e) {
    }
    // Groups
    Group group1 = Group.Builder.newGroup().id("test").ruleSource(ruleSource).get();
    Group group2 = Group.Builder.newGroup().id("test").ruleSource(ruleSource).get();
    builder.addGroup(group1);
    try {
        builder.addGroup(group2);
        Assert.fail("Expecting an exception");
    } catch (RuleException e) {
    }
}
Also used : RuleSource(com.buschmais.jqassistant.core.rule.api.source.RuleSource) FileRuleSource(com.buschmais.jqassistant.core.rule.api.source.FileRuleSource) FileRuleSource(com.buschmais.jqassistant.core.rule.api.source.FileRuleSource) File(java.io.File) Test(org.junit.Test)

Example 3 with RuleSource

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

use of com.buschmais.jqassistant.core.rule.api.source.RuleSource in project jqa-core-framework by buschmais.

the class RuleSetTestHelper method readRuleSet.

public static RuleSet readRuleSet(String resource, RuleConfiguration ruleConfiguration) throws RuleException {
    RuleSetBuilder ruleSetBuilder = RuleSetBuilder.newInstance();
    CompoundRuleSetReader reader = new CompoundRuleSetReader(ruleConfiguration);
    URL url = RuleSetTestHelper.class.getResource(resource);
    assertThat("Cannot read resource URL:" + resource, url, notNullValue());
    RuleSource ruleSource = new UrlRuleSource(url);
    reader.read(Collections.singletonList(ruleSource), ruleSetBuilder);
    return ruleSetBuilder.getRuleSet();
}
Also used : RuleSource(com.buschmais.jqassistant.core.rule.api.source.RuleSource) UrlRuleSource(com.buschmais.jqassistant.core.rule.api.source.UrlRuleSource) UrlRuleSource(com.buschmais.jqassistant.core.rule.api.source.UrlRuleSource) CompoundRuleSetReader(com.buschmais.jqassistant.core.rule.impl.reader.CompoundRuleSetReader) URL(java.net.URL)

Aggregations

RuleSource (com.buschmais.jqassistant.core.rule.api.source.RuleSource)4 JqassistantPlugin (com.buschmais.jqassistant.core.plugin.schema.v1.JqassistantPlugin)1 RulesType (com.buschmais.jqassistant.core.plugin.schema.v1.RulesType)1 ClasspathRuleSource (com.buschmais.jqassistant.core.rule.api.source.ClasspathRuleSource)1 FileRuleSource (com.buschmais.jqassistant.core.rule.api.source.FileRuleSource)1 UrlRuleSource (com.buschmais.jqassistant.core.rule.api.source.UrlRuleSource)1 CompoundRuleSetReader (com.buschmais.jqassistant.core.rule.impl.reader.CompoundRuleSetReader)1 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1