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());
}
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++);
}
}
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
}
}
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));
}
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!");
}
}
Aggregations