Search in sources :

Example 1 with JavaSdkType

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));
    }
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JavaSdkType

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);
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 3 with JavaSdkType

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) ParametersList(com.intellij.execution.configurations.ParametersList) JavaParameters(com.intellij.execution.configurations.JavaParameters) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Example 4 with JavaSdkType

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);
            });
        }
    }
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 5 with JavaSdkType

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) IdeaInputHandler(com.intellij.rt.ant.execution.IdeaInputHandler) AntMain2(com.intellij.rt.ant.execution.AntMain2) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) CantRunException(com.intellij.execution.CantRunException) IdeaAntLogger2(com.intellij.rt.ant.execution.IdeaAntLogger2) ParametersList(com.intellij.execution.configurations.ParametersList) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId)

Aggregations

JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)14 Sdk (com.intellij.openapi.projectRoots.Sdk)14 Module (com.intellij.openapi.module.Module)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)4 ExecutionException (com.intellij.execution.ExecutionException)3 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)3 SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)3 File (java.io.File)3 IOException (java.io.IOException)3 CantRunException (com.intellij.execution.CantRunException)2 JavaParameters (com.intellij.execution.configurations.JavaParameters)2 ParametersList (com.intellij.execution.configurations.ParametersList)2 Nullable (org.jetbrains.annotations.Nullable)2 JpsJavaSdkType (org.jetbrains.jps.model.java.JpsJavaSdkType)2 CompilerConfiguration (com.intellij.compiler.CompilerConfiguration)1 CompilerWorkspaceConfiguration (com.intellij.compiler.CompilerWorkspaceConfiguration)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1