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; }
/** * @param project * @param parameters * @param coreSettings * @param runnerSettings * @param runConfiguration used to creation fix if maven home not found * @return * @throws ExecutionException */ public static JavaParameters createJavaParameters( @Nullable final Project project, @NotNull final MavenRunnerParameters parameters, @Nullable MavenGeneralSettings coreSettings, @Nullable MavenRunnerSettings runnerSettings, @Nullable MavenRunConfiguration runConfiguration) throws ExecutionException { final JavaParameters params = new JavaParameters(); ApplicationManager.getApplication().assertReadAccessAllowed(); if (coreSettings == null) { coreSettings = project == null ? new MavenGeneralSettings() : MavenProjectsManager.getInstance(project).getGeneralSettings(); } if (runnerSettings == null) { runnerSettings = project == null ? new MavenRunnerSettings() : MavenRunner.getInstance(project).getState(); } params.setWorkingDirectory(parameters.getWorkingDirFile()); params.setJdk( getJdk( project, runnerSettings, project != null && MavenRunner.getInstance(project).getState() == runnerSettings)); final String mavenHome = resolveMavenHome(coreSettings, project, runConfiguration); addVMParameters(params.getVMParametersList(), mavenHome, runnerSettings); File confFile = MavenUtil.getMavenConfFile(new File(mavenHome)); if (!confFile.isFile()) { throw new ExecutionException( "Configuration file is not exists in maven home: " + confFile.getAbsolutePath()); } if (project != null && parameters.isResolveToWorkspace()) { try { String resolverJar = getArtifactResolverJar(MavenUtil.isMaven3(mavenHome)); confFile = patchConfFile(confFile, resolverJar); File modulesPathsFile = dumpModulesPaths(project); params .getVMParametersList() .addProperty(MavenModuleMap.PATHS_FILE_PROPERTY, modulesPathsFile.getAbsolutePath()); } catch (IOException e) { LOG.error(e); throw new ExecutionException("Failed to run maven configuration", e); } } params.getVMParametersList().addProperty("classworlds.conf", confFile.getPath()); for (String path : getMavenClasspathEntries(mavenHome)) { params.getClassPath().add(path); } params.setMainClass(MAVEN_LAUNCHER_CLASS); EncodingManager encodingManager = project == null ? EncodingProjectManager.getInstance() : EncodingProjectManager.getInstance(project); params.setCharset(encodingManager.getDefaultCharset()); addMavenParameters( params.getProgramParametersList(), mavenHome, coreSettings, runnerSettings, parameters); return params; }