public void testEmbeddedRebar() throws Exception { final Project createdProject = doTest(null); if (SystemInfo.isWindows) return; assertEquals( createdProject.getBasePath() + "/rebar", RebarSettings.getInstance(createdProject).getRebarPath()); }
@Nullable public CvsTabbedWindow openTabbedWindow(final CvsHandler output) { if (ApplicationManager.getApplication().isUnitTestMode()) return null; if (myProject != null && myProject.isDefault()) return null; if (myProject != null) { if (myConfiguration != null && myConfiguration.SHOW_OUTPUT && !myIsQuietOperation) { if (ApplicationManager.getApplication().isDispatchThread()) { connectToOutput(output); } else { ApplicationManager.getApplication() .invokeAndWait( new Runnable() { public void run() { connectToOutput(output); } }, ModalityState.defaultModalityState()); } } if (!myProject.isDisposed()) { return CvsTabbedWindow.getInstance(myProject); } } return null; }
private static String getPresentableName(final Project project) { if (project.isDefault()) { return project.getName(); } String location = project.getLocation(); if (location == null) return null; String projectName = FileUtil.toSystemIndependentName(location); if (projectName.endsWith("/")) { projectName = projectName.substring(0, projectName.length() - 1); } final int lastSlash = projectName.lastIndexOf('/'); if (lastSlash >= 0 && lastSlash + 1 < projectName.length()) { projectName = projectName.substring(lastSlash + 1); } if (StringUtil.endsWithIgnoreCase(projectName, ProjectFileType.DOT_DEFAULT_EXTENSION)) { projectName = projectName.substring( 0, projectName.length() - ProjectFileType.DOT_DEFAULT_EXTENSION.length()); } projectName = projectName.toLowerCase(Locale.US); return projectName; }
@Override public void documentChanged(DocumentEvent e) { UndoManager undoManager = UndoManager.getInstance(myProject); boolean undoOrRedo = undoManager.isUndoInProgress() || undoManager.isRedoInProgress(); if (undoOrRedo) { // allow undo/redo up until 'creation stamp' back in time // and check it after action is completed if (e.getDocument() == myOrigDocument) { //noinspection SSBasedInspection SwingUtilities.invokeLater( () -> { if (myOrigCreationStamp > myOrigDocument.getModificationStamp()) { closeEditor(); } }); } } else if (e.getDocument() == myNewDocument) { commitToOriginal(e); if (!isValid()) { ApplicationManager.getApplication() .invokeLater(() -> closeEditor(), myProject.getDisposed()); } } else if (e.getDocument() == myOrigDocument) { if (myCommittingToOriginal || myAltFullRange != null && myAltFullRange.isValid()) return; ApplicationManager.getApplication().invokeLater(() -> closeEditor(), myProject.getDisposed()); } }
@Override public WorkspaceConfig get() { SimpleWorkspaceConfig _xblockexpression = null; { ProjectManager _instance = ProjectManager.getInstance(); Project[] _openProjects = _instance.getOpenProjects(); final Project project = IterableExtensions.<Project>head( ((Iterable<Project>) Conversions.doWrapArray(_openProjects))); String _basePath = project.getBasePath(); final SimpleWorkspaceConfig result = new SimpleWorkspaceConfig(_basePath); ModuleManager _instance_1 = ModuleManager.getInstance(project); Module[] _modules = _instance_1.getModules(); final Procedure1<Module> _function = new Procedure1<Module>() { @Override public void apply(final Module m) { IdeaModuleConfig _ideaModuleConfig = new IdeaModuleConfig(m, IdeaWorkspaceConfigProvider.this.outputConfigurations); result.addProjectConfig(_ideaModuleConfig); } }; IterableExtensions.<Module>forEach( ((Iterable<Module>) Conversions.doWrapArray(_modules)), _function); _xblockexpression = result; } return _xblockexpression; }
@SuppressWarnings("unchecked") @Nullable public static <T> T getToolWindowElement( @NotNull Class<T> clazz, @NotNull Project project, @NotNull DataKey<T> key, @NotNull ProjectSystemId externalSystemId) { if (project.isDisposed() || !project.isOpen()) { return null; } final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); if (toolWindowManager == null) { return null; } final ToolWindow toolWindow = ensureToolWindowContentInitialized(project, externalSystemId); if (toolWindow == null) { return null; } final ContentManager contentManager = toolWindow.getContentManager(); if (contentManager == null) { return null; } for (Content content : contentManager.getContents()) { final JComponent component = content.getComponent(); if (component instanceof DataProvider) { final Object data = ((DataProvider) component).getData(key.getName()); if (data != null && clazz.isInstance(data)) { return (T) data; } } } return null; }
static void subscribeTo(NavBarPanel panel) { if (panel.getClientProperty(LISTENER) != null) { unsubscribeFrom(panel); } final NavBarListener listener = new NavBarListener(panel); final Project project = panel.getProject(); panel.putClientProperty(LISTENER, listener); KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(listener); FileStatusManager.getInstance(project).addFileStatusListener(listener); PsiManager.getInstance(project).addPsiTreeChangeListener(listener); WolfTheProblemSolver.getInstance(project).addProblemListener(listener); ActionManager.getInstance().addAnActionListener(listener); final MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener); connection.subscribe(NavBarModelListener.NAV_BAR, listener); connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener); panel.putClientProperty(BUS, connection); panel.addKeyListener(listener); if (panel.isInFloatingMode()) { final Window window = SwingUtilities.windowForComponent(panel); if (window != null) { window.addWindowFocusListener(listener); } } }
@Override public String getDescription(@NotNull final String refSuffix, @NotNull final Editor editor) { final Project project = editor.getProject(); if (project == null) { LOG.error(editor); return null; } if (project.isDisposed()) return null; final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file == null) { return null; } final InspectionProfile profile = InspectionProfileManager.getInstance().getCurrentProfile(); final InspectionToolWrapper toolWrapper = profile.getInspectionTool(refSuffix, file); if (toolWrapper == null) return null; String description = toolWrapper.loadDescription(); if (description == null) { LOG.warn("No description for inspection '" + refSuffix + "'"); description = InspectionsBundle.message("inspection.tool.description.under.construction.text"); } return description; }
@Override public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException { String contentEntryPath = getContentEntryPath(); if (StringUtil.isEmpty(contentEntryPath)) { return; } File contentRootDir = new File(contentEntryPath); FileUtilRt.createDirectory(contentRootDir); LocalFileSystem fileSystem = LocalFileSystem.getInstance(); VirtualFile modelContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir); if (modelContentRootDir == null) { return; } modifiableRootModel.addContentEntry(modelContentRootDir); modifiableRootModel.inheritSdk(); final Project project = modifiableRootModel.getProject(); setupGradleBuildFile(modelContentRootDir); setupGradleSettingsFile(modelContentRootDir, modifiableRootModel); if (myWizardContext.isCreatingNewProject()) { String externalProjectPath = FileUtil.toCanonicalPath(project.getBasePath()); getExternalProjectSettings().setExternalProjectPath(externalProjectPath); AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID); //noinspection unchecked settings.linkProject(getExternalProjectSettings()); } else { FileDocumentManager.getInstance().saveAllDocuments(); ExternalSystemUtil.refreshProjects(project, GradleConstants.SYSTEM_ID, false); } }
@Override public void processTerminated(ProcessEvent event) { if (myProject.isDisposed()) return; if (!myTerminateNotified.compareAndSet(false, true)) return; ApplicationManager.getApplication() .invokeLater( () -> { RunnerLayoutUi ui = myDescriptor.getRunnerLayoutUi(); if (ui != null && !ui.isDisposed()) { ui.updateActionsNow(); } }, ModalityState.any()); myProject .getMessageBus() .syncPublisher(EXECUTION_TOPIC) .processTerminated(myExecutorId, myEnvironment, myProcessHandler, event.getExitCode()); SaveAndSyncHandler saveAndSyncHandler = SaveAndSyncHandler.getInstance(); if (saveAndSyncHandler != null) { saveAndSyncHandler.scheduleRefresh(); } }
@Override public void caretPositionChanged(CaretEvent event) { if (project.isDisposed()) { return; } VirtualFile file = FileDocumentManager.getInstance().getFile(event.getEditor().getDocument()); // Make sure file exists if (file == null) { return; } // Make sure file is in the project if (!ProjectFileIndex.SERVICE.getInstance(project).isInSource(file)) { return; } int offset = event.getEditor().logicalPositionToOffset(event.getNewPosition()); // Get path relative to project root (e.g. src/Sample.java) Path basePath = Paths.get(project.getBasePath()); Path absoluteFilePath = Paths.get(file.getPath()); String relativeFilePath = basePath.relativize(absoluteFilePath).toString(); CursorMovement cursorMovement = new CursorMovement(-1, relativeFilePath, offset); for (EditorEvent editorEvent : events) { editorEvent.sendCursorMovement(cursorMovement); } }
@Override public void moduleAdded() { if (!myModuleInitialized) { myConnection.subscribe( ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() { @Override public void rootsChanged(ModuleRootEvent event) { scheduleUpdate(); } }); myConnection.subscribe(GoLibrariesService.LIBRARIES_TOPIC, newRootUrls -> scheduleUpdate()); Project project = myModule.getProject(); StartupManager.getInstance(project) .runWhenProjectIsInitialized( () -> { if (!project.isDisposed() && !myModule.isDisposed()) { for (PsiFileSystemItem vendor : FilenameIndex.getFilesByName( project, GoConstants.VENDOR, GoUtil.moduleScope(myModule), true)) { if (vendor.isDirectory()) { showVendoringNotification(); break; } } } }); VirtualFileManager.getInstance().addVirtualFileListener(myFilesListener); } scheduleUpdate(0); myModuleInitialized = true; }
private void removeFromEditor() { Editor editor = mySearchResults.getEditor(); if (myReplacementBalloon != null) { myReplacementBalloon.hide(); } if (editor != null) { for (VisibleAreaListener visibleAreaListener : myVisibleAreaListenersToRemove) { editor.getScrollingModel().removeVisibleAreaListener(visibleAreaListener); } myVisibleAreaListenersToRemove.clear(); Project project = mySearchResults.getProject(); if (project != null && !project.isDisposed()) { for (RangeHighlighter h : myHighlighters) { HighlightManager.getInstance(project).removeSegmentHighlighter(editor, h); } if (myCursorHighlighter != null) { HighlightManager.getInstance(project) .removeSegmentHighlighter(editor, myCursorHighlighter); myCursorHighlighter = null; } } myHighlighters.clear(); if (myListeningSelection) { editor.getSelectionModel().removeSelectionListener(this); myListeningSelection = false; } } }
@Override public UpdateInfoTree showUpdateProjectInfo( UpdatedFiles updatedFiles, String displayActionName, ActionInfo actionInfo, boolean canceled) { if (!myProject.isOpen() || myProject.isDisposed()) return null; ContentManager contentManager = getContentManager(); if (contentManager == null) { return null; // content manager is made null during dispose; flag is set later } final UpdateInfoTree updateInfoTree = new UpdateInfoTree(contentManager, myProject, updatedFiles, displayActionName, actionInfo); Content content = ContentFactory.SERVICE .getInstance() .createContent( updateInfoTree, canceled ? VcsBundle.message( "toolwindow.title.update.action.canceled.info", displayActionName) : VcsBundle.message("toolwindow.title.update.action.info", displayActionName), true); Disposer.register(content, updateInfoTree); ContentsUtil.addContent(contentManager, content, true); ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.VCS).activate(null); updateInfoTree.expandRootChildren(); return updateInfoTree; }
@Override public void actionPerformed(AnActionEvent e) { final Project project = getEventProject(e); final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY); FeatureUsageTracker.getInstance().triggerFeatureUsed("jar.diff"); if (project != null && files != null) { VirtualFileDiffElement src = null; VirtualFileDiffElement trg = null; if (files.length == 2 && isArchive(files[0]) && isArchive(files[1])) { src = new JarFileDiffElement(files[0]); trg = new JarFileDiffElement(files[1]); } else if (files.length == 1 && isArchive(files[0])) { src = new JarFileDiffElement(files[0]); final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, false) { @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { return file.isDirectory() || (!file.isDirectory() && isArchive(file)); } }; final VirtualFile[] result = FileChooser.chooseFiles(descriptor, project, project.getBaseDir()); if (result.length == 1 && result[0] != null && isArchive(result[0])) { trg = new JarFileDiffElement(result[0]); } } final DirDiffManager mgr = DirDiffManager.getInstance(project); if (src != null && trg != null && mgr.canShow(src, trg)) { mgr.showDiff(src, trg, new DirDiffSettings(), null); } } }
public void commitSynchronously( @NotNull Document document, @NotNull Project project, PsiFile excludeFile) { assert !isDisposed; if (!project.isInitialized() && !project.isDefault()) { @NonNls String s = project + "; Disposed: " + project.isDisposed() + "; Open: " + project.isOpen(); s += "; SA Passed: "; try { s += ((StartupManagerImpl) StartupManager.getInstance(project)).startupActivityPassed(); } catch (Exception e) { s += e; } throw new RuntimeException(s); } ApplicationManager.getApplication().assertWriteAccessAllowed(); synchronized (documentsToCommit) { setCommitStage(document, CommitStage.ABOUT_TO_BE_SYNC_COMMITTED, true); removeCommitFromQueue(document); } ProgressIndicatorBase indicator = new ProgressIndicatorBase(); indicator.start(); log("About to commit sync", document, true, indicator); Runnable finish = commit(document, project, excludeFile, indicator, true, "Sync commit"); log("Committed sync", document, true, finish, indicator); assert finish != null; finish.run(); }
private void sendModuleList(HttpExchange exchange) { StringBuilder response = new StringBuilder(); response.append( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"); response.append("<html>\n"); response.append("<head>\n"); response.append("<title>Web View</title>\n"); response.append("</head>\n"); response.append("<body>\n"); response.append("<div>\n"); Project[] projects = ProjectManager.getInstance().getOpenProjects(); if (projects.length > 0) { response.append("Please, choose the project:<br/>"); for (Project project : projects) { String projectName = project.getName(); response.append("<a href=\"/project="); response.append(projectName); response.append("/\">"); response.append(projectName); response.append("</a><br/>"); } } else { response.append("There is no open project in Intellij IDEA"); } response.append("</div>\n"); response.append("</body>\n"); response.append("</html>\n"); writeResponse(exchange, response.toString(), 200); }
@Nullable public VirtualFile getBeforeVFUnderProject(final Project project) { if (myBeforePath == null || project.getBaseDir() == null) return null; final File baseDir = new File(project.getBaseDir().getPath()); final File file = new File(baseDir, myBeforePath); return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); }
public GitVcs( @NotNull Project project, @NotNull Git git, @NotNull final ProjectLevelVcsManager gitVcsManager, @NotNull final GitAnnotationProvider gitAnnotationProvider, @NotNull final GitDiffProvider gitDiffProvider, @NotNull final GitHistoryProvider gitHistoryProvider, @NotNull final GitRollbackEnvironment gitRollbackEnvironment, @NotNull final GitVcsApplicationSettings gitSettings, @NotNull final GitVcsSettings gitProjectSettings, @NotNull GitSharedSettings sharedSettings) { super(project, NAME); myGit = git; myVcsManager = gitVcsManager; myAppSettings = gitSettings; myChangeProvider = project.isDefault() ? null : ServiceManager.getService(project, GitChangeProvider.class); myCheckinEnvironment = project.isDefault() ? null : ServiceManager.getService(project, GitCheckinEnvironment.class); myAnnotationProvider = gitAnnotationProvider; myDiffProvider = gitDiffProvider; myHistoryProvider = gitHistoryProvider; myRollbackEnvironment = gitRollbackEnvironment; myRevSelector = new GitRevisionSelector(); myConfigurable = new GitVcsConfigurable(myProject, gitProjectSettings, sharedSettings); myUpdateEnvironment = new GitUpdateEnvironment(myProject, gitProjectSettings); myCommittedChangeListProvider = new GitCommittedChangeListProvider(myProject); myOutgoingChangesProvider = new GitOutgoingChangesProvider(myProject); myTreeDiffProvider = new GitTreeDiffProvider(myProject); myCommitAndPushExecutor = new GitCommitAndPushExecutor(myCheckinEnvironment); myExecutableValidator = new GitExecutableValidator(myProject); }
@Override @NotNull public Project[] getOpenProjects() { synchronized (myOpenProjects) { if (myOpenProjectsArrayCache.length != myOpenProjects.size()) { LOG.error( "Open projects: " + myOpenProjects + "; cache: " + Arrays.asList(myOpenProjectsArrayCache)); } if (myOpenProjectsArrayCache.length > 0 && myOpenProjectsArrayCache[0] != myOpenProjects.get(0)) { LOG.error( "Open projects cache corrupted. Open projects: " + myOpenProjects + "; cache: " + Arrays.asList(myOpenProjectsArrayCache)); } if (ApplicationManager.getApplication().isUnitTestMode()) { Project[] testProjects = myTestProjects.toArray(new Project[myTestProjects.size()]); for (Project testProject : testProjects) { assert !testProject.isDisposed() : testProject; } return ArrayUtil.mergeArrays(myOpenProjectsArrayCache, testProjects); } return myOpenProjectsArrayCache; } }
public boolean canCloseProject(final Project project) { assert project != null; if (!project.equals(myProject)) { return true; } if (shouldAskUser()) { int result = Messages.showOkCancelDialog( myProject, CompilerBundle.message("warning.compiler.running.on.project.close"), CompilerBundle.message("compiler.running.dialog.title"), Messages.getQuestionIcon()); if (result != 0) { return false; // veto closing } myUserAcceptedCancel = true; final MessageBusConnection connection = project.getMessageBus().connect(); connection.subscribe( CompilerTopics.COMPILATION_STATUS, new CompilationStatusAdapter() { public void compilationFinished( boolean aborted, int errors, int warnings, final CompileContext compileContext) { connection.disconnect(); ProjectUtil.closeAndDispose(project); } }); cancel(); return false; // cancel compiler and let it finish, after compilation close the project, but // currently - veto closing } return !myIndicator.isRunning(); }
public static Project getProjectByProjectName(String projectName) { for (Project p : ProjectManager.getInstance().getOpenProjects()) { if (p.getName().equals(projectName)) { return p; } } return null; }
public void focusTable() { final Project project = myModel.getProject(); final IdeFocusManager focusManager = project == null || project.isDefault() ? IdeFocusManager.getGlobalInstance() : IdeFocusManager.getInstance(project); focusManager.requestFocus(myTable, true); }
public void apply() throws ConfigurationException { myPanel.saveSettings(); if (myPanel.getProjectSettings().isCheckIncomingOutgoing()) { myProject.getMessageBus().syncPublisher(HgVcs.INCOMING_OUTGOING_CHECK_TOPIC).show(); } else { myProject.getMessageBus().syncPublisher(HgVcs.INCOMING_OUTGOING_CHECK_TOPIC).hide(); } }
public void update(AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); if (project == null || project.isDefault()) { setVisibleEnabled(e, false, false); return; } setVisibleEnabled(e, true, true); }
/** Make sure to set it to <code>false</code> in the corresponding <code>finally</code> block */ public static void setDartPackageRootUpdateScheduledOrInProgress( @NotNull final Project project, final boolean scheduledOrInProgress) { if (scheduledOrInProgress) { project.putUserData(DART_PACKAGE_ROOTS_UPDATE_SCHEDULED_OR_IN_PROGRESS, true); } else { project.putUserData(DART_PACKAGE_ROOTS_UPDATE_SCHEDULED_OR_IN_PROGRESS, null); } }
@Nullable public static IProject getFrom(@NotNull Project project) { IProject gsProject = project.getUserData(PROJECT_KEY); if (gsProject == null) { project.putUserData(PROJECT_KEY, gsProject = new IjProject(project)); } return gsProject; }
static void createProjectStructure(@NotNull Project project, @NotNull Collection<String> paths) { for (String path : paths) { cd(project.getBaseDir().getPath()); File f = new File(project.getBaseDir().getPath(), path); f.mkdirs(); LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f); } }
public void scheduleRestart() { ApplicationManager.getApplication().assertIsDispatchThread(); cancel(); final CompletionProgressIndicator current = CompletionServiceImpl.getCompletionService().getCurrentCompletion(); if (this != current) { LOG.error(current + "!=" + this); } if (isAutopopupCompletion() && !myLookup.isShown()) { if (CompletionServiceImpl.getCompletionService().getCurrentCompletion() == this) { closeAndFinish(true); } AutoPopupController.getInstance(getProject()).scheduleAutoPopup(myEditor, null); return; } hideAutopopupIfMeaningless(); CompletionPhase oldPhase = CompletionServiceImpl.getCompletionPhase(); if (oldPhase instanceof CompletionPhase.CommittingDocuments) { ((CompletionPhase.CommittingDocuments) oldPhase).replaced = true; } final CompletionPhase.CommittingDocuments phase = new CompletionPhase.CommittingDocuments(this, myEditor); CompletionServiceImpl.setCompletionPhase(phase); final Project project = getProject(); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { CompletionAutoPopupHandler.runLaterWithCommitted( project, myEditor.getDocument(), new Runnable() { @Override public void run() { if (phase.checkExpired()) return; CompletionAutoPopupHandler.invokeCompletion( myParameters.getCompletionType(), isAutopopupCompletion(), project, myEditor, myParameters.getInvocationCount(), true); } }); } }, project.getDisposed()); }
@Override public void exitDumbMode() { if (!ProjectPane.isShowGenStatus()) return; Project p = myTree.getProject(); if (p.isDisposed()) return; myGenStatusVisitor.dispatchForHierarchy(myTree.getRootNode()); }