@Override public void processPacket(Packet packet) { try { doProcessPacket(packet); } catch (Throwable e) { LOG.error(e.getMessage(), e); } }
@Override public void run() { try { data.set(calculateItems(initContext, weigher)); } catch (ProcessCanceledException ignore) { } catch (Throwable t) { LOG.error(t); cancel(); } }
public final Action action(final String aActionID) { if (!myActions.containsKey(aActionID)) { try { final Action action = createAction(aActionID); myActions.put(aActionID, action); } catch (final Exception e) { LOG.error("failed creating action: %s", e); throw new RuntimeException(e); } } return myActions.get(aActionID); }
@Override public void run() { try { if (myDisposed) { return; } synchronized (LOCK) { if (myTask == null) return; } final Runnable scheduledTask = new Runnable() { @Override public void run() { final Runnable task; synchronized (LOCK) { task = myTask; if (task == null) return; myTask = null; myRequests.remove(Request.this); } if (myThreadToUse == ThreadToUse.SWING_THREAD && !isEdt()) { try { SwingUtilities.invokeAndWait(task); } catch (Exception e) { LOG.error(e); } } else { try { task.run(); } catch (Exception e) { LOG.error(e); } } } }; if (myModalityState == null) { myFuture = myExecutorService.submit(scheduledTask); } else { final Application app = ApplicationManager.getApplication(); if (app != null) { app.invokeLater(scheduledTask, myModalityState); } else { SwingUtilities.invokeLater(scheduledTask); } } } catch (Throwable e) { LOG.error(e); } }
public Task[] getIssues(@Nullable String request, int max, long since) throws Exception { String query = getDefaultSearch(); if (request != null) { query += " " + request; } String requestUrl = "/rest/project/issues/?filter=" + encodeUrl(query) + "&max=" + max + "&updatedAfter" + since; HttpMethod method = doREST(requestUrl, false); InputStream stream = method.getResponseBodyAsStream(); // todo workaround for http://youtrack.jetbrains.net/issue/JT-7984 String s = StreamUtil.readText(stream, "UTF-8"); for (int i = 0; i < s.length(); i++) { if (!XMLChar.isValid(s.charAt(i))) { s = s.replace(s.charAt(i), ' '); } } Element element; try { // InputSource source = new InputSource(stream); // source.setEncoding("UTF-8"); // element = new SAXBuilder(false).build(source).getRootElement(); element = new SAXBuilder(false).build(new StringReader(s)).getRootElement(); } catch (JDOMException e) { LOG.error("Can't parse YouTrack response for " + requestUrl, e); throw e; } if ("error".equals(element.getName())) { throw new Exception( "Error from YouTrack for " + requestUrl + ": '" + element.getText() + "'"); } List<Element> children = element.getChildren("issue"); final List<Task> tasks = ContainerUtil.mapNotNull( children, new NullableFunction<Element, Task>() { public Task fun(Element o) { return createIssue(o); } }); return tasks.toArray(new Task[tasks.size()]); }
/** @see Runnable#run() */ public void run() { try { jasper(id); ComponentUtils.centerComponentOnScreen(AbstractJasperViewerDialog.this); setVisible(true); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(e.getMessage(), e); } e.printStackTrace(); } }
private Action createAction(final String aActionID) throws Exception { final String actionClassName = getActionClassName(aActionID); final Class actionClass = Class.forName(actionClassName); { final Action action = tryEmptyConstructor(actionClass); if (action != null) return action; } { final Action action = tryDefaultConstructor(actionClass); if (action != null) return action; } LOG.error("action class not found or incompatible: %s", aActionID); throw new IllegalArgumentException(aActionID); }
@NotNull public T getTool() { if (myTool == null) { //noinspection unchecked if (ApplicationManager.getApplication().isUnitTestMode()) { instantated = new Throwable(); } myTool = (T) myEP.instantiateTool(); if (!myTool.getShortName().equals(myEP.getShortName())) { LOG.error( "Short name not matched for " + myTool.getClass() + ": getShortName() = " + myTool.getShortName() + "; ep.shortName = " + myEP.getShortName()); } } return myTool; }
@Override protected VirtualFile[] doAddItems() { Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myPanel)); try { String[] files = PythonRemoteInterpreterManager.getInstance() .chooseRemoteFiles( project, (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData(), false); final String sourcesLocalPath = PySdkUtil.getRemoteSourcesLocalPath(mySdk.getHomePath()); VirtualFile[] vFiles = new VirtualFile[files.length]; int i = 0; for (String file : files) { String localRoot = PyRemoteSourceItem.localPathForRemoteRoot(sourcesLocalPath, file); myNewMappings.add(new PathMappingSettings.PathMapping(localRoot, file)); myRemoteSdkData.getPathMappings().addMappingCheckUnique(localRoot, file); if (!new File(localRoot).exists()) { new File(localRoot).mkdirs(); } vFiles[i++] = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(localRoot)); } vFiles = adjustAddedFileSet(myPanel, vFiles); List<VirtualFile> added = new ArrayList<VirtualFile>(vFiles.length); for (VirtualFile vFile : vFiles) { if (addElement(vFile)) { added.add(vFile); } } return VfsUtilCore.toVirtualFileArray(added); } catch (Exception e) { LOG.error(e); } return new VirtualFile[0]; }
@Override protected JPanel processFiles(@NotNull List<Element> fileElements, final JPanel context) { final Ref<EditorWindow> windowRef = new Ref<EditorWindow>(); UIUtil.invokeAndWaitIfNeeded( new Runnable() { @Override public void run() { windowRef.set(context == null ? createEditorWindow() : findWindowWith(context)); } }); final EditorWindow window = windowRef.get(); LOG.assertTrue(window != null); VirtualFile focusedFile = null; for (int i = 0; i < fileElements.size(); i++) { final Element file = fileElements.get(i); if (i == 0) { EditorTabbedContainer tabbedPane = window.getTabbedPane(); if (tabbedPane != null) { try { int limit = Integer.parseInt( file.getParentElement() .getAttributeValue( JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY.toString(), String.valueOf(JBTabsImpl.DEFAULT_MAX_TAB_WIDTH))); UIUtil.putClientProperty( tabbedPane.getComponent(), JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY, limit); } catch (NumberFormatException e) { // ignore } } } try { final FileEditorManagerImpl fileEditorManager = getManager(); Element historyElement = file.getChild(HistoryEntry.TAG); final HistoryEntry entry = HistoryEntry.createLight(fileEditorManager.getProject(), historyElement); final VirtualFile virtualFile = entry.getFile(); if (virtualFile == null) throw new InvalidDataException("No file exists: " + entry.getFilePointer().getUrl()); Document document = ApplicationManager.getApplication() .runReadAction( new Computable<Document>() { @Override public Document compute() { return virtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(virtualFile) : null; } }); final boolean isCurrentInTab = Boolean.valueOf(file.getAttributeValue(CURRENT_IN_TAB)).booleanValue(); Boolean pin = Boolean.valueOf(file.getAttributeValue(PINNED)); fileEditorManager.openFileImpl4( window, virtualFile, entry, isCurrentInTab, isCurrentInTab, pin, i); if (isCurrentInTab) { focusedFile = virtualFile; } if (document != null) { // This is just to make sure document reference is kept on stack till this point // so that document is available for folding state deserialization in HistoryEntry // constructor // and that document will be created only once during file opening document.putUserData(DUMMY_KEY, null); } updateProgress(); } catch (InvalidDataException e) { if (ApplicationManager.getApplication().isUnitTestMode()) { LOG.error(e); } } } if (focusedFile != null) { getManager().addSelectionRecord(focusedFile, window); } return window.myPanel; }
public void findUsages(final Set<PsiFile> searchIn, final Set<PsiFile> searchFor) { cancelCurrentFindRequest(); myAlarm.cancelAllRequests(); myAlarm.addRequest( () -> ApplicationManager.getApplication() .executeOnPooledThread( () -> { final ProgressIndicator progress = new PanelProgressIndicator(component -> setToComponent(component)); myCurrentProgress = progress; ProgressManager.getInstance() .runProcess( () -> { ApplicationManager.getApplication() .runReadAction( () -> { UsageInfo[] usages = new UsageInfo[0]; Set<PsiFile> elementsToSearch = null; try { if (myBuilders.get(0).isBackward()) { elementsToSearch = searchIn; usages = FindDependencyUtil.findBackwardDependencies( myBuilders, searchFor, searchIn); } else { elementsToSearch = searchFor; usages = FindDependencyUtil.findDependencies( myBuilders, searchIn, searchFor); } assert !new HashSet<PsiFile>(elementsToSearch) .contains(null); } catch (ProcessCanceledException e) { } catch (Exception e) { LOG.error(e); } if (!progress.isCanceled()) { final UsageInfo[] finalUsages = usages; final PsiElement[] _elementsToSearch = elementsToSearch != null ? PsiUtilCore.toPsiElementArray( elementsToSearch) : PsiElement.EMPTY_ARRAY; ApplicationManager.getApplication() .invokeLater( () -> showUsages(_elementsToSearch, finalUsages), ModalityState.stateForComponent( DependenciesUsagesPanel.this)); } }); myCurrentProgress = null; }, progress); }), 300); }
protected DebuggerSession createLocalSession(final JavaParameters javaParameters) throws ExecutionException, InterruptedException { createBreakpoints(javaParameters.getMainClass()); DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = DebuggerSettings.SOCKET_TRANSPORT; GenericDebuggerRunnerSettings debuggerRunnerSettings = new GenericDebuggerRunnerSettings(); debuggerRunnerSettings.LOCAL = true; final RemoteConnection debugParameters = DebuggerManagerImpl.createDebugParameters(javaParameters, debuggerRunnerSettings, false); ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()) .runnerSettings(debuggerRunnerSettings) .runProfile(new MockConfiguration()) .build(); final JavaCommandLineState javaCommandLineState = new JavaCommandLineState(environment) { @Override protected JavaParameters createJavaParameters() { return javaParameters; } @Override protected GeneralCommandLine createCommandLine() throws ExecutionException { return CommandLineBuilder.createFromJavaParameters(getJavaParameters()); } }; ApplicationManager.getApplication() .invokeAndWait( () -> { try { myDebuggerSession = DebuggerManagerEx.getInstanceEx(myProject) .attachVirtualMachine( new DefaultDebugEnvironment( new ExecutionEnvironmentBuilder( myProject, DefaultDebugExecutor.getDebugExecutorInstance()) .runProfile(new MockConfiguration()) .build(), javaCommandLineState, debugParameters, false)); XDebuggerManager.getInstance(myProject) .startSession( javaCommandLineState.getEnvironment(), new XDebugProcessStarter() { @Override @NotNull public XDebugProcess start(@NotNull XDebugSession session) { return JavaDebugProcess.create(session, myDebuggerSession); } }); } catch (ExecutionException e) { LOG.error(e); } }); myDebugProcess = myDebuggerSession.getProcess(); myDebugProcess.addProcessListener( new ProcessAdapter() { @Override public void onTextAvailable(ProcessEvent event, Key outputType) { print(event.getText(), outputType); } }); assertNotNull(myDebuggerSession); assertNotNull(myDebugProcess); return myDebuggerSession; }