diff --git a/python/lib/jython.bat b/python/lib/jython.bat new file mode 100644 index 000000000000..b8f361c77387 --- /dev/null +++ b/python/lib/jython.bat @@ -0,0 +1,14 @@ +@echo off +rem This file was generated by the Jython installer +rem Created on Wed Mar 05 12:52:03 MSK 2008 by yole + +set ARGS= + +:loop +if [%1] == [] goto end + set ARGS=%ARGS% %1 + shift + goto loop +:end + +"C:\Program Files (x86)\Java\jre1.6.0_04\bin\java.exe" -Dpython.home="C:\jython2.2.1" -classpath "C:\jython2.2.1\jython.jar;%CLASSPATH%" org.python.util.jython %ARGS% diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkType.java b/python/src/com/jetbrains/python/sdk/PythonSdkType.java index 4ab07307b945..9559d83eb641 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkType.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkType.java @@ -239,9 +239,16 @@ public class PythonSdkType extends SdkType { } - protected SdkModificator setupSdkPathsUnderProgress(final Sdk sdk, ProgressIndicator indicator) { + protected SdkModificator setupSdkPathsUnderProgress(final Sdk sdk, @Nullable ProgressIndicator indicator) { final SdkModificator sdkModificator = sdk.getSdkModificator(); - String sdk_path = sdk.getHomePath(); + setupSdkPaths(sdkModificator, indicator); + + return sdkModificator; + //sdkModificator.commitChanges() must happen outside, and probably in a different thread. + } + + public static void setupSdkPaths(SdkModificator sdkModificator, ProgressIndicator indicator) { + String sdk_path = sdkModificator.getHomePath(); String bin_path = getInterpreterPath(sdk_path); @NonNls final String stubs_path = PathManager.getSystemPath() + File.separator + "python_stubs" + File.separator + sdk_path.hashCode() + File.separator; @@ -280,9 +287,6 @@ public class PythonSdkType extends SdkType { sdkModificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByPath(stubs_path), OrderRootType.SOURCES); } generateBinaryStubs(sdk_path, stubs_path, indicator); - - return sdkModificator; - //sdkModificator.commitChanges() must happen outside, and probably in a different thread. } private static List getSysPath(String sdk_path, String bin_path) { diff --git a/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java b/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java index 23b2de602eb6..ccda3d8ee937 100644 --- a/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java +++ b/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java @@ -2,6 +2,7 @@ package com.jetbrains.python; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.projectRoots.Sdk; import com.intellij.testFramework.InspectionTestCase; import com.jetbrains.python.inspections.*; @@ -9,6 +10,11 @@ import com.jetbrains.python.inspections.*; * @author yole */ public class PythonInspectionsTest extends InspectionTestCase { + @Override + protected Sdk getTestProjectJdk() { + return PythonMockSdk.findOrCreate(); + } + public void testReturnValueFromInit() throws Exception { final JythonManager manager = JythonManager.getInstance(); manager.execScriptFromResource("inspections/inspections.py"); // could be moved to setUp() if more jython-based inspections existed diff --git a/python/testSrc/com/jetbrains/python/PythonMockSdk.java b/python/testSrc/com/jetbrains/python/PythonMockSdk.java new file mode 100644 index 000000000000..9127f9265fb2 --- /dev/null +++ b/python/testSrc/com/jetbrains/python/PythonMockSdk.java @@ -0,0 +1,42 @@ +package com.jetbrains.python; + +import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.projectRoots.ProjectJdkTable; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.SdkModificator; +import com.intellij.openapi.projectRoots.SdkType; +import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl; +import com.jetbrains.python.sdk.PythonSdkType; +import org.jetbrains.annotations.NonNls; + +import java.io.File; +import java.util.List; + +/** + * @author yole + */ +public class PythonMockSdk { + @NonNls private static final String MOCK_SDK_NAME = "Mock Jython SDK"; + + public static Sdk findOrCreate() { + final List sdkList = ProjectJdkTable.getInstance().getSdksOfType(PythonSdkType.getInstance()); + for (Sdk sdk : sdkList) { + if (sdk.getName().equals(MOCK_SDK_NAME)) { + return sdk; + } + } + return create(); + } + + public static Sdk create() { + String sdkHome = new File(PathManager.getHomePath(), "plugins/python/lib").getPath(); + SdkType sdkType = PythonSdkType.getInstance(); + + final Sdk sdk = new ProjectJdkImpl(MOCK_SDK_NAME, sdkType); + final SdkModificator sdkModificator = sdk.getSdkModificator(); + sdkModificator.setHomePath(sdkHome); + PythonSdkType.setupSdkPaths(sdkModificator, null); + sdkModificator.commitChanges(); + return sdk; + } +}