use of org.drools.compiler.compiler.io.FileSystemItem in project drools by kiegroup.
the class AbstractKnowledgeTest method writeFs.
public void writeFs(MemoryFileSystem mfs, Folder f, java.io.File file1) {
for (FileSystemItem 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.FileSystemItem in project drools by kiegroup.
the class MemoryFileSystem method writeAsFs.
public void writeAsFs(Folder f, java.io.File file1) {
for (FileSystemItem 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.FileSystemItem in project drools by kiegroup.
the class MemoryFileSystem method remove.
public void remove(Set<FileSystemItem> members) {
for (Iterator<FileSystemItem> it = members.iterator(); it.hasNext(); ) {
FileSystemItem res = it.next();
if (res instanceof Folder) {
remove(folders.get(res.getPath()));
} else {
KiePath filePath = res.getPath();
fileContents.remove(filePath);
if (modifiedFilesSinceLastMark != null) {
modifiedFilesSinceLastMark.add(filePath.asString());
}
}
it.remove();
}
}
use of org.drools.compiler.compiler.io.FileSystemItem in project drools by kiegroup.
the class MemoryFileSystem method copyFolder.
private static int copyFolder(MemoryFileSystem srcMfs, Folder srcFolder, MemoryFileSystem trgMfs, Folder trgFolder, int count, String... filters) {
if (!trgFolder.exists()) {
trgMfs.getFolder(trgFolder.getPath()).create();
}
if (srcFolder != null) {
for (FileSystemItem rs : srcFolder.getMembers()) {
if (rs instanceof Folder) {
count = copyFolder(srcMfs, (Folder) rs, trgMfs, trgFolder.getFolder(((Folder) rs).getName()), count, filters);
} else {
MemoryFile trgFile = (MemoryFile) trgFolder.getFile(((org.drools.compiler.compiler.io.File) rs).getName());
boolean accept = false;
if (filters == null || filters.length == 0) {
accept = true;
} else {
for (String filter : filters) {
if (trgFile.getName().endsWith(filter)) {
accept = true;
break;
}
}
}
if (accept) {
try {
trgMfs.setFileContents(trgFile, srcMfs.getResource((MemoryFile) rs));
count++;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}
return count;
}
use of org.drools.compiler.compiler.io.FileSystemItem in project drools by kiegroup.
the class MemoryFileSystem method writeJarEntries.
private void writeJarEntries(Folder f, ZipOutputStream out) throws IOException {
for (FileSystemItem rs : f.getMembers()) {
String rname = rs.getPath().asString();
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