@Override
  protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    if (getProject() == null || !getProject().isAccessible()) return new IProject[0];

    List<BuildParticipant> participants = getBuildParticipants();
    List<BuildContext> contexts = getBuildContexts(kind);
    boolean isBatch = isBatch(kind);
    for (BuildParticipant buildParticipant : participants) {
      long start = System.currentTimeMillis();
      try {
        buildParticipant.buildStarting(contexts, isBatch, monitor);
      } catch (Exception e) {
        IdeLog.logError(AptanaCorePlugin.getDefault(), e.getMessage(), e);
      }
      if (DEBUG)
        System.out.println(
            "Took "
                + (System.currentTimeMillis() - start)
                + "ms for build participant: "
                + buildParticipant.getClass().getSimpleName());
    }
    while (!contexts.isEmpty()) {
      BuildContext context = contexts.remove(0);
      for (BuildParticipant buildParticipant : participants) {
        try {
          buildParticipant.build(context, monitor);
        } catch (Exception e) {
          IdeLog.logError(AptanaCorePlugin.getDefault(), e.getMessage(), e);
        }
      }
      cleanProblemMarkers(context);
      List<IProblem> problems = context.getRecordedProblems();
      if (problems.isEmpty()) continue;
      // Generate markers for each problem!
      for (IProblem problem : problems) {
        addMarker(context, problem);
      }
    }
    for (BuildParticipant buildParticipant : participants) {
      long start = System.currentTimeMillis();
      try {
        buildParticipant.buildFinishing(monitor);
      } catch (Exception e) {
        IdeLog.logError(AptanaCorePlugin.getDefault(), e.getMessage(), e);
      }
      if (DEBUG)
        System.out.println(
            "Took "
                + (System.currentTimeMillis() - start)
                + "ms for build participant: "
                + buildParticipant.getClass().getSimpleName());
    }
    return new IProject[0];
  }
 /* (non-Javadoc)
  * @see com.aptana.ide.core.ftp.IFTPConnectionFileManager#init(java.lang.String, int, org.eclipse.core.runtime.IPath, java.lang.String, char[], boolean, java.lang.String, java.lang.String, java.lang.String)
  */
 public void init(
     String host,
     int port,
     IPath basePath,
     String login,
     char[] password,
     boolean passive,
     String transferType,
     String encoding,
     String timezone) {
   Assert.isTrue(ftpClient == null, Messages.FTPConnectionFileManager_already_initialized);
   try {
     this.pool = new FTPClientPool(this);
     ftpClient = createFTPClient();
     this.host = host;
     this.port = port;
     this.login = login;
     this.password = (password == null) ? new char[0] : password;
     this.basePath = basePath != null ? basePath : Path.ROOT;
     this.authId = Policy.generateAuthId("FTP", login, host, port); // $NON-NLS-1$
     this.transferType = transferType;
     this.timezone = timezone != null && timezone.length() == 0 ? null : timezone;
     initFTPClient(ftpClient, passive, encoding);
   } catch (Exception e) {
     IdeLog.logImportant(
         FTPPlugin.getDefault(), Messages.FTPConnectionFileManager_initialization_failed, e);
     ftpClient = null;
   }
 }
 private void clearCache() {
   if (UnifiedEditorsPlugin.getDefault()
       .getPreferenceStore()
       .getBoolean(IPreferenceConstants.CACHE_BUST_BROWSERS)) {
     try {
       nsICacheService cache =
           (nsICacheService)
               Mozilla.getInstance()
                   .getServiceManager()
                   .getServiceByContractID(
                       "@mozilla.org/network/cache-service;1", //$NON-NLS-1$
                       nsICacheService.NS_ICACHESERVICE_IID);
       cache.evictEntries(nsICache.STORE_ANYWHERE);
     } catch (Exception e) {
       if (e instanceof XPCOMException
           && ((XPCOMException) e).errorcode == Mozilla.NS_ERROR_FILE_NOT_FOUND) {
         /*Not an error since disk cache wasn't created yet  */
         return;
       }
       IdeLog.logError(
           Activator.getDefault(),
           Messages.getString("FirefoxBrowser.Error_Clearing_Cache"),
           e); //$NON-NLS-1$
     }
   }
 }
  /**
   * getXPathResults
   *
   * @param expression
   * @return List
   */
  private List getXPathResults(String expression, IParseNode root) {
    List result = null;

    try {
      XPath xpath = new ParseNodeXPath(expression);

      result = (List) xpath.evaluate(root);
    } catch (JaxenException e) {
      IdeLog.logInfo(TestingPlugin.getDefault(), "getXPathResults failed", e); // $NON-NLS-1$
    }

    return result;
  }
 private void handleProgressCompleted(ProgressEvent event) {
   document = internalGetDocument();
   if (document != null) {
     selectionBox = new SelectionBox(document);
   } else {
     IdeLog.logError(
         Activator.getDefault(),
         Messages.getString("FirefoxBrowser.Cannot_Get_Document")); // $NON-NLS-1$
   }
   if (outline != null) {
     outline.refresh();
   }
 }
  /**
   * getParseResults
   *
   * @param source
   * @return IParseNode
   */
  private IParseNode getParseResults(String source) {
    IParseNode result = null;

    this._parseState.setEditState(source, source, 0, 0);

    try {
      this._parser.parse(this._parseState);

      result = this._parseState.getParseResults();
    } catch (Exception e) {
      IdeLog.logInfo(TestingPlugin.getDefault(), "getParseResults failed", e); // $NON-NLS-1$
    }

    return result;
  }
Example #7
0
 /** @see org.eclipse.jface.action.Action#run() */
 public void run() {
   IStructuredSelection selection = (IStructuredSelection) provider.getSelection();
   if (!selection.isEmpty()) {
     IServer server = (IServer) selection.getFirstElement();
     try {
       server.start(mode, null, null);
     } catch (Exception e) {
       IdeLog.log(
           ServerUIPlugin.getDefault(),
           IStatus.ERROR,
           "exception while starting server",
           e); //$NON-NLS-1$
     }
   }
 }
 private List<BuildContext> getFullProjectContexts() {
   final List<BuildContext> contexts = new ArrayList<BuildContext>();
   try {
     getProject()
         .accept(
             new IResourceProxyVisitor() {
               public boolean visit(IResourceProxy proxy) throws CoreException {
                 if (proxy.getType() == IResource.FILE) {
                   contexts.add(new BuildContext((IFile) proxy.requestResource()));
                 }
                 return true;
               }
             },
             IResource.NONE);
   } catch (CoreException e) {
     IdeLog.logError(AptanaCorePlugin.getDefault(), e.getMessage(), e);
   }
   return contexts;
 }
  private List<BuildParticipant> getBuildParticipants() {
    IExtensionPoint extensionPoint =
        Platform.getExtensionRegistry()
            .getExtensionPoint(AptanaCorePlugin.ID, BUILD_PARTICIPANT_EXTENSION_POINT_ID);
    if (extensionPoint == null) return Collections.emptyList();
    // TODO Store the configElements long term and create new instances of classes each time
    final Map<BuildParticipant, Integer> participants = new HashMap<BuildParticipant, Integer>();
    IExtension[] extensions = extensionPoint.getExtensions();
    for (IExtension extension : extensions) {
      IConfigurationElement[] configElements = extension.getConfigurationElements();
      for (IConfigurationElement configElement : configElements) {
        try {
          BuildParticipant participant =
              (BuildParticipant) configElement.createExecutableExtension("class");
          if (participant.isActive(getProject())) {
            String rawPriority = configElement.getAttribute("priority");
            Integer priority = DEFAULT_PRIORITY;
            try {
              if (rawPriority != null) priority = Integer.parseInt(rawPriority);
            } catch (NumberFormatException e) {
              priority = DEFAULT_PRIORITY;
            }
            participants.put(participant, priority);
          }
        } catch (CoreException e) {
          IdeLog.logError(AptanaCorePlugin.getDefault(), e.getMessage(), e);
        }
      }
    }
    // sort by priority
    List<BuildParticipant> sorted = new ArrayList<BuildParticipant>(participants.keySet());
    Collections.sort(
        sorted,
        new Comparator<BuildParticipant>() {

          public int compare(BuildParticipant o1, BuildParticipant o2) {
            return participants.get(o2).compareTo(participants.get(o1));
          }
        });
    return sorted;
  }
 private List<BuildContext> getIncrementalContexts() {
   final List<BuildContext> contexts = new ArrayList<BuildContext>();
   try {
     getDelta(getProject())
         .accept(
             new IResourceDeltaVisitor() {
               public boolean visit(IResourceDelta delta) throws CoreException {
                 IResource resource = delta.getResource();
                 if (resource.getType() == IResource.FILE) {
                   if (delta.getKind() == IResourceDelta.ADDED
                       || delta.getKind() == IResourceDelta.CHANGED) {
                     contexts.add(new BuildContext((IFile) resource));
                   }
                 }
                 return true;
               }
             });
   } catch (CoreException e) {
     IdeLog.logError(AptanaCorePlugin.getDefault(), e.getMessage(), e);
   }
   return contexts;
 }
  @SuppressWarnings("deprecation")
  protected void getherServerInfo(ConnectionContext context, IProgressMonitor monitor) {
    Policy.checkCanceled(monitor);
    monitor.subTask(Messages.FTPConnectionFileManager_gethering_server_info);
    serverFeatures = null;
    try {
      String[] features = ftpClient.features();
      if (features != null && features.length > 0) {
        serverFeatures = new ArrayList<String>();
        for (int i = 0; i < features.length; ++i) {
          String feature = features[i].trim();
          if (feature.indexOf(' ') > 0) {
            feature = feature.substring(0, feature.indexOf(' '));
          }
          serverFeatures.add(feature);
        }
      }
    } catch (Exception e) {
    }
    try {
      String[] validCodes = {"214"}; // $NON-NLS-1$
      FTPReply reply = ftpClient.sendCommand("SITE HELP"); // $NON-NLS-1$
      ftpClient.validateReply(reply, validCodes);
      if (serverFeatures == null) {
        serverFeatures = new ArrayList<String>();
      }
      String[] data = reply.getReplyData();
      for (int i = 0; i < data.length; ++i) {
        String cmd = data[i].trim();
        if (cmd.startsWith("214")) { // $NON-NLS-1$
          continue;
        }
        serverFeatures.add(MessageFormat.format("SITE {0}", cmd)); // $NON-NLS-1$
      }
    } catch (Exception e) {
      e.getCause();
    }

    Policy.checkCanceled(monitor);
    FTPFile[] rootFiles = null;
    try {
      rootFiles = listFiles(Path.ROOT, monitor);
    } catch (Exception e) {
    }

    if (context != null && context.getBoolean(ConnectionContext.DETECT_TIMEZONE)) {
      serverTimeZoneShift = Integer.MIN_VALUE;
    } else if (timezone != null) {
      TimeZone tz = TimeZone.getTimeZone(timezone);
      if (tz != null) {
        long time = new Date().getTime();
        serverTimeZoneShift = TimeZone.getDefault().getOffset(time) - tz.getOffset(time);
      }
    }
    if (serverTimeZoneShift == Integer.MIN_VALUE) {
      Policy.checkCanceled(monitor);
      try {
        changeCurrentDir(Path.ROOT);
        FTPFile file = null;
        if (rootFiles != null) {
          for (FTPFile ftpFile : rootFiles) {
            if (ftpFile.isFile()
                && !ftpFile.getName().startsWith(".ht")
                && !(ftpFile.lastModified().getHours() == 0
                    && ftpFile.lastModified().getMinutes() == 0
                    && ftpFile.lastModified().getSeconds() == 0)) {
              file = ftpFile;
              break;
            }
          }
        }
        if (file == null && !Path.ROOT.equals(basePath)) {
          FTPFile[] ftpFiles = listFiles(basePath, monitor);
          for (FTPFile ftpFile : ftpFiles) {
            if (ftpFile.isFile()
                && !ftpFile.getName().startsWith(".ht")
                && !(ftpFile.lastModified().getHours() == 0
                    && ftpFile.lastModified().getMinutes() == 0
                    && ftpFile.lastModified().getSeconds() == 0)) {
              file = ftpFile;
              break;
            }
          }
        }
        Date lastModifiedLocal = null;
        if (file == null) {
          changeCurrentDir(basePath);
          lastModifiedLocal = new Date();
          ftpClient.put(new ByteArrayInputStream(new byte[] {}), TMP_TIMEZONE_CHECK);
          for (FTPFile ftpFile : listFiles(basePath, monitor)) {
            if (TMP_TIMEZONE_CHECK.equals(ftpFile.getName())) {
              file = ftpFile;
              break;
            }
          }
        }
        if (file != null) {
          Date lastModifiedServerInLocalTZ = file.lastModified();
          if (serverSupportsFeature("MDTM")) { // $NON-NLS-1$
            Date lastModifiedLocalTZ = ftpClient.modtime(file.getName());
            if (lastModifiedLocalTZ != null) {
              // align to minutes
              serverTimeZoneShift =
                  (lastModifiedLocalTZ.getTime() - lastModifiedLocalTZ.getTime() % 60000)
                      - (lastModifiedServerInLocalTZ.getTime()
                          - lastModifiedServerInLocalTZ.getTime() % 60000);
            }
          }
          if (serverTimeZoneShift == Integer.MIN_VALUE) {
            serverTimeZoneShift =
                (lastModifiedLocal.getTime() - lastModifiedLocal.getTime() % 60000)
                    - (lastModifiedServerInLocalTZ.getTime()
                        - lastModifiedServerInLocalTZ.getTime() % 60000);
            // align to 1/4 hour
            long rem = serverTimeZoneShift % 900000;
            if (rem < 450000) {
              serverTimeZoneShift -= rem;
            } else {
              serverTimeZoneShift += (900000 - rem);
            }
          }
          if (TMP_TIMEZONE_CHECK.equals(file.getName())) {
            ftpClient.delete(file.getName());
          }
          if (context != null) {
            Calendar cal = Calendar.getInstance();
            int rawOffset =
                (int)
                    (cal.get(Calendar.ZONE_OFFSET)
                        + cal.get(Calendar.DST_OFFSET)
                        - serverTimeZoneShift);
            context.put(ConnectionContext.SERVER_TIMEZONE, TimeZone.getAvailableIDs(rawOffset));
          }
        }
      } catch (OperationCanceledException e) {
        throw e;
      } catch (Exception e) {
        IdeLog.logImportant(
            FTPPlugin.getDefault(), Messages.FTPConnectionFileManager_server_tz_check, e);
      }
      if (serverTimeZoneShift == Integer.MIN_VALUE) {
        Calendar cal = Calendar.getInstance();
        serverTimeZoneShift = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
      }
    }

    hasServerInfo = true;
  }
  /* (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;
  }
Example #13
0
  private Browser createSWTBrowser(Composite parent) {
    try {
      if (System.getProperty(XULRUNNER_ENV) == null) {
        Bundle bundle = null;
        if (CoreUIUtils.onWindows) {
          bundle = Platform.getBundle(XULRUNNER_WIN32_PLUGIN);
        } else if (CoreUIUtils.onMacOSX) {
          bundle = Platform.getBundle(XULRUNNER_MAC_PLUGIN);
        }
        if (bundle != null) {
          URL xulrunner = bundle.getEntry(XULRUNNER_PATH);
          if (xulrunner != null) {
            try {
              xulrunner = FileLocator.toFileURL(xulrunner);
              if (xulrunner != null) {
                File xulrunnerFolder = new File(xulrunner.getFile());
                String message =
                    MessageFormat.format(
                        Messages.getString("FirefoxBrowser.Setting_Path_To"), // $NON-NLS-1$
                        new Object[] {xulrunnerFolder.getAbsolutePath()});
                System.setProperty(XULRUNNER_ENV, xulrunnerFolder.getAbsolutePath());
                IdeLog.logInfo(Activator.getDefault(), message);
              }
            } catch (IOException e) {
              IdeLog.logError(
                  Activator.getDefault(),
                  Messages.getString("FirefoxBrowser.Error_Setting_Path"),
                  e); //$NON-NLS-1$
            }
          }
        }
      }
    } catch (Exception e) {
      IdeLog.logError(
          Activator.getDefault(),
          Messages.getString("FirefoxBrowser.Error_Setting_Path"),
          e); //$NON-NLS-1$
    }

    browser = new Browser(parent, SWT.MOZILLA);
    browser.addProgressListener(progressListener);
    browser.addOpenWindowListener(openWindowListener);

    // Disable Java
    nsIPrefService prefService =
        (nsIPrefService)
            Mozilla.getInstance()
                .getServiceManager()
                .getServiceByContractID(
                    "@mozilla.org/preferences-service;1",
                    nsIPrefService.NS_IPREFSERVICE_IID); // $NON-NLS-1$
    nsIPrefBranch prefBranch = prefService.getBranch(""); // $NON-NLS-1$
    prefBranch.setBoolPref("security.enable_java", 0); // $NON-NLS-1$

    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
      nsIWebBrowserSetup webBrowserSetup =
          (nsIWebBrowserSetup)
              internalGetWebBrowser().queryInterface(nsIWebBrowserSetup.NS_IWEBBROWSERSETUP_IID);
      if (webBrowserSetup != null) {
        webBrowserSetup.setProperty(nsIWebBrowserSetup.SETUP_ALLOW_PLUGINS, 0);
      }
    }
    return browser;
  }