use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class ProjectServiceTest method registerImporter.
private void registerImporter(String importType, InputStream zip) throws Exception {
final ValueHolder<FolderEntry> folderHolder = new ValueHolder<>();
importerRegistry.register(new ProjectImporter() {
@Override
public String getId() {
return importType;
}
@Override
public boolean isInternal() {
return false;
}
@Override
public String getDescription() {
return "Chuck importer";
}
@Override
public void importSources(FolderEntry baseFolder, SourceStorage storage) throws ConflictException, ServerException, ForbiddenException {
importSources(baseFolder, storage, LineConsumerFactory.NULL);
}
@Override
public void importSources(FolderEntry baseFolder, SourceStorage storage, LineConsumerFactory importOutputConsumerFactory) throws ConflictException, ServerException, ForbiddenException {
// Don't really use location in this test.
baseFolder.getVirtualFile().unzip(zip, true, 0);
folderHolder.set(baseFolder);
}
@Override
public ImporterCategory getCategory() {
return ImporterCategory.ARCHIVE;
}
});
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class LocalVirtualFileSystem method getFileLock.
private FileLock getFileLock(LocalVirtualFile virtualFile) throws ServerException {
final PathLockFactory.PathLock lockFilePathLock = pathLockFactory.getLock(virtualFile.getPath(), true).acquire(WAIT_FOR_FILE_LOCK_TIMEOUT);
try {
final FileLock lock;
try {
lock = lockTokensCache.get(virtualFile.getPath());
} catch (ExecutionException e) {
String errorMessage = String.format("Unable get lock of file '%s'", virtualFile.getPath());
LOG.error(errorMessage + "\n" + e.getCause().getMessage(), e.getCause());
throw new ServerException(errorMessage);
}
if (NO_LOCK == lock) {
return lock;
}
if (lock.getExpired() < System.currentTimeMillis()) {
final File fileLockIoFile = getFileLockIoFile(virtualFile.getPath());
if (!fileLockIoFile.delete()) {
if (fileLockIoFile.exists()) {
FileCleaner.addFile(fileLockIoFile);
LOG.warn("Unable delete lock file %s", fileLockIoFile);
}
}
lockTokensCache.put(virtualFile.getPath(), NO_LOCK);
return NO_LOCK;
}
return lock;
} finally {
lockFilePathLock.release();
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class LocalVirtualFileSystem method untar.
void untar(LocalVirtualFile parent, InputStream tarArchive, boolean overwrite, int stripNumber) throws ForbiddenException, ConflictException, ServerException {
if (archiverFactory == null)
throw new ServerException("VFS: Could not create tar archiver. Archiver Factory is not properly configured (is null)");
if (parent.isFolder()) {
extract(archiverFactory.createArchiver(parent, "tar"), tarArchive, overwrite, stripNumber);
addInSearcher(parent);
} else {
throw new ForbiddenException(String.format("Unable import tar archive. Item '%s' is not a folder", parent.getPath()));
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class MemoryVirtualFile method compress.
private InputStream compress(Archiver archiver) throws ForbiddenException, ServerException {
try {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
archiver.compress(byteOut);
return new ByteArrayInputStream(byteOut.toByteArray());
} catch (IOException e) {
throw new ServerException(e.getMessage(), e);
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class MemoryVirtualFile method copyTo.
@Override
public VirtualFile copyTo(VirtualFile parent, String newName, boolean overwrite) throws ForbiddenException, ConflictException, ServerException {
checkExistence();
((MemoryVirtualFile) parent).checkExistence();
if (isRoot()) {
throw new ServerException("Unable copy root folder");
}
if (newName == null || newName.trim().isEmpty()) {
newName = this.getName();
}
if (parent.isFolder()) {
VirtualFile copy = doCopy((MemoryVirtualFile) parent, newName, overwrite);
addInSearcher(copy);
return copy;
} else {
throw new ForbiddenException(String.format("Unable create copy of '%s'. Item '%s' specified as parent is not a folder.", getPath(), parent.getPath()));
}
}
Aggregations