public static ProcessOutput runJython(String workDir, String pythonPath, String... args) throws ExecutionException { final SimpleJavaSdkType sdkType = new SimpleJavaSdkType(); final Sdk ideaJdk = sdkType.createJdk("tmp", SystemProperties.getJavaHome()); SimpleJavaParameters parameters = new SimpleJavaParameters(); parameters.setJdk(ideaJdk); parameters.setMainClass("org.python.util.jython"); File jythonJar = new File(PythonHelpersLocator.getPythonCommunityPath(), "lib/jython.jar"); parameters.getClassPath().add(jythonJar.getPath()); parameters.getProgramParametersList().add("-Dpython.path=" + pythonPath + File.pathSeparator + workDir); parameters.getProgramParametersList().addAll(args); parameters.setWorkingDirectory(workDir); final GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(sdkType.getVMExecutablePath(ideaJdk), parameters, false); final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine.createProcess()); return processHandler.runProcess(); }
protected void configureJdk() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @SuppressWarnings("UseOfSystemOutOrSystemErr") @Override public void run() { addSdk(new SimpleJavaSdkType().createJdk(DEFAULT_SDK, SystemProperties.getJavaHome())); addSdk(new SimpleJavaSdkType().createJdk("_other", SystemProperties.getJavaHome())); System.out.println("ProjectWizardTestCase.configureJdk:"); System.out.println(Arrays.asList(ProjectJdkTable.getInstance().getAllJdks())); } }); }
public static JavaParameters createJavaParametersWithSdk(@Nullable Module module) { JavaParameters params = new JavaParameters(); params.setCharset(null); if (module != null) { final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) { params.setJdk(sdk); } } if (params.getJdk() == null) { params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome())); } return params; }
private Sdk createAlternativeJdk(@NotNull String jreHome) throws CantRunException { final Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(jreHome); if (configuredJdk != null) { return configuredJdk; } if (!JdkUtil.checkForJre(jreHome) && !JdkUtil.checkForJdk(jreHome)) { throw new CantRunException(ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jreHome)); } final String versionString = SdkVersionUtil.detectJdkVersion(jreHome); final Sdk jdk = new SimpleJavaSdkType().createJdk(versionString != null ? versionString : "", jreHome); if (jdk == null) throw CantRunException.noJdkConfigured(); return jdk; }
private static synchronized Sdk getDefaultSdk() { if(ourDefaultSdk == null) { final String jdkHome = SystemProperties.getJavaHome(); final String versionName = ProjectBundle.message("sdk.java.name.template", SystemProperties.getJavaVersion()); Sdk sdk = SdkTable.getInstance().createSdk(versionName, new SimpleJavaSdkType()); SdkModificator modificator = sdk.getSdkModificator(); modificator.setHomePath(jdkHome); modificator.commitChanges(); ourDefaultSdk = sdk; } return ourDefaultSdk; }