mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-11823 Test Runner detection in settings doesn't pick up just installed test runner
extracted application service, because of xml serialization/deserialization messes VFSTestFrameworkListener up
This commit is contained in:
@@ -365,6 +365,8 @@
|
||||
|
||||
<applicationService serviceInterface="com.jetbrains.python.codeInsight.PyCodeInsightSettings"
|
||||
serviceImplementation="com.jetbrains.python.codeInsight.PyCodeInsightSettings"/>
|
||||
<applicationService serviceInterface="com.jetbrains.python.testing.PyTestFrameworkService"
|
||||
serviceImplementation="com.jetbrains.python.testing.PyTestFrameworkService"/>
|
||||
<autoImportOptionsProvider instance="com.jetbrains.python.codeInsight.imports.PyAutoImportOptions"/>
|
||||
|
||||
<defaultLiveTemplatesProvider implementation="com.jetbrains.python.codeInsight.liveTemplates.PyDefaultLiveTemplatesProvider"/>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.testing;
|
||||
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@State(
|
||||
name = "PyTestFrameworkService",
|
||||
storages = {
|
||||
@Storage(
|
||||
file = StoragePathMacros.APP_CONFIG + "/other.xml"
|
||||
)}
|
||||
)
|
||||
public class PyTestFrameworkService implements PersistentStateComponent<PyTestFrameworkService> {
|
||||
|
||||
public static PyTestFrameworkService getInstance() {
|
||||
return ServiceManager.getService(PyTestFrameworkService.class);
|
||||
}
|
||||
|
||||
public Map<String, Boolean> SDK_TO_PYTEST = new HashMap<String, Boolean>();
|
||||
public Map <String, Boolean> SDK_TO_NOSETEST = new HashMap<String, Boolean>();
|
||||
public Map <String, Boolean> SDK_TO_ATTEST = new HashMap<String, Boolean>();
|
||||
|
||||
@Override
|
||||
public PyTestFrameworkService getState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(PyTestFrameworkService state) {
|
||||
XmlSerializerUtil.copyBean(state, this);
|
||||
}
|
||||
}
|
||||
@@ -16,22 +16,22 @@
|
||||
package com.jetbrains.python.testing;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent;
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue;
|
||||
import com.intellij.util.ui.update.Update;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.packaging.PyExternalProcessException;
|
||||
import com.jetbrains.python.packaging.PyPackageManager;
|
||||
@@ -41,25 +41,17 @@ import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: catherine
|
||||
*/
|
||||
@State(
|
||||
name = "VFSTestFrameworkListener",
|
||||
storages = {
|
||||
@Storage(
|
||||
file = StoragePathMacros.APP_CONFIG + "/other.xml"
|
||||
)}
|
||||
)
|
||||
public class VFSTestFrameworkListener implements ApplicationComponent, PersistentStateComponent<VFSTestFrameworkListener> {
|
||||
|
||||
public class VFSTestFrameworkListener implements ApplicationComponent {
|
||||
private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.testing.VFSTestFrameworkListener");
|
||||
|
||||
private static final MergingUpdateQueue myQueue = new MergingUpdateQueue("TestFrameworkChecker", 5000, true, null);
|
||||
private PyTestFrameworkService myService;
|
||||
|
||||
public VFSTestFrameworkListener() {
|
||||
myService = PyTestFrameworkService.getInstance();
|
||||
MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();
|
||||
messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
|
||||
@Override
|
||||
@@ -76,8 +68,9 @@ public class VFSTestFrameworkListener implements ApplicationComponent, Persisten
|
||||
if (PySdkUtil.isRemote(sdk)) {
|
||||
continue;
|
||||
}
|
||||
for (String root : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) {
|
||||
if (path.contains(root)) {
|
||||
for (VirtualFile virtualFile : sdk.getRootProvider().getFiles(OrderRootType.CLASSES)) {
|
||||
String root = virtualFile.getCanonicalPath();
|
||||
if (root != null && path.contains(root)) {
|
||||
if (containsNose) {
|
||||
updateTestFrameworks(sdk, PyNames.NOSE_TEST);
|
||||
return;
|
||||
@@ -152,26 +145,12 @@ public class VFSTestFrameworkListener implements ApplicationComponent, Persisten
|
||||
return ServiceManager.getService(VFSTestFrameworkListener.class);
|
||||
}
|
||||
|
||||
public Map<String, Boolean> SDK_TO_PYTEST = new HashMap<String, Boolean>();
|
||||
public Map <String, Boolean> SDK_TO_NOSETEST = new HashMap<String, Boolean>();
|
||||
public Map <String, Boolean> SDK_TO_ATTEST = new HashMap<String, Boolean>();
|
||||
|
||||
@Override
|
||||
public VFSTestFrameworkListener getState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(VFSTestFrameworkListener state) {
|
||||
XmlSerializerUtil.copyBean(state, this);
|
||||
}
|
||||
|
||||
public void pyTestInstalled(boolean installed, String sdkHome) {
|
||||
SDK_TO_PYTEST.put(sdkHome, installed);
|
||||
myService.SDK_TO_PYTEST.put(sdkHome, installed);
|
||||
}
|
||||
|
||||
public boolean isPyTestInstalled(final Sdk sdk) {
|
||||
Boolean isInstalled = SDK_TO_PYTEST.get(sdk.getHomePath());
|
||||
Boolean isInstalled = myService.SDK_TO_PYTEST.get(sdk.getHomePath());
|
||||
if (isInstalled == null) {
|
||||
updateTestFrameworks(sdk, PyNames.PY_TEST);
|
||||
return true;
|
||||
@@ -180,11 +159,11 @@ public class VFSTestFrameworkListener implements ApplicationComponent, Persisten
|
||||
}
|
||||
|
||||
public void noseTestInstalled(boolean installed, String sdkHome) {
|
||||
SDK_TO_NOSETEST.put(sdkHome, installed);
|
||||
myService.SDK_TO_NOSETEST.put(sdkHome, installed);
|
||||
}
|
||||
|
||||
public boolean isNoseTestInstalled(final Sdk sdk) {
|
||||
Boolean isInstalled = SDK_TO_NOSETEST.get(sdk.getHomePath());
|
||||
Boolean isInstalled = myService.SDK_TO_NOSETEST.get(sdk.getHomePath());
|
||||
if (isInstalled == null) {
|
||||
updateTestFrameworks(sdk, PyNames.NOSE_TEST);
|
||||
return true;
|
||||
@@ -193,11 +172,11 @@ public class VFSTestFrameworkListener implements ApplicationComponent, Persisten
|
||||
}
|
||||
|
||||
public void atTestInstalled(boolean installed, String sdkHome) {
|
||||
SDK_TO_ATTEST.put(sdkHome, installed);
|
||||
myService.SDK_TO_ATTEST.put(sdkHome, installed);
|
||||
}
|
||||
|
||||
public boolean isAtTestInstalled(final Sdk sdk) {
|
||||
Boolean isInstalled = SDK_TO_ATTEST.get(sdk.getHomePath());
|
||||
Boolean isInstalled = myService.SDK_TO_ATTEST.get(sdk.getHomePath());
|
||||
if (isInstalled == null) {
|
||||
updateTestFrameworks(sdk, PyNames.AT_TEST);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user