use of org.drools.compiler.compiler.io.Resource 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.Resource in project drools by kiegroup.
the class MemoryFileSystem method writeAsFs.
public void writeAsFs(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();
writeAsFs((Folder) rs, file2);
} else {
byte[] bytes = getFileContents((MemoryFile) rs);
try {
IoUtils.write(new java.io.File(file1, ((File) rs).getName()), bytes);
} catch (IOException e) {
throw new RuntimeException("Unable to write project to file system\n", e);
}
}
}
}
use of org.drools.compiler.compiler.io.Resource in project drools by kiegroup.
the class MemoryFileSystem method createFolder.
public void createFolder(MemoryFolder folder) {
// create current, if it does not exist.
if (!existsFolder(folder)) {
// create parent if it does not exist
if (!existsFolder((MemoryFolder) folder.getParent())) {
createFolder((MemoryFolder) folder.getParent());
}
folders.put(folder.getPath().toPortableString(), new HashSet<Resource>());
Folder parent = folder.getParent();
folders.get(parent.getPath().toPortableString()).add(folder);
}
}
use of org.drools.compiler.compiler.io.Resource in project drools by kiegroup.
the class MemoryFileSystem method remove.
public void remove(Set<Resource> members) {
for (Iterator<Resource> it = members.iterator(); it.hasNext(); ) {
Resource res = it.next();
if (res instanceof Folder) {
remove(folders.get(res.getPath().toPortableString()));
} else {
String fileName = res.getPath().toPortableString();
fileContents.remove(fileName);
if (modifiedFilesSinceLastMark != null) {
modifiedFilesSinceLastMark.add(fileName);
}
}
it.remove();
}
}
use of org.drools.compiler.compiler.io.Resource in project drools by kiegroup.
the class MemoryFileSystem method writeJarEntries.
private void writeJarEntries(Folder f, ZipOutputStream out) throws IOException {
for (Resource rs : f.getMembers()) {
String rname = rs.getPath().toPortableString();
if (rs instanceof Folder) {
// a folder name must end with / according to ZIP spec
rname = rname.endsWith("/") ? rname : rname + "/";
ZipEntry entry = new ZipEntry(rname);
out.putNextEntry(entry);
writeJarEntries((Folder) rs, out);
} else {
ZipEntry entry = new ZipEntry(rname);
out.putNextEntry(entry);
byte[] contents = getFileContents((MemoryFile) rs);
if (contents == null) {
IOException e = new IOException("No content found for: " + rs);
log.error(e.getMessage(), e);
throw e;
}
out.write(contents);
out.closeEntry();
}
}
}
Aggregations