Search in sources :

Example 1 with AbstractRuleProvider

use of org.jboss.windup.config.AbstractRuleProvider in project windup by windup.

the class MetaDataHandlerTest method testXmlRuleOverrideProviderMetadata.

public void testXmlRuleOverrideProviderMetadata(File fXmlFile) throws Exception {
    RuleLoaderContext loaderContext = new RuleLoaderContext(Collections.singleton(fXmlFile.toPath()), null);
    ParserContext parser = new ParserContext(furnace, loaderContext);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document firstXmlFile = dBuilder.parse(fXmlFile);
    parser.processElement(firstXmlFile.getDocumentElement());
    // verify xmlfile
    Assert.assertEquals(1, parser.getRuleProviders().size());
    AbstractRuleProvider abstractRuleProvider = parser.getRuleProviders().get(0);
    RuleProviderMetadata metadata = abstractRuleProvider.getMetadata();
    Assert.assertTrue(metadata.isOverrideProvider());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) ParserContext(org.jboss.windup.config.parser.ParserContext) Document(org.w3c.dom.Document) RuleLoaderContext(org.jboss.windup.config.loader.RuleLoaderContext)

Example 2 with AbstractRuleProvider

use of org.jboss.windup.config.AbstractRuleProvider in project windup by windup.

the class RuleProviderSorter method sort.

/**
 * Perform the entire sort operation
 */
private void sort() {
    DefaultDirectedWeightedGraph<RuleProvider, DefaultEdge> graph = new DefaultDirectedWeightedGraph<>(DefaultEdge.class);
    for (RuleProvider provider : providers) {
        graph.addVertex(provider);
    }
    addProviderRelationships(graph);
    checkForCycles(graph);
    List<RuleProvider> result = new ArrayList<>(this.providers.size());
    TopologicalOrderIterator<RuleProvider, DefaultEdge> iterator = new TopologicalOrderIterator<>(graph);
    while (iterator.hasNext()) {
        RuleProvider provider = iterator.next();
        result.add(provider);
    }
    this.providers = Collections.unmodifiableList(result);
    int index = 0;
    for (RuleProvider provider : this.providers) {
        if (provider instanceof AbstractRuleProvider)
            ((AbstractRuleProvider) provider).setExecutionIndex(index++);
    }
}
Also used : ArrayList(java.util.ArrayList) DefaultEdge(org.jgrapht.graph.DefaultEdge) TopologicalOrderIterator(org.jgrapht.traverse.TopologicalOrderIterator) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) RuleProvider(org.jboss.windup.config.RuleProvider) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) DefaultDirectedWeightedGraph(org.jgrapht.graph.DefaultDirectedWeightedGraph)

Example 3 with AbstractRuleProvider

use of org.jboss.windup.config.AbstractRuleProvider in project windup by windup.

the class RuleProviderSorterTest method testImproperCrossPhaseDependency.

@Test
public void testImproperCrossPhaseDependency() {
    AbstractRuleProvider v1 = new WCPPhase1Class1();
    AbstractRuleProvider v2 = new WCPPhase1Class2();
    AbstractRuleProvider v3 = new WCPPhase1Class3();
    AbstractRuleProvider v4 = new WCPPhase2Class1();
    AbstractRuleProvider v5 = new WCPPhase2Class3();
    AbstractRuleProvider v6 = new WCPPhase2Class4();
    AbstractRuleProvider wrongPhaseDep = new WCPPhase1WrongPhaseDep();
    List<RuleProvider> ruleProviders = new ArrayList<>();
    ruleProviders.add(v6);
    ruleProviders.add(v5);
    ruleProviders.add(v3);
    ruleProviders.add(v4);
    ruleProviders.add(v2);
    ruleProviders.add(v1);
    ruleProviders.add(wrongPhaseDep);
    try {
        RuleProviderSorter.sort(ruleProviders);
        Assert.fail("No improper phase dependencies detected!");
    } catch (IncorrectPhaseDependencyException | WindupMultiStringException e) {
    // ignore... this exception is expected in this test
    }
}
Also used : WindupMultiStringException(org.jboss.windup.util.exception.WindupMultiStringException) ArrayList(java.util.ArrayList) RuleProvider(org.jboss.windup.config.RuleProvider) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) Test(org.junit.Test)

Example 4 with AbstractRuleProvider

use of org.jboss.windup.config.AbstractRuleProvider in project windup by windup.

the class RuleProviderSorterTest method testSort.

@Test
public void testSort() {
    AbstractRuleProvider v1 = new WCPPhase1Class1();
    AbstractRuleProvider v2 = new WCPPhase1Class2();
    AbstractRuleProvider vI = new WCPPhaseDependentClass2();
    AbstractRuleProvider v3 = new WCPPhase1Class3();
    AbstractRuleProvider v4 = new WCPPhase2Class1();
    AbstractRuleProvider v5 = new WCPDependentPhase2Step2();
    AbstractRuleProvider v6 = new WCPPhase2Class3();
    AbstractRuleProvider v7 = new WCPPhase2Class4();
    List<RuleProvider> ruleProviders = new ArrayList<>();
    ruleProviders.add(v7);
    ruleProviders.add(v6);
    ruleProviders.add(vI);
    ruleProviders.add(v5);
    ruleProviders.add(v3);
    ruleProviders.add(v4);
    ruleProviders.add(v2);
    ruleProviders.add(v1);
    ruleProviders.addAll(getPhases());
    List<RuleProvider> sortedRuleProviders = new ArrayList<>(RuleProviderSorter.sort(ruleProviders));
    System.out.println("Results With Phases:  " + sortedRuleProviders);
    /*
         * Remove phases (this makes asserting on the results easier)
         */
    ListIterator<RuleProvider> iterator = sortedRuleProviders.listIterator();
    while (iterator.hasNext()) {
        RuleProvider p = iterator.next();
        if (p instanceof RulePhase) {
            iterator.remove();
        }
    }
    System.out.println("Results without Phases:  " + sortedRuleProviders);
    Assert.assertEquals(v1, sortedRuleProviders.get(0));
    Assert.assertEquals(v2, sortedRuleProviders.get(1));
    Assert.assertEquals(vI, sortedRuleProviders.get(2));
    Assert.assertEquals(v3, sortedRuleProviders.get(3));
    Assert.assertEquals(v4, sortedRuleProviders.get(4));
    Assert.assertEquals(v5, sortedRuleProviders.get(5));
    Assert.assertEquals(v6, sortedRuleProviders.get(6));
    Assert.assertEquals(v7, sortedRuleProviders.get(7));
}
Also used : ArrayList(java.util.ArrayList) RuleProvider(org.jboss.windup.config.RuleProvider) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) RulePhase(org.jboss.windup.config.phase.RulePhase) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) Test(org.junit.Test)

Example 5 with AbstractRuleProvider

use of org.jboss.windup.config.AbstractRuleProvider in project windup by windup.

the class RuleProviderSorterTest method testAcceptableCrossPhaseDependency.

@Test
public void testAcceptableCrossPhaseDependency() {
    AbstractRuleProvider v1 = new WCPPhase1Class1();
    AbstractRuleProvider v2 = new WCPPhase1Class2();
    AbstractRuleProvider v3 = new WCPPhase1Class3();
    AbstractRuleProvider v4 = new WCPPhase2Class1();
    AbstractRuleProvider v5 = new WCPDependentPhase2Step2();
    AbstractRuleProvider v6 = new WCPPhase2Class3();
    AbstractRuleProvider v7 = new WCPPhase2Class4();
    AbstractRuleProvider acceptablePhaseDep = new WCPAcceptableCrossPhaseDep();
    List<RuleProvider> ruleProviders = new ArrayList<>();
    ruleProviders.add(v7);
    ruleProviders.add(v6);
    ruleProviders.add(v5);
    ruleProviders.add(v3);
    ruleProviders.add(v4);
    ruleProviders.add(v2);
    ruleProviders.add(v1);
    ruleProviders.add(acceptablePhaseDep);
    try {
        RuleProviderSorter.sort(ruleProviders);
    } catch (IncorrectPhaseDependencyException e) {
        e.printStackTrace();
        Assert.fail("This cross-dependency should be acceptable!");
    }
}
Also used : ArrayList(java.util.ArrayList) RuleProvider(org.jboss.windup.config.RuleProvider) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) AbstractRuleProvider(org.jboss.windup.config.AbstractRuleProvider) Test(org.junit.Test)

Aggregations

AbstractRuleProvider (org.jboss.windup.config.AbstractRuleProvider)13 RuleProvider (org.jboss.windup.config.RuleProvider)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)4 Map (java.util.Map)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 Document (org.w3c.dom.Document)3 IOException (java.io.IOException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 List (java.util.List)2 RuleLoaderContext (org.jboss.windup.config.loader.RuleLoaderContext)2 ParserContext (org.jboss.windup.config.parser.ParserContext)2 RulePhase (org.jboss.windup.config.phase.RulePhase)2 WindupException (org.jboss.windup.util.exception.WindupException)2 EvaluationContext (org.ocpsoft.rewrite.context.EvaluationContext)2 StringModel (freemarker.ext.beans.StringModel)1 TemplateModelException (freemarker.template.TemplateModelException)1 Binding (groovy.lang.Binding)1