Search in sources :

Example 1 with RepositoryCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage in project legend-pure by finos.

the class PureCodeStorage method writeContent.

@Override
public void writeContent(String path, String content) {
    // Special case: /welcome.pure
    if (isWelcomePath(path)) {
        if (!hasRootPath()) {
            throw new RuntimeException("Error trying to write content to " + path + ": no such file");
        }
        try {
            Files.write(resolveWelcomePath(), content.getBytes(StandardCharsets.UTF_8));
            return;
        } catch (IOException e) {
            throw new RuntimeException("Error trying to write content to " + path, e);
        }
    }
    // General case
    RepositoryCodeStorage codeStorage = getCodeStorage(path);
    if (!(codeStorage instanceof MutableRepositoryCodeStorage)) {
        throw new IllegalArgumentException("Cannot write content to '" + path + "'");
    }
    ((MutableRepositoryCodeStorage) codeStorage).writeContent(path, content);
}
Also used : IOException(java.io.IOException) MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage) RepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage) MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage)

Example 2 with RepositoryCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage in project legend-pure by finos.

the class PureCodeStorage method cleanup.

@Override
public void cleanup() {
    MutableList<Exception> exceptions = Lists.mutable.empty();
    for (RepositoryCodeStorage codeStorage : this.codeStorages) {
        if (codeStorage instanceof MutableVersionControlledCodeStorage) {
            try {
                ((MutableVersionControlledCodeStorage) codeStorage).cleanup();
            } catch (Exception e) {
                exceptions.add(e);
            }
        }
    }
    if (exceptions.size() == 1) {
        Exception e = exceptions.get(0);
        if (e instanceof PureVCSException) {
            throw (PureVCSException) e;
        }
        throw new PureVCSException("Error performing cleanup", e);
    }
    if (exceptions.size() > 1) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        pw.println("Multiple errors occurred during cleanup:");
        for (Exception e : exceptions) {
            pw.println("------");
            e.printStackTrace(pw);
        }
        pw.println("------");
        pw.flush();
        throw new PureVCSException(sw.toString());
    }
}
Also used : StringWriter(java.io.StringWriter) IOException(java.io.IOException) RepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage) MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage) MutableVersionControlledCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.vcs.MutableVersionControlledCodeStorage) PrintWriter(java.io.PrintWriter)

Example 3 with RepositoryCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage in project legend-pure by finos.

the class PureCodeStorage method deleteFile.

@Override
public void deleteFile(String path) {
    RepositoryCodeStorage codeStorage = getCodeStorage(path);
    if (!(codeStorage instanceof MutableRepositoryCodeStorage)) {
        throw new IllegalArgumentException("Cannot delete file " + path);
    }
    ((MutableRepositoryCodeStorage) codeStorage).deleteFile(path);
}
Also used : MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage) RepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage) MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage)

Example 4 with RepositoryCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage in project legend-pure by finos.

the class PureCodeStorage method createFile.

@Override
public void createFile(String path) {
    RepositoryCodeStorage codeStorage = getCodeStorage(path);
    if (!(codeStorage instanceof MutableRepositoryCodeStorage)) {
        throw new IllegalArgumentException("Cannot create file " + path);
    }
    ((MutableRepositoryCodeStorage) codeStorage).createFile(path);
}
Also used : MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage) RepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage) MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage)

Example 5 with RepositoryCodeStorage

use of org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage in project legend-pure by finos.

the class PureCodeStorage method createFolder.

@Override
public void createFolder(String path) {
    RepositoryCodeStorage codeStorage = getCodeStorage(path);
    if (!(codeStorage instanceof MutableRepositoryCodeStorage)) {
        throw new IllegalArgumentException("Cannot create folder " + path);
    }
    ((MutableRepositoryCodeStorage) codeStorage).createFolder(path);
}
Also used : MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage) RepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage) MutableRepositoryCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage)

Aggregations

RepositoryCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.RepositoryCodeStorage)14 MutableRepositoryCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableRepositoryCodeStorage)11 IOException (java.io.IOException)4 ClassLoaderCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.classpath.ClassLoaderCodeStorage)4 MutableVersionControlledCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.vcs.MutableVersionControlledCodeStorage)4 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)3 MutableFSCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.fs.MutableFSCodeStorage)3 PureRuntime (org.finos.legend.pure.m3.serialization.runtime.PureRuntime)3 PureRuntimeBuilder (org.finos.legend.pure.m3.serialization.runtime.PureRuntimeBuilder)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Lists (org.eclipse.collections.api.factory.Lists)2 MutableList (org.eclipse.collections.api.list.MutableList)2 CodeRepository (org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository)2 MutableCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.usercodestorage.MutableCodeStorage)2 Message (org.finos.legend.pure.m3.serialization.runtime.Message)2 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1