use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieRepositoryImpl method getKieModule.
public KieModule getKieModule(Resource resource) {
InternalResource res = (InternalResource) resource;
try {
KieModule kModule;
// find kmodule.xml
if (res.hasURL()) {
String urlPath = res.getURL().toExternalForm();
if (res.isDirectory()) {
if (!urlPath.endsWith("/")) {
urlPath = urlPath + "/";
}
urlPath = urlPath + KieModuleModelImpl.KMODULE_JAR_PATH;
} else {
urlPath = "jar:" + urlPath + "!/" + KieModuleModelImpl.KMODULE_JAR_PATH;
}
kModule = ClasspathKieProject.fetchKModule(new URL(urlPath));
log.debug("Fetched KieModule from resource: " + resource);
} else {
// might be a byte[] resource
MemoryFileSystem mfs = MemoryFileSystem.readFromJar(res.getInputStream());
byte[] bytes = mfs.getBytes(KieModuleModelImpl.KMODULE_JAR_PATH);
KieModuleModel kieProject = KieModuleModelImpl.fromXML(new ByteArrayInputStream(bytes));
setDefaultsforEmptyKieModule(kieProject);
String pomProperties = mfs.findPomProperties();
ReleaseId releaseId = ReleaseIdImpl.fromPropertiesString(pomProperties);
kModule = new MemoryKieModule(releaseId, kieProject, mfs);
}
return kModule;
} catch (Exception e) {
throw new RuntimeException("Unable to fetch module from resource: " + res, e);
}
}
use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieBuilderTest method testInvalidPomXmlGAV.
@Test
public void testInvalidPomXmlGAV() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
KieModuleModel kProj = createKieProject(namespace);
ReleaseId releaseId = new ReleaseIdImpl("", "", "");
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generatePomXML(kfs, releaseId);
generateMessageClass(kfs, namespace);
generateRule(kfs, namespace);
MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
KieBuilder kieBuilder = createKieBuilder(kfs);
kieBuilder.buildAll();
assertTrue(kieBuilder.getResults().hasMessages(Level.ERROR));
}
use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieBuilderTest method testEmptyProjectXml.
@Test
public void testEmptyProjectXml() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
KieServices ks = KieServices.Factory.get();
KieModuleModel kProj = ks.newKieModuleModel();
ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "memory", "1.0-SNAPSHOT");
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generateKProjectXML(kfs, namespace, kProj);
generatePomXML(kfs, releaseId);
generateMessageClass(kfs, namespace);
generateRule(kfs, namespace);
MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
createAndTestKieContainer(releaseId, createKieBuilder(kfs), null);
}
use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieBuilderTest method testOnDisc.
@Test
public void testOnDisc() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
KieModuleModel kProj = createKieProject(namespace);
ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "memory", "1.0-SNAPSHOT");
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generateAll(kfs, namespace, releaseId, kProj);
MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
File file = fileManager.getRootDirectory();
mfs.writeAsFs(file);
createAndTestKieContainer(releaseId, createKieBuilder(kfs), namespace);
}
use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class CanonicalModelKieProject method writeProjectOutput.
@Override
public void writeProjectOutput(MemoryFileSystem trgMfs, ResultsImpl messages) {
MemoryFileSystem srcMfs = new MemoryFileSystem();
ModelWriter modelWriter = new ModelWriter();
List<String> modelFiles = new ArrayList<>();
for (ModelBuilderImpl modelBuilder : modelBuilders) {
final ModelWriter.Result result = modelWriter.writeModel(srcMfs, modelBuilder.getPackageModels());
modelFiles.addAll(result.getModelFiles());
final String[] sources = result.getSources();
if (sources.length != 0) {
CompilationResult res = getCompiler().compile(sources, srcMfs, trgMfs, getClassLoader());
Stream.of(res.getErrors()).collect(groupingBy(CompilationProblem::getFileName)).forEach((name, errors) -> {
errors.forEach(messages::addMessage);
File srcFile = srcMfs.getFile(name);
if (srcFile instanceof MemoryFile) {
String src = new String(srcMfs.getFileContents((MemoryFile) srcFile));
messages.addMessage(Message.Level.ERROR, name, "Java source of " + name + " in error:\n" + src);
}
});
for (CompilationProblem problem : res.getWarnings()) {
messages.addMessage(problem);
}
}
}
modelWriter.writeModelFile(modelFiles, trgMfs);
}
Aggregations