use of org.drools.compiler.compiler.io.memory.MemoryFile in project drools by kiegroup.
the class MemoryKieModuleResourceProviderTest method testGetResourceAsStreamForFile.
@Test
public void testGetResourceAsStreamForFile() throws Exception {
MemoryFileSystem mfs = new MemoryFileSystem();
mfs.setFileContents(new MemoryFile(mfs, "my-file1", mfs.getFolder("src/main/resources")), new byte[] { 65, 66 });
MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs);
ResourceProvider resourceProvider = mkm.createResourceProvider();
String folderContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1"));
// "AB" == new byte[] {65, 66}
Assertions.assertThat(folderContents).hasLineCount(1).contains("AB");
}
use of org.drools.compiler.compiler.io.memory.MemoryFile in project drools by kiegroup.
the class MemoryKieModuleResourceProviderTest method testGetResourceTrailingSlashIgnored.
@Test
public void testGetResourceTrailingSlashIgnored() throws Exception {
MemoryFileSystem mfs = new MemoryFileSystem();
mfs.setFileContents(new MemoryFile(mfs, "my-file1", mfs.getFolder("src/main/resources")), new byte[] { 65, 66 });
MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs);
ResourceProvider resourceProvider = mkm.createResourceProvider();
String noTrailingSlashContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1"));
// "AB" == new byte[] {65, 66}
Assertions.assertThat(noTrailingSlashContents).hasLineCount(1).contains("AB");
String withTrailingSlashContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1/"));
// "AB" == new byte[] {65, 66}
Assertions.assertThat(withTrailingSlashContents).hasLineCount(1).contains("AB");
}
use of org.drools.compiler.compiler.io.memory.MemoryFile in project drools by kiegroup.
the class AbstractKnowledgeTest method writeFs.
public void writeFs(MemoryFileSystem mfs, Folder f, java.io.File file1) {
for (Resource rs : f.getMembers()) {
if (rs instanceof Folder) {
java.io.File file2 = new java.io.File(file1, ((Folder) rs).getName());
file2.mkdir();
writeFs(mfs, (Folder) rs, file2);
} else {
byte[] bytes = mfs.getFileContents((MemoryFile) rs);
try {
IoUtils.write(new java.io.File(file1, ((File) rs).getName()), bytes);
} catch (IOException e) {
fail("Unable to write project to file system\n" + e.getMessage());
}
}
}
}
use of org.drools.compiler.compiler.io.memory.MemoryFile 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);
}
use of org.drools.compiler.compiler.io.memory.MemoryFile in project drools by kiegroup.
the class MemoryKieModuleResourceProviderTest method testGetResourceForFolderWithFilesAndSubFolders.
@Test
public void testGetResourceForFolderWithFilesAndSubFolders() throws Exception {
MemoryFileSystem mfs = new MemoryFileSystem();
mfs.createFolder(new MemoryFolder(mfs, "src/main/java"));
mfs.createFolder(new MemoryFolder(mfs, "src/main/java/org"));
mfs.createFolder(new MemoryFolder(mfs, "src/main/java/com"));
mfs.setFileContents(new MemoryFile(mfs, "my-file1", mfs.getFolder("src/main/java")), new byte[10]);
mfs.setFileContents(new MemoryFile(mfs, "my-file2", mfs.getFolder("src/main/java")), new byte[10]);
MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs);
ResourceProvider resourceProvider = mkm.createResourceProvider();
String folderContents = IOUtils.toString(resourceProvider.getResource("src/main/java").openStream());
Assertions.assertThat(folderContents).hasLineCount(4).contains("com", "org", "my-file1", "my-file2");
}
Aggregations