Search in sources :

Example 1 with KiePath

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);
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystem(org.kie.api.builder.KieFileSystem) KieFileSystemImpl(org.drools.compiler.kie.builder.impl.KieFileSystemImpl) KiePath(org.kie.memorycompiler.resources.KiePath) Test(org.junit.Test)

Example 2 with KiePath

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;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) KiePath(org.kie.memorycompiler.resources.KiePath) IOException(java.io.IOException) Folder(org.drools.compiler.compiler.io.Folder) ZipFile(java.util.zip.ZipFile) File(org.drools.compiler.compiler.io.File)

Example 3 with KiePath

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);
}
Also used : KiePath(org.kie.memorycompiler.resources.KiePath)

Example 4 with KiePath

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();
    }
}
Also used : FileSystemItem(org.drools.compiler.compiler.io.FileSystemItem) KiePath(org.kie.memorycompiler.resources.KiePath) Folder(org.drools.compiler.compiler.io.Folder)

Example 5 with KiePath

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();
}
Also used : Resource(org.kie.api.io.Resource) InternalResource(org.drools.core.io.internal.InternalResource) KiePath(org.kie.memorycompiler.resources.KiePath)

Aggregations

KiePath (org.kie.memorycompiler.resources.KiePath)13 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 File (org.drools.compiler.compiler.io.File)2 Folder (org.drools.compiler.compiler.io.Folder)2 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)2 CompilationProblem (org.kie.memorycompiler.CompilationProblem)2 CompilationResult (org.kie.memorycompiler.CompilationResult)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLDecoder (java.net.URLDecoder)1 Collection (java.util.Collection)1 List (java.util.List)1 Locale (java.util.Locale)1 StringTokenizer (java.util.StringTokenizer)1