Search in sources :

Example 71 with Project

use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.

the class RepositoryAttachHandler method searchArtifacts.

public static void searchArtifacts(final Project project, String coord, final PairProcessor<Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>>, Boolean> resultProcessor) {
    if (coord == null || coord.length() == 0)
        return;
    final MavenArtifactInfo template;
    if (coord.indexOf(':') == -1 && Character.isUpperCase(coord.charAt(0))) {
        template = new MavenArtifactInfo(null, null, null, "jar", null, coord, null);
    } else {
        template = new MavenArtifactInfo(getMavenId(coord), "jar", null);
    }
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Maven", false) {

        public void run(@NotNull ProgressIndicator indicator) {
            String[] urls = MavenRepositoryServicesManager.getServiceUrls();
            boolean tooManyResults = false;
            final AtomicBoolean proceedFlag = new AtomicBoolean(true);
            for (int i = 0, length = urls.length; i < length; i++) {
                if (!proceedFlag.get())
                    break;
                final List<Pair<MavenArtifactInfo, MavenRepositoryInfo>> resultList = new ArrayList<>();
                try {
                    String serviceUrl = urls[i];
                    final List<MavenArtifactInfo> artifacts;
                    artifacts = MavenRepositoryServicesManager.findArtifacts(template, serviceUrl);
                    if (!artifacts.isEmpty()) {
                        if (!proceedFlag.get()) {
                            break;
                        }
                        List<MavenRepositoryInfo> repositories = MavenRepositoryServicesManager.getRepositories(serviceUrl);
                        Map<String, MavenRepositoryInfo> map = new THashMap<>();
                        for (MavenRepositoryInfo repository : repositories) {
                            map.put(repository.getId(), repository);
                        }
                        for (MavenArtifactInfo artifact : artifacts) {
                            if (artifact == null) {
                                tooManyResults = true;
                            } else {
                                MavenRepositoryInfo repository = map.get(artifact.getRepositoryId());
                                // because it won't be resolved anyway
                                if (repository == null)
                                    continue;
                                resultList.add(Pair.create(artifact, repository));
                            }
                        }
                    }
                } catch (Exception e) {
                    MavenLog.LOG.error(e);
                } finally {
                    if (!proceedFlag.get())
                        break;
                    final Boolean aBoolean = i == length - 1 ? tooManyResults : null;
                    ApplicationManager.getApplication().invokeLater(() -> proceedFlag.set(resultProcessor.process(resultList, aBoolean)), o -> !proceedFlag.get());
                }
            }
        }
    });
}
Also used : MavenRepositoryServicesManager(org.jetbrains.idea.maven.services.MavenRepositoryServicesManager) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) JBIterable(com.intellij.util.containers.JBIterable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) PairProcessor(com.intellij.util.PairProcessor) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager) Task(com.intellij.openapi.progress.Task) SmartList(com.intellij.util.SmartList) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole) ProjectBundle(org.jetbrains.idea.maven.project.ProjectBundle) RepositoryAttachDialog(org.jetbrains.idea.maven.utils.RepositoryAttachDialog) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) NotificationType(com.intellij.notification.NotificationType) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) WriteAction(com.intellij.openapi.application.WriteAction) MavenLog(org.jetbrains.idea.maven.utils.MavenLog) MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) org.jetbrains.idea.maven.model(org.jetbrains.idea.maven.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) File(java.io.File) Pair(com.intellij.openapi.util.Pair) MavenDependenciesRemoteManager(org.jetbrains.idea.maven.utils.library.remote.MavenDependenciesRemoteManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SmartList(com.intellij.util.SmartList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) THashMap(gnu.trove.THashMap)

Example 72 with Project

use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.

the class MavenProjectImportProvider method createSteps.

public ModuleWizardStep[] createSteps(final WizardContext wizardContext) {
    final ProjectWizardStepFactory stepFactory = ProjectWizardStepFactory.getInstance();
    return new ModuleWizardStep[] { new MavenProjectImportStep(wizardContext), new SelectProfilesStep(wizardContext), new SelectImportedProjectsStep<MavenProject>(wizardContext) {

        @Override
        protected String getElementText(final MavenProject project) {
            final StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(project.getMavenId());
            VirtualFile root = ((MavenProjectBuilder) getBuilder()).getRootDirectory();
            if (root != null) {
                final String relPath = VfsUtilCore.getRelativePath(project.getDirectoryFile(), root, File.separatorChar);
                if (StringUtil.isNotEmpty(relPath)) {
                    stringBuilder.append(" [").append(relPath).append("]");
                }
            }
            if (!isElementEnabled(project)) {
                stringBuilder.append(" (project is ignored. See ").append(CommonBundle.settingsActionPath()).append(" | Maven | Ignored Files)");
            }
            return stringBuilder.toString();
        }

        @Override
        protected boolean isElementEnabled(MavenProject mavenProject) {
            Project project = wizardContext.getProject();
            if (project == null)
                return true;
            return !MavenProjectsManager.getInstance(project).isIgnored(mavenProject);
        }

        @Override
        public void updateDataModel() {
            super.updateDataModel();
            getWizardContext().setProjectName(((MavenProjectBuilder) getBuilder()).getSuggestedProjectName());
        }

        @Override
        public String getHelpId() {
            return "reference.dialogs.new.project.import.maven.page3";
        }
    }, stepFactory.createProjectJdkStep(wizardContext), stepFactory.createNameAndLocationStep(wizardContext) };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SelectImportedProjectsStep(com.intellij.projectImport.SelectImportedProjectsStep) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ProjectWizardStepFactory(com.intellij.ide.util.projectWizard.ProjectWizardStepFactory)

Example 73 with Project

use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.

the class SelectPropertiesStep method initComponents.

private void initComponents() {
    myEnvironmentForm = new MavenEnvironmentForm();
    Project project = myProjectOrNull == null ? ProjectManager.getInstance().getDefaultProject() : myProjectOrNull;
    myEnvironmentForm.getData(MavenProjectsManager.getInstance(project).getGeneralSettings().clone());
    myEnvironmentPanel.add(myEnvironmentForm.createComponent(), BorderLayout.CENTER);
    myMavenPropertiesPanel = new MavenPropertiesPanel(myAvailableProperties);
    myPropertiesPanel.add(myMavenPropertiesPanel);
}
Also used : Project(com.intellij.openapi.project.Project) MavenEnvironmentForm(org.jetbrains.idea.maven.project.MavenEnvironmentForm) MavenPropertiesPanel(org.jetbrains.idea.maven.execution.MavenPropertiesPanel)

Example 74 with Project

use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.

the class SvnTestCase method imitUpdate.

protected static void imitUpdate(final Project project) {
    ProjectLevelVcsManagerEx.getInstanceEx(project).getOptions(VcsConfiguration.StandardOption.UPDATE).setValue(false);
    final CommonUpdateProjectAction action = new CommonUpdateProjectAction();
    action.getTemplatePresentation().setText("1");
    action.actionPerformed(new AnActionEvent(null, dataId -> {
        if (CommonDataKeys.PROJECT.is(dataId)) {
            return project;
        }
        return null;
    }, "test", new Presentation(), ActionManager.getInstance(), 0));
    final ChangeListManager clManager = ChangeListManager.getInstance(project);
    clManager.ensureUpToDate(false);
    // wait for after-events like annotations recalculation
    clManager.ensureUpToDate(false);
    // zipper updater
    sleep(100);
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) PluginPathManager(com.intellij.openapi.application.PluginPathManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.openapi.vcs.changes(com.intellij.openapi.vcs.changes) Presentation(com.intellij.openapi.actionSystem.Presentation) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) MockChangelistBuilder(com.intellij.testFramework.vcs.MockChangelistBuilder) Semaphore(com.intellij.util.concurrency.Semaphore) After(org.junit.After) ProjectLevelVcsManagerEx(com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx) Messages(com.intellij.openapi.ui.Messages) SvnVcs(org.jetbrains.idea.svn.SvnVcs) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) FileUtil(com.intellij.openapi.util.io.FileUtil) VcsException(com.intellij.openapi.vcs.VcsException) SvnConfiguration(org.jetbrains.idea.svn.SvnConfiguration) CommonUpdateProjectAction(com.intellij.openapi.vcs.update.CommonUpdateProjectAction) SvnFileUrlMappingImpl(org.jetbrains.idea.svn.SvnFileUrlMappingImpl) MockChangeListManagerGate(com.intellij.testFramework.vcs.MockChangeListManagerGate) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) TimeoutUtil(com.intellij.util.TimeoutUtil) Processor(com.intellij.util.Processor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VcsShowConfirmationOption(com.intellij.openapi.vcs.VcsShowConfirmationOption) NotNull(org.jetbrains.annotations.NotNull) java.util(java.util) TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) PathManager(com.intellij.openapi.application.PathManager) ActionManager(com.intellij.openapi.actionSystem.ActionManager) VcsConfiguration(com.intellij.openapi.vcs.VcsConfiguration) StartupManager(com.intellij.openapi.startup.StartupManager) Project(com.intellij.openapi.project.Project) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) Before(org.junit.Before) StringUtil(com.intellij.openapi.util.text.StringUtil) TestClientRunner(com.intellij.testFramework.vcs.TestClientRunner) IOException(java.io.IOException) TestDialog(com.intellij.openapi.ui.TestDialog) CreateExternalAction(org.jetbrains.idea.svn.actions.CreateExternalAction) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) AbstractJunitVcsTestCase(com.intellij.testFramework.vcs.AbstractJunitVcsTestCase) UndoManager(com.intellij.openapi.command.undo.UndoManager) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) ProcessOutput(com.intellij.execution.process.ProcessOutput) SvnApplicationSettings(org.jetbrains.idea.svn.SvnApplicationSettings) Assert(org.junit.Assert) IdeaTestFixtureFactory(com.intellij.testFramework.fixtures.IdeaTestFixtureFactory) ZipUtil(com.intellij.util.io.ZipUtil) CommonUpdateProjectAction(com.intellij.openapi.vcs.update.CommonUpdateProjectAction) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 75 with Project

use of com.intellij.openapi.project.Project in project intellij-community by JetBrains.

the class Form2SourceCompiler method getProcessingItems.

@NotNull
public ProcessingItem[] getProcessingItems(final CompileContext context) {
    final Project project = context.getProject();
    if (GuiDesignerConfiguration.getInstance(project).INSTRUMENT_CLASSES) {
        return ProcessingItem.EMPTY_ARRAY;
    }
    final ArrayList<ProcessingItem> items = new ArrayList<>();
    DumbService.getInstance(project).runReadActionInSmartMode(() -> {
        final CompileScope scope = context.getCompileScope();
        final CompileScope projectScope = context.getProjectCompileScope();
        final VirtualFile[] formFiles = projectScope.getFiles(StdFileTypes.GUI_DESIGNER_FORM, true);
        final CompilerManager compilerManager = CompilerManager.getInstance(project);
        final BindingsCache bindingsCache = new BindingsCache(project);
        try {
            final HashMap<String, VirtualFile> class2form = new HashMap<>();
            for (final VirtualFile formFile : formFiles) {
                if (compilerManager.isExcludedFromCompilation(formFile)) {
                    continue;
                }
                final String classToBind;
                try {
                    classToBind = bindingsCache.getBoundClassName(formFile);
                } catch (AlienFormFileException e) {
                    // ignore non-IDEA forms
                    continue;
                } catch (Exception e) {
                    addError(context, new FormErrorInfo(null, UIDesignerBundle.message("error.cannot.process.form.file", e)), formFile);
                    continue;
                }
                if (classToBind == null) {
                    continue;
                }
                final VirtualFile sourceFile = findSourceFile(context, formFile, classToBind);
                if (sourceFile == null) {
                    if (scope.belongs(formFile.getUrl())) {
                        addError(context, new FormErrorInfo(null, UIDesignerBundle.message("error.class.to.bind.does.not.exist", classToBind)), formFile);
                    }
                    continue;
                }
                final boolean inScope = scope.belongs(sourceFile.getUrl()) || scope.belongs(formFile.getUrl());
                final VirtualFile alreadyProcessedForm = class2form.get(classToBind);
                if (alreadyProcessedForm != null) {
                    if (inScope) {
                        addError(context, new FormErrorInfo(null, UIDesignerBundle.message("error.duplicate.bind", classToBind, alreadyProcessedForm.getPresentableUrl())), formFile);
                    }
                    continue;
                }
                class2form.put(classToBind, formFile);
                if (!inScope) {
                    continue;
                }
                items.add(new MyInstrumentationItem(sourceFile, formFile));
            }
        } finally {
            bindingsCache.close();
        }
    });
    return items.toArray(new ProcessingItem[items.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlienFormFileException(com.intellij.uiDesigner.compiler.AlienFormFileException) IOException(java.io.IOException) AlienFormFileException(com.intellij.uiDesigner.compiler.AlienFormFileException) Project(com.intellij.openapi.project.Project) FormErrorInfo(com.intellij.uiDesigner.compiler.FormErrorInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Project (com.intellij.openapi.project.Project)3623 VirtualFile (com.intellij.openapi.vfs.VirtualFile)874 NotNull (org.jetbrains.annotations.NotNull)580 Nullable (org.jetbrains.annotations.Nullable)478 Module (com.intellij.openapi.module.Module)368 PsiFile (com.intellij.psi.PsiFile)334 Editor (com.intellij.openapi.editor.Editor)301 PsiElement (com.intellij.psi.PsiElement)292 ArrayList (java.util.ArrayList)214 File (java.io.File)212 Document (com.intellij.openapi.editor.Document)180 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)172 List (java.util.List)158 IOException (java.io.IOException)107 TextRange (com.intellij.openapi.util.TextRange)99 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)96 IncorrectOperationException (com.intellij.util.IncorrectOperationException)95 Presentation (com.intellij.openapi.actionSystem.Presentation)94 DataContext (com.intellij.openapi.actionSystem.DataContext)92 PsiDirectory (com.intellij.psi.PsiDirectory)90