Example #1
0
  @Override
  public String toString() {
    StringBuilder text = new StringBuilder();
    text.append('(');
    IConnectionPoint source = getSource();
    if (source == null) {
      text.append(Messages.SiteConnection_LBL_NoSource);
    } else {
      ConnectionPointType type = CoreIOPlugin.getConnectionPointManager().getType(source);
      if (type != null) {
        text.append(type.getName()).append(':');
      }
      text.append(source.getName());
    }

    text.append(" <-> "); // $NON-NLS-1$

    IConnectionPoint target = getDestination();
    if (target == null) {
      text.append(Messages.SiteConnection_LBL_NoDestination);
    } else {
      ConnectionPointType type = CoreIOPlugin.getConnectionPointManager().getType(target);
      if (type != null) {
        text.append(type.getName()).append(':');
      }
      text.append(target.getName());
    }
    text.append(')');

    return text.toString();
  }
Example #2
0
 private synchronized IConnectionFileManager getConnectionFileManager() {
   if (connectionFileManager == null) {
     // find contributed first
     connectionFileManager =
         (IFTPConnectionFileManager) super.getAdapter(IFTPConnectionFileManager.class);
     if (connectionFileManager == null
         && Platform.getAdapterManager()
             .hasAdapter(this, IFTPConnectionFileManager.class.getName())) {
       connectionFileManager =
           (IFTPConnectionFileManager)
               Platform.getAdapterManager()
                   .loadAdapter(this, IFTPConnectionFileManager.class.getName());
     }
     if (connectionFileManager == null) {
       connectionFileManager = new FTPConnectionFileManager();
     }
     ConnectionContext context = CoreIOPlugin.getConnectionContext(this);
     if (context != null) {
       CoreIOPlugin.setConnectionContext(connectionFileManager, context);
     }
     connectionFileManager.init(
         host, port, path, login, password, passiveMode, transferType, encoding, timezone);
   }
   return connectionFileManager;
 }
Example #3
0
 /* (non-Javadoc)
  * @see com.aptana.ide.core.io.ConnectionPoint#connect(boolean, org.eclipse.core.runtime.IProgressMonitor)
  */
 @Override
 public void connect(boolean force, IProgressMonitor monitor) throws CoreException {
   if (!force && isConnected()) {
     return;
   }
   ConnectionContext context = CoreIOPlugin.getConnectionContext(this);
   if (context != null) {
     CoreIOPlugin.setConnectionContext(connectionFileManager, context);
   }
   getConnectionFileManager().connect(monitor);
 }
  public void widgetSelected(SelectionEvent e) {
    Object source = e.getSource();

    if (source == newSiteButton) {
      final Shell shell = getShell();
      Dialog dlg =
          new FTPPropertyDialogProvider()
              .createPropertyDialog(
                  new IShellProvider() {

                    public Shell getShell() {
                      return shell;
                    }
                  });
      if (dlg instanceof IPropertyDialog) {
        ((IPropertyDialog) dlg)
            .setPropertySource(
                CoreIOPlugin.getConnectionPointManager().getType(IBaseFTPConnectionPoint.TYPE_FTP));
      }
      int ret = dlg.open();

      if (ret == Window.OK) {
        populateTable();

        if (dlg instanceof IPropertyDialog) {
          checkItem((IConnectionPoint) ((IPropertyDialog) dlg).getPropertySource());
        }
      }
    } else if (source == syncOnFinish) {
      setSynchronize(syncOnFinish.getSelection());
    }
  }
  @Override
  protected void setUp() throws Exception {
    File baseTempFile = File.createTempFile("test", ".txt"); // $NON-NLS-1$ //$NON-NLS-2$
    baseTempFile.deleteOnExit();

    File baseDirectory = baseTempFile.getParentFile();

    LocalConnectionPoint lcp = new LocalConnectionPoint();
    lcp.setPath(new Path(baseDirectory.getAbsolutePath()));
    clientManager = lcp;

    SFTPConnectionPoint ftpcp = new SFTPConnectionPoint();
    ftpcp.setHost(getConfig().getProperty("sftp.host")); // $NON-NLS-1$
    ftpcp.setLogin(getConfig().getProperty("sftp.username")); // $NON-NLS-1$
    ftpcp.setPassword(getConfig().getProperty("sftp.password").toCharArray());
    ftpcp.setPort(
        Integer.valueOf(getConfig().getProperty("sftp.port", "22"))); // $NON-NLS-1$ //$NON-NLS-2$
    ftpcp.setPath(Path.fromPortableString(getConfig().getProperty("sftp.path"))); // $NON-NLS-1$
    serverManager = ftpcp;

    ConnectionContext context = new ConnectionContext();
    context.put(ConnectionContext.COMMAND_LOG, System.out);
    CoreIOPlugin.setConnectionContext(ftpcp, context);

    fileName = "file name.txt";
    folderName = "folder name";

    super.setUp();
  }
  /** @see junit.framework.TestCase#setUp() */
  protected void setUp() throws Exception {
    ConnectionContext context = new ConnectionContext();
    context.put(ConnectionContext.COMMAND_LOG, System.out);
    CoreIOPlugin.setConnectionContext(clientManager, context);

    context.put(ConnectionContext.COMMAND_LOG, System.out);
    CoreIOPlugin.setConnectionContext(serverManager, context);

    clientDirectory =
        clientManager.getRoot().getFileStore(new Path("/client" + System.currentTimeMillis()));
    assertNotNull(clientDirectory);
    clientDirectory.mkdir(EFS.NONE, null);

    serverDirectory =
        serverManager.getRoot().getFileStore(new Path("/server" + System.currentTimeMillis()));
    assertNotNull(serverDirectory);
    serverDirectory.mkdir(EFS.NONE, null);

    super.setUp();
  }
 /* (non-Javadoc)
  * @see org.eclipse.jface.dialogs.Dialog#okPressed()
  */
 @Override
 protected void okPressed() {
   if (!isValid()) {
     return;
   }
   if (savePropertiesTo(genericConnectionPoint)) {
     /* TODO: notify */
   }
   if (isNew) {
     CoreIOPlugin.getConnectionPointManager().addConnectionPoint(genericConnectionPoint);
   }
   super.okPressed();
 }
  /*
   * (non-Javadoc)
   * @see com.aptana.core.io.vfs.BaseConnectionFileManager#canUseTemporaryFile(org.eclipse.core.runtime.IPath,
   * com.aptana.core.io.vfs.ExtendedFileInfo, org.eclipse.core.runtime.IProgressMonitor)
   */
  @Override
  protected boolean canUseTemporaryFile(
      IPath path, ExtendedFileInfo fileInfo, IProgressMonitor monitor) {
    ConnectionContext context = CoreIOPlugin.getConnectionContext(this);
    if (context != null && context.containsKey(ConnectionContext.USE_TEMPORARY_ON_UPLOAD)) {
      return context.getBoolean(ConnectionContext.USE_TEMPORARY_ON_UPLOAD);
    }
    if (fileInfo.exists()) {
      // test if using temporary file for existing file may cause any differences on remote side
      if (defaultOwner == null || defaultGroup == null) {
        IPath tempFile =
            basePath
                .append(path)
                .removeLastSegments(1)
                .append(System.currentTimeMillis() + TMP_UPLOAD_SUFFIX);
        ExtendedFileInfo tempFileInfo = null;
        monitor.beginTask(Messages.BaseFTPConnectionFileManager_GetheringServerDetails, 3);
        try {
          try {
            createFile(tempFile, Policy.subMonitorFor(monitor, 1));
            tempFileInfo = fetchFileInternal(tempFile, EFS.NONE, Policy.subMonitorFor(monitor, 1));
          } finally {
            deleteFile(tempFile, Policy.subMonitorFor(monitor, 1));
          }
        } catch (Exception e) {
          FTPPlugin.log(
              new Status(
                  IStatus.WARNING,
                  FTPPlugin.PLUGIN_ID,
                  Messages.BaseFTPConnectionFileManager_ErrorDetectOwnerGroup,
                  e));
        }

        if (tempFileInfo != null) {
          defaultOwner = tempFileInfo.getOwner();
          defaultGroup = tempFileInfo.getGroup();
        }
      }
      if (defaultOwner == null) {
        defaultOwner = Long.toHexString(System.currentTimeMillis());
      }
      if (defaultGroup == null) {
        defaultGroup = Long.toHexString(System.currentTimeMillis());
      }
      if (!defaultOwner.equals(fileInfo.getOwner()) || !defaultGroup.equals(fileInfo.getGroup())) {
        return false;
      }
    }
    return true;
  }
  private void populateTable() {
    connectionTable.removeAll();

    IConnectionPointManager manager = CoreIOPlugin.getConnectionPointManager();
    IConnectionPoint[] remoteSites =
        manager
            .getConnectionPointCategory(IBaseRemoteConnectionPoint.CATEGORY)
            .getConnectionPoints();
    for (IConnectionPoint site : remoteSites) {
      if (site instanceof IBaseRemoteConnectionPoint) {
        TableItem item = new TableItem(connectionTable, SWT.NONE);
        item.setText(
            MessageFormat.format(
                "{0}: {1}", manager.getType(site).getName(), site.getName())); // $NON-NLS-1$
        item.setData(site);
      }
    }
  }
  /* (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();
    }
  }
  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
   */
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);

    if (genericConnectionPoint != null) {
      setTitle("Edit the Connection");
      getShell().setText("Edit Connection");
    } else {
      setTitle("Create a Connection");
      getShell().setText("New Connection");
    }

    Composite container = new Composite(dialogArea, SWT.NONE);
    container.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    container.setLayout(
        GridLayoutFactory.swtDefaults()
            .margins(
                convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN),
                convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN))
            .spacing(
                convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING),
                convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING))
            .numColumns(2)
            .create());

    /* row 1 */
    Label label = new Label(container, SWT.NONE);
    label.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(
                new PixelConverter(label)
                    .convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                SWT.DEFAULT)
            .create());
    label.setText(StringUtils.makeFormLabel("Name"));

    nameText = new Text(container, SWT.SINGLE | SWT.BORDER);
    nameText.setLayoutData(
        GridDataFactory.fillDefaults()
            .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT)
            .grab(true, false)
            .create());

    /* row 2 */
    label = new Label(container, SWT.NONE);
    label.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(
                new PixelConverter(label)
                    .convertHorizontalDLUsToPixels(IDialogConstants.LABEL_WIDTH),
                SWT.DEFAULT)
            .create());
    label.setText(StringUtils.makeFormLabel("URI"));

    uriText = new Text(container, SWT.SINGLE | SWT.BORDER);
    uriText.setLayoutData(
        GridDataFactory.swtDefaults()
            .hint(convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH), SWT.DEFAULT)
            .grab(true, false)
            .create());

    /* -- */
    addListeners();

    if (genericConnectionPoint == null) {
      try {
        genericConnectionPoint =
            (GenericConnectionPoint)
                CoreIOPlugin.getConnectionPointManager()
                    .createConnectionPoint(getConnectionPointType());
        genericConnectionPoint.setName(DEFAULT_NAME);
        isNew = true;
      } catch (CoreException e) {
        IdeLog.logError(IOUIPlugin.getDefault(), "Create new connection failed", e);
        close();
      }
    }
    loadPropertiesFrom(genericConnectionPoint);

    return dialogArea;
  }