Search in sources :

Example 11 with JavaSdkType

use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.

the class GrabDependencies method isCorrectModule.

private static boolean isCorrectModule(PsiFile file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null) {
        return false;
    }
    final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk == null) {
        return false;
    }
    return file.getOriginalFile().getVirtualFile() != null && sdk.getSdkType() instanceof JavaSdkType;
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 12 with JavaSdkType

use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.

the class GroovyScriptRunConfiguration method createJavaParametersWithSdk.

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

Example 13 with JavaSdkType

use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.

the class JavaFxChunkBuildExtension method initArtifacts.

@Override
public void initArtifacts(Project project, GenerationOptions genOptions, CompositeGenerator generator) {
    final Collection<? extends Artifact> artifacts = ArtifactManager.getInstance(project).getArtifactsByType(JavaFxApplicationArtifactType.getInstance());
    if (artifacts.isEmpty())
        return;
    final Sdk[] jdks = BuildProperties.getUsedJdks(project);
    Sdk javaSdk = null;
    for (Sdk jdk : jdks) {
        if (jdk.getSdkType() instanceof JavaSdkType) {
            javaSdk = jdk;
            break;
        }
    }
    if (javaSdk != null) {
        final Tag taskdef = new Tag("taskdef", Couple.of("resource", "com/sun/javafx/tools/ant/antlib.xml"), Couple.of("uri", "javafx:com.sun.javafx.tools.ant"), Couple.of("classpath", BuildProperties.propertyRef(BuildProperties.getJdkHomeProperty(javaSdk.getName())) + "/lib/ant-javafx.jar"));
        generator.add(taskdef);
    }
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 14 with JavaSdkType

use of com.intellij.openapi.projectRoots.JavaSdkType in project intellij-community by JetBrains.

the class GradleApplicationEnvironmentProvider method createExecutionEnvironment.

@Nullable
public ExecutionEnvironment createExecutionEnvironment(@NotNull Project project, @NotNull ExecuteRunConfigurationTask executeRunConfigurationTask, @Nullable Executor executor) {
    if (!isApplicable(executeRunConfigurationTask))
        return null;
    ApplicationConfiguration applicationConfiguration = (ApplicationConfiguration) executeRunConfigurationTask.getRunProfile();
    PsiClass mainClass = applicationConfiguration.getMainClass();
    if (mainClass == null)
        return null;
    VirtualFile virtualFile = mainClass.getContainingFile().getVirtualFile();
    Module module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile);
    if (module == null)
        return null;
    final JavaParameters params = new JavaParameters();
    JavaParametersUtil.configureConfiguration(params, applicationConfiguration);
    params.getVMParametersList().addParametersString(applicationConfiguration.getVMParameters());
    String javaExePath = null;
    try {
        final Sdk jdk = JavaParametersUtil.createProjectJdk(project, applicationConfiguration.getAlternativeJrePath());
        if (jdk == null)
            throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
        final SdkTypeId type = jdk.getSdkType();
        if (!(type instanceof JavaSdkType))
            throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
        javaExePath = ((JavaSdkType) type).getVMExecutablePath(jdk);
        if (javaExePath == null)
            throw new RuntimeException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
        javaExePath = FileUtil.toSystemIndependentName(javaExePath);
    } catch (CantRunException e) {
        ExecutionErrorDialog.show(e, "Cannot use specified JRE", project);
    }
    StringBuilder parametersString = new StringBuilder();
    for (String parameter : params.getProgramParametersList().getParameters()) {
        parametersString.append("args '").append(parameter).append("'\n");
    }
    StringBuilder vmParametersString = new StringBuilder();
    for (String parameter : params.getVMParametersList().getParameters()) {
        vmParametersString.append("jvmArgs '").append(parameter).append("'\n");
    }
    ExternalSystemTaskExecutionSettings taskSettings = new ExternalSystemTaskExecutionSettings();
    taskSettings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
    taskSettings.setExternalProjectPath(ExternalSystemApiUtil.getExternalProjectPath(module));
    final String runAppTaskName = "run " + mainClass.getName();
    taskSettings.setTaskNames(Collections.singletonList(runAppTaskName));
    String executorId = executor == null ? DefaultRunExecutor.EXECUTOR_ID : executor.getId();
    ExecutionEnvironment environment = ExternalSystemUtil.createExecutionEnvironment(project, GradleConstants.SYSTEM_ID, taskSettings, executorId);
    if (environment != null) {
        RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
        assert runnerAndConfigurationSettings != null;
        ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
        final String gradlePath = GradleProjectResolverUtil.getGradlePath(module);
        if (gradlePath == null)
            return null;
        final String sourceSetName;
        if (GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY.equals(ExternalSystemApiUtil.getExternalModuleType(module))) {
            sourceSetName = GradleProjectResolverUtil.getSourceSetName(module);
        } else {
            sourceSetName = ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(virtualFile) ? "test" : "main";
        }
        if (sourceSetName == null)
            return null;
        @Language("Groovy") String initScript = "projectsEvaluated {\n" + "  rootProject.allprojects {\n" + "    if(project.path == '" + gradlePath + "' && project.sourceSets) {\n" + "      project.tasks.create(name: '" + runAppTaskName + "', overwrite: true, type: JavaExec) {\n" + (javaExePath != null ? "        executable = '" + javaExePath + "'\n" : "") + "        classpath = project.sourceSets.'" + sourceSetName + "'.runtimeClasspath\n" + "        main = '" + mainClass.getQualifiedName() + "'\n" + parametersString.toString() + vmParametersString.toString() + "      }\n" + "    }\n" + "  }\n" + "}\n";
        runConfiguration.putUserData(GradleTaskManager.INIT_SCRIPT_KEY, initScript);
        return environment;
    } else {
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) CantRunException(com.intellij.execution.CantRunException) Language(org.intellij.lang.annotations.Language) JavaParameters(com.intellij.execution.configurations.JavaParameters) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) Module(com.intellij.openapi.module.Module) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) Nullable(org.jetbrains.annotations.Nullable)

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