use of org.drools.compiler.kie.builder.impl.KieRepositoryImpl in project drools by kiegroup.
the class KieModuleMavenTest method testKieModuleFromMavenNoDependencies.
@Test
public void testKieModuleFromMavenNoDependencies() throws Exception {
final KieServices ks = new KieServicesImpl() {
@Override
public KieRepository getRepository() {
// override repository to not store the artifact on deploy to trigger load from maven repo
return new KieRepositoryImpl();
}
};
ReleaseId releaseId = ks.newReleaseId("org.kie", "maven-test", "1.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJar(ks, releaseId, true, "rule1", "rule2");
String pomText = getPom(releaseId);
File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile);
fos.write(pomText.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieBaseModel kbaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
assertNotNull("Default kbase was not found", kbaseModel);
String kbaseName = kbaseModel.getName();
assertEquals("KBase1", kbaseName);
// Check classloader
assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources(""));
assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources("KBase1/org/test"));
assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources("KBase1/org/test/"));
}
use of org.drools.compiler.kie.builder.impl.KieRepositoryImpl in project drools by kiegroup.
the class KieModuleMavenTest method testKieModuleFromMavenWithDependenciesProperties.
@Test
public void testKieModuleFromMavenWithDependenciesProperties() throws Exception {
final KieServices ks = new KieServicesImpl() {
@Override
public KieRepository getRepository() {
// override repository to not store the artifact on deploy to trigger load from maven repo
return new KieRepositoryImpl();
}
};
ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "${version.org.drools}");
ReleaseId releaseId = ks.newReleaseId("org.kie.test", "maven-test", "1.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJarWithProperties(ks, releaseId, true, "5.5.0.Final", new ReleaseId[] { dependency }, "rule1", "rule2");
String pomText = generatePomXmlWithProperties(releaseId, "5.5.0.Final", dependency);
File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile);
fos.write(pomText.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieBaseModel kbaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
assertNotNull("Default kbase was not found", kbaseModel);
String kbaseName = kbaseModel.getName();
assertEquals("KBase1", kbaseName);
}
use of org.drools.compiler.kie.builder.impl.KieRepositoryImpl in project drools by kiegroup.
the class KieModuleMavenTest method testKieModuleFromMavenWithDependencies.
@Test
public void testKieModuleFromMavenWithDependencies() throws Exception {
final KieServices ks = new KieServicesImpl() {
@Override
public KieRepository getRepository() {
// override repository to not store the artifact on deploy to trigger load from maven repo
return new KieRepositoryImpl();
}
};
ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final");
ReleaseId releaseId = ks.newReleaseId("org.kie", "maven-test", "1.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJar(ks, releaseId, true, "rule1", "rule2");
String pomText = getPom(releaseId, dependency);
File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile);
fos.write(pomText.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieBaseModel kbaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
assertNotNull("Default kbase was not found", kbaseModel);
String kbaseName = kbaseModel.getName();
assertEquals("KBase1", kbaseName);
}
use of org.drools.compiler.kie.builder.impl.KieRepositoryImpl in project drools by kiegroup.
the class DroolsAbstractPMMLTest method createExecutor.
protected RuleUnitExecutor createExecutor(String sourceName) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
ReleaseId releaseId = new ReleaseIdImpl("org.kie:pmmlTest:1.0-SNAPSHOT");
((KieRepositoryImpl) kr).setDefaultGAV(releaseId);
Resource res = ResourceFactory.newClassPathResource(sourceName);
kbase = new KieHelper().addResource(res, ResourceType.PMML).build();
assertNotNull(kbase);
RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
KieContainer kc = ((KnowledgeBaseImpl) ((InternalRuleUnitExecutor) executor).getKieSession().getKieBase()).getKieContainer();
InternalKieModule ikm = (InternalKieModule) kr.getKieModule(releaseId);
try (FileOutputStream fos = new FileOutputStream("/tmp/outputModule.jar")) {
fos.write(ikm.getBytes());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
kc.getKieBaseNames().forEach(n -> {
System.out.println(n);
});
data = executor.newDataSource("request");
resultData = executor.newDataSource("results");
pmmlData = executor.newDataSource("pmmlData");
return executor;
}
use of org.drools.compiler.kie.builder.impl.KieRepositoryImpl in project drools by kiegroup.
the class KieModuleMavenTest method testKieModuleFromMavenWithTransitiveDependencies.
@Test
public void testKieModuleFromMavenWithTransitiveDependencies() throws Exception {
final KieServices ks = new KieServicesImpl() {
@Override
public KieRepository getRepository() {
// override repository to not store the artifact on deploy to trigger load from maven repo
return new KieRepositoryImpl();
}
};
ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final");
ReleaseId releaseId = ks.newReleaseId("org.kie", "maven-test", "1.0-SNAPSHOT");
String pomText = getPom(releaseId, dependency);
InternalKieModule kJar1 = createKieJar(ks, releaseId, pomText, true, "rule1", "rule2");
File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile);
fos.write(pomText.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
KieContainer kieContainer = ks.newKieContainer(releaseId);
Collection<ReleaseId> expectedDependencies = new HashSet<ReleaseId>();
expectedDependencies.add(ks.newReleaseId("org.drools", "knowledge-api", "5.5.0.Final"));
expectedDependencies.add(ks.newReleaseId("org.drools", "knowledge-internal-api", "5.5.0.Final"));
expectedDependencies.add(ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final"));
expectedDependencies.add(ks.newReleaseId("org.mvel", "mvel2", "2.1.3.Final"));
expectedDependencies.add(ks.newReleaseId("org.slf4j", "slf4j-api", "1.6.4"));
Collection<ReleaseId> dependencies = ((InternalKieModule) ((KieContainerImpl) kieContainer).getKieModuleForKBase("KBase1")).getJarDependencies(DependencyFilter.TAKE_ALL_FILTER);
assertNotNull(dependencies);
assertEquals(5, dependencies.size());
boolean matchedAll = dependencies.containsAll(expectedDependencies);
assertTrue(matchedAll);
}
Aggregations