public static List<ScannableFile> createAndValidate(@NotNull final Collection<PsiFile> psiFiles, @NotNull final CheckStylePlugin plugin, @Nullable final Module module) { final AccessToken readAccessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { return psiFiles.stream().filter(psiFile -> PsiFileValidator.isScannable(psiFile, ofNullable(module), plugin.configurationManager())).map(psiFile -> ScannableFile.create(psiFile, module)).filter (Objects::nonNull).collect(Collectors.toList()); } finally { readAccessToken.finish(); } }
private void initializeApplication(Application application) { DefaultPicoContainer pico = new DefaultPicoContainer(); when(application.getPicoContainer()).thenReturn(pico); MessageBus bus = new SingleThreadedMessageBus(null); when(application.getMessageBus()).thenReturn(bus); // Service setup. See ServiceManager pico.registerComponent(service(PasswordSafe.class, new MockPasswordSafe())); pico.registerComponent(service(VcsContextFactory.class, new MockVcsContextFactory())); VirtualFileManager vfm = mock(VirtualFileManager.class); when(application.getComponent(VirtualFileManager.class)).thenReturn(vfm); AccessToken readToken = mock(AccessToken.class); when(application.acquireReadActionLock()).thenReturn(readToken); ApplicationInfo appInfo = mock(ApplicationInfo.class); when(appInfo.getApiVersion()).thenReturn("IC-182.1.1"); registerApplicationService(ApplicationInfo.class, appInfo); }
@Before public void prepare() { when(event.getProject()).thenReturn(project); when(app.acquireReadActionLock()).thenReturn(mock(AccessToken.class)); }
private List<String> collectPathsForModule() { List<String> paths = new ArrayList<>(); AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); moduleRootManager.getFileIndex().iterateContent(virtualFile -> { if (!virtualFile.isDirectory()) { String path = appUtils.getPathRelativeToProjectBaseDir(module.getProject(), virtualFile); if (path != null) { paths.add(path); } } return true; }); } finally { accessToken.finish(); } return paths; } }
private void moveMavenModulesToGroup( final @NotNull Project project, final @NotNull List<Module> mavenModules, final @NotNull Map<String, String[]> mavenGroupMapping ) { AccessToken token = null; final ModifiableModuleModel modifiableModuleModel; try { token = ApplicationManager.getApplication().acquireReadActionLock(); modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel(); for (Module module : mavenModules) { module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.MAVEN.name()); final String[] groupPath = modifiableModuleModel.getModuleGroupPath(module); modifiableModuleModel.setModuleGroupPath(module, ArrayUtils.addAll(mavenGroupMapping.get(module.getName()), groupPath)); } } finally { if (token != null) { token.finish(); } } ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModuleModel::commit)); }
@Override public Integer getLine() { if (range != null && isValid()) { AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { return range.getDocument().getLineNumber(range.getStartOffset()) + 1; } finally { accessToken.finish(); } } return null; }
@Before public void prepare() throws InvalidBindingException { analyzer = new SonarLintAnalyzer(projectBindingManager, encodingProjectManager, console, fileDocumentManager, telemetry, appUtils); when(app.acquireReadActionLock()).thenReturn(mock(AccessToken.class)); when(projectBindingManager.getFacade(true)).thenReturn(facade); when(facade.startAnalysis(anyList(), any(IssueListener.class), anyMap(), any(ProgressMonitor.class))).thenReturn(new DefaultAnalysisResult()); super.register(module, VirtualFileTestPredicate.class, testPredicate); super.register(module, AnalysisConfigurator.class, configurator); super.registerEP(AnalysisConfigurator.EP_NAME, AnalysisConfigurator.class); when(project.getBasePath()).thenReturn("project"); }
@Before public void prepare() throws IOException, InvalidBindingException { super.register(app, SonarApplication.class, mock(SonarApplication.class)); super.register(module, ModuleBindingManager.class, moduleBindingManager); when(module.getProject()).thenReturn(project); when(app.acquireReadActionLock()).thenReturn(mock(AccessToken.class)); Path projectBaseDir = temp.newFolder().toPath(); when(moduleBindingManager.getBinding()).thenReturn(new ProjectBinding(PROJECT_KEY, "", "")); when(indicator.isModal()).thenReturn(false); when(project.getBasePath()).thenReturn(FileUtil.toSystemIndependentName(projectBaseDir.toString())); settings.setProjectKey(PROJECT_KEY); // mock creation of engine / server when(bindingManager.getConnectedEngine()).thenReturn(engine); SonarQubeServer server = mock(SonarQubeServer.class); when(server.getHostUrl()).thenReturn("http://dummyserver:9000"); when(bindingManager.getSonarQubeServer()).thenReturn(server); }
@Before public final void setUp() { ApplicationManager.setApplication(app, mock(Disposable.class)); when(app.isUnitTestMode()).thenReturn(true); when(app.getMessageBus()).thenReturn(new MessageBusImpl.RootBus(this)); when(app.isHeadlessEnvironment()).thenReturn(true); when(app.acquireReadActionLock()).thenReturn(mock(AccessToken.class)); when(app.getMessageBus()).thenReturn(new MessageBusImpl.RootBus(this)); Answer<Void> runArg = invocation -> { ((ThrowableComputable) invocation.getArgument(0)).compute(); return null; }; doAnswer(runArg).when(app).runReadAction(any(ThrowableComputable.class)); register(app, CertificateManager.class, new CertificateManager()); createModuleRoot(); }
public Tracking<RAW, BASE> track(Input<RAW> rawInput, Input<BASE> baseInput) { AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock(); try { Tracking<RAW, BASE> tracking = new Tracking<>(rawInput, baseInput); // 1. match issues with same rule, same line and same text range hash, but not necessarily with same message match(tracking, LineAndTextRangeHashKeyFactory.INSTANCE); // 2. match issues with same rule, same message and same text range hash match(tracking, TextRangeHashAndMessageKeyFactory.INSTANCE); // 3. match issues with same rule, same line and same message match(tracking, LineAndMessageKeyFactory.INSTANCE); // 4. match issues with same rule and same text range hash but different line and different message. // See SONAR-2812 match(tracking, TextRangeHashKeyFactory.INSTANCE); // 5. match issues with same rule, same line and same line hash match(tracking, LineAndLineHashKeyFactory.INSTANCE); // 6. match issues with same rule and same same line hash match(tracking, LineHashKeyFactory.INSTANCE); // 7. match issues with same server issue key match(tracking, ServerIssueSearchKeyFactory.INSTANCE); return tracking; } finally { accessToken.finish(); } }