use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieUtil method buildAndInstallKieModuleIntoRepo.
public static KieModule buildAndInstallKieModuleIntoRepo(final KieBaseTestConfiguration kieBaseTestConfiguration, final ReleaseId releaseId, final KieModuleModel kieModuleModel, final Resource... resources) {
final KieServices kieServices = KieServices.Factory.get();
final KieFileSystem fileSystem = getKieFileSystemWithKieModule(kieModuleModel, releaseId, resources);
final KieBuilder builder = getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, fileSystem, true);
KieModule kieModule = builder.getKieModule();
if (kieBaseTestConfiguration.useCanonicalModel()) {
final File kjarFile = FileUtil.bytesToTempKJARFile(releaseId, ((InternalKieModule) kieModule).getBytes(), ".jar");
kieModule = new CanonicalKieModule(releaseId, kieModuleModel, kjarFile);
}
kieServices.getRepository().addKieModule(kieModule);
return kieModule;
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class IncrementalCompilationTest method createAndDeployJarWithDSL.
public static KieModule createAndDeployJarWithDSL(KieServices ks, ReleaseId releaseId, String... drls) {
KieFileSystem kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId);
for (int i = 0; i < drls.length; i++) {
String extension = i == 0 ? "dsl" : "rdslr";
if (drls[i] != null) {
kfs.write("src/main/resources/r" + i + "." + extension, drls[i]);
}
}
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
if (kb.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
for (org.kie.api.builder.Message result : kb.getResults().getMessages()) {
System.out.println(result.getText());
}
return null;
}
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return deployJar(ks, jar);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieModuleDeploymentHelperImpl method internalCreateAndDeployKjarToMaven.
/**
* Internal methods
*/
/**
* Create a KJar and deploy it to maven.
*
* @param releaseId The {@link ReleaseId} of the jar.
* @param kbaseName The name to use for the (default) {@link KieBase} in the kmodule.xml.
* @param ksessionName The name to use for the (default) {@link KieSession} in the kmodule.xml.
* @param resourceFilePaths A (possibly null) list of files to be added to the kjar.
* @param classes
* @param dependencies
*/
private synchronized void internalCreateAndDeployKjarToMaven(ReleaseId releaseId, String kbaseName, String ksessionName, List<String> resourceFilePaths, List<Class<?>> classes, List<String> dependencies) {
InternalKieModule kjar = (InternalKieModule) internalCreateKieJar(releaseId, kbaseName, ksessionName, resourceFilePaths, classes, dependencies);
String pomFileName = MavenRepository.toFileName(releaseId, null) + ".pom";
File pomFile = new File(System.getProperty("java.io.tmpdir"), pomFileName);
try {
FileOutputStream fos = new FileOutputStream(pomFile);
fos.write(config.pomText.getBytes(IoUtils.UTF8_CHARSET));
fos.flush();
fos.close();
} catch (IOException ioe) {
throw new RuntimeException("Unable to write pom.xml to temporary file : " + ioe.getMessage(), ioe);
}
KieMavenRepository repository = getKieMavenRepository();
repository.installArtifact(releaseId, kjar, pomFile);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class CommonTestMethodBase method createKJar.
public static byte[] createKJar(KieServices ks, ReleaseId releaseId, Resource pom, Resource... resources) {
KieFileSystem kfs = ks.newKieFileSystem();
if (pom != null) {
kfs.write(pom);
} else {
kfs.generateAndWritePomXML(releaseId);
}
for (int i = 0; i < resources.length; i++) {
if (resources[i] != null) {
kfs.write(resources[i]);
}
}
ks.newKieBuilder(kfs).buildAll();
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return jar;
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class CommonTestMethodBase method buildKJar.
public static byte[] buildKJar(KieServices ks, KieFileSystem kfs, ReleaseId releaseId) {
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
for (Message result : kb.getResults().getMessages()) {
System.out.println(result.getText());
}
return null;
}
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return jar;
}
Aggregations