Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[JBRULES-3668] remove namespaces from KBase and KSession

  • Loading branch information...
commit 484800ad6c8d77dfb5c1912c48ab3fdb841529e8 1 parent b042ae4
Mario Fusco mariofusco authored
Showing with 180 additions and 1,167 deletions.
  1. +20 −146 drools-cdi-example/src/main/resources/META-INF/kproject.xml
  2. +1 −1  drools-compiler/src/main/java/org/drools/builder/impl/KBaseUnitCachingFactory.java
  3. +3 −3 drools-compiler/src/main/java/org/drools/builder/impl/KBaseUnitImpl.java
  4. +20 −17 drools-compiler/src/main/java/org/drools/builder/impl/KnowledgeContainerImpl.java
  5. +27 −27 drools-compiler/src/main/java/org/drools/cdi/KProjectExtension.java
  6. +0 −76 drools-compiler/src/main/java/org/drools/kproject/GenerateKBaseProjectFiles.java
  7. +0 −67 drools-compiler/src/main/java/org/drools/kproject/GenerateKSessionProducer.java
  8. +1 −7 drools-compiler/src/main/java/org/drools/kproject/KBase.java
  9. +24 −47 drools-compiler/src/main/java/org/drools/kproject/KBaseImpl.java
  10. +11 −12 drools-compiler/src/main/java/org/drools/kproject/KProject.java
  11. +0 −237 drools-compiler/src/main/java/org/drools/kproject/KProjectChangeLog.java
  12. +4 −5 drools-compiler/src/main/java/org/drools/kproject/KProjectImpl.java
  13. +10 −16 drools-compiler/src/main/java/org/drools/kproject/KSession.java
  14. +2 −34 drools-compiler/src/main/java/org/drools/kproject/KSessionImpl.java
  15. +20 −20 drools-compiler/src/test/java/org/drools/kproject/AbstractKnowledgeTest.java
  16. +10 −10 drools-compiler/src/test/java/org/drools/kproject/KJarTest.java
  17. +0 −411 drools-compiler/src/test/java/org/drools/kproject/KProjectDirtyLogTest.java
  18. +4 −4 drools-compiler/src/test/java/org/drools/kproject/KProjectTest.java
  19. +9 −9 drools-compiler/src/test/java/org/drools/kproject/KnowledgeContainerTest.java
  20. 0  ...ven-plugin-example/src/kbases/{org.drools.FireAlarmKBase → FireAlarmKBase}/org.drools.sample/alarm.drl
  21. 0  ...ven-plugin-example/src/kbases/{org.drools.FireAlarmKBase → FireAlarmKBase}/org.drools.sample/rules.drl
  22. 0  ...en-plugin-example/src/kbases/{org.drools.FireAlarmKBase → FireAlarmKBase}/org.drools.sample/rules2.drl
  23. 0  drools-maven-plugin-example/src/kbases/{org.test.KBase1 → KBase1}/org.drools.test/decA.drl
  24. 0  drools-maven-plugin-example/src/kbases/{org.test.KBase1 → KBase1}/org.drools.test/decB.drl
  25. 0  drools-maven-plugin-example/src/kbases/{org.test.KBase1 → KBase1}/org.drools.test/rule.drl
  26. +4 −4 drools-maven-plugin-example/src/main/resources/META-INF/kproject.xml
  27. +6 −6 drools-maven-plugin-example/src/test/java/org/drools/kproject/KProjectTest.java
  28. +1 −1  drools-maven-plugin/src/main/java/org/drools/BuildMojo.java
  29. +3 −7 drools-maven-plugin/src/main/java/org/drools/KProjectMojo.java
166 drools-cdi-example/src/main/resources/META-INF/kproject.xml
View
@@ -1,151 +1,25 @@
-<org.drools.kproject.KProjectImpl>
+<kproject kProjectPath="src/main/resources/" kBasesPath="src/kbases">
<groupArtifactVersion>
<groupId>org.test</groupId>
<artifactId>fol4</artifactId>
<version>0.1</version>
</groupArtifactVersion>
- <kProjectPath>src/main/resources/</kProjectPath>
- <kBasesPath>src/kbases</kBasesPath>
- <kBases>
- <entry>
- <string>fol4.test1.KBase1</string>
- <org.drools.kproject.KBaseImpl>
- <namespace>fol4.test1</namespace>
- <name>KBase1</name>
- <includes/>
- <files class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>fol4/test1/rule1.drl</string>
- <string>fol4/test1/rule2.drl</string>
- </a>
- </files>
- <annotations class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>@ApplicationScoped; @Inject</string>
- </a>
- </annotations>
- <equalsBehavior>EQUALITY</equalsBehavior>
- <eventProcessingMode>STREAM</eventProcessingMode>
- <kSessions>
- <entry>
- <string>fol4.test1.KSession2</string>
- <org.drools.kproject.KSessionImpl>
- <namespace>fol4.test1</namespace>
- <name>KSession2</name>
- <type>stateful</type>
- <clockType>
- <clockType>pseudo</clockType>
- </clockType>
- <annotations class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>@ApplicationScoped; @Inject</string>
- </a>
- </annotations>
- <kBase reference="../../../.."/>
- </org.drools.kproject.KSessionImpl>
- </entry>
- <entry>
- <string>fol4.test1.KSession1</string>
- <org.drools.kproject.KSessionImpl>
- <namespace>fol4.test1</namespace>
- <name>KSession1</name>
- <type>stateless</type>
- <clockType>
- <clockType>realtime</clockType>
- </clockType>
- <annotations class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>@ApplicationScoped; @Inject</string>
- </a>
- </annotations>
- <kBase reference="../../../.."/>
- </org.drools.kproject.KSessionImpl>
- </entry>
- </kSessions>
- <kProject reference="../../../.."/>
- </org.drools.kproject.KBaseImpl>
- </entry>
- <entry>
- <string>fol4.test3.KBase3</string>
- <org.drools.kproject.KBaseImpl>
- <namespace>fol4.test3</namespace>
- <name>KBase3</name>
- <includes>
- <string>fol4.test1.KBase1</string>
- <string>fol4.test2.KBase2</string>
- </includes>
- <files class="java.util.Arrays$ArrayList">
- <a class="string-array"/>
- </files>
- <annotations class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>@ApplicationScoped</string>
- </a>
- </annotations>
- <equalsBehavior>IDENTITY</equalsBehavior>
- <eventProcessingMode>CLOUD</eventProcessingMode>
- <kSessions>
- <entry>
- <string>fol4.test3.KSession4</string>
- <org.drools.kproject.KSessionImpl>
- <namespace>fol4.test3</namespace>
- <name>KSession4</name>
- <type>stateless</type>
- <clockType>
- <clockType>pseudo</clockType>
- </clockType>
- <annotations class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>@ApplicationScoped</string>
- </a>
- </annotations>
- <kBase reference="../../../.."/>
- </org.drools.kproject.KSessionImpl>
- </entry>
- </kSessions>
- <kProject reference="../../../.."/>
- </org.drools.kproject.KBaseImpl>
- </entry>
- <entry>
- <string>fol4.test2.KBase2</string>
- <org.drools.kproject.KBaseImpl>
- <namespace>fol4.test2</namespace>
- <name>KBase2</name>
- <includes/>
- <files class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>fol4/test2/rule1.drl</string>
- <string>fol4/test2/rule2.drl</string>
- </a>
- </files>
- <annotations class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>@ApplicationScoped</string>
- </a>
- </annotations>
- <equalsBehavior>IDENTITY</equalsBehavior>
- <eventProcessingMode>CLOUD</eventProcessingMode>
- <kSessions>
- <entry>
- <string>fol4.test2.KSession3</string>
- <org.drools.kproject.KSessionImpl>
- <namespace>fol4.test2</namespace>
- <name>KSession3</name>
- <type>stateful</type>
- <clockType>
- <clockType>pseudo</clockType>
- </clockType>
- <annotations class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>@ApplicationScoped</string>
- </a>
- </annotations>
- <kBase reference="../../../.."/>
- </org.drools.kproject.KSessionImpl>
- </entry>
- </kSessions>
- <kProject reference="../../../.."/>
- </org.drools.kproject.KBaseImpl>
- </entry>
- </kBases>
-</org.drools.kproject.KProjectImpl>
+ <kbases>
+ <kbase name="fol4.test1.KBase1" equalsBehavior="EQUALITY" eventProcessingMode="STREAM">
+ <ksessions>
+ <ksession name="fol4.test1.KSession2" type="stateful" clockType="pseudo"/>
+ <ksession name="fol4.test1.KSession1" type="stateless" clockType="realtime"/>
+ </ksessions>
+ </kbase>
+ <kbase name="fol4.test3.KBase3" equalsBehavior="IDENTITY" eventProcessingMode="CLOUD">
+ <ksessions>
+ <ksession name="fol4.test3.KSession4" type="stateless" clockType="pseudo"/>
+ </ksessions>
+ </kbase>
+ <kbase name="fol4.test2.KBase2" equalsBehavior="IDENTITY" eventProcessingMode="CLOUD">
+ <ksessions>
+ <ksession name="fol4.test2.KSession3" type="stateful" clockType="pseudo"/>
+ </ksessions>
+ </kbase>
+ </kbases>
+</kproject>
2  drools-compiler/src/main/java/org/drools/builder/impl/KBaseUnitCachingFactory.java
View
@@ -15,7 +15,7 @@
private static final Map<String, KBaseUnitImpl> cache = new EvictionCache<String, KBaseUnitImpl>(EVICTION_TIME);
static KBaseUnitImpl getOrCreateKBaseUnit(String url, KBase kBase) {
- String kBaseName = kBase.getQName();
+ String kBaseName = kBase.getName();
KBaseUnitImpl unit = cache.get(kBaseName);
if (unit == null) {
unit = new KBaseUnitImpl(url, kBase);
6 drools-compiler/src/main/java/org/drools/builder/impl/KBaseUnitImpl.java
View
@@ -79,7 +79,7 @@ boolean hasIncludes() {
}
public String getKBaseName() {
- return kBase.getQName();
+ return kBase.getName();
}
public boolean hasErrors() {
@@ -140,7 +140,7 @@ private void buildKBaseFiles(CompositeKnowledgeBuilder ckbuilder, KBase kBase) {
}
try {
- for ( String file : getFiles(kBase.getQName(), zipFile) ) {
+ for ( String file : getFiles(kBase.getName(), zipFile) ) {
ZipEntry zipEntry = zipFile.getEntry( file );
ckbuilder.add( ResourceFactory.newInputStreamResource( zipFile.getInputStream( zipEntry ) ), ResourceType.DRL );
}
@@ -154,7 +154,7 @@ private void buildKBaseFiles(CompositeKnowledgeBuilder ckbuilder, KBase kBase) {
}
} else {
try {
- for ( String file : getFiles(kBase.getQName(), new File(rootPath)) ) {
+ for ( String file : getFiles(kBase.getName(), new File(rootPath)) ) {
ckbuilder.add( ResourceFactory.newFileResource( new File(rootPath, file) ), ResourceType.DRL );
}
} catch ( Exception e) {
37 drools-compiler/src/main/java/org/drools/builder/impl/KnowledgeContainerImpl.java
View
@@ -40,7 +40,7 @@
private static final Logger log = LoggerFactory.getLogger(KnowledgeContainer.class);
- public static final String KBASES_FOLDER = "kbases";
+ public static final String KBASES_FOLDER = "src/kbases";
public static final String KPROJECT_JAR_PATH = "META-INF/kproject.xml";
public static final String KPROJECT_RELATIVE_PATH = "src/main/resources/" + KPROJECT_JAR_PATH;
@@ -79,7 +79,7 @@ public File buildKJar(File rootFolder, File outputFolder, String jarName) {
public List<KBaseUnit> getKBaseUnits() {
List<KBaseUnit> units = new ArrayList<KBaseUnit>();
for (KBase kBase : kBases.values()) {
- units.add(getOrCreateKBaseUnit(urls.get(kBase.getQName()), kBase));
+ units.add(getOrCreateKBaseUnit(urls.get(kBase.getName()), kBase));
}
return units;
}
@@ -88,7 +88,7 @@ public File buildKJar(File rootFolder, File outputFolder, String jarName) {
List<KBaseUnit> units = new ArrayList<KBaseUnit>();
KProject kProject = fromXML(new File(rootFolder, KPROJECT_RELATIVE_PATH));
for (KBase kBase : kProject.getKBases().values()) {
- units.add(new KBaseUnitImpl( sourceFolder.getAbsolutePath() + "/" + kBase.getQName(), kBase, classLoader ));
+ units.add(new KBaseUnitImpl( sourceFolder.getAbsolutePath() + "/" + kBase.getName(), kBase, classLoader ));
}
return units;
}
@@ -99,9 +99,8 @@ public void copyKBasesToOutput(File rootFolder, File outputFolder) {
copyFile(kProjectFile, new File(outputFolder, KPROJECT_JAR_PATH));
for (KBase kBase : kProject.getKBases().values()) {
- for (String kBaseFile : getFiles(kBase.getQName(), rootFolder)) {
- String file = KBASES_FOLDER + "/" + kBase.getQName() + "/" + kBaseFile;
- copyFile(new File(rootFolder + "/src", file), new File(outputFolder, kBaseFile));
+ for (String kBaseFile : getFiles(kBase.getName(), new File(rootFolder, KBASES_FOLDER))) {
+ copyFile(new File(rootFolder, KBASES_FOLDER + "/" + kBaseFile), new File(outputFolder, kBaseFile));
}
}
}
@@ -130,7 +129,11 @@ public StatefulKnowledgeSession getStatefulKnowlegeSession(String kSessionName)
}
public StatelessKnowledgeSession getStatelessKnowlegeSession(String kSessionName) {
- return getKBaseUnit(kSessions.get(kSessionName)).newStatelessKnowledegSession(kSessionName);
+ String kBaseName = kSessions.get(kSessionName);
+ if (kBaseName == null) {
+ throw new RuntimeException("Unknown KnowledgeSession: " + kSessionName);
+ }
+ return getKBaseUnit(kBaseName).newStatelessKnowledegSession(kSessionName);
}
private void loadKProjects(ClassLoader classLoader, boolean doEvict) {
@@ -150,34 +153,34 @@ private void loadKProjects(ClassLoader classLoader, boolean doEvict) {
private void indexKSessions(KProject kProject, String url, boolean doEvict) {
for (KBase kBase : kProject.getKBases().values()) {
cleanUpExistingKBase(kBase, doEvict);
- kBases.put(kBase.getQName(), kBase);
- urls.put(kBase.getQName(), url);
+ kBases.put(kBase.getName(), kBase);
+ urls.put(kBase.getName(), url);
for (KSession kSession : kBase.getKSessions().values()) {
- kSessions.put(kSession.getQName(), kBase.getQName());
+ kSessions.put(kSession.getName(), kBase.getName());
}
}
}
private void cleanUpExistingKBase(KBase kBase, boolean doEvict) {
if (doEvict) {
- evictKBaseUnit(kBase.getQName());
+ evictKBaseUnit(kBase.getName());
}
- KBase oldKbase = kBases.get(kBase.getQName());
+ KBase oldKbase = kBases.get(kBase.getName());
if (oldKbase != null) {
- urls.remove(oldKbase.getQName());
+ urls.remove(oldKbase.getName());
for (KSession kSession : oldKbase.getKSessions().values()) {
- kSessions.remove(kSession.getQName());
+ kSessions.remove(kSession.getName());
}
}
}
private File writeKJar(File rootFolder, File outputFolder, String jarName, KProject kProject) {
- File kBasesFolder = new File(rootFolder, "src/" + KBASES_FOLDER);
+ File kBasesFolder = new File(rootFolder, KBASES_FOLDER);
Map<String, String> jarEntries = new HashMap<String, String>();
jarEntries.put(KPROJECT_RELATIVE_PATH, KPROJECT_JAR_PATH);
for (KBase kBase : kProject.getKBases().values()) {
- for (String kBaseFile : getFiles(kBase.getQName(), kBasesFolder)) {
- jarEntries.put("src/" + KBASES_FOLDER + "/" + kBaseFile, kBaseFile);
+ for (String kBaseFile : getFiles(kBase.getName(), kBasesFolder)) {
+ jarEntries.put(KBASES_FOLDER + "/" + kBaseFile, kBaseFile);
}
}
return writeAsJar(rootFolder, outputFolder, jarName, jarEntries);
54 drools-compiler/src/main/java/org/drools/cdi/KProjectExtension.java
View
@@ -12,7 +12,6 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipEntry;
@@ -49,8 +48,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.thoughtworks.xstream.XStream;
-
import static org.drools.kproject.KBaseImpl.getFiles;
public class KProjectExtension
@@ -59,8 +56,8 @@
private static final Logger log = LoggerFactory.getLogger( KProjectExtension.class );
- private Set<String> kBaseQNames;
- private Set<String> kSessionQNames;
+ private Set<String> kBaseNames;
+ private Set<String> kSessionNames;
private Map<String, String> kBaseURLs;
private Map<String, KProject> kProjects;
@@ -87,18 +84,18 @@ public void init() {
for ( InjectionPoint ip : pit.getInjectionTarget().getInjectionPoints() ) {
KBase kBase = ip.getAnnotated().getAnnotation( KBase.class );
if ( kBase != null ) {
- if ( kBaseQNames == null ) {
- kBaseQNames = new HashSet<String>();
+ if ( kBaseNames == null ) {
+ kBaseNames = new HashSet<String>();
}
- kBaseQNames.add( kBase.value() );
+ kBaseNames.add(kBase.value());
}
KSession kSession = ip.getAnnotated().getAnnotation( KSession.class );
if ( kSession != null ) {
- if ( kSessionQNames == null ) {
- kSessionQNames = new HashSet<String>();
+ if ( kSessionNames == null ) {
+ kSessionNames = new HashSet<String>();
}
- kSessionQNames.add( kSession.value() );
+ kSessionNames.add(kSession.value());
}
}
}
@@ -111,8 +108,8 @@ void afterBeanDiscovery(@Observes AfterBeanDiscovery abd,
// if kProjects null, processInjectionTarget was not called, so beans to create
Map<String, KBaseBean> kBaseBeans = new HashMap<String, KProjectExtension.KBaseBean>();
- if ( kBaseQNames != null ) {
- for ( String kBaseQName : kBaseQNames ) {
+ if ( kBaseNames != null ) {
+ for ( String kBaseQName : kBaseNames) {
KBaseBean bean = new KBaseBean( kBases.get( kBaseQName ),
kBaseURLs.get( kBaseQName ),
kBaseBeans );
@@ -120,12 +117,15 @@ void afterBeanDiscovery(@Observes AfterBeanDiscovery abd,
abd.addBean( bean );
}
}
- kBaseQNames = null;
+ kBaseNames = null;
- if ( kSessionQNames != null ) {
- for ( String kSessionQName : kSessionQNames ) {
- org.drools.kproject.KSession kSession = kSessions.get( kSessionQName );
- KBaseBean bean = kBaseBeans.get( ((KSessionImpl)kSession).getKBase().getQName() );
+ if ( kSessionNames != null ) {
+ for ( String kSessionName : kSessionNames) {
+ org.drools.kproject.KSession kSession = kSessions.get( kSessionName );
+ if (kSession == null) {
+ throw new RuntimeException("Unknown KnowledgeSession: " + kSessionName);
+ }
+ KBaseBean bean = kBaseBeans.get( ((KSessionImpl)kSession).getKBase().getName() );
if ( "stateless".equals( kSession.getType() ) ) {
abd.addBean( new StatelessKSessionBean( kSession, bean ) );
} else {
@@ -133,7 +133,7 @@ void afterBeanDiscovery(@Observes AfterBeanDiscovery abd,
}
}
}
- kSessionQNames = null;
+ kSessionNames = null;
kBaseURLs = null;
kProjects = null;
@@ -170,7 +170,7 @@ public KBaseBean(final org.drools.kproject.KBase kBaseModel,
}
public String value() {
- return kBaseModel.getQName();
+ return kBaseModel.getName();
}
}
) ) );
@@ -219,7 +219,7 @@ private void addFiles(CompositeKnowledgeBuilder ckbuilder, org.drools.kproject.K
}
try {
- for ( String file : getFiles(kBase.getQName(), zipFile) ) {
+ for ( String file : getFiles(kBase.getName(), zipFile) ) {
ZipEntry zipEntry = zipFile.getEntry( file );
ckbuilder.add( ResourceFactory.newInputStreamResource( zipFile.getInputStream( zipEntry ) ), ResourceType.DRL );
}
@@ -234,7 +234,7 @@ private void addFiles(CompositeKnowledgeBuilder ckbuilder, org.drools.kproject.K
}
} else {
try {
- for ( String file : getFiles(kBase.getQName(), new File(rootPath)) ) {
+ for ( String file : getFiles(kBase.getName(), new File(rootPath)) ) {
ckbuilder.add( ResourceFactory.newFileResource( new File(rootPath, file) ), ResourceType.DRL );
}
} catch ( Exception e) {
@@ -327,7 +327,7 @@ public StatelessKSessionBean(final org.drools.kproject.KSession kSessionModel, K
}
public String value() {
- return kSessionModel.getQName();
+ return kSessionModel.getName();
}
}
) ) );
@@ -405,7 +405,7 @@ public StatefulKSessionBean(final org.drools.kproject.KSession kSessionModel, KB
}
public String value() {
- return kSessionModel.getQName();
+ return kSessionModel.getName();
}
}
) ) );
@@ -485,14 +485,14 @@ public void buildKProjects() {
for ( KProject kProject : kProjects.values() ) {
for ( org.drools.kproject.KBase kBase : kProject.getKBases().values() ) {
- kBases.put( kBase.getQName(), kBase );
+ kBases.put( kBase.getName(), kBase );
((KBaseImpl) kBase).setKProject( kProject ); // should already be set, but just in case
String kProjectId = kProject.getGroupArtifactVersion().getGroupId() + ":" + kProject.getGroupArtifactVersion().getArtifactId();
- kBaseURLs.put( kBase.getQName(), urls.get( kProjectId ) );
+ kBaseURLs.put( kBase.getName(), urls.get( kProjectId ) );
for ( org.drools.kproject.KSession kSession : kBase.getKSessions().values() ) {
((KSessionImpl) kSession).setKBase( kBase ); // should already be set, but just in case
- kSessions.put( kSession.getQName(),
+ kSessions.put( kSession.getName(),
kSession );
}
}
76 drools-compiler/src/main/java/org/drools/kproject/GenerateKBaseProjectFiles.java
View
@@ -1,76 +0,0 @@
-package org.drools.kproject;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-
-
-public class GenerateKBaseProjectFiles {
- public static String generateQualifier(KBase kbase) {
- String s = "package " + kbase.getNamespace() + ";\n"
- + "import static java.lang.annotation.ElementType.TYPE;\n"
- + "import static java.lang.annotation.ElementType.FIELD;\n"
- + "import static java.lang.annotation.ElementType.PARAMETER;\n"
- + "import static java.lang.annotation.ElementType.METHOD;\n"
- + "import java.lang.annotation.Retention;\n"
- + "import java.lang.annotation.RetentionPolicy;\n"
- + "import java.lang.annotation.Target;\n"
- + "import javax.inject.Qualifier;"
- + "@Retention(RetentionPolicy.RUNTIME)\n"
- + "@Target({FIELD,METHOD,PARAMETER,TYPE})\n" + "@Qualifier\n"
- + "public @interface " + kbase.getName() + " {\n" + "\n"
- + "}\n" + "";
- return s;
- }
-
-
- public static String generateProducer(KBase kbase) {
- String s = "package " + kbase.getNamespace() + ";\n" +
- "import java.util.Properties;\n" +
- "import java.io.IOException;\n" +
- "import java.io.InputStream;\n" +
- "import javax.enterprise.inject.Produces;\n" +
- "import javax.inject.Named;\n" +
- "import org.kie.KnowledgeBase;\n" +
- "import org.kie.KnowledgeBaseConfiguration;\n" +
- "import org.kie.KnowledgeBaseFactory;\n" +
- "import org.kie.builder.CompositeKnowledgeBuilder;\n" +
- "import org.kie.builder.KnowledgeBuilder;\n" +
- "import org.kie.builder.KnowledgeBuilderFactory;\n" +
- "import org.kie.builder.ResourceType;\n" +
- "import org.kie.io.ResourceFactory;\n" +
- "public class " + kbase.getName() + "Producer extends "+ KBaseBuilder.class.getName() + " {\n" +
- " @Produces \n" +
- " @" + kbase.getName() + "\n" +
- " public KnowledgeBase newKnowledgeBase() {\n" +
- " return " + KBaseBuilder.class.getName() +".fluent()\n";
- switch ( kbase.getEventProcessingMode() ) {
- case CLOUD:
- s += " .setEventProcessingMode( " + kbase.getEventProcessingMode().getClass().getName() + ".CLOUD )\n";
- break;
- case STREAM:
- s += " .setEventProcessingMode( " + kbase.getEventProcessingMode().getClass().getName() + ".STREAM )\n";
- break;
- }
-
- switch( kbase.getEqualsBehavior() ) {
- case EQUALITY:
- s += " .setEqualsBehavior( " + kbase.getEqualsBehavior().getClass().getName() + ".EQUALITY )\n";
- break;
- case IDENTITY:
- s += " .setEqualsBehavior( " + kbase.getEqualsBehavior().getClass().getName() + ".IDENTITY )\n";
- break;
- }
-
- s += " .build( new Class[] { " + kbase.getQName() + ".class";
- for( String kBaseQName : kbase.getIncludes() ) {
- s += ", " + kBaseQName + ".class";
- }
- s += "} );\n" +
- " }\n" +
- "}\n";
-
- return s;
- }
-}
67 drools-compiler/src/main/java/org/drools/kproject/GenerateKSessionProducer.java
View
@@ -1,67 +0,0 @@
-package org.drools.kproject;
-
-
-
-public class GenerateKSessionProducer {
- public static String generateQualifier(KSession kSession) {
- String s = "package " + kSession.getNamespace() + ";\n"+
- "import static java.lang.annotation.ElementType.TYPE;\n" +
- "import static java.lang.annotation.ElementType.FIELD;\n" +
- "import static java.lang.annotation.ElementType.PARAMETER;\n" +
- "import static java.lang.annotation.ElementType.METHOD;\n" +
- "import java.lang.annotation.Retention;\n" +
- "import java.lang.annotation.RetentionPolicy;\n" +
- "import java.lang.annotation.Target;\n" +
- "import javax.inject.Qualifier;" +
- "@Retention(RetentionPolicy.RUNTIME)\n" +
- "@Target({FIELD,METHOD,PARAMETER,TYPE})\n" +
- "@Qualifier\n" +
- "public @interface " + kSession.getName() +" {\n" +
- "\n" +
- "}\n" +
- "";
- return s;
- }
-
- public static String generateProducer(KBase kBase, KSession kSession) {
- String s =
- "package " + kSession.getNamespace() + ";\n" +
- "import javax.enterprise.inject.Produces;\n" +
- "\n" +
- "import org.kie.KnowledgeBase;\n" +
- "import org.kie.KnowledgeBaseFactory;\n" +
- "import org.kie.runtime.KnowledgeSessionConfiguration;\n" +
- "import org.kie.runtime.StatefulKnowledgeSession;\n" +
- "import org.kie.runtime.StatelessKnowledgeSession;\n" +
- "import org.kie.runtime.conf.ClockTypeOption;\n" +
- "import " + kBase.getQName() + ";\n" +
- "public class " + kSession.getName() + "Producer {\n" +
- " \n" +
- " @Produces\n" +
- " @" + kSession.getName() + "\n";
-
- if ( kSession.getType().equals( "stateful" ) ) {
- s = s+
- " public StatefulKnowledgeSession newStatefulKnowledgeSession(@" + kBase.getName() + " KnowledgeBase kbase) {\n" +
- " KnowledgeSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();\n" +
- " ksconf.setOption( ClockTypeOption.get( \"" + kSession.getClockType().getClockType() + "\" ) );\n" +
- " \n" +
- " return kbase.newStatefulKnowledgeSession( ksconf, null );\n" +
- " }\n";
- } else {
- s = s+
- " public StatelessKnowledgeSession newStatelessKnowledgeSession(@" + kBase.getName() + " KnowledgeBase kbase) {\n" +
- " KnowledgeSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();\n" +
- " ksconf.setOption( ClockTypeOption.get( \"" + kSession.getClockType().getClockType() + "\" ) );\n" +
- " \n" +
- " return kbase.newStatelessKnowledgeSession( ksconf );\n" +
- " }\n";
- }
- s = s+ "\n" +
- "}\n" +
- "";
-
- return s;
-
- }
-}
8 drools-compiler/src/main/java/org/drools/kproject/KBase.java
View
@@ -11,7 +11,7 @@
public interface KBase {
- KSession newKSession(String namespace, String name);
+ KSession newKSession(String name);
KBase removeKSession(String qName);
@@ -27,16 +27,10 @@
KBase setListener(PropertyChangeListener listener);
- String getNamespace();
-
- KBase setNamespace(String namespace);
-
String getName();
KBase setName(String name);
- String getQName();
-
AssertBehaviorOption getEqualsBehavior();
KBase setEqualsBehavior(AssertBehaviorOption equalsBehaviour);
71 drools-compiler/src/main/java/org/drools/kproject/KBaseImpl.java
View
@@ -27,8 +27,6 @@
public class KBaseImpl
implements
KBase {
- private String namespace;
-
private String name;
private Set<String> includes;
@@ -49,11 +47,8 @@ private KBaseImpl() {
this.includes = new HashSet<String>();
}
- public KBaseImpl(KProjectImpl kProject,
- String namespace,
- String name) {
+ public KBaseImpl(KProjectImpl kProject, String name) {
this.kProject = kProject;
- this.namespace = namespace;
this.includes = new HashSet<String>();
this.name = name;
this.kSessions = Collections.emptyMap();
@@ -91,12 +86,11 @@ private void setKSessions(Map<String, KSession> kSessions) {
/* (non-Javadoc)
* @see org.kie.kproject.KBase#addKSession(org.kie.kproject.KSessionImpl)
*/
- public KSession newKSession(String namespace,
- String name) {
- KSession kSession = new KSessionImpl( this, namespace, name );
+ public KSession newKSession(String name) {
+ KSession kSession = new KSessionImpl( this, name );
Map<String, KSession> newMap = new HashMap<String, KSession>();
newMap.putAll( this.kSessions );
- newMap.put( kSession.getQName(), kSession );
+ newMap.put( kSession.getName(), kSession );
setKSessions( newMap );
return kSession;
@@ -142,24 +136,6 @@ public KBase setListener(PropertyChangeListener listener) {
}
/* (non-Javadoc)
- * @see org.kie.kproject.KBase#getNamespace()
- */
- public String getNamespace() {
- return namespace;
- }
-
- /* (non-Javadoc)
- * @see org.kie.kproject.KBase#setNamespace(java.lang.String)
- */
- public KBase setNamespace(String namespace) {
- if ( listener != null ) {
- listener.propertyChange( new PropertyChangeEvent( this, "namespace", this.namespace, namespace ) );
- }
- this.namespace = namespace;
- return this;
- }
-
- /* (non-Javadoc)
* @see org.kie.kproject.KBase#getName()
*/
public String getName() {
@@ -177,13 +153,6 @@ public KBase setName(String name) {
return this;
}
- /* (non-Javadoc)
- * @see org.kie.kproject.KBase#getQName()
- */
- public String getQName() {
- return this.namespace + "." + this.name;
- }
-
public Set<String> getIncludes() {
return Collections.unmodifiableSet( includes );
}
@@ -257,32 +226,42 @@ public KBase setAnnotations(List<String> annotations) {
*/
@Override
public String toString() {
- return "KBase [namespace=" + namespace + ", name=" + name + ", annotations=" + annotations + ", equalsBehaviour=" + equalsBehavior + ", eventProcessingMode=" + eventProcessingMode + ", ksessions=" + kSessions + "]";
+ return "KBase [name=" + name + ", annotations=" + annotations + ", equalsBehaviour=" + equalsBehavior + ", eventProcessingMode=" + eventProcessingMode + ", ksessions=" + kSessions + "]";
}
- public static List<String> getFiles(String kBaseQName, ZipFile zipFile) {
+ public static List<String> getFiles(String kBaseName, ZipFile zipFile) {
List<String> files = new ArrayList<String>();
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
while (zipEntries.hasMoreElements()) {
ZipEntry zipEntry = zipEntries.nextElement();
String fileName = zipEntry.getName();
- if (filterFileInKBase(kBaseQName, fileName)) {
+ if (filterFileInKBase(kBaseName, fileName)) {
files.add(fileName);
}
}
return files;
}
- public static List<String> getFiles(String kBaseQName, java.io.File root) {
+ public static List<String> getFiles(String kBaseName, java.io.File root) {
+ String prefix = "";
java.io.File kBaseRoot = null;
- for (java.io.File child : root.listFiles()) {
- if (child.getName().equals(kBaseQName)) {
- kBaseRoot = child;
- break;
+ if (root.getName().equals(kBaseName)) {
+ kBaseRoot = root;
+ } else {
+ for (java.io.File child : root.listFiles()) {
+ if (child.getName().equals(kBaseName)) {
+ kBaseRoot = child;
+ break;
+ }
}
+ prefix = kBaseName + "/";
+ }
+
+ if (kBaseRoot == null) {
+ throw new RuntimeException("Unable to find KBase " + kBaseName + " in " + root);
}
- return recursiveListFile(kBaseRoot, kBaseQName + "/", new Predicate<java.io.File>() {
+ return recursiveListFile(kBaseRoot, prefix, new Predicate<java.io.File>() {
public boolean apply(java.io.File file) {
String fileName = file.getName();
return fileName.endsWith(".drl") || fileName.endsWith(".bpm2");
@@ -303,7 +282,6 @@ public KBaseConverter() {
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
KBaseImpl kBase = (KBaseImpl) value;
writer.addAttribute("name", kBase.getName());
- writer.addAttribute("namespace", kBase.getNamespace());
if (kBase.getEventProcessingMode() != null) {
writer.addAttribute("eventProcessingMode", kBase.getEventProcessingMode().getMode());
}
@@ -318,7 +296,6 @@ public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingCo
public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
final KBaseImpl kBase = new KBaseImpl();
kBase.setName(reader.getAttribute("name"));
- kBase.setNamespace(reader.getAttribute("namespace"));
String eventMode = reader.getAttribute("eventProcessingMode");
if (eventMode != null) {
@@ -335,7 +312,7 @@ public void onNode(HierarchicalStreamReader reader, String name, String value) {
Map<String, KSession> kSessions = new HashMap<String, KSession>();
for (KSessionImpl kSession : readObjectList(reader, context, KSessionImpl.class)) {
kSession.setKBase(kBase);
- kSessions.put( kSession.getQName(), kSession );
+ kSessions.put( kSession.getName(), kSession );
}
kBase.setKSessions(kSessions);
} else if ("includes".equals(name)) {
23 drools-compiler/src/main/java/org/drools/kproject/KProject.java
View
@@ -6,27 +6,26 @@
public interface KProject {
- public GroupArtifactVersion getGroupArtifactVersion();
+ GroupArtifactVersion getGroupArtifactVersion();
- public void setGroupArtifactVersion(GroupArtifactVersion gav);
+ void setGroupArtifactVersion(GroupArtifactVersion gav);
- public PropertyChangeListener getListener();
+ PropertyChangeListener getListener();
- public KProject setListener(PropertyChangeListener listener);
+ KProject setListener(PropertyChangeListener listener);
- public String getKProjectPath();
+ String getKProjectPath();
- public KProject setKProjectPath(String kprojectPath);
+ KProject setKProjectPath(String kprojectPath);
- public String getKBasesPath();
+ String getKBasesPath();
- public KProject setKBasesPath(String kprojectPath);
+ KProject setKBasesPath(String kprojectPath);
- public KBase newKBase(String namespace,
- String name);
+ KBase newKBase(String name);
- public void removeKBase(String qName);
+ void removeKBase(String qName);
- public Map<String, KBase> getKBases();
+ Map<String, KBase> getKBases();
}
237 drools-compiler/src/main/java/org/drools/kproject/KProjectChangeLog.java
View
@@ -1,237 +0,0 @@
-package org.drools.kproject;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-public class KProjectChangeLog
- implements
- PropertyChangeListener {
-
- private boolean kProjectDirty;
-
- private Set<String> addedKBases;
- private Set<String> removedKBases;
-
- private Set<String> removedKSessions;
- private Set<String> addedKSessions;
-
- private Map<String, KSession> kSessions;
- private Map<String, KBase> kBases;
-
- public KProjectChangeLog() {
- reset();
- }
-
- public boolean isKProjectDirty() {
- return kProjectDirty;
- }
-
- public void setKProjectDirty(boolean kProjectDirty) {
- this.kProjectDirty = kProjectDirty;
- }
-
- public boolean iskProjectDirty() {
- return kProjectDirty;
- }
-
- public void setkProjectDirty(boolean kProjectDirty) {
- this.kProjectDirty = kProjectDirty;
- }
-
- public Set<String> getAddedKBases() {
- return addedKBases;
- }
-
- public void setAddedKBases(Set<String> addedKBases) {
- this.addedKBases = addedKBases;
- }
-
- public Set<String> getRemovedKBases() {
- return removedKBases;
- }
-
- public void setRemovedKBases(Set<String> removedKBases) {
- this.removedKBases = removedKBases;
- }
-
- public Set<String> getRemovedKSessions() {
- return removedKSessions;
- }
-
- public void setRemovedKSessions(Set<String> removedKSessions) {
- this.removedKSessions = removedKSessions;
- }
-
- public Set<String> getAddedKSessions() {
- return addedKSessions;
- }
-
- public void setAddedKSessions(Set<String> addedKSessions) {
- this.addedKSessions = addedKSessions;
- }
-
- public Map<String, KSession> getKSessions() {
- return kSessions;
- }
-
- public void setKSessions(Map<String, KSession> kSessions) {
- this.kSessions = kSessions;
- }
-
- public Map<String, KBase> getKBases() {
- return kBases;
- }
-
- public void setKBases(Map<String, KBase> kBases) {
- this.kBases = kBases;
- }
-
- public void propertyChange(PropertyChangeEvent evt) {
- if ( evt.getSource() instanceof KProjectImpl ) {
- KProject kProject = (KProject) evt.getSource();
- if ( "kBases".equals( evt.getPropertyName() ) ) {
- Map<String, KBaseImpl> oldKBases = (Map<String, KBaseImpl>) evt.getOldValue();
- Map<String, KBaseImpl> newKBases = (Map<String, KBaseImpl>) evt.getNewValue();
- if ( oldKBases.size() < newKBases.size() ) {
- // kBase added
- for ( Entry<String, KBaseImpl> entry : newKBases.entrySet() ) {
- if ( !oldKBases.containsKey( entry.getKey() ) ) {
- removedKBases.remove( entry.getKey() );
- addedKBases.add( entry.getKey() );
- kBases.put( entry.getKey(), newKBases.get( entry.getKey() ) );
- return;
- }
- }
- throw new IllegalStateException( "Maps are different sizes, yet we can't find the new KBase" );
- } else if ( oldKBases.size() > newKBases.size() ) {
- // kBase removed
- for ( Entry<String, KBaseImpl> entry : oldKBases.entrySet() ) {
- if ( !newKBases.containsKey( entry.getKey() ) ) {
- addedKBases.remove( entry.getKey() );
- removedKBases.add( entry.getKey() );
- kBases.put( entry.getKey(), oldKBases.get( entry.getKey() ) );
- return;
- }
- }
- throw new IllegalStateException( "Maps are different sizes, yet we can't find the removed KBase" );
- }
- } else {
- kProjectDirty = true;
- }
-
- } else if ( evt.getSource() instanceof KBaseImpl ) {
- KBaseImpl kBase = (KBaseImpl) evt.getSource();
- if ( "kSessions".equals( evt.getPropertyName() ) ) {
- Map<String, KSessionImpl> oldKSession = (Map<String, KSessionImpl>) evt.getOldValue();
- Map<String, KSessionImpl> newKSession = (Map<String, KSessionImpl>) evt.getNewValue();
- if ( oldKSession.size() < newKSession.size() ) {
- // KSession added
- for ( Entry<String, KSessionImpl> entry : newKSession.entrySet() ) {
- if ( !oldKSession.containsKey( entry.getKey() ) ) {
- removedKSessions.remove( entry.getKey() );
- addedKSessions.add( entry.getKey() );
- kSessions.put( entry.getKey(), newKSession.get( entry.getKey() ) );
- return;
- }
- }
- throw new IllegalStateException( "Maps are different sizes, yet we can't find the new KBase" );
- } else if ( oldKSession.size() > newKSession.size() ) {
- // KSession removed
- for ( Entry<String, KSessionImpl> entry : oldKSession.entrySet() ) {
- if ( !newKSession.containsKey( entry.getKey() ) ) {
- addedKSessions.remove( entry.getKey() );
- removedKSessions.add( entry.getKey() );
- kSessions.put( entry.getKey(), oldKSession.get( entry.getKey() ) );
- return;
- }
- }
- throw new IllegalStateException( "Maps are different sizes, yet we can't find the removed KBase" );
- }
- } else if ( "namespace".equals( evt.getPropertyName() ) ) {
- String oldV = (String) evt.getOldValue();
- String newV = (String) evt.getNewValue();
-
- String oldQName = oldV + "." + kBase.getName();
- String newQName = newV + "." + kBase.getName();
-
- kBase.getKProject().moveKBase( oldQName, newQName );
-
- removedKBases.remove( newQName );
- removedKBases.add( oldQName );
- addedKBases.remove( oldQName );
- addedKBases.add( newQName );
- kBases.put( newQName, kBase );
- } else if ( "name".equals( evt.getPropertyName() ) ) {
- String oldV = (String) evt.getOldValue();
- String newV = (String) evt.getNewValue();
-
- String oldQName = kBase.getNamespace() + "." + oldV;
- String newQName = kBase.getNamespace() + "." + newV;
-
- kBase.getKProject().moveKBase( oldQName, newQName );
-
- removedKBases.remove( newQName );
- removedKBases.add( oldQName );
- addedKBases.remove( oldQName );
- addedKBases.add( newQName );
- kBases.put( newQName, kBase );
- } else {
- addedKBases.add( kBase.getQName() );
- }
-
- } else if ( evt.getSource() instanceof KSessionImpl ) {
- KSessionImpl kSession = (KSessionImpl) evt.getSource();
- if ( "namespace".equals( evt.getPropertyName() ) ) {
- String oldV = (String) evt.getOldValue();
- String newV = (String) evt.getNewValue();
-
- String oldQName = oldV + "." + kSession.getName();
- String newQName = newV + "." + kSession.getName();
-
- kSession.getKBase().moveKSession( oldQName, newQName );
-
- removedKSessions.remove( newQName );
- removedKSessions.add( oldQName );
- addedKSessions.remove( oldQName );
- addedKSessions.add( newQName );
- kSessions.put( newQName, kSession );
- } else if ( "name".equals( evt.getPropertyName() ) ) {
- String oldV = (String) evt.getOldValue();
- String newV = (String) evt.getNewValue();
-
- String oldQName = kSession.getNamespace() + "." + oldV;
- String newQName = kSession.getNamespace() + "." + newV;
-
- kSession.getKBase().moveKSession( oldQName, newQName );
-
- removedKSessions.remove( newQName );
- removedKSessions.add( oldQName );
- addedKSessions.remove( oldQName );
- addedKSessions.add( newQName );
- kSessions.put( newQName, kSession );
- } else {
- addedKSessions.add( kSession.getQName() );
- kSessions.put( kSession.getQName() , kSession );
- }
- }
- }
-
- public void reset() {
- kProjectDirty = false;
- removedKBases = new HashSet<String>();
- addedKBases = new HashSet<String>();
-
- removedKSessions = new HashSet<String>();
- addedKSessions = new HashSet<String>();
-
- kBases = new HashMap<String, KBase>();
- kSessions = new HashMap<String, KSession>();
-
- }
-
-}
9 drools-compiler/src/main/java/org/drools/kproject/KProjectImpl.java
View
@@ -104,12 +104,11 @@ public KProject setKBasesPath(String kprojectPath) {
/* (non-Javadoc)
* @see org.kie.kproject.KProject#addKBase(org.kie.kproject.KBaseImpl)
*/
- public KBase newKBase(String namespace,
- String name) {
- KBase kbase = new KBaseImpl(this, namespace, name);
+ public KBase newKBase(String name) {
+ KBase kbase = new KBaseImpl(this, name);
Map<String, KBase> newMap = new HashMap<String, KBase>();
newMap.putAll( this.kBases );
- newMap.put( kbase.getQName(), kbase );
+ newMap.put( kbase.getName(), kbase );
setKBases( newMap );
return kbase;
@@ -258,7 +257,7 @@ public void onNode(HierarchicalStreamReader reader, String name, String value) {
Map<String, KBase> kBases = new HashMap<String, KBase>();
for (KBaseImpl kBase : readObjectList(reader, context, KBaseImpl.class)) {
kBase.setKProject(kProject);
- kBases.put(kBase.getQName(), kBase);
+ kBases.put(kBase.getName(), kBase);
}
kProject.setKBases(kBases);
}
26 drools-compiler/src/main/java/org/drools/kproject/KSession.java
View
@@ -7,30 +7,24 @@
public interface KSession {
- public PropertyChangeListener getListener();
+ PropertyChangeListener getListener();
- public KSession setListener(PropertyChangeListener listener);
+ KSession setListener(PropertyChangeListener listener);
- public String getNamespace();
+ String getName();
- public KSession setNamespace(String namespace);
+ KSession setName(String name);
- public String getName();
+ String getType();
- public KSession setName(String name);
+ KSession setType(String type);
- public String getQName();
+ ClockTypeOption getClockType();
- public String getType();
+ KSession setClockType(ClockTypeOption clockType);
- public KSession setType(String type);
+ List<String> getAnnotations();
- public ClockTypeOption getClockType();
-
- public KSession setClockType(ClockTypeOption clockType);
-
- public List<String> getAnnotations();
-
- public KSession setAnnotations(List<String> annotations);
+ KSession setAnnotations(List<String> annotations);
}
36 drools-compiler/src/main/java/org/drools/kproject/KSessionImpl.java
View
@@ -5,7 +5,6 @@
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import org.drools.core.util.AbstractXStreamConverter;
-import org.kie.conf.AssertBehaviorOption;
import org.kie.runtime.conf.ClockTypeOption;
import java.beans.PropertyChangeEvent;
@@ -16,7 +15,6 @@
public class KSessionImpl
implements
KSession {
- private String namespace;
private String name;
private String type;
@@ -30,11 +28,8 @@
private KSessionImpl() { }
- public KSessionImpl(KBaseImpl kBase,
- String namespace,
- String name) {
+ public KSessionImpl(KBaseImpl kBase, String name) {
this.kBase = kBase;
- this.namespace = namespace;
this.name = name;
this.annotations = new ArrayList<String>();
}
@@ -63,24 +58,6 @@ public KSession setListener(PropertyChangeListener listener) {
}
/* (non-Javadoc)
- * @see org.kie.kproject.KSession#getNamespace()
- */
- public String getNamespace() {
- return namespace;
- }
-
- /* (non-Javadoc)
- * @see org.kie.kproject.KSession#setNamespace(java.lang.String)
- */
- public KSession setNamespace(String namespace) {
- if ( listener != null ) {
- listener.propertyChange( new PropertyChangeEvent( this, "namespace", this.namespace, namespace ) );
- }
- this.namespace = namespace;
- return this;
- }
-
- /* (non-Javadoc)
* @see org.kie.kproject.KSession#getName()
*/
public String getName() {
@@ -99,13 +76,6 @@ public KSession setName(String name) {
}
/* (non-Javadoc)
- * @see org.kie.kproject.KSession#getQName()
- */
- public String getQName() {
- return this.namespace + "." + this.name;
- }
-
- /* (non-Javadoc)
* @see org.kie.kproject.KSession#getType()
*/
public String getType() {
@@ -161,7 +131,7 @@ public KSession setAnnotations(List<String> annotations) {
@Override
public String toString() {
- return "KSession [namespace=" + namespace + ", name=" + name + ", clockType=" + clockType + ", annotations=" + annotations + "]";
+ return "KSession [name=" + name + ", clockType=" + clockType + ", annotations=" + annotations + "]";
}
public static class KSessionConverter extends AbstractXStreamConverter {
@@ -173,7 +143,6 @@ public KSessionConverter() {
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
KSessionImpl kSession = (KSessionImpl) value;
writer.addAttribute("name", kSession.getName());
- writer.addAttribute("namespace", kSession.getNamespace());
writer.addAttribute("type", kSession.getType());
if (kSession.getClockType() != null) {
writer.addAttribute("clockType", kSession.getClockType().getClockType());
@@ -183,7 +152,6 @@ public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingCo
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
KSessionImpl kSession = new KSessionImpl();
kSession.setName(reader.getAttribute("name"));
- kSession.setNamespace(reader.getAttribute("namespace"));
kSession.setType(reader.getAttribute("type"));
String clockType = reader.getAttribute("clockType");
40 drools-compiler/src/test/java/org/drools/kproject/AbstractKnowledgeTest.java
View
@@ -50,39 +50,39 @@ public void createKProjectJar(String namespace,
kproj.setKProjectPath( "src/main/resources/" );
kproj.setKBasesPath( "src/kbases" );
- KBase kBase1 = kproj.newKBase( namespace + ".test1", "KBase1" )
+ KBase kBase1 = kproj.newKBase( namespace + ".KBase1" )
.setAnnotations( asList( "@ApplicationScoped; @Inject" ) )
.setEqualsBehavior( AssertBehaviorOption.EQUALITY )
.setEventProcessingMode( EventProcessingOption.STREAM );
- KSession ksession1 = kBase1.newKSession( namespace + ".test1", "KSession1" )
+ KSession ksession1 = kBase1.newKSession( namespace + ".KSession1" )
.setType( "stateless" )
.setAnnotations( asList( "@ApplicationScoped; @Inject" ) )
.setClockType( ClockTypeOption.get("realtime") );
- KSession ksession2 = kBase1.newKSession( namespace + ".test1", "KSession2" )
+ KSession ksession2 = kBase1.newKSession( namespace + ".KSession2" )
.setType( "stateful" )
.setAnnotations( asList( "@ApplicationScoped; @Inject" ) )
.setClockType( ClockTypeOption.get( "pseudo" ) );
- KBase kBase2 = kproj.newKBase( namespace + ".test2", "KBase2" )
+ KBase kBase2 = kproj.newKBase( namespace + ".KBase2" )
.setAnnotations( asList( "@ApplicationScoped" ) )
.setEqualsBehavior( AssertBehaviorOption.IDENTITY )
.setEventProcessingMode( EventProcessingOption.CLOUD );
- KSession ksession3 = kBase2.newKSession( namespace + ".test2", "KSession3" )
+ KSession ksession3 = kBase2.newKSession( namespace + ".KSession3" )
.setType( "stateful" )
.setAnnotations( asList( "@ApplicationScoped" ) )
.setClockType( ClockTypeOption.get( "pseudo" ) );
- KBase kBase3 = kproj.newKBase( namespace + ".test3", "KBase3" )
- .addInclude( kBase1.getQName() )
- .addInclude( kBase2.getQName() )
+ KBase kBase3 = kproj.newKBase( namespace + ".KBase3" )
+ .addInclude( kBase1.getName() )
+ .addInclude( kBase2.getName() )
.setAnnotations( asList( "@ApplicationScoped" ) )
.setEqualsBehavior( AssertBehaviorOption.IDENTITY )
.setEventProcessingMode( EventProcessingOption.CLOUD );
- KSession ksession4 = kBase3.newKSession( namespace + ".test3", "KSession4" )
+ KSession ksession4 = kBase3.newKSession( namespace + ".KSession4" )
.setType( "stateless" )
.setAnnotations( asList( "@ApplicationScoped" ) )
.setClockType( ClockTypeOption.get( "pseudo" ) );
@@ -103,8 +103,8 @@ public void createKProjectJar(String namespace,
String kbase2R1 = getRule( namespace + ".test2", "rule1" );
String kbase2R2 = getRule( namespace + ".test2", "rule2" );
- String fldKB1 = kproj.getKBasesPath() + "/" + kBase1.getQName();
- String fldKB2 = kproj.getKBasesPath() + "/" + kBase2.getQName();
+ String fldKB1 = kproj.getKBasesPath() + "/" + kBase1.getName();
+ String fldKB2 = kproj.getKBasesPath() + "/" + kBase2.getName();
mfs.getFolder( fldKB1 ).create();
mfs.getFolder( fldKB2 ).create();
@@ -171,34 +171,34 @@ public String generateKProjectTestClass(KProject kproject,
"@KPTest(\"" + namespace + "\") \n" +
"public class KProjectTestClass" + namespace + " implements org.drools.kproject.KProjectTestClass {\n" +
- " private @Inject @KBase(\"" + namespace + ".test1.KBase1\") " +
+ " private @Inject @KBase(\"" + namespace + ".KBase1\") " +
" KnowledgeBase kBase1; \n" +
" public KnowledgeBase getKBase1() {\n" +
" return kBase1;\n" +
" }\n" +
- " private @Inject @KBase(\"" + namespace + ".test2.KBase2\") " +
+ " private @Inject @KBase(\"" + namespace + ".KBase2\") " +
" KnowledgeBase kBase2; \n" +
" public KnowledgeBase getKBase2() {\n" +
" return kBase2;\n" +
" }\n" +
- " private @Inject @KBase(\"" + namespace + ".test3.KBase3\") \n" +
+ " private @Inject @KBase(\"" + namespace + ".KBase3\") \n" +
" KnowledgeBase kBase3; \n" +
" public KnowledgeBase getKBase3() {\n" +
" return kBase3;\n" +
" }\n" +
- " private @Inject @KSession(\"" + namespace + ".test1.KSession1\") StatelessKnowledgeSession kBase1kSession1; \n" +
+ " private @Inject @KSession(\"" + namespace + ".KSession1\") StatelessKnowledgeSession kBase1kSession1; \n" +
" public StatelessKnowledgeSession getKBase1KSession1() {\n" +
" return kBase1kSession1;\n" +
" }\n" +
- " private @Inject @KSession(\"" + namespace + ".test1.KSession2\") StatefulKnowledgeSession kBase1kSession2; \n" +
+ " private @Inject @KSession(\"" + namespace + ".KSession2\") StatefulKnowledgeSession kBase1kSession2; \n" +
" public StatefulKnowledgeSession getKBase1KSession2() {\n" +
" return kBase1kSession2;\n" +
" }\n" +
- " private @Inject @KSession(\"" + namespace + ".test2.KSession3\") StatefulKnowledgeSession kBase2kSession3; \n" +
+ " private @Inject @KSession(\"" + namespace + ".KSession3\") StatefulKnowledgeSession kBase2kSession3; \n" +
" public StatefulKnowledgeSession getKBase2KSession3() {\n" +
" return kBase2kSession3;\n" +
" }\n" +
- " private @Inject @KSession(\"" + namespace + ".test3.KSession4\") StatelessKnowledgeSession kBase3kSession4; \n" +
+ " private @Inject @KSession(\"" + namespace + ".KSession4\") StatelessKnowledgeSession kBase3kSession4; \n" +
" public StatelessKnowledgeSession getKBase3KSession4() {\n" +
" return kBase3kSession4;\n" +
" }\n" +
@@ -210,8 +210,8 @@ public String generateKProjectTestClass(KProject kproject,
MemoryFileSystem trgMfs,
List<String> classes) {
for ( KBase kbase : kproj.getKBases().values() ) {
- Folder srcFolder = srcMfs.getFolder( kproj.getKBasesPath() + "/" + kbase.getQName() );
- Folder trgFolder = trgMfs.getFolder(kbase.getQName());
+ Folder srcFolder = srcMfs.getFolder( kproj.getKBasesPath() + "/" + kbase.getName() );
+ Folder trgFolder = trgMfs.getFolder(kbase.getName());
copyFolder( srcMfs, srcFolder, trgMfs, trgFolder, kproj );
}
20 drools-compiler/src/test/java/org/drools/kproject/KJarTest.java
View
@@ -49,13 +49,13 @@ public void tearDown() throws Exception {
public void testKBUnit() throws Exception {
createKJar();
- KBaseUnit unit = KnowledgeBaseFactory.getKBaseUnit("org.test.KBase1");
+ KBaseUnit unit = KnowledgeBaseFactory.getKBaseUnit("KBase1");
if ( unit.hasErrors() ) {
fail( unit.getErrors().toString() );
}
KnowledgeBase kbase = unit.getKnowledgeBase();
- StatefulKnowledgeSession ksession = unit.newStatefulKnowledegSession( "org.test.KSession1" );
+ StatefulKnowledgeSession ksession = unit.newStatefulKnowledegSession( "KSession1" );
useKSession(kbase, ksession);
}
@@ -64,7 +64,7 @@ public void testKBUnit() throws Exception {
public void testSessionFactory() throws Exception {
createKJar();
- StatefulKnowledgeSession ksession = KnowledgeBaseFactory.getStatefulKnowlegeSession("org.test.KSession1");
+ StatefulKnowledgeSession ksession = KnowledgeBaseFactory.getStatefulKnowlegeSession("KSession1");
useKSession(ksession.getKnowledgeBase(), ksession);
}
@@ -73,8 +73,8 @@ public void testSessionFactory() throws Exception {
public void testKBaseAndSessionFactories() throws Exception {
createKJar();
- KnowledgeBase kbase = KnowledgeBaseFactory.getKnowledgeBase("org.test.KBase1");
- StatefulKnowledgeSession ksession = KnowledgeBaseFactory.getStatefulKnowlegeSession("org.test.KSession1");
+ KnowledgeBase kbase = KnowledgeBaseFactory.getKnowledgeBase("KBase1");
+ StatefulKnowledgeSession ksession = KnowledgeBaseFactory.getStatefulKnowlegeSession("KSession1");
useKSession(kbase, ksession);
}
@@ -98,16 +98,16 @@ private void createKJar() throws IOException {
"end\n";
- fileManager.write(fileManager.newFile("src/kbases/org.test.KBase1/org/test/rule.drl"), rule);
- fileManager.write(fileManager.newFile("src/kbases/org.test.KBase1/org/test/decA.drl"), declarationA);
- fileManager.write(fileManager.newFile("src/kbases/org.test.KBase1/org/test/decB.drl"), declarationB);
+ fileManager.write(fileManager.newFile("src/kbases/KBase1/org/test/rule.drl"), rule);
+ fileManager.write(fileManager.newFile("src/kbases/KBase1/org/test/decA.drl"), declarationA);
+ fileManager.write(fileManager.newFile("src/kbases/KBase1/org/test/decB.drl"), declarationB);
KProject kproj = new KProjectImpl();
- KBase kBase1 = kproj.newKBase( "org.test", "KBase1" )
+ KBase kBase1 = kproj.newKBase( "KBase1" )
.setEqualsBehavior( AssertBehaviorOption.EQUALITY )
.setEventProcessingMode( EventProcessingOption.STREAM );
- KSession ksession1 = kBase1.newKSession( "org.test", "KSession1" )
+ KSession ksession1 = kBase1.newKSession( "KSession1" )
.setType( "stateful" )
.setAnnotations( asList( "@ApplicationScoped; @Inject" ) )
.setClockType( ClockTypeOption.get("realtime") );
411 drools-compiler/src/test/java/org/drools/kproject/KProjectDirtyLogTest.java
View
@@ -1,411 +0,0 @@
-package org.drools.kproject;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-
-import org.junit.Test;
-import org.kie.conf.AssertBehaviorOption;
-import org.kie.conf.EventProcessingOption;
-import org.kie.runtime.conf.ClockTypeOption;
-
-public class KProjectDirtyLogTest {
-
- @Test
- public void testKProjectModified() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- assertFalse( dirtyLog.isKProjectDirty() );
-
- kproj.setKProjectPath( "src/main/resources/" );
- kproj.setKBasesPath( "src/kbases" );
-
- assertTrue( dirtyLog.isKProjectDirty() );
- }
-
- @Test
- public void testKBaseAdded() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
- assertTrue( dirtyLog.getAddedKBases().contains( kbase1.getQName() ) );
- }
-
- @Test
- public void testKBaseRemoved() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
- assertTrue( dirtyLog.getAddedKBases().contains( kbase1.getQName() ) );
-
- kproj.removeKBase( kbase1.getQName() );
- assertTrue( dirtyLog.getRemovedKBases().contains( kbase1.getQName() ) );
- assertFalse( dirtyLog.getAddedKBases().contains( kbase1.getQName() ) );
- }
-
- @Test
- public void testKBaseExistsRemovedAdded() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- dirtyLog.reset();
-
- kproj.removeKBase( kbase1.getQName() );
- assertTrue( dirtyLog.getRemovedKBases().contains( kbase1.getQName() ) );
-
- kbase1 = kproj.newKBase( "org.test1", "KBase1" );
- assertFalse( dirtyLog.getRemovedKBases().contains( kbase1.getQName() ) );
- assertTrue( dirtyLog.getAddedKBases().contains( kbase1.getQName() ) );
- }
-
- @Test
- public void testKBaseExistsModifyRemovedAdded() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- dirtyLog.reset();
-
- kbase1.setNamespace( "org.test2" );
- assertEquals( 1, dirtyLog.getRemovedKBases().size() );
- assertEquals( 1, dirtyLog.getAddedKBases().size() );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase1" ) );
- assertTrue( dirtyLog.getAddedKBases().contains( "org.test2.KBase1" ) );
-
- kproj.removeKBase( kbase1.getQName() );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase1") );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test2.KBase1") );
- assertEquals( 0, dirtyLog.getAddedKBases().size() );
- }
-
- @Test
- public void testKBaseDoesntExistsModify() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- kproj.removeKBase( kbase1.getQName() );
-
- kbase1 = kproj.newKBase( "org.test2", "KBase1" );
-
- assertEquals( 1, dirtyLog.getRemovedKBases().size() );
- assertEquals( 1, dirtyLog.getAddedKBases().size() );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase1" ) );
- assertTrue( dirtyLog.getAddedKBases().contains( "org.test2.KBase1" ) );
- }
-
- @Test
- public void testKBaseExistsQNameModified() {
- KProjectImpl kproj = ( KProjectImpl ) new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
- dirtyLog.reset();
-
- kbase1.setNamespace( "org.test2" );
-
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase1" ) );
- assertTrue( dirtyLog.getAddedKBases().contains( "org.test2.KBase1" ) );
-
- kbase1.setName( "KBase2" );
-
- assertEquals( 2, dirtyLog.getRemovedKBases().size() );
- assertEquals( 1, dirtyLog.getAddedKBases().size() );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase1" ) );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test2.KBase1" ) );
- assertTrue( dirtyLog.getAddedKBases().contains( "org.test2.KBase2" ) );
- }
-
- @Test
- public void testKBaseExistsModifyRemovedAddedWithOverlappingNames() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
- KBase kbase2 = kproj.newKBase( "org.test1", "KBase2" );
-
- dirtyLog.reset();
-
- kbase1.setNamespace( "org.test2" );
- kbase2.setName( "KBase1" );
-
- assertEquals( 1, dirtyLog.getRemovedKBases().size() );
- assertEquals( 2, dirtyLog.getAddedKBases().size() );
-
-
- assertTrue( dirtyLog.getAddedKBases().contains( "org.test2.KBase1" ) );
- assertTrue( dirtyLog.getAddedKBases().contains( "org.test1.KBase1" ) );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase2" ) );
-
- kproj.removeKBase( kbase1.getQName() );
-
- assertEquals( 2, dirtyLog.getRemovedKBases().size() );
- assertEquals( 1, dirtyLog.getAddedKBases().size() );
-
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test2.KBase1" ) );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase2" ) );
-
- assertTrue( dirtyLog.getAddedKBases().contains( "org.test1.KBase1" ) );
-
- kproj.removeKBase( kbase2.getQName() );
- assertEquals( 3, dirtyLog.getRemovedKBases().size() );
- assertEquals( 0, dirtyLog.getAddedKBases().size() );
-
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test2.KBase1" ) );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase1" ) );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase2" ) );
-
- kproj.newKBase( kbase1.getNamespace(), kbase1.getName() );
- assertEquals( 2, dirtyLog.getRemovedKBases().size() );
- assertEquals( 1, dirtyLog.getAddedKBases().size() );
-
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase1" ) );
- assertTrue( dirtyLog.getRemovedKBases().contains( "org.test1.KBase2" ) );
- assertTrue( dirtyLog.getAddedKBases().contains( "org.test2.KBase1" ) );
- }
-
- @Test
- public void testKSessionAdded() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- KSession kSession = kbase1.newKSession( "org.domain", "KSession1" );
-
- assertTrue( dirtyLog.getAddedKSessions().contains( kSession.getQName() ) );
- }
-
- @Test
- public void testKSessionRemoved() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- KSession kSession = kbase1.newKSession( "org.domain", "KSession1" );
-
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.domain.KSession1" ) );
-
- kbase1.removeKSession( kSession.getQName() );
- assertEquals( 0, dirtyLog.getRemovedKBases().size() );
- assertEquals( 1, dirtyLog.getAddedKBases().size() );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.domain.KSession1" ) );
- assertFalse( dirtyLog.getAddedKSessions().contains( "org.domain.KSession1" ) );
- }
-
- @Test
- public void testKSessionExistsRemovedAdded() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- KSession kSession = kbase1.newKSession( "org.domain", "KSession1" );
-
- dirtyLog.reset();
-
- kbase1.removeKSession( kSession.getQName() );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.domain.KSession1" ) );
-
- kbase1.newKSession( kSession.getNamespace(), kSession.getName() );
-
- assertEquals( 0, dirtyLog.getRemovedKSessions().size() );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.domain.KSession1" ) );
- }
-
-
- @Test
- public void testKSessionExistsModifyRemovedAdded() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- KSession kSession = kbase1.newKSession( "org.test1", "KSession1" );
-
- dirtyLog.reset();
-
- kSession.setNamespace( "org.test2" );
-
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession1" ) );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test2.KSession1") );
-
- kbase1.removeKSession( kSession.getQName() );
- assertEquals( 2, dirtyLog.getRemovedKSessions().size() );
- assertEquals( 0, dirtyLog.getAddedKSessions().size() );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test2.KSession1" ) );
-
- kbase1.newKSession( kSession.getNamespace(), kSession.getName() );
-
- assertEquals( 1, dirtyLog.getRemovedKSessions().size() );
- assertEquals( 1, dirtyLog.getAddedKSessions().size() );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession1" ) );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test2.KSession1" ) );
- }
-
- @Test
- public void testKSessionDoesntExistsModify() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- KSession kSession = kbase1.newKSession( "org.test1", "KSession1" );
- kSession.setNamespace( "org.test2" );
-
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession1" ) );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test2.KSession1") );
- }
-
- @Test
- public void testKSessioExistsnQNameModified() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- assertFalse( dirtyLog.isKProjectDirty() );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- KSession kSession = kbase1.newKSession( "org.test1", "KSession1" );
-
- dirtyLog.reset();
-
- kSession.setNamespace( "org.test2" );
-
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test2.KSession1" ) );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession1") );
-
- kSession.setName( "KSession2" );
-
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test2.KSession1" ) );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession1") );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test2.KSession2" ) );
- }
-
- @Test
- public void testKsessionExistsModifyRemovedAddedWithOverlappingNames() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- KSession kSession1 = kbase1.newKSession( "org.test1", "KSession1" );
-
- KSession kSession2 = kbase1.newKSession( "org.test1", "KSession2" );
-
- dirtyLog.reset();
-
- kSession1.setNamespace( "org.test2" );
-
- kSession2.setName( "KSession1" );
-
- assertEquals( 1, dirtyLog.getRemovedKSessions().size() );
- assertEquals( 2, dirtyLog.getAddedKSessions().size() );
-
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession2") );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test2.KSession1" ) );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test1.KSession1" ) );
-
- kbase1.removeKSession( kSession1.getQName() );
- assertEquals( 2, dirtyLog.getRemovedKSessions().size() );
- assertEquals( 1, dirtyLog.getAddedKSessions().size() );
-
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession2") );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test2.KSession1" ) );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test1.KSession1" ) );
-
- kbase1.removeKSession( kSession2.getQName() );
- assertEquals( 3, dirtyLog.getRemovedKSessions().size() );
- assertEquals( 0, dirtyLog.getAddedKSessions().size() );
-
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession2") );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test2.KSession1" ) );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession1" ) );
-
- kbase1.newKSession( kSession1.getNamespace(), kSession1.getName() );
- assertEquals( 2, dirtyLog.getRemovedKSessions().size() );
- assertEquals( 1, dirtyLog.getAddedKSessions().size() );
-
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession2") );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession1" ) );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test2.KSession1" ) );
-
-
- kbase1.newKSession( kSession2.getNamespace(), kSession2.getName() );
- assertEquals( 1, dirtyLog.getRemovedKSessions().size() );
- assertEquals( 2, dirtyLog.getAddedKSessions().size() );
-
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession2") );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test1.KSession1" ) );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test2.KSession1" ) );
- }
-
-
- @Test
- public void testKSessionModified() {
- KProject kproj = new KProjectImpl();
-
- KProjectChangeLog dirtyLog = new KProjectChangeLog();
- kproj.setListener( dirtyLog );
-
- assertFalse( dirtyLog.isKProjectDirty() );
-
- KBase kbase1 = kproj.newKBase( "org.test1", "KBase1" );
-
- KSession kSession = kbase1.newKSession( "org.test1", "KSession1" );
- kSession.setClockType( ClockTypeOption.get( "pseudo" ) );
- kSession.setType( "stateless" );
-
- kSession.setClockType( ClockTypeOption.get( "realtime" ) );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test1.KSession1" ) );
-
- dirtyLog.reset();
-
- kSession.setType( "stateful" );
- assertTrue( dirtyLog.getAddedKSessions().contains( "org.test1.KSession1" ) );
-
- kbase1.removeKSession( kSession.getQName() );
- assertFalse( dirtyLog.getAddedKSessions().contains( "org.test1.KSession1") );
- assertTrue( dirtyLog.getRemovedKSessions().contains( "org.test1.KSession1" ) );
- }
-
-
-}
8 drools-compiler/src/test/java/org/drools/kproject/KProjectTest.java
View
@@ -174,11 +174,11 @@ public void testEntry(KProjectTestClass testClass, String jarName) {
public void populateClasses(KProject kproject,
List<String> classes) {
for ( KBase kBase : kproject.getKBases().values() ) {
- classes.add(kBase.getNamespace().replace('.', '/') + "/" + kBase.getName() + "Producer.java");
- classes.add( kBase.getNamespace().replace( '.', '/' ) + "/" + kBase.getName() + ".java" );
+ classes.add(kBase.getName() + "Producer.java");
+ classes.add(kBase.getName() + ".java" );
for ( KSession kSession : kBase.getKSessions().values() ) {
- classes.add( kSession.getNamespace().replace( '.', '/' ) + "/" + kSession.getName() + "Producer.java" );
- classes.add( kSession.getNamespace().replace( '.', '/' ) + "/" + kSession.getName() + ".java" );
+ classes.add( kSession.getName() + "Producer.java" );
+ classes.add( kSession.getName() + ".java" );
}
}
}
18 drools-compiler/src/test/java/org/drools/kproject/KnowledgeContainerTest.java
View
@@ -33,7 +33,7 @@ public void testKContainer() throws Exception {
kContainer.deploy(kJar1);
// create a ksesion and check it works as expected
- StatefulKnowledgeSession ksession = kContainer.getStatefulKnowlegeSession("org.test.KSession1");
+ StatefulKnowledgeSession ksession = kContainer.getStatefulKnowlegeSession("KSession1");
checkKSession(ksession, "rule1", "rule2");
this.fileManager.tearDown();
@@ -47,7 +47,7 @@ public void testKContainer() throws Exception {
kContainer.deploy(kJar2);
// create a ksesion and check it works as expected
- StatefulKnowledgeSession ksession2 = kContainer.getStatefulKnowlegeSession("org.test.KSession1");
+ StatefulKnowledgeSession ksession2 = kContainer.getStatefulKnowlegeSession("KSession1");
checkKSession(ksession2, "rule2", "rule3");
}
@@ -89,16 +89,16 @@ private File createKJar(KnowledgeContainer kContainer, String kjarName, String..
for (String rule : rules) {
String file = "org/test/" + rule + ".drl";
- fileManager.write(fileManager.newFile("src/kbases/org.test.KBase1/" + file), createDRL(rule));
+ fileManager.write(fileManager.newFile("src/kbases/KBase1/" + file), createDRL(rule));
files.add(file);
}
KProject kproj = new KProjectImpl();
- KBase kBase1 = kproj.newKBase( "org.test", "KBase1" )
+ KBase kBase1 = kproj.newKBase( "KBase1" )
.setEqualsBehavior( AssertBehaviorOption.EQUALITY )
.setEventProcessingMode( EventProcessingOption.STREAM );
- KSession ksession1 = kBase1.newKSession( "org.test", "KSession1" )
+ KSession ksession1 = kBase1.newKSession( "KSession1" )
.setType( "stateful" )
.setAnnotations( asList( "@ApplicationScoped; @Inject" ) )
.setClockType( ClockTypeOption.get("realtime") );
@@ -121,7 +121,7 @@ private String createDRL(String ruleName) {
public void testKBaseUnit(KnowledgeContainer kContainer, String jarName) {
List<String> list = new ArrayList<String>();
- StatelessKnowledgeSession stlsKsession = kContainer.getStatelessKnowlegeSession(jarName + ".test1.KSession1");
+ StatelessKnowledgeSession stlsKsession = kContainer.getStatelessKnowlegeSession(jarName + ".KSession1");
stlsKsession.setGlobal( "list", list );
stlsKsession.execute( "dummy" );
assertEquals( 2, list.size() );
@@ -129,7 +129,7 @@ public void testKBaseUnit(KnowledgeContainer kContainer, String jarName) {
assertTrue( list.contains( jarName + ".test1:rule2" ) );
list.clear();
- StatefulKnowledgeSession stflKsession = kContainer.getStatefulKnowlegeSession(jarName + ".test1.KSession2");
+ StatefulKnowledgeSession stflKsession = kContainer.getStatefulKnowlegeSession(jarName + ".KSession2");
stflKsession.setGlobal( "list", list );
stflKsession.fireAllRules();
assertEquals( 2, list.size() );
@@ -137,7 +137,7 @@ public void testKBaseUnit(KnowledgeContainer kContainer, String jarName) {
assertTrue( list.contains( jarName + ".test1:rule2" ) );
list.clear();
- stflKsession = kContainer.getStatefulKnowlegeSession(jarName + ".test2.KSession3");
+ stflKsession = kContainer.getStatefulKnowlegeSession(jarName + ".KSession3");
stflKsession.setGlobal( "list", list );
stflKsession.fireAllRules();
assertEquals( 2, list.size() );
@@ -146,7 +146,7 @@ public void testKBaseUnit(KnowledgeContainer kContainer, String jarName) {
assertTrue( list.contains( jarName + ".test2:rule2" ) );
list.clear();
- stlsKsession = kContainer.getStatelessKnowlegeSession(jarName + ".test3.KSession4");
+ stlsKsession = kContainer.getStatelessKnowlegeSession(jarName + ".KSession4");
stlsKsession.setGlobal( "list", list );
stlsKsession.execute( "dummy" );
assertEquals( 4, list.size() );
0  ...drools.FireAlarmKBase/org.drools.sample/alarm.drl → ...kbases/FireAlarmKBase/org.drools.sample/alarm.drl
View
File renamed without changes
0  ...drools.FireAlarmKBase/org.drools.sample/rules.drl → ...kbases/FireAlarmKBase/org.drools.sample/rules.drl
View
File renamed without changes
0  ...rools.FireAlarmKBase/org.drools.sample/rules2.drl → ...bases/FireAlarmKBase/org.drools.sample/rules2.drl
View
File renamed without changes
0  ...c/kbases/org.test.KBase1/org.drools.test/decA.drl → ...xample/src/kbases/KBase1/org.drools.test/decA.drl
View
File renamed without changes
0  ...c/kbases/org.test.KBase1/org.drools.test/decB.drl → ...xample/src/kbases/KBase1/org.drools.test/decB.drl
View
File renamed without changes
0  ...c/kbases/org.test.KBase1/org.drools.test/rule.drl → ...xample/src/kbases/KBase1/org.drools.test/rule.drl
View
File renamed without changes
8 drools-maven-plugin-example/src/main/resources/META-INF/kproject.xml
View
@@ -1,13 +1,13 @@
<kproject>
<kbases>
- <kbase name="FireAlarmKBase" namespace="org.drools">
+ <kbase name="KBase1">
<ksessions>
- <ksession name="FireAlarmKBase.session" namespace="org.drools" type="stateful"/>
+ <ksession name="KBase1.session" type="stateful"/>
</ksessions>
</kbase>
- <kbase name="KBase1" namespace="org.test">
+ <kbase name="FireAlarmKBase">
<ksessions>
- <ksession name="KBase1.session" namespace="org.test" type="stateful"/>
+ <ksession name="FireAlarmKBase.session" type="stateful"/>
</ksessions>
</kbase>
</kbases>
12 drools-maven-plugin-example/src/test/java/org/drools/kproject/KProjectTest.java
View
@@ -1,9 +1,9 @@
package org.drools.kproject;
-import org.drools.KnowledgeBase;
-import org.drools.KnowledgeBaseFactory;
-import org.drools.definition.type.FactType;
-import org.drools.runtime.StatefulKnowledgeSession;
+import org.kie.KnowledgeBase;
+import org.kie.KnowledgeBaseFactory;
+import org.kie.definition.type.FactType;
+import org.kie.runtime.StatefulKnowledgeSession;
import org.junit.Ignore;
import org.junit.Test;
@@ -17,10 +17,10 @@
@Test @Ignore
public void testKJar() throws Exception {
// Simulate having the jar in the classpath
- URLClassLoader urlClassLoader = new URLClassLoader( new URL[] { new java.io.File("drools-maven-example/target/classes/test.jar").toURI().toURL() } );
+ URLClassLoader urlClassLoader = new URLClassLoader( new URL[] { new java.io.File("drools-maven-plugin-example/target/classes/test.jar").toURI().toURL() } );
Thread.currentThread().setContextClassLoader( urlClassLoader );
- StatefulKnowledgeSession ksession = KnowledgeBaseFactory.getStatefulKnowlegeSession("org.test.KSession1");
+ StatefulKnowledgeSession ksession = KnowledgeBaseFactory.getStatefulKnowlegeSession("KBase1.session");
useKSession(ksession);
}
2  drools-maven-plugin/src/main/java/org/drools/BuildMojo.java
View
@@ -31,7 +31,7 @@
private File rootFolder;
/**
- * Project root folder.
+ * Project sourceFolder folder.
*
* @parameter default-value="src/kbases"
* @required
10 drools-maven-plugin/src/main/java/org/drools/KProjectMojo.java
View
@@ -58,13 +58,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
KProjectImpl kproj = new KProjectImpl();
for (File kBaseFolder : sourceFolder.listFiles()) {
- String qName = kBaseFolder.getName();
- int dotPos = qName.lastIndexOf('.');
- String namespace = dotPos > 0 ? qName.substring(0, dotPos) : "";
- String kBaseName = dotPos > 0 ? qName.substring(dotPos+1) : qName;
-
- kproj.newKBase( namespace, kBaseName )
- .newKSession( namespace, kBaseName + ".session" )
+ String kBaseName = kBaseFolder.getName();
+ kproj.newKBase( kBaseName )
+ .newKSession( kBaseName + ".session" )
.setType( "stateful" );
}
Please sign in to comment.
Something went wrong with that request. Please try again.