Skip to content

Commit

Permalink
ongoign work on model based configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Mar 5, 2019
1 parent b920447 commit 330af63
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 41 deletions.
Expand Up @@ -174,7 +174,7 @@ public void doConfigure(final List<SaxEvent> eventList) throws JoranException {
}

Model top = interpreter.getInterpretationContext().peekModel();
doConfigure(top, interpreter);
doConfigure(top);
}

public void doConfigure(Model model) {
Expand Down
Expand Up @@ -30,6 +30,7 @@
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.action.NOPAction;
import ch.qos.logback.core.joran.action.TopElementAction;
import ch.qos.logback.core.joran.action.ext.BadBeginAction;
import ch.qos.logback.core.joran.action.ext.BadEndAction;
import ch.qos.logback.core.joran.action.ext.HelloAction;
Expand Down Expand Up @@ -58,7 +59,7 @@ SAXParser createParser() throws Exception {

void doTest(String filename, Integer expectedInt, Class<?> exceptionClass) throws Exception {

rulesMap.put(new ElementSelector("test"), new NOPAction());
rulesMap.put(new ElementSelector("test"), new TopElementAction());
rulesMap.put(new ElementSelector("test/badBegin"), new BadBeginAction());
rulesMap.put(new ElementSelector("test/badBegin/touch"), new TouchAction());
rulesMap.put(new ElementSelector("test/badEnd"), new BadEndAction());
Expand Down
Expand Up @@ -27,12 +27,14 @@
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;

import org.junit.Before;
import org.junit.Test;

import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.action.TopElementAction;
import ch.qos.logback.core.joran.action.ext.IncAction;
import ch.qos.logback.core.joran.spi.ElementSelector;
import ch.qos.logback.core.joran.spi.JoranException;
Expand All @@ -46,11 +48,16 @@ public class TrivialConfiguratorTest {
Context context = new ContextBase();
HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>();

public void doTest(String filename) throws Exception {


@Before
public void setUp() {
// rule store is case insensitve
rulesMap.put(new ElementSelector("x"), new TopElementAction());
rulesMap.put(new ElementSelector("x/inc"), new IncAction());

}

public void doTest(String filename) throws Exception {
TrivialConfigurator trivialConfigurator = new TrivialConfigurator(rulesMap);

trivialConfigurator.setContext(context);
Expand Down
Expand Up @@ -3,7 +3,6 @@
import org.xml.sax.Attributes;

import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.TopModel;

/**
Expand Down
Expand Up @@ -30,6 +30,7 @@
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.action.IncludeAction;
import ch.qos.logback.core.joran.action.NOPAction;
import ch.qos.logback.core.joran.action.TopElementAction;
import ch.qos.logback.core.joran.action.ext.StackAction;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.testUtil.CoreTestConstants;
Expand All @@ -55,7 +56,7 @@ public class IfThenElseAndIncludeCompositionTest {
@Before
public void setUp() throws Exception {
HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>();
rulesMap.put(new ElementSelector("x"), new NOPAction());
rulesMap.put(new ElementSelector("x"), new TopElementAction());
rulesMap.put(new ElementSelector("x/stack"), stackAction);
rulesMap.put(new ElementSelector("*/if"), new IfAction());
rulesMap.put(new ElementSelector("*/if/then"), new ThenAction());
Expand Down
Expand Up @@ -21,20 +21,23 @@
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.ActionException;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.model.TopModel;

public class ListenAction extends Action implements InPlayListener {

List<SaxEvent> seList = new ArrayList<SaxEvent>();

@Override
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
ec.addInPlayListener(this);
public void begin(InterpretationContext interpretationContext, String name, Attributes attributes) throws ActionException {
TopModel topModel = new TopModel();
topModel.setTag(name);
interpretationContext.pushModel(topModel);
interpretationContext.addInPlayListener(this);
}

@Override
public void end(InterpretationContext ec, String name) throws ActionException {
ec.removeInPlayListener(this);

}

public void inPlay(SaxEvent event) {
Expand Down
Expand Up @@ -39,7 +39,7 @@ public FruitConfigurator(FruitFactory ff) {


@Override
final public void doConfigure(Model model) throws JoranException {
final public void doConfigure(Model model) {
buildInterpreter();
interpreter.getInterpretationContext().pushObject(ff);

Expand Down
Expand Up @@ -46,7 +46,10 @@ public Fruit buildFruit() {
for (Model m : modelList)
ic.pushModel(m);
DefaultProcessor defaultProcessor = fruitConfigurator.buildDefaultProcessor(context, ic);
defaultProcessor.process();

Model top = ic.peekModel();

defaultProcessor.process(top);

return fruit;
}
Expand Down
39 changes: 9 additions & 30 deletions pom.xml
Expand Up @@ -47,7 +47,7 @@
</modules>

<properties>
<jdk.version>1.8</jdk.version>
<jdk.version>8</jdk.version>
<maven.compiler.source>${jdk.version}</maven.compiler.source>
<maven.compiler.target>${jdk.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -369,6 +369,7 @@

<plugins>

<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
Expand All @@ -392,41 +393,19 @@
</toolchains>
</configuration>
</plugin>

-->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>

<execution>
<id>base-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>

<execution>
<id>default-compile</id>
<configuration>
<jdkToolchain>
<version>[9, )</version>
</jdkToolchain>
<release>9</release>
</configuration>
</execution>
</executions>
<configuration>
<jdkToolchain>
<version>[8,)</version>
</jdkToolchain>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</configuration>

</plugin>


Expand Down

0 comments on commit 330af63

Please sign in to comment.