use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.
the class MavenExternalParameters method getJdk.
@NotNull
private static Sdk getJdk(@Nullable Project project, MavenRunnerSettings runnerSettings, boolean isGlobalRunnerSettings) throws ExecutionException {
String name = runnerSettings.getJreName();
if (name.equals(MavenRunnerSettings.USE_INTERNAL_JAVA)) {
return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
}
if (name.equals(MavenRunnerSettings.USE_PROJECT_JDK)) {
if (project != null) {
Sdk res = ProjectRootManager.getInstance(project).getProjectSdk();
if (res != null) {
return res;
}
Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
return sdk;
}
}
}
if (project == null) {
Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
if (recent != null)
return recent;
return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
}
throw new ProjectJdkSettingsOpenerExecutionException("Project JDK is not specified. <a href=''>Configure</a>", project);
}
if (name.equals(MavenRunnerSettings.USE_JAVA_HOME)) {
final String javaHome = System.getenv("JAVA_HOME");
if (StringUtil.isEmptyOrSpaces(javaHome)) {
throw new ExecutionException(RunnerBundle.message("maven.java.home.undefined"));
}
final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
if (jdk == null) {
throw new ExecutionException(RunnerBundle.message("maven.java.home.invalid", javaHome));
}
return jdk;
}
for (Sdk projectJdk : ProjectJdkTable.getInstance().getAllJdks()) {
if (projectJdk.getName().equals(name)) {
return projectJdk;
}
}
if (isGlobalRunnerSettings) {
throw new ExecutionException(RunnerBundle.message("maven.java.not.found.default.config", name));
} else {
throw new ExecutionException(RunnerBundle.message("maven.java.not.found", name));
}
}
use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.
the class MvcRunConfiguration method getState.
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
final Module module = getModule();
if (module == null) {
throw new ExecutionException("Module is not specified");
}
if (!isSupport(module)) {
throw new ExecutionException(getNoSdkMessage());
}
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final Sdk sdk = rootManager.getSdk();
if (sdk == null || !(sdk.getSdkType() instanceof JavaSdkType)) {
throw CantRunException.noJdkForModule(module);
}
return createCommandLineState(environment, module);
}
use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.
the class GriffonFramework method createJavaParameters.
@Override
public JavaParameters createJavaParameters(@NotNull Module module, boolean forCreation, boolean forTests, boolean classpathFromDependencies, @NotNull MvcCommand command) throws ExecutionException {
JavaParameters params = new JavaParameters();
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
params.setJdk(sdk);
final VirtualFile sdkRoot = getSdkRoot(module);
if (sdkRoot == null) {
return params;
}
params.addEnv(getSdkHomePropertyName(), FileUtil.toSystemDependentName(sdkRoot.getPath()));
final VirtualFile lib = sdkRoot.findChild("lib");
if (lib != null) {
for (final VirtualFile child : lib.getChildren()) {
final String name = child.getName();
if (name.startsWith("groovy-all-") && name.endsWith(".jar")) {
params.getClassPath().add(child);
}
}
}
final VirtualFile dist = sdkRoot.findChild("dist");
if (dist != null) {
for (final VirtualFile child : dist.getChildren()) {
final String name = child.getName();
if (name.endsWith(".jar")) {
if (name.startsWith("griffon-cli-") || name.startsWith("griffon-rt-") || name.startsWith("griffon-resources-")) {
params.getClassPath().add(child);
}
}
}
}
/////////////////////////////////////////////////////////////
params.setMainClass("org.codehaus.griffon.cli.support.GriffonStarter");
final VirtualFile rootFile;
if (forCreation) {
VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
if (roots.length != 1) {
throw new ExecutionException("Failed to initialize griffon module: module " + module.getName() + " contains more than one root");
}
command.getArgs().add(0, roots[0].getName());
rootFile = roots[0].getParent();
} else {
rootFile = findAppRoot(module);
if (rootFile == null) {
throw new ExecutionException("Failed to run griffon command: module " + module.getName() + " is not a Griffon module");
}
}
String workDir = VfsUtilCore.virtualToIoFile(rootFile).getAbsolutePath();
params.getVMParametersList().addParametersString(command.getVmOptions());
if (!params.getVMParametersList().getParametersString().contains(XMX_JVM_PARAMETER)) {
params.getVMParametersList().add("-Xmx256M");
}
final String griffonHomePath = FileUtil.toSystemDependentName(sdkRoot.getPath());
params.getVMParametersList().add("-Dgriffon.home=" + griffonHomePath);
params.getVMParametersList().add("-Dbase.dir=" + workDir);
assert sdk != null;
params.getVMParametersList().add("-Dtools.jar=" + ((JavaSdkType) sdk.getSdkType()).getToolsPath(sdk));
final String confpath = griffonHomePath + GROOVY_STARTER_CONF;
params.getVMParametersList().add("-Dgroovy.starter.conf=" + confpath);
params.getVMParametersList().add("-Dgroovy.sanitized.stacktraces=\"groovy., org.codehaus.groovy., java., javax., sun., gjdk.groovy., gant., org.codehaus.gant.\"");
params.getProgramParametersList().add("--main");
params.getProgramParametersList().add("org.codehaus.griffon.cli.GriffonScriptRunner");
params.getProgramParametersList().add("--conf");
params.getProgramParametersList().add(confpath);
if (!forCreation && classpathFromDependencies) {
final String path = getApplicationClassPath(module).getPathsString();
if (StringUtil.isNotEmpty(path)) {
params.getProgramParametersList().add("--classpath");
params.getProgramParametersList().add(path);
}
}
params.setWorkingDirectory(workDir);
ParametersList paramList = new ParametersList();
command.addToParametersList(paramList);
params.getProgramParametersList().add(paramList.getParametersString());
params.setDefaultCharset(module.getProject());
return params;
}
use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.
the class DebugProcessImpl method checkVirtualMachineVersion.
private void checkVirtualMachineVersion(VirtualMachine vm) {
final String version = vm.version();
if ("1.4.0".equals(version)) {
DebuggerInvocationUtil.swingInvokeLater(myProject, () -> Messages.showMessageDialog(myProject, DebuggerBundle.message("warning.jdk140.unstable"), DebuggerBundle.message("title.jdk140.unstable"), Messages.getWarningIcon()));
}
if (getSession().getAlternativeJre() == null) {
Sdk runjre = getSession().getRunJre();
if ((runjre == null || runjre.getSdkType() instanceof JavaSdkType) && !versionMatch(runjre, version)) {
Arrays.stream(ProjectJdkTable.getInstance().getAllJdks()).filter(sdk -> versionMatch(sdk, version)).findFirst().ifPresent(sdk -> {
XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("message.remote.jre.version.mismatch", version, runjre != null ? runjre.getVersionString() : "unknown", sdk.getName()), MessageType.INFO).notify(myProject);
getSession().setAlternativeJre(sdk);
});
}
}
}
use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.
the class AntCommandLineBuilder method setBuildFile.
public void setBuildFile(AbstractProperty.AbstractPropertyContainer container, File buildFile) throws CantRunException {
String jdkName = AntBuildFileImpl.CUSTOM_JDK_NAME.get(container);
Sdk jdk;
if (jdkName != null && jdkName.length() > 0) {
jdk = GlobalAntConfiguration.findJdk(jdkName);
} else {
jdkName = AntConfigurationImpl.DEFAULT_JDK_NAME.get(container);
if (jdkName == null || jdkName.length() == 0) {
throw new CantRunException(AntBundle.message("project.jdk.not.specified.error.message"));
}
jdk = GlobalAntConfiguration.findJdk(jdkName);
}
if (jdk == null) {
throw new CantRunException(AntBundle.message("jdk.with.name.not.configured.error.message", jdkName));
}
VirtualFile homeDirectory = jdk.getHomeDirectory();
if (homeDirectory == null) {
throw new CantRunException(AntBundle.message("jdk.with.name.bad.configured.error.message", jdkName));
}
myCommandLine.setJdk(jdk);
final ParametersList vmParametersList = myCommandLine.getVMParametersList();
vmParametersList.add("-Xmx" + AntBuildFileImpl.MAX_HEAP_SIZE.get(container) + "m");
vmParametersList.add("-Xss" + AntBuildFileImpl.MAX_STACK_SIZE.get(container) + "m");
final AntInstallation antInstallation = AntBuildFileImpl.ANT_INSTALLATION.get(container);
if (antInstallation == null) {
throw new CantRunException(AntBundle.message("ant.installation.not.configured.error.message"));
}
final String antHome = AntInstallation.HOME_DIR.get(antInstallation.getProperties());
vmParametersList.add("-Dant.home=" + antHome);
final String libraryDir = antHome + (antHome.endsWith("/") || antHome.endsWith(File.separator) ? "" : File.separator) + "lib";
vmParametersList.add("-Dant.library.dir=" + libraryDir);
String[] urls = jdk.getRootProvider().getUrls(OrderRootType.CLASSES);
final String jdkHome = homeDirectory.getPath().replace('/', File.separatorChar);
@NonNls final String pathToJre = jdkHome + File.separator + "jre" + File.separator;
for (String url : urls) {
final String path = PathUtil.toPresentableUrl(url);
if (!path.startsWith(pathToJre)) {
myCommandLine.getClassPath().add(path);
}
}
myCommandLine.getClassPath().addAllFiles(AntBuildFileImpl.ALL_CLASS_PATH.get(container));
myCommandLine.getClassPath().addAllFiles(AntBuildFileImpl.getUserHomeLibraries());
final SdkTypeId sdkType = jdk.getSdkType();
if (sdkType instanceof JavaSdkType) {
final String toolsJar = ((JavaSdkType) sdkType).getToolsPath(jdk);
if (toolsJar != null) {
myCommandLine.getClassPath().add(toolsJar);
}
}
PathUtilEx.addRtJar(myCommandLine.getClassPath());
myCommandLine.setMainClass(AntMain2.class.getName());
final ParametersList programParameters = myCommandLine.getProgramParametersList();
final String additionalParams = AntBuildFileImpl.ANT_COMMAND_LINE_PARAMETERS.get(container);
if (additionalParams != null) {
for (String param : ParametersList.parse(additionalParams)) {
if (param.startsWith("-J")) {
final String cutParam = param.substring("-J".length());
if (cutParam.length() > 0) {
vmParametersList.add(cutParam);
}
} else {
programParameters.add(param);
}
}
}
if (!(programParameters.getList().contains(LOGGER_PARAMETER))) {
programParameters.add(LOGGER_PARAMETER, IdeaAntLogger2.class.getName());
}
if (!programParameters.getList().contains(INPUT_HANDLER_PARAMETER)) {
programParameters.add(INPUT_HANDLER_PARAMETER, IdeaInputHandler.class.getName());
}
myProperties = AntBuildFileImpl.ANT_PROPERTIES.get(container);
myBuildFilePath = buildFile.getAbsolutePath();
myCommandLine.setWorkingDirectory(buildFile.getParent());
}
Aggregations