use of org.kie.memorycompiler.resources.KiePath in project drools by kiegroup.
the class KieFileSystemImplTest method testClone.
@Test
public void testClone() {
KieFileSystem clonedKieFileSystem = kieFileSystem.clone();
MemoryFileSystem clonedMfs = ((KieFileSystemImpl) clonedKieFileSystem).getMfs();
Collection<KiePath> clonedFileNames = clonedMfs.getFilePaths();
assertTrue(kieFileSystem != clonedKieFileSystem);
assertTrue(kieFileSystem.getMfs() != clonedMfs);
assertEquals(kieFileSystem.getMfs().getFilePaths(), clonedFileNames);
}
use of org.kie.memorycompiler.resources.KiePath in project drools by kiegroup.
the class MemoryFileSystem method readFromJar.
public static MemoryFileSystem readFromJar(java.io.File jarFile) {
MemoryFileSystem mfs = new MemoryFileSystem();
try (ZipFile zipFile = new ZipFile(jarFile)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
int separator = entry.getName().lastIndexOf('/');
KiePath path = separator > 0 ? KiePath.of(entry.getName().substring(0, separator)) : ROOT_PATH;
String name = entry.getName().substring(separator + 1);
Folder folder = mfs.getFolder(path);
folder.create();
File file = folder.getFile(name);
file.create(zipFile.getInputStream(entry));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return mfs;
}
use of org.kie.memorycompiler.resources.KiePath in project drools by kiegroup.
the class MemoryFileSystem method setFileContents.
public void setFileContents(MemoryFile file, Resource resource) throws IOException {
if (!existsFolder((MemoryFolder) file.getFolder())) {
createFolder((MemoryFolder) file.getFolder());
}
KiePath filePath = file.getPath();
if (modifiedFilesSinceLastMark != null) {
byte[] contents = resourceToBytes(resource);
byte[] oldContent = resourceToBytes(fileContents.get(filePath));
if (oldContent == null || !Arrays.equals(oldContent, contents)) {
modifiedFilesSinceLastMark.add(filePath.asString());
}
}
fileContents.put(filePath, (InternalResource) resource);
resource.setSourcePath(file.getPath().asString());
folders.get(file.getFolder().getPath()).add(file);
}
use of org.kie.memorycompiler.resources.KiePath 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.kie.memorycompiler.resources.KiePath in project drools by kiegroup.
the class KieBuilderImpl method copySourceToTarget.
String copySourceToTarget(KiePath filePath) {
if (!filePath.startsWith(RESOURCES_ROOT)) {
return null;
}
Resource resource = getResource(srcMfs, filePath);
KiePath trgFileName = filePath.substring(RESOURCES_ROOT.length());
if (resource != null) {
trgMfs.write(trgFileName, resource, true);
} else {
trgMfs.remove(trgFileName);
}
return trgFileName.asString();
}
Aggregations