@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;
        }
      }

      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));
    }
  }
 /* Remoting */
 private static void checkTargetJPDAInstalled(JavaParameters parameters)
     throws ExecutionException {
   final Sdk jdk = parameters.getJdk();
   if (jdk == null) {
     throw new ExecutionException(DebuggerBundle.message("error.jdk.not.specified"));
   }
   final JavaSdkVersion version = JavaSdk.getInstance().getVersion(jdk);
   String versionString = jdk.getVersionString();
   if (version == JavaSdkVersion.JDK_1_0 || version == JavaSdkVersion.JDK_1_1) {
     throw new ExecutionException(
         DebuggerBundle.message("error.unsupported.jdk.version", versionString));
   }
   if (SystemInfo.isWindows && version == JavaSdkVersion.JDK_1_2) {
     final VirtualFile homeDirectory = jdk.getHomeDirectory();
     if (homeDirectory == null || !homeDirectory.isValid()) {
       throw new ExecutionException(
           DebuggerBundle.message("error.invalid.jdk.home", versionString));
     }
     //noinspection HardCodedStringLiteral
     File dllFile =
         new File(
             homeDirectory.getPath().replace('/', File.separatorChar)
                 + File.separator
                 + "bin"
                 + File.separator
                 + "jdwp.dll");
     if (!dllFile.exists()) {
       GetJPDADialog dialog = new GetJPDADialog();
       dialog.show();
       throw new ExecutionException(DebuggerBundle.message("error.debug.libraries.missing"));
     }
   }
 }
 @Nullable
 public String getVMExecutablePath(Sdk sdk) {
   final Sdk internalJavaSdk = getInternalJavaSdk(sdk);
   return internalJavaSdk == null
       ? null
       : JavaSdk.getInstance().getVMExecutablePath(internalJavaSdk);
 }
  @Override
  public void setDefaultParameters(
      @NotNull Project project,
      @NotNull VirtualFile virtualFile,
      @NotNull BackgroundTaskByVfsParameters backgroundTaskByVfsParameters) {
    Sdk sdk = null;
    Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
    if (module != null) {
      sdk = ModuleUtilCore.getSdk(module, JavaModuleExtension.class);
    }

    if (sdk == null) {
      sdk = SdkTable.getInstance().findPredefinedSdkByType(JavaSdk.getInstance());
    }

    if (sdk == null) {
      sdk = SdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
    }

    List<String> parameters = new ArrayList<String>();
    if (sdk != null) {
      GeneralCommandLine generalCommandLine = new GeneralCommandLine();

      ((JavaSdkType) sdk.getSdkType()).setupCommandLine(generalCommandLine, sdk);
      backgroundTaskByVfsParameters.setExePath(generalCommandLine.getExePath());
      parameters.addAll(generalCommandLine.getParametersList().getList());
    } else {
      backgroundTaskByVfsParameters.setExePath(SystemInfo.isWindows ? "java.exe" : "java");
    }

    PluginClassLoader classLoader =
        (PluginClassLoader) JFlexBackgroundTaskProvider.class.getClassLoader();
    IdeaPluginDescriptor plugin = PluginManager.getPlugin(classLoader.getPluginId());
    assert plugin != null;
    parameters.add("-jar");
    parameters.add(new File(plugin.getPath(), "jflex/jflex.jar").getAbsolutePath());
    parameters.add("--charat");
    parameters.add("--noconstr");
    parameters.add("--nobak");
    parameters.add("--skel");
    parameters.add(new File(plugin.getPath(), "jflex/idea-flex.skeleton").getAbsolutePath());
    parameters.add("$FilePath$");

    backgroundTaskByVfsParameters.setProgramParameters(StringUtil.join(parameters, " "));
    backgroundTaskByVfsParameters.setWorkingDirectory("$FileParentPath$");
    backgroundTaskByVfsParameters.setOutPath("$FileParentPath$");
  }
 @Nullable
 public String getToolsPath(Sdk sdk) {
   final Sdk jdk = getInternalJavaSdk(sdk);
   if (jdk != null && jdk.getVersionString() != null) {
     return JavaSdk.getInstance().getToolsPath(jdk);
   }
   return null;
 }
 @TestOnly
 public static void setTestVersion(
     @NotNull final JavaSdkVersion testVersion,
     @NotNull Module module,
     @NotNull Disposable parentDisposable) {
   ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
   final Sdk sdk = rootManager.getSdk();
   final String oldVersionString = sdk.getVersionString();
   ((ProjectJdkImpl) sdk).setVersionString(testVersion.getDescription());
   assert JavaSdk.getInstance().getVersion(sdk) == testVersion;
   Disposer.register(
       parentDisposable,
       new Disposable() {
         @Override
         public void dispose() {
           ((ProjectJdkImpl) sdk).setVersionString(oldVersionString);
         }
       });
 }
 @Override
 public ModuleWizardStep[] createWizardSteps(
     final WizardContext wizardContext,
     final JavaModuleBuilder moduleBuilder,
     final ModulesProvider modulesProvider) {
   final ProjectWizardStepFactory wizardFactory = ProjectWizardStepFactory.getInstance();
   ArrayList<ModuleWizardStep> steps = new ArrayList<ModuleWizardStep>();
   steps.add(
       wizardFactory.createSourcePathsStep(
           wizardContext,
           moduleBuilder,
           getWizardIcon(),
           "reference.dialogs.new.project.fromScratch.source"));
   steps.add(
       wizardFactory.createProjectJdkStep(
           wizardContext,
           JavaSdk.getInstance(),
           moduleBuilder,
           new Computable<Boolean>() {
             @Override
             public Boolean compute() {
               final Sdk projectJdk = wizardFactory.getNewProjectSdk(wizardContext);
               return projectJdk == null || projectJdk.getSdkType() != JavaSdk.getInstance()
                   ? Boolean.TRUE
                   : Boolean.FALSE;
             }
           },
           getWizardIcon(),
           "reference.dialogs.new.project.fromScratch.sdk"));
   final ModuleWizardStep supportForFrameworksStep =
       wizardFactory.createSupportForFrameworksStep(wizardContext, moduleBuilder, modulesProvider);
   if (supportForFrameworksStep != null) {
     steps.add(supportForFrameworksStep);
   }
   final ModuleWizardStep[] wizardSteps = steps.toArray(new ModuleWizardStep[steps.size()]);
   return ArrayUtil.mergeArrays(
       wizardSteps, super.createWizardSteps(wizardContext, moduleBuilder, modulesProvider));
 }
Example #8
0
 protected static Sdk getFullJavaJDK() {
   return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
 }
 private static boolean isJdk6(final Sdk jdk) {
   return jdk != null && JavaSdk.getInstance().isOfVersionOrHigher(jdk, JavaSdkVersion.JDK_1_6);
 }
Example #10
0
 @Override
 protected Sdk getProjectJDK() {
   return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
 }
 @Override
 @Nullable
 public String getBinPath(@NotNull Sdk sdk) {
   Sdk internalJavaSdk = getInternalJavaSdk(sdk);
   return internalJavaSdk == null ? null : JavaSdk.getInstance().getBinPath(internalJavaSdk);
 }
 @Override
 protected Sdk getProjectJDK() {
   return JavaSdk.getInstance().createJdk("java sdk", JDK_HOME, false);
 }
 @Override
 public boolean isRootTypeApplicable(OrderRootType type) {
   return JavaSdk.getInstance().isRootTypeApplicable(type);
 }
 public static Sdk getMockJdk14() {
   return JavaSdk.getInstance().createJdk("java 1.4", getMockJdk14Path().getPath(), false);
 }
 public static Sdk getMockJdk17(@NotNull String name) {
   return JavaSdk.getInstance().createJdk(name, getMockJdk17Path().getPath(), false);
 }