Skip to content

Commit

Permalink
Parametrize inclusion of Eclipse-compatibility plugin in pom.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
tarilabs committed Sep 8, 2014
1 parent 814eed1 commit 4c57951
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/maven/archetype-metadata.xml
Expand Up @@ -6,6 +6,9 @@
<requiredProperty key="droolsVersion">
<defaultValue>6.1.0.Final</defaultValue>
</requiredProperty>
<requiredProperty key="pomEclipseCompatible">
<defaultValue>true</defaultValue>
</requiredProperty>
</requiredProperties>
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/archetype-resources/pom.xml
@@ -1,3 +1,6 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -68,6 +71,7 @@
</plugin>
</plugins>

#if( $pomEclipseCompatible == "true" )
<!-- The following is added to avoid Eclipse ERROR at the pom.xml line defining the kie-maven-plugin, by explicitly telling Eclipse to avoid run the plugin on Eclipse-build, leaving it trigger only when running Maven, eg "mvn package" or "mvn deploy", etc etc , see http://wiki.eclipse.org/M2E_plugin_execution_not_covered -->
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -97,5 +101,6 @@
</plugin>
</plugins>
</pluginManagement>
#end
</build>
</project>
Expand Up @@ -4,3 +4,4 @@ version=0.1-SNAPSHOT
groupId=archetype.it
artifactId=basic
droolsVersion=6.1.0.CR2
pomEclipseCompatible=true
@@ -0,0 +1,7 @@
#Sun Sep 07 11:34:37 CEST 2014
package=it.pkg
version=0.1-SNAPSHOT
groupId=archetype.it
artifactId=basic
droolsVersion=6.1.0.CR2
pomEclipseCompatible=false
Empty file.
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>archetype.it</groupId>
<artifactId>basic</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>kjar</packaging> <!-- I can use all the src/test/resources correctly, thanks to resolved DROOLS-495 -->

<name>basic</name>
<url>http://drools.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<drools-version>6.1.0.CR2</drools-version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-bom</artifactId>
<type>pom</type>
<version>${drools-version}</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>${drools-version}</version>
<extensions>true</extensions>
<!-- no more need of declaring 'object models' dependencies here, thanks to resolved DROOLS-373 -->
</plugin>
</plugins>

</build>
</project>
@@ -0,0 +1,34 @@
package it.pkg;

public class Measurement {
private String id;
private String val;

public Measurement(String id, String val) {
super();
this.id = id;
this.val = val;
}

public String getId() {
return id;
}

public String getVal() {
return val;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Measurement [");
if (id != null)
builder.append("id=").append(id).append(", ");
if (val != null)
builder.append("val=").append(val);
builder.append("]");
return builder.toString();
}


}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<!-- see http://docs.jboss.org/drools/release/6.1.0.Final/drools-docs/html_single/index.html#d0e1112 -->
</kmodule>
@@ -0,0 +1,18 @@
package it.pkg;

global java.util.Set assertLast2m;

declare Measurement
@role(event)
end

rule "colors seen in the last 2 minutes"
no-loop
when
accumulate ( Measurement( id == "color", $colorVal : val) over window:time(2m);
$mySet : collectSet( $colorVal )
)
then
assertLast2m.clear();
assertLast2m.addAll($mySet);
end
@@ -0,0 +1,86 @@
package it.pkg;

import static org.junit.Assert.*;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.drools.core.time.SessionPseudoClock;
import org.junit.Test;
import org.kie.api.KieBase;
import org.kie.api.KieBaseConfiguration;
import org.kie.api.KieServices;
import org.kie.api.builder.Message;
import org.kie.api.builder.Results;
import org.kie.api.conf.EventProcessingOption;
import org.kie.api.definition.KiePackage;
import org.kie.api.definition.rule.Rule;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.KieSessionConfiguration;
import org.kie.api.runtime.conf.ClockTypeOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RuleTest {
static final Logger LOG = LoggerFactory.getLogger(RuleTest.class);

@Test
public void test() {
KieServices kieServices = KieServices.Factory.get();

KieContainer kContainer = kieServices.getKieClasspathContainer();
Results verifyResults = kContainer.verify();
for (Message m : verifyResults.getMessages()) {
LOG.info("{}", m);
}

LOG.info("Creating kieBase with STREAM option");
KieBaseConfiguration kieBaseConf = kieServices.newKieBaseConfiguration();
kieBaseConf.setOption( EventProcessingOption.STREAM );
KieBase kieBase = kContainer.newKieBase(kieBaseConf);

LOG.info("There should be rules: ");
for ( KiePackage kp : kieBase.getKiePackages() ) {
for (Rule rule : kp.getRules()) {
LOG.info("kp " + kp + " rule " + rule.getName());
}
}

LOG.info("Creating kieSession");
KieSessionConfiguration config = kieServices.newKieSessionConfiguration();
config.setOption( ClockTypeOption.get("pseudo") );
KieSession session = kieBase.newKieSession(config, null);
SessionPseudoClock clock = session.getSessionClock();

LOG.info("Populating globals");
Set<String> check = new HashSet<String>();
session.setGlobal("assertLast2m", check);

LOG.info("Now running data");

clock.advanceTime(1, TimeUnit.MINUTES);
Measurement mRed= new Measurement("color", "red");
session.insert(mRed);
session.fireAllRules();

clock.advanceTime(1, TimeUnit.MINUTES);
Measurement mGreen= new Measurement("color", "green");
session.insert(mGreen);
session.fireAllRules();

clock.advanceTime(1, TimeUnit.MINUTES);
Measurement mBlue= new Measurement("color", "blue");
session.insert(mBlue);
session.fireAllRules();

LOG.info("Final checks");

assertEquals("Size of object in Working Memory is 2 for the last 2", 2, session.getObjects().size());
assertFalse("contains red", check.contains("red"));
assertTrue("contains green", check.contains("green"));
assertTrue("contains blue", check.contains("blue"));

}
}
@@ -0,0 +1,14 @@
log4j.rootLogger=INFO, A1

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p [%c] (%t) %m%n

log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.File=basic.log
log4j.appender.A2.DatePattern='.'yyyy-MM-dd
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d %-5p [%c] (%t) %m%n

# Print only messages of level WARN or above in the package it.pkg.
#log4j.logger.it.pkg=DEBUG

0 comments on commit 4c57951

Please sign in to comment.