Exemplo n.º 1
0
  public Notification(
      @NotNull String groupDisplayId,
      @NotNull Icon icon,
      @Nullable String title,
      @Nullable String subtitle,
      @Nullable String content,
      @NotNull NotificationType type,
      @Nullable NotificationListener listener) {
    myGroupId = groupDisplayId;
    myTitle = StringUtil.notNullize(title);
    myContent = StringUtil.notNullize(content);
    myType = type;
    myListener = listener;
    myTimestamp = System.currentTimeMillis();

    myIcon = icon;
    mySubtitle = subtitle;

    LOG.assertTrue(
        isTitle() || isContent(),
        "Notification should have title: "
            + title
            + " and/or subtitle and/or content groupId: "
            + myGroupId);

    id =
        String.valueOf(System.currentTimeMillis())
            + "."
            + String.valueOf(System.identityHashCode(this));
  }
 private boolean handshake() {
   boolean res;
   long started = System.currentTimeMillis();
   do {
     try {
       res = myPydevConsoleCommunication.handshake();
     } catch (XmlRpcException ignored) {
       res = false;
     }
     if (res) {
       break;
     } else {
       long now = System.currentTimeMillis();
       if (now - started > APPROPRIATE_TO_WAIT) {
         break;
       } else {
         try {
           Thread.sleep(100);
         } catch (InterruptedException ignored) {
         }
       }
     }
   } while (true);
   return res;
 }
  public static InputEvent getInputEvent(String actionName) {
    final Shortcut[] shortcuts =
        KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionName);
    KeyStroke keyStroke = null;
    for (Shortcut each : shortcuts) {
      if (each instanceof KeyboardShortcut) {
        keyStroke = ((KeyboardShortcut) each).getFirstKeyStroke();
        if (keyStroke != null) break;
      }
    }

    if (keyStroke != null) {
      return new KeyEvent(
          JOptionPane.getRootFrame(),
          KeyEvent.KEY_PRESSED,
          System.currentTimeMillis(),
          keyStroke.getModifiers(),
          keyStroke.getKeyCode(),
          keyStroke.getKeyChar(),
          KeyEvent.KEY_LOCATION_STANDARD);
    } else {
      return new MouseEvent(
          JOptionPane.getRootFrame(),
          MouseEvent.MOUSE_PRESSED,
          0,
          0,
          0,
          0,
          1,
          false,
          MouseEvent.BUTTON1);
    }
  }
Exemplo n.º 4
0
  /**
   * @param groupDisplayId this should be a human-readable, capitalized string like "Facet
   *     Detector". It will appear in "Notifications" configurable.
   * @param title notification title
   * @param content notification content
   * @param type notification type
   * @param listener notification lifecycle listener
   */
  public Notification(
      @NotNull String groupDisplayId,
      @NotNull String title,
      @NotNull String content,
      @NotNull NotificationType type,
      @Nullable NotificationListener listener) {
    myGroupId = groupDisplayId;
    myTitle = title;
    myContent = content;
    myType = type;
    myListener = listener;
    myTimestamp = System.currentTimeMillis();

    LOG.assertTrue(
        isContent(),
        "Notification should have content, title: " + title + ", groupId: " + myGroupId);
    id = String.valueOf(System.currentTimeMillis()) + "." + String.valueOf(hashCode());
  }
  private static int readInt(Scanner s, Process process) throws ExecutionException {
    long started = System.currentTimeMillis();

    while (System.currentTimeMillis() - started < PORTS_WAITING_TIMEOUT) {
      if (s.hasNextLine()) {
        String line = s.nextLine();
        try {
          return Integer.parseInt(line);
        } catch (NumberFormatException ignored) {
          continue;
        }
      }

      try {

        Thread.sleep(200);
      } catch (InterruptedException ignored) {
      }

      if (process.exitValue() != 0) {
        String error;
        try {
          error =
              "Console process terminated with error:\n"
                  + StreamUtil.readText(process.getErrorStream());
        } catch (Exception ignored) {
          error = "Console process terminated with exit code " + process.exitValue();
        }
        throw new ExecutionException(error);
      } else {
        break;
      }
    }

    throw new ExecutionException("Couldn't read integer value from stream");
  }
    public void showPreview(@Nullable ResourceItem element) {
      CardLayout layout = (CardLayout) myPreviewPanel.getLayout();

      if (element == null || element.getGroup().getType() == ResourceType.ID) {
        layout.show(myPreviewPanel, NONE);
        return;
      }

      try {
        VirtualFile file = element.getFile();
        if (file == null) {
          String value = element.getPreviewString();
          if (value == null) {
            java.util.List<ResourceElement> resources = element.getPreviewResources();

            if (resources == null) {
              long time = System.currentTimeMillis();
              resources =
                  myManager.findValueResources(
                      element.getGroup().getType().getName(), element.toString());
              if (ApplicationManagerEx.getApplicationEx().isInternal()) {
                System.out.println("Time: " + (System.currentTimeMillis() - time)); // XXX
              }

              int size = resources.size();
              if (size == 1) {
                value = getResourceElementValue(resources.get(0));
                element.setPreviewString(value);
              } else if (size > 1) {
                resources = new ArrayList<ResourceElement>(resources);
                Collections.sort(
                    resources,
                    new Comparator<ResourceElement>() {
                      @Override
                      public int compare(ResourceElement element1, ResourceElement element2) {
                        PsiDirectory directory1 =
                            element1.getXmlTag().getContainingFile().getParent();
                        PsiDirectory directory2 =
                            element2.getXmlTag().getContainingFile().getParent();

                        if (directory1 == null && directory2 == null) {
                          return 0;
                        }
                        if (directory2 == null) {
                          return 1;
                        }
                        if (directory1 == null) {
                          return -1;
                        }

                        return directory1.getName().compareTo(directory2.getName());
                      }
                    });

                DefaultComboBoxModel model = new DefaultComboBoxModel();
                String defaultSelection = null;
                for (int i = 0; i < size; i++) {
                  ResourceElement resource = resources.get(i);
                  PsiDirectory directory = resource.getXmlTag().getContainingFile().getParent();
                  String name = directory == null ? "unknown-" + i : directory.getName();
                  model.addElement(name);
                  if (defaultSelection == null && "values".equalsIgnoreCase(name)) {
                    defaultSelection = name;
                  }
                }
                element.setPreviewResources(resources, model, defaultSelection);

                showComboPreview(element);
                return;
              } else {
                layout.show(myPreviewPanel, NONE);
                return;
              }
            } else {
              showComboPreview(element);
              return;
            }
          }
          if (value == null) {
            layout.show(myPreviewPanel, NONE);
            return;
          }

          myTextArea.setText(value);
          layout.show(myPreviewPanel, TEXT);
        } else if (ImageFileTypeManager.getInstance().isImage(file)) {
          Icon icon = element.getPreviewIcon();
          if (icon == null) {
            icon = new SizedIcon(100, 100, new ImageIcon(file.getPath()));
            element.setPreviewIcon(icon);
          }
          myImageComponent.setIcon(icon);
          layout.show(myPreviewPanel, IMAGE);
        } else if (file.getFileType() == XmlFileType.INSTANCE) {
          String value = element.getPreviewString();
          if (value == null) {
            value = new String(file.contentsToByteArray());
            element.setPreviewString(value);
          }
          myTextArea.setText(value);
          myTextArea.setEditable(false);
          layout.show(myPreviewPanel, TEXT);
        } else {
          layout.show(myPreviewPanel, NONE);
        }
      } catch (IOException e) {
        layout.show(myPreviewPanel, NONE);
      }
    }
 public static long measure(@NotNull Runnable actionToMeasure) {
   long start = System.currentTimeMillis();
   actionToMeasure.run();
   long finish = System.currentTimeMillis();
   return finish - start;
 }
    public void assertTiming() {
      assert expectedMs != 0 : "Must call .expect() before run test";
      if (COVERAGE_ENABLED_BUILD) return;

      while (true) {
        attempts--;
        long start;
        try {
          if (setup != null) setup.run();
          start = System.currentTimeMillis();
          test.run();
        } catch (Throwable throwable) {
          throw new RuntimeException(throwable);
        }
        long finish = System.currentTimeMillis();
        long duration = finish - start;

        int expectedOnMyMachine = expectedMs;
        if (adjustForCPU) {
          expectedOnMyMachine =
              adjust(expectedOnMyMachine, Timings.CPU_TIMING, Timings.ETALON_CPU_TIMING);

          expectedOnMyMachine =
              usesAllCPUCores
                  ? expectedOnMyMachine * 8 / JobSchedulerImpl.CORES_COUNT
                  : expectedOnMyMachine;
        }
        if (adjustForIO) {
          expectedOnMyMachine =
              adjust(expectedOnMyMachine, Timings.IO_TIMING, Timings.ETALON_IO_TIMING);
        }

        // Allow 10% more in case of test machine is busy.
        String logMessage = message;
        if (duration > expectedOnMyMachine) {
          int percentage = (int) (100.0 * (duration - expectedOnMyMachine) / expectedOnMyMachine);
          logMessage += ": " + percentage + "% longer";
        }
        logMessage +=
            ". Expected: "
                + formatTime(expectedOnMyMachine)
                + ". Actual: "
                + formatTime(duration)
                + "."
                + Timings.getStatistics();
        final double acceptableChangeFactor = 1.1;
        if (duration < expectedOnMyMachine) {
          int percentage = (int) (100.0 * (expectedOnMyMachine - duration) / expectedOnMyMachine);
          logMessage = percentage + "% faster. " + logMessage;

          TeamCityLogger.info(logMessage);
          System.out.println("SUCCESS: " + logMessage);
        } else if (duration < expectedOnMyMachine * acceptableChangeFactor) {
          TeamCityLogger.warning(logMessage, null);
          System.out.println("WARNING: " + logMessage);
        } else {
          // try one more time
          if (attempts == 0) {
            // try {
            //  Object result =
            // Class.forName("com.intellij.util.ProfilingUtil").getMethod("captureCPUSnapshot").invoke(null);
            //  System.err.println("CPU snapshot captured in '"+result+"'");
            // }
            // catch (Exception e) {
            // }

            throw new AssertionFailedError(logMessage);
          }
          System.gc();
          System.gc();
          System.gc();
          String s = "Another epic fail (remaining attempts: " + attempts + "): " + logMessage;
          TeamCityLogger.warning(s, null);
          System.err.println(s);
          // if (attempts == 1) {
          //  try {
          //
          // Class.forName("com.intellij.util.ProfilingUtil").getMethod("startCPUProfiling").invoke(null);
          //  }
          //  catch (Exception e) {
          //  }
          // }
          continue;
        }
        break;
      }
    }