/* (non-Javadoc) * @see com.aptana.ide.core.io.vfs.IConnectionFileManager#disconnect(org.eclipse.core.runtime.IProgressMonitor) */ public synchronized void disconnect(IProgressMonitor monitor) throws CoreException { try { checkConnected(); } catch (Exception ignore) { } if (!isConnected()) { return; } monitor = Policy.monitorFor(monitor); monitor.beginTask( Messages.FTPConnectionFileManager_closing_connection, IProgressMonitor.UNKNOWN); try { ftpClient.quit(); } catch (Exception e) { try { ftpClient.quitImmediately(); } catch (Exception ignore) { } throw new CoreException( new Status( Status.ERROR, FTPPlugin.PLUGIN_ID, Messages.FTPConnectionFileManager_disconnect_failed, e)); } finally { cwd = null; pool.dispose(); cleanup(); monitor.done(); } }
@Override public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException { monitor = Policy.monitorFor(monitor); try { String message = NLS.bind(Messages.resources_settingCharset, getFullPath()); monitor.beginTask(message, Policy.totalWork); // need to get the project as a scheduling rule because we might be creating a new folder/file // to // hold the project settings final ISchedulingRule rule = workspace.getRuleFactory().charsetRule(this); try { workspace.prepareOperation(rule, monitor); ResourceInfo info = getResourceInfo(false, false); checkAccessible(getFlags(info)); workspace.beginOperation(true); workspace.getCharsetManager().setCharsetFor(getFullPath(), newCharset); info = getResourceInfo(false, true); info.incrementCharsetGenerationCount(); monitor.worked(Policy.opWork); } catch (OperationCanceledException e) { workspace.getWorkManager().operationCanceled(); throw e; } finally { workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); } } finally { monitor.done(); } }
@Override public void setContents(InputStream content, int updateFlags, IProgressMonitor monitor) throws CoreException { monitor = Policy.monitorFor(monitor); try { String message = NLS.bind(Messages.resources_settingContents, getFullPath()); monitor.beginTask(message, Policy.totalWork); if (workspace.shouldValidate) workspace.validateSave(this); final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this); try { workspace.prepareOperation(rule, monitor); ResourceInfo info = getResourceInfo(false, false); checkAccessible(getFlags(info)); workspace.beginOperation(true); IFileInfo fileInfo = getStore().fetchInfo(); internalSetContents( content, fileInfo, updateFlags, false, Policy.subMonitorFor(monitor, Policy.opWork)); } catch (OperationCanceledException e) { workspace.getWorkManager().operationCanceled(); throw e; } finally { workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); } } finally { monitor.done(); FileUtil.safeClose(content); } }
/* (non-Javadoc) * @see com.aptana.ide.core.io.vfs.IConnectionFileManager#connect(org.eclipse.core.runtime.IProgressMonitor) */ public void connect(IProgressMonitor monitor) throws CoreException { Assert.isTrue(ftpClient != null, Messages.FTPConnectionFileManager_not_initialized); monitor = Policy.monitorFor(monitor); try { cwd = null; cleanup(); ConnectionContext context = CoreIOPlugin.getConnectionContext(this); if (messageLogWriter == null) { if (context != null) { Object object = context.get(ConnectionContext.COMMAND_LOG); if (object instanceof PrintWriter) { messageLogWriter = (PrintWriter) object; } else if (object instanceof OutputStream) { messageLogWriter = new PrintWriter((OutputStream) object); } } if (messageLogWriter == null) { messageLogWriter = FTPPlugin.getDefault().getFTPLogWriter(); } if (messageLogWriter != null) { messageLogWriter.println(StringUtils.format("---------- FTP {0} ----------", host)); setMessageLogger(ftpClient, messageLogWriter); } } else { messageLogWriter.println( StringUtils.format("---------- RECONNECTING - FTP {0} ----------", host)); } monitor.beginTask( Messages.FTPConnectionFileManager_establishing_connection, IProgressMonitor.UNKNOWN); ftpClient.setRemoteHost(host); ftpClient.setRemotePort(port); while (true) { monitor.subTask(Messages.FTPConnectionFileManager_connecting); ftpClient.connect(); if (password.length == 0 && !IFTPConstants.LOGIN_ANONYMOUS.equals(login) && (context == null || !context.getBoolean(ConnectionContext.NO_PASSWORD_PROMPT))) { getOrPromptPassword( StringUtils.format(Messages.FTPConnectionFileManager_ftp_auth, host), Messages.FTPConnectionFileManager_specify_password); } Policy.checkCanceled(monitor); monitor.subTask(Messages.FTPConnectionFileManager_authenticating); try { ftpClient.login(login, String.copyValueOf(password)); } catch (FTPException e) { Policy.checkCanceled(monitor); if (ftpClient.getLastValidReply() == null || "331".equals(ftpClient.getLastValidReply().getReplyCode())) { // $NON-NLS-1$ if (context != null && context.getBoolean(ConnectionContext.NO_PASSWORD_PROMPT)) { throw new CoreException( new Status( Status.ERROR, FTPPlugin.PLUGIN_ID, StringUtils.format("Authentication failed: {0}", e.getLocalizedMessage()), e)); } promptPassword( StringUtils.format(Messages.FTPConnectionFileManager_ftp_auth, host), Messages.FTPConnectionFileManager_invalid_password); safeQuit(); continue; } throw e; } break; } Policy.checkCanceled(monitor); changeCurrentDir(basePath); ftpClient.setType( IFTPConstants.TRANSFER_TYPE_ASCII.equals(transferType) ? FTPTransferType.ASCII : FTPTransferType.BINARY); if ((hasServerInfo || (context != null && context.getBoolean(ConnectionContext.QUICK_CONNECT))) && !(context != null && context.getBoolean(ConnectionContext.DETECT_TIMEZONE))) { return; } getherServerInfo(context, monitor); } catch (OperationCanceledException e) { safeQuit(); throw e; } catch (CoreException e) { safeQuit(); throw e; } catch (UnknownHostException e) { safeQuit(); throw new CoreException( new Status( Status.ERROR, FTPPlugin.PLUGIN_ID, "Host name not found: " + e.getLocalizedMessage(), e)); } catch (FileNotFoundException e) { safeQuit(); throw new CoreException( new Status( Status.ERROR, FTPPlugin.PLUGIN_ID, "Remote folder not found: " + e.getLocalizedMessage(), e)); } catch (Exception e) { safeQuit(); throw new CoreException( new Status( Status.ERROR, FTPPlugin.PLUGIN_ID, Messages.FTPConnectionFileManager_connection_failed + e.getLocalizedMessage(), e)); } finally { monitor.done(); } }
@Override public void create(InputStream content, int updateFlags, IProgressMonitor monitor) throws CoreException { final boolean monitorNull = monitor == null; monitor = Policy.monitorFor(monitor); try { String message = monitorNull ? "" : NLS.bind(Messages.resources_creating, getFullPath()); // $NON-NLS-1$ monitor.beginTask(message, Policy.totalWork); checkValidPath(path, FILE, true); final ISchedulingRule rule = workspace.getRuleFactory().createRule(this); try { workspace.prepareOperation(rule, monitor); checkDoesNotExist(); Container parent = (Container) getParent(); ResourceInfo info = parent.getResourceInfo(false, false); parent.checkAccessible(getFlags(info)); checkValidGroupContainer(parent, false, false); workspace.beginOperation(true); IFileStore store = getStore(); IFileInfo localInfo = store.fetchInfo(); if (BitMask.isSet(updateFlags, IResource.FORCE)) { if (!Workspace.caseSensitive) { if (localInfo.exists()) { String name = getLocalManager().getLocalName(store); if (name == null || localInfo.getName().equals(name)) { delete(true, null); } else { // The file system is not case sensitive and there is already a file // under this location. message = NLS.bind( Messages.resources_existsLocalDifferentCase, new Path(store.toString()).removeLastSegments(1).append(name).toOSString()); throw new ResourceException( IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null); } } } } else { if (localInfo.exists()) { // return an appropriate error message for case variant collisions if (!Workspace.caseSensitive) { String name = getLocalManager().getLocalName(store); if (name != null && !localInfo.getName().equals(name)) { message = NLS.bind( Messages.resources_existsLocalDifferentCase, new Path(store.toString()).removeLastSegments(1).append(name).toOSString()); throw new ResourceException( IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null); } } message = NLS.bind(Messages.resources_fileExists, store.toString()); throw new ResourceException( IResourceStatus.FAILED_WRITE_LOCAL, getFullPath(), message, null); } } monitor.worked(Policy.opWork * 40 / 100); info = workspace.createResource(this, updateFlags); boolean local = content != null; if (local) { try { internalSetContents( content, localInfo, updateFlags, false, Policy.subMonitorFor(monitor, Policy.opWork * 60 / 100)); } catch (CoreException e) { // a problem happened creating the file on disk, so delete from the workspace and disk workspace.deleteResource(this); store.delete(EFS.NONE, null); throw e; // rethrow } catch (OperationCanceledException e) { // the operation of setting contents has been canceled, so delete the file from the // workspace and disk workspace.deleteResource(this); store.delete(EFS.NONE, null); throw e; } } internalSetLocal(local, DEPTH_ZERO); if (!local) getResourceInfo(true, true).clearModificationStamp(); } catch (OperationCanceledException e) { workspace.getWorkManager().operationCanceled(); throw e; } finally { workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); } } finally { monitor.done(); FileUtil.safeClose(content); } }