Java 类com.intellij.openapi.projectRoots.JdkUtil 实例源码

项目:intellij-ce-playground    文件:DebuggerManagerImpl.java   
/**
 * for Target JDKs versions 1.2.x - 1.3.0 the Classic VM should be used for debugging
 */
private static boolean shouldForceClassicVM(Sdk jdk) {
  if (SystemInfo.isMac) {
    return false;
  }
  if (jdk == null) return false;

  String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
  if (version != null) {
    if (version.compareTo("1.4") >= 0) {
      return false;
    }
    if (version.startsWith("1.2") && SystemInfo.isWindows) {
      return true;
    }
    version += ".0";
    if (version.startsWith("1.3.0") && SystemInfo.isWindows) {
      return true;
    }
    if ((version.startsWith("1.3.1_07") || version.startsWith("1.3.1_08")) && SystemInfo.isWindows) {
      return false; // fixes bug for these JDKs that it cannot start with -classic option
    }
  }

  return DebuggerSettings.getInstance().FORCE_CLASSIC_VM;
}
项目:intellij-ce-playground    文件:DebuggerManagerImpl.java   
private static boolean shouldAddXdebugKey(Sdk jdk) {
  if (jdk == null) {
    return true; // conservative choice
  }
  if (DebuggerSettings.getInstance().DISABLE_JIT) {
    return true;
  }

  //if (ApplicationManager.getApplication().isUnitTestMode()) {
  // need this in unit tests to avoid false alarms when comparing actual output with expected output
  //return true;
  //}

  final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
  return version == null ||
         //version.startsWith("1.5") ||
         version.startsWith("1.4") ||
         version.startsWith("1.3") ||
         version.startsWith("1.2") ||
         version.startsWith("1.1") ||
         version.startsWith("1.0");
}
项目:intellij-ce-playground    文件:JythonUnitTestUtil.java   
public static ProcessOutput runJython(String workDir, String pythonPath, String... args) throws ExecutionException {
  final SimpleJavaSdkType sdkType = new SimpleJavaSdkType();
  final Sdk ideaJdk = sdkType.createJdk("tmp", SystemProperties.getJavaHome());
  SimpleJavaParameters parameters = new SimpleJavaParameters();
  parameters.setJdk(ideaJdk);
  parameters.setMainClass("org.python.util.jython");

  File jythonJar = new File(PythonHelpersLocator.getPythonCommunityPath(), "lib/jython.jar");
  parameters.getClassPath().add(jythonJar.getPath());

  parameters.getProgramParametersList().add("-Dpython.path=" + pythonPath + File.pathSeparator + workDir);
  parameters.getProgramParametersList().addAll(args);
  parameters.setWorkingDirectory(workDir);

  final GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine(sdkType.getVMExecutablePath(ideaJdk), parameters, false);
  final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine.createProcess());
  return processHandler.runProcess();
}
项目:tools-idea    文件:DebuggerManagerImpl.java   
/**
 * for Target JDKs versions 1.2.x - 1.3.0 the Classic VM should be used for debugging
 */
private static boolean shouldForceClassicVM(Sdk jdk) {
  if (SystemInfo.isMac) {
    return false;
  }
  if (jdk == null) return false;

  String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
  if (version != null) {
    if (version.compareTo("1.4") >= 0) {
      return false;
    }
    if (version.startsWith("1.2") && SystemInfo.isWindows) {
      return true;
    }
    version += ".0";
    if (version.startsWith("1.3.0") && SystemInfo.isWindows) {
      return true;
    }
    if ((version.startsWith("1.3.1_07") || version.startsWith("1.3.1_08")) && SystemInfo.isWindows) {
      return false; // fixes bug for these JDKs that it cannot start with -classic option
    }
  }

  return DebuggerSettings.getInstance().FORCE_CLASSIC_VM;
}
项目:tools-idea    文件:DebuggerManagerImpl.java   
private static boolean shouldAddXdebugKey(Sdk jdk) {
  if (jdk == null) {
    return true; // conservative choice
  }
  if (DebuggerSettings.getInstance().DISABLE_JIT) {
    return true;
  }

  //if (ApplicationManager.getApplication().isUnitTestMode()) {
  // need this in unit tests to avoid false alarms when comparing actual output with expected output
  //return true;
  //}

  final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
  return version == null ||
         //version.startsWith("1.5") ||
         version.startsWith("1.4") ||
         version.startsWith("1.3") ||
         version.startsWith("1.2") ||
         version.startsWith("1.1") ||
         version.startsWith("1.0");
}
项目:consulo-java    文件:DebuggerManagerImpl.java   
private static boolean shouldForceNoJIT(Sdk jdk)
{
    if(DebuggerSettings.getInstance().DISABLE_JIT)
    {
        return true;
    }
    if(jdk != null)
    {
        final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
        if(version != null && (version.startsWith("1.2") || version.startsWith("1.3")))
        {
            return true;
        }
    }
    return false;
}
项目:consulo-java    文件:DebuggerManagerImpl.java   
private static boolean shouldAddXdebugKey(Sdk jdk)
{
    if(jdk == null)
    {
        return true; // conservative choice
    }
    if(DebuggerSettings.getInstance().DISABLE_JIT)
    {
        return true;
    }

    //if (ApplicationManager.getApplication().isUnitTestMode()) {
    // need this in unit tests to avoid false alarms when comparing actual output with expected output
    //return true;
    //}

    final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
    return version == null ||
            //version.startsWith("1.5") ||
            version.startsWith("1.4") || version.startsWith("1.3") || version.startsWith("1.2") || version.startsWith("1.1") || version.startsWith("1.0");
}
项目:intellij-ce-playground    文件:DebuggerManagerImpl.java   
private static boolean shouldForceNoJIT(Sdk jdk) {
  if (DebuggerSettings.getInstance().DISABLE_JIT) {
    return true;
  }
  if (jdk != null) {
    final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
    if (version != null && (version.startsWith("1.2") || version.startsWith("1.3"))) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:DebuggerManagerImpl.java   
private static boolean isJVMTIAvailable(Sdk jdk) {
  if (jdk == null) {
    return false; // conservative choice
  }

  final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
  if (version == null) {
    return false;
  }
  return !(version.startsWith("1.4") ||
           version.startsWith("1.3") ||
           version.startsWith("1.2") ||
           version.startsWith("1.1") ||
           version.startsWith("1.0"));
}
项目:intellij-ce-playground    文件:JarVersionDetectionUtil.java   
@Nullable
public static String detectJarVersion(@NotNull String detectionClass, @NotNull Module module) {
  for (OrderEntry library : ModuleRootManager.getInstance(module).getOrderEntries()) {
    if (library instanceof LibraryOrderEntry) {
      VirtualFile jar = LibrariesHelper.getInstance().findJarByClass(((LibraryOrderEntry)library).getLibrary(), detectionClass);
      if (jar != null && jar.getFileSystem() instanceof JarFileSystem) {
        return JdkUtil.getJarMainAttribute(jar, Attributes.Name.IMPLEMENTATION_VERSION);
      }
    }
  }

  return null;
}
项目:intellij-ce-playground    文件:JavaParametersUtil.java   
private static Sdk createAlternativeJdk(@NotNull String jreHome) throws CantRunException {
  final Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(jreHome);
  if (configuredJdk != null) {
    return configuredJdk;
  }

  if (!JdkUtil.checkForJre(jreHome) && !JdkUtil.checkForJdk(jreHome)) {
    throw new CantRunException(ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jreHome));
  }

  final Sdk jdk = JavaSdk.getInstance().createJdk("", jreHome);
  if (jdk == null) throw CantRunException.noJdkConfigured();
  return jdk;
}
项目:intellij-ce-playground    文件:LibraryJarUsagesCollector.java   
@Nullable
private static String getVersionByJarManifest(@NotNull VirtualFile file) {
  String version = JdkUtil.getJarMainAttribute(file, Attributes.Name.IMPLEMENTATION_VERSION);
  if (version == null) return null;

  Matcher versionMatcher = DIGIT_VERSION_PATTERN.matcher(version);
  if (!versionMatcher.matches()) return null;

  return versionMatcher.group(1);
}
项目:intellij-ce-playground    文件:JdkDetection.java   
@Nullable
public static String validateJdkLocation(@Nullable File location) {
  if (location == null) {
    return "Path is empty";
  }
  if (!JdkUtil.checkForJdk(location)) {
    return "Path specified is not a valid JDK location";
  }
  if (!isJdk7(location)) {
    return "JDK 7.0 or newer is required";
  }
  return null;
}
项目:intellij-ce-playground    文件:GradleInstallationManager.java   
@Nullable
private Sdk doGetGradleJdk(@Nullable Project project, String linkedProjectPath) {
  if (project == null) {
    return null;
  }

  final GradleProjectSettings settings = GradleSettings.getInstance(project).getLinkedProjectSettings(linkedProjectPath);
  if (settings == null) {
    return null;
  }

  final String gradleJvm = settings.getGradleJvm();
  final Sdk sdk;
  try {
    sdk = ExternalSystemJdkUtil.getJdk(project, gradleJvm);
  }
  catch (ExternalSystemJdkException e) {
    throw new ExternalSystemJdkException(
      String.format("Invalid Gradle JDK configuration found. <a href='%s'>Open Gradle Settings</a> \n",
                    OpenExternalSystemSettingsCallback.ID),
      linkedProjectPath, e, OpenExternalSystemSettingsCallback.ID);
  }

  if (sdk == null && gradleJvm != null) {
    throw new ExternalSystemJdkException(
      String.format("Invalid Gradle JDK configuration found. <a href='%s'>Open Gradle Settings</a> \n",
                    OpenExternalSystemSettingsCallback.ID),
      linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
  }

  final File sdkHomePath = sdk != null && sdk.getHomePath() != null ? new File(sdk.getHomePath()) : null;
  if (sdkHomePath != null && JdkUtil.checkForJre(sdkHomePath.getPath()) && !JdkUtil.checkForJdk(sdkHomePath)) {
    throw new ExternalSystemJdkException(
      String.format("Please, use JDK instead of JRE for Gradle importer. <a href='%s'>Open Gradle Settings</a> \n",
                    OpenExternalSystemSettingsCallback.ID),
      linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
  }
  return sdk;
}
项目:tools-idea    文件:DebuggerManagerImpl.java   
private static boolean shouldForceNoJIT(Sdk jdk) {
  if (DebuggerSettings.getInstance().DISABLE_JIT) {
    return true;
  }
  if (jdk != null) {
    final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
    if (version != null && (version.startsWith("1.2") || version.startsWith("1.3"))) {
      return true;
    }
  }
  return false;
}
项目:tools-idea    文件:DebuggerManagerImpl.java   
private static boolean isJVMTIAvailable(Sdk jdk) {
  if (jdk == null) {
    return false; // conservative choice
  }

  final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
  if (version == null) {
    return false;
  }
  return !(version.startsWith("1.4") ||
           version.startsWith("1.3") ||
           version.startsWith("1.2") ||
           version.startsWith("1.1") ||
           version.startsWith("1.0"));
}
项目:intellij-xquery    文件:XQueryRunProfileState.java   
private Sdk createAlternativeJdk(@NotNull String jreHome) throws CantRunException {
    final Sdk configuredJdk = ProjectJdkTable.getInstance().findJdk(jreHome);
    if (configuredJdk != null) {
        return configuredJdk;
    }

    if (!JdkUtil.checkForJre(jreHome) && !JdkUtil.checkForJdk(jreHome)) {
        throw new CantRunException(ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jreHome));
    }

    final String versionString = SdkVersionUtil.detectJdkVersion(jreHome);
    final Sdk jdk = new SimpleJavaSdkType().createJdk(versionString != null ? versionString : "", jreHome);
    if (jdk == null) throw CantRunException.noJdkConfigured();
    return jdk;
}
项目:consulo-java    文件:DebuggerManagerImpl.java   
/**
 * for Target JDKs versions 1.2.x - 1.3.0 the Classic VM should be used for debugging
 */
private static boolean shouldForceClassicVM(Sdk jdk)
{
    if(SystemInfo.isMac)
    {
        return false;
    }
    if(jdk == null)
    {
        return false;
    }

    String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
    if(version == null || StringUtil.compareVersionNumbers(version, "1.4") >= 0)
    {
        return false;
    }

    if(version.startsWith("1.2") && SystemInfo.isWindows)
    {
        return true;
    }
    version += ".0";
    if(version.startsWith("1.3.0") && SystemInfo.isWindows)
    {
        return true;
    }
    if((version.startsWith("1.3.1_07") || version.startsWith("1.3.1_08")) && SystemInfo.isWindows)
    {
        return false; // fixes bug for these JDKs that it cannot start with -classic option
    }
    return DebuggerSettings.getInstance().FORCE_CLASSIC_VM;
}
项目:consulo-java    文件:DebuggerManagerImpl.java   
private static boolean isJVMTIAvailable(Sdk jdk)
{
    if(jdk == null)
    {
        return false; // conservative choice
    }

    final String version = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VERSION);
    if(version == null)
    {
        return false;
    }
    return !(version.startsWith("1.4") || version.startsWith("1.3") || version.startsWith("1.2") || version.startsWith("1.1") || version.startsWith("1.0"));
}
项目:intellij-ce-playground    文件:JarVersionDetectionUtil.java   
@Nullable
public static String detectJarVersion(@NotNull String detectionClass, @NotNull List<VirtualFile> files) {
  VirtualFile jarRoot = LibrariesHelper.getInstance().findRootByClass(files, detectionClass);
  return jarRoot != null && jarRoot.getFileSystem() instanceof JarFileSystem ?
         JdkUtil.getJarMainAttribute(jarRoot, Attributes.Name.IMPLEMENTATION_VERSION) : null;
}
项目:intellij-ce-playground    文件:GroovyHotSwapper.java   
@Override
public void patchJavaParameters(Executor executor, RunProfile configuration, JavaParameters javaParameters) {
  if (!executor.getId().equals(DefaultDebugExecutor.EXECUTOR_ID)) {
    return;
  }

  if (!GroovyDebuggerSettings.getInstance().ENABLE_GROOVY_HOTSWAP) {
    return;
  }

  if (hasSpringLoadedReloader(javaParameters)) {
    return;
  }

  if (!(configuration instanceof RunConfiguration)) {
    return;
  }

  final Project project = ((RunConfiguration)configuration).getProject();
  if (project == null) {
    return;
  }

  if (!LanguageLevelProjectExtension.getInstance(project).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
    return;
  }

  if (configuration instanceof ModuleBasedConfiguration) {
    final Module module = ((ModuleBasedConfiguration)configuration).getConfigurationModule().getModule();
    if (module != null) {
      final LanguageLevel level = LanguageLevelModuleExtensionImpl.getInstance(module).getLanguageLevel();
      if (level != null && !level.isAtLeast(LanguageLevel.JDK_1_5)) {
        return;
      }
    }
  }

  Sdk jdk = javaParameters.getJdk();
  if (jdk != null) {
    String vendor = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VENDOR);
    if (vendor != null && vendor.contains("IBM")) {
      LOG.info("Due to IBM JDK pecularities (IDEA-59070) we don't add groovy agent when running applications under it");
      return;
    }
  }

  if (!project.isDefault() && containsGroovyClasses(project)) {
    final String agentPath = handleSpacesInPath(getAgentJarPath());
    if (agentPath != null) {
      javaParameters.getVMParametersList().add("-javaagent:" + agentPath);
    }
  }
}
项目:embeddedlinux-jvmdebugger-intellij    文件:RemoteCommandLineBuilder.java   
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters,
                                                          final Project project,
                                                          final boolean dynamicClasspath) throws CantRunException {
    return createFromJavaParameters(javaParameters, dynamicClasspath && JdkUtil.useDynamicClasspath(project));
}
项目:tools-idea    文件:GroovyHotSwapper.java   
public void patchJavaParameters(Executor executor, RunProfile configuration, JavaParameters javaParameters) {
  if (!executor.getId().equals(DefaultDebugExecutor.EXECUTOR_ID)) {
    return;
  }

  if (!GroovyDebuggerSettings.getInstance().ENABLE_GROOVY_HOTSWAP) {
    return;
  }

  if (hasSpringLoadedReloader(javaParameters)) {
    return;
  }

  if (!(configuration instanceof RunConfiguration)) {
    return;
  }

  final Project project = ((RunConfiguration)configuration).getProject();
  if (project == null) {
    return;
  }

  if (!LanguageLevelProjectExtension.getInstance(project).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
    return;
  }

  if (configuration instanceof ModuleBasedConfiguration) {
    final Module module = ((ModuleBasedConfiguration)configuration).getConfigurationModule().getModule();
    if (module != null) {
      final LanguageLevel level = LanguageLevelModuleExtension.getInstance(module).getLanguageLevel();
      if (level != null && !level.isAtLeast(LanguageLevel.JDK_1_5)) {
        return;
      }
    }
  }

  Sdk jdk = javaParameters.getJdk();
  if (jdk != null) {
    String vendor = JdkUtil.getJdkMainAttribute(jdk, Attributes.Name.IMPLEMENTATION_VENDOR);
    if (vendor != null && vendor.contains("IBM")) {
      LOG.info("Due to IBM JDK pecularities (IDEA-59070) we don't add groovy agent when running applications under it");
      return;
    }
  }

  if (!project.isDefault() && containsGroovyClasses(project)) {
    final String agentPath = handleSpacesInPath(getAgentJarPath());
    if (agentPath != null) {
      javaParameters.getVMParametersList().add("-javaagent:" + agentPath);
    }
  }
}
项目:intellij-xquery    文件:AlternativeJreValidator.java   
public static void checkAlternativeJRE(@Nullable String jrePath) throws RuntimeConfigurationWarning {
    if (StringUtil.isEmpty(jrePath) ||
            ProjectJdkTable.getInstance().findJdk(jrePath) == null && !JdkUtil.checkForJre(jrePath)) {
        throw new RuntimeConfigurationWarning(ExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jrePath));
    }
}
项目:intellij-xquery    文件:XQueryRunProfileState.java   
private GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters,
                                                    final Project project) throws CantRunException {
    return createFromJavaParameters(javaParameters, JdkUtil.useDynamicClasspath(project));
}
项目:intellij-ce-playground    文件:CommandLineBuilder.java   
/**
 * In order to avoid too long cmd problem dynamic classpath can be used - if allowed by both  {@code dynamicClasspath} parameter
 * and project settings.
 *
 * @param javaParameters   parameters.
 * @param project          a project to get a dynamic classpath setting from.
 * @param dynamicClasspath whether system properties and project settings will be able to cause using dynamic classpath. If false,
 *                         classpath will always be passed through the command line.
 * @return a command line.
 * @throws CantRunException if there are problems with JDK setup.
 */
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters,
                                                          final Project project,
                                                          final boolean dynamicClasspath) throws CantRunException {
  return createFromJavaParameters(javaParameters, dynamicClasspath && JdkUtil.useDynamicClasspath(project));
}
项目:tools-idea    文件:CommandLineBuilder.java   
/**
 * In order to avoid too long cmd problem dynamic classpath can be used - if allowed by both  {@code dynamicClasspath} parameter
 * and project settings.
 *
 * @param javaParameters   parameters.
 * @param project          a project to get a dynamic classpath setting from.
 * @param dynamicClasspath whether system properties and project settings will be able to cause using dynamic classpath. If false,
 *                         classpath will always be passed through the command line.
 * @return a command line.
 * @throws CantRunException if there are problems with JDK setup.
 */
public static GeneralCommandLine createFromJavaParameters(final SimpleJavaParameters javaParameters,
                                                          final Project project,
                                                          final boolean dynamicClasspath) throws CantRunException {
  return createFromJavaParameters(javaParameters, dynamicClasspath && JdkUtil.useDynamicClasspath(project));
}