use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieRepositoryScannerTest method testKScannerWithRange.
@Test
public void testKScannerWithRange() throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "scanner-range-test", "1.0.1");
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "scanner-range-test", "1.0.2");
ReleaseId releaseRange = ks.newReleaseId("org.kie", "scanner-range-test", "[1.0.0,)");
InternalKieModule kJar1 = createKieJar(ks, releaseId1, "rule1", "rule2");
KieContainer kieContainer = ks.newKieContainer(releaseRange);
KieMavenRepository repository = getKieMavenRepository();
repository.installArtifact(releaseId1, kJar1, createKPom(fileManager, releaseId1));
// create a ksesion and check it works as expected
KieSession ksession = kieContainer.newKieSession("KSession1");
checkKSession(ksession, "rule1", "rule2");
// create a new kjar
InternalKieModule kJar2 = createKieJar(ks, releaseId2, "rule2", "rule3");
// deploy it on maven
repository.installArtifact(releaseId2, kJar2, createKPom(fileManager, releaseId2));
// since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
InternalKieScanner scanner = (InternalKieScanner) ks.newKieScanner(kieContainer);
assertEquals(releaseId1, scanner.getCurrentReleaseId());
assertEquals(InternalKieScanner.Status.STOPPED, scanner.getStatus());
// scan the maven repo to get the new kjar version and deploy it on the kcontainer
scanner.scanNow();
assertEquals(releaseId2, scanner.getCurrentReleaseId());
assertEquals(InternalKieScanner.Status.STOPPED, scanner.getStatus());
// create a ksesion and check it works as expected
KieSession ksession2 = kieContainer.newKieSession("KSession1");
checkKSession(ksession2, "rule2", "rule3");
ks.getRepository().removeKieModule(releaseId1);
ks.getRepository().removeKieModule(releaseId2);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieRepositoryScannerTest method testScannerOnPomProjectSameKieSession.
@Test
public void testScannerOnPomProjectSameKieSession() throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "scanner-test", "1.0");
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "scanner-test", "2.0");
KieMavenRepository repository = getKieMavenRepository();
repository.deployPomArtifact("org.kie", "scanner-master-test", "1.0", createMasterKPom("scanner-test", "1.0"));
resetFileManager();
InternalKieModule kJar1 = createKieJarWithClass(ks, releaseId1, true, 2, 7);
repository.installArtifact(releaseId1, kJar1, createKPom(fileManager, releaseId1));
KieContainer kieContainer = ks.newKieContainer(ks.newReleaseId("org.kie", "scanner-master-test", "LATEST"));
KieSession ksession = kieContainer.newKieSession("KSession1");
checkKSession(false, ksession, 14);
KieScanner scanner = ks.newKieScanner(kieContainer);
repository.deployPomArtifact("org.kie", "scanner-master-test", "2.0", createMasterKPom("scanner-test", "2.0"));
InternalKieModule kJar2 = createKieJarWithClass(ks, releaseId2, true, 3, 5);
repository.installArtifact(releaseId2, kJar2, createKPom(fileManager, releaseId1));
scanner.scanNow();
checkKSession(ksession, 10, 15);
ks.getRepository().removeKieModule(releaseId1);
ks.getRepository().removeKieModule(releaseId2);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieRepositoryScannerTest method testKeepDefaultOnTopLevelProject.
@Test
public void testKeepDefaultOnTopLevelProject() throws Exception {
// DROOLS-1740
KieMavenRepository repository = getKieMavenRepository();
KieServices ks = KieServices.get();
ReleaseId depReleaseId = ks.newReleaseId("org.kie", "test-dep", "1.0.0-SNAPSHOT");
KieFileSystem kfs1 = ks.newKieFileSystem();
KieModuleModel kproj1 = ks.newKieModuleModel();
kproj1.newKieBaseModel("KBase1").setDefault(true).newKieSessionModel("KSession1").setDefault(true);
kfs1.writeKModuleXML(kproj1.toXML());
kfs1.writePomXML(getPom(depReleaseId));
kfs1.write("src/main/resources/org/test/rule1.drl", createDRL("rule1"));
KieBuilder kieBuilder1 = ks.newKieBuilder(kfs1);
assertTrue(kieBuilder1.buildAll().getResults().getMessages().isEmpty());
InternalKieModule kJar1 = (InternalKieModule) kieBuilder1.getKieModule();
repository.installArtifact(depReleaseId, kJar1, createKPom(fileManager, depReleaseId));
ReleaseId topReleaseId = KieServices.Factory.get().newReleaseId("org.kie", "test-top", "1.0.0-SNAPSHOT");
KieFileSystem kfs2 = ks.newKieFileSystem();
KieModuleModel kproj2 = ks.newKieModuleModel();
kproj2.newKieBaseModel("KBase2").setDefault(true).newKieSessionModel("KSession2").setDefault(true);
kfs2.writeKModuleXML(kproj2.toXML());
kfs2.writePomXML(getPom(topReleaseId, depReleaseId));
kfs2.write("src/main/resources/org/test/rule2.drl", createDRL("rule2"));
KieBuilder kieBuilder2 = ks.newKieBuilder(kfs2);
assertTrue(kieBuilder2.buildAll().getResults().getMessages().isEmpty());
InternalKieModule kJar2 = (InternalKieModule) kieBuilder2.getKieModule();
repository.installArtifact(topReleaseId, kJar2, createKPom(fileManager, topReleaseId, depReleaseId));
KieContainer kieContainer = ks.newKieContainer(topReleaseId);
KieSession ksession = kieContainer.newKieSession();
checkKSession(ksession, "rule2");
kieContainer = ks.newKieContainer(depReleaseId);
ksession = kieContainer.newKieSession();
checkKSession(ksession, "rule1");
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class MavenClassLoaderResolver method getClassLoader.
@Override
public ClassLoader getClassLoader(KieModule kmodule) {
ClassLoader parent = Thread.currentThread().getContextClassLoader();
if (parent == null) {
parent = ClassLoader.getSystemClassLoader();
}
if (parent == null) {
parent = MavenClassLoaderResolver.class.getClassLoader();
}
InternalKieModule internalKModule = (InternalKieModule) kmodule;
Collection<ReleaseId> jarDependencies = internalKModule.getJarDependencies(DependencyFilter.COMPILE_FILTER);
if (jarDependencies.isEmpty()) {
return parent;
}
ArtifactResolver resolver = ArtifactResolver.getResolverFor(internalKModule.getPomModel());
List<URL> urls = new ArrayList<URL>();
List<ReleaseId> unresolvedDeps = new ArrayList<ReleaseId>();
for (ReleaseId rid : jarDependencies) {
try {
Artifact artifact = resolver.resolveArtifact(rid);
if (artifact != null) {
File jar = artifact.getFile();
urls.add(jar.toURI().toURL());
} else {
logger.error("Dependency artifact not found for: " + rid);
unresolvedDeps.add(rid);
}
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
internalKModule.setUnresolvedDependencies(unresolvedDeps);
return new URLClassLoader(urls.toArray(new URL[urls.size()]), parent);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class AbstractKieCiTest method createKieJarWithPom.
protected InternalKieModule createKieJarWithPom(KieServices ks, ReleaseId releaseId, boolean isdefault, String rule, String pom) throws IOException {
KieFileSystem kfs = createKieFileSystemWithKProject(ks, isdefault);
kfs.writePomXML(pom);
String file = "org/test/" + rule + ".drl";
kfs.write("src/main/resources/KBase1/" + file, createDRL(rule));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
return (InternalKieModule) kieBuilder.getKieModule();
}
Aggregations