Java 类com.intellij.openapi.projectRoots.ex.JavaSdkUtil 实例源码

项目:intellij-ce-playground    文件:ProcessProxyFactoryImpl.java   
public ProcessProxy createCommandLineProxy(final JavaCommandLine javaCmdLine) throws ExecutionException {
  ProcessProxyImpl proxy = null;
  final JavaParameters javaParameters = javaCmdLine.getJavaParameters();
  String mainClass = javaParameters.getMainClass();
  if (ProcessProxyImpl.useLauncher() && mainClass != null) {
    try {
      proxy = new ProcessProxyImpl();
      JavaSdkUtil.addRtJar(javaParameters.getClassPath());
      final ParametersList vmParametersList = javaParameters.getVMParametersList();
      vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_PORT_NUMBER, String.valueOf(proxy.getPortNumber()));
      vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_BINPATH, PathManager.getBinPath());
      javaParameters.getProgramParametersList().prepend(mainClass);
      javaParameters.setMainClass(ProcessProxyImpl.LAUNCH_MAIN_CLASS);
    }
    catch (ProcessProxyImpl.NoMoreSocketsException e) {
      proxy = null;
    }
  }
  return proxy;
}
项目:tools-idea    文件:ProcessProxyFactoryImpl.java   
public ProcessProxy createCommandLineProxy(final JavaCommandLine javaCmdLine) throws ExecutionException {
  ProcessProxyImpl proxy = null;
  if (ProcessProxyImpl.useLauncher()) {
    try {
      proxy = new ProcessProxyImpl();
      final JavaParameters javaParameters = javaCmdLine.getJavaParameters();
      JavaSdkUtil.addRtJar(javaParameters.getClassPath());
      final ParametersList vmParametersList = javaParameters.getVMParametersList();
      vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_PORT_NUMBER, String.valueOf(proxy.getPortNumber()));
      vmParametersList.defineProperty(ProcessProxyImpl.PROPERTY_BINPATH, PathManager.getBinPath());
      javaParameters.getProgramParametersList().prepend(javaParameters.getMainClass());
      javaParameters.setMainClass(ProcessProxyImpl.LAUNCH_MAIN_CLASS);
    }
    catch (ProcessProxyImpl.NoMoreSocketsException e) {
      proxy = null;
    }
  }
  return proxy;
}
项目:tools-idea    文件:JavacOutputParserPool.java   
private static String[] createParserSetupCommand(final Sdk jdk) {

    final VirtualFile homeDirectory = jdk.getHomeDirectory();
    if (homeDirectory == null) {
      throw new IllegalArgumentException(CompilerBundle.jdkHomeNotFoundMessage(jdk));
    }

    final List<String> commandLine = new ArrayList<String>();
    commandLine.add(((JavaSdkType)jdk.getSdkType()).getVMExecutablePath(jdk));

    CompilerUtil.addLocaleOptions(commandLine, false);

    //noinspection HardCodedStringLiteral
    commandLine.add("-classpath");
    commandLine.add(((JavaSdkType)jdk.getSdkType()).getToolsPath(jdk) + File.pathSeparator + JavaSdkUtil.getIdeaRtJarPath());

    commandLine.add(JavacResourcesReader.class.getName());

    return ArrayUtil.toStringArray(commandLine);
  }
项目:intellij-ce-playground    文件:JavaTestFrameworkRunnableState.java   
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
  final JavaParameters javaParameters = new JavaParameters();
  javaParameters.setUseClasspathJar(true);
  final Module module = getConfiguration().getConfigurationModule().getModule();

  Project project = getConfiguration().getProject();
  Sdk jdk = module == null ? ProjectRootManager.getInstance(project).getProjectSdk() : ModuleRootManager.getInstance(module).getSdk();
  javaParameters.setJdk(jdk);

  final String parameters = getConfiguration().getProgramParameters();
  getConfiguration().setProgramParameters(null);
  try {
    JavaParametersUtil.configureConfiguration(javaParameters, getConfiguration());
  }
  finally {
    getConfiguration().setProgramParameters(parameters);
  }
  javaParameters.getClassPath().addFirst(JavaSdkUtil.getIdeaRtJarPath());
  configureClasspath(javaParameters);

  final Object[] patchers = Extensions.getExtensions(ExtensionPoints.JUNIT_PATCHER);
  for (Object patcher : patchers) {
    ((JUnitPatcher)patcher).patchJavaParameters(module, javaParameters);
  }

  // Append coverage parameters if appropriate
  for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
    ext.updateJavaParameters(getConfiguration(), javaParameters, getRunnerSettings());
  }

  if (!StringUtil.isEmptyOrSpaces(parameters)) {
    javaParameters.getProgramParametersList().addAll(getNamedParams(parameters));
  }

  return javaParameters;
}
项目:intellij-ce-playground    文件:JavaTestFrameworkRunnableState.java   
protected void writeClassesPerModule(String packageName, JavaParameters javaParameters, Map<Module, List<String>> perModule)
  throws FileNotFoundException, UnsupportedEncodingException, CantRunException {
  if (perModule != null && perModule.size() > 1) {
    final String classpath = getScope() == TestSearchScope.WHOLE_PROJECT
                             ? null : javaParameters.getClassPath().getPathsString();

    final PrintWriter wWriter = new PrintWriter(myWorkingDirsFile, CharsetToolkit.UTF8);
    try {
      wWriter.println(packageName);
      for (Module module : perModule.keySet()) {
        wWriter.println(PathMacroUtil.getModuleDir(module.getModuleFilePath()));
        wWriter.println(module.getName());

        if (classpath == null) {
          final JavaParameters parameters = new JavaParameters();
          parameters.getClassPath().add(JavaSdkUtil.getIdeaRtJarPath());
          configureRTClasspath(parameters);
          JavaParametersUtil.configureModule(module, parameters, JavaParameters.JDK_AND_CLASSES_AND_TESTS,
                                             getConfiguration().isAlternativeJrePathEnabled() ? getConfiguration()
                                               .getAlternativeJrePath() : null);
          wWriter.println(parameters.getClassPath().getPathsString());
        }
        else {
          wWriter.println(classpath);
        }

        final List<String> classNames = perModule.get(module);
        wWriter.println(classNames.size());
        for (String className : classNames) {
          wWriter.println(className);
        }
      }
    }
    finally {
      wWriter.close();
    }
  }
}
项目:intellij-ce-playground    文件:IncreaseLanguageLevelFix.java   
@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return false;
  final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
  if (module == null) return false;
  return JavaSdkUtil.isLanguageLevelAcceptable(project, module, myLevel);
}
项目:intellij-ce-playground    文件:IdeaProjectModelModifier.java   
@Override
public Promise<Void> changeLanguageLevel(@NotNull Module module, @NotNull LanguageLevel level) {
  final LanguageLevel moduleLevel = LanguageLevelModuleExtensionImpl.getInstance(module).getLanguageLevel();
  if (moduleLevel != null && JavaSdkUtil.isLanguageLevelAcceptable(myProject, module, level)) {
    final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
    rootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(level);
    rootModel.commit();
  }
  else {
    LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(level);
    ProjectRootManagerEx.getInstanceEx(myProject).makeRootsChange(EmptyRunnable.INSTANCE, false, true);
  }
  return Promise.DONE;
}
项目:intellij-ce-playground    文件:JUnitDependencyScopeSuggesterTest.java   
@Override
protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception {
  moduleBuilder.addLibrary("junit3", JavaSdkUtil.getJunit3JarPath());
  moduleBuilder.addLibrary("junit4", ArrayUtil.toStringArray(JavaSdkUtil.getJUnit4JarPaths()));
  moduleBuilder.addLibrary("ideaRt", JavaSdkUtil.getIdeaRtJarPath());
  moduleBuilder.addLibrary("empty");
}
项目:intellij-ce-playground    文件:JUnitClasspathTest.java   
private static String preparePathsForComparison(String fileContent, Module mod1, Module mod2) {
  fileContent = FileUtil.toSystemIndependentName(fileContent);
  fileContent = replace(fileContent, ModuleRootManager.getInstance(mod1).getContentRoots()[0].getPath(), "MODULE_1");
  fileContent = replace(fileContent, ModuleRootManager.getInstance(mod2).getContentRoots()[0].getPath(), "MODULE_2");
  fileContent = replace(fileContent, PathUtil.getJarPathForClass(ServiceMessageTypes.class), "SERVICE_MESSAGES");
  fileContent = fileContent.replaceAll(FileUtil.toSystemIndependentName(PathUtil.getJarPathForClass(JUnitStarter.class)) + File.pathSeparator, "");
  fileContent = fileContent.replaceAll(FileUtil.toSystemIndependentName(JavaSdkUtil.getIdeaRtJarPath()) + File.pathSeparator, "");
  fileContent = replace(fileContent, PathManager.getHomePath() + "/community", "IDEA_HOME");
  fileContent = replace(fileContent, PathManager.getHomePath(), "IDEA_HOME");
  fileContent = fileContent.replaceAll(File.pathSeparator, ";");
  return StringUtil.convertLineSeparators(fileContent);
}
项目:intellij-ce-playground    文件:EclipseClasspathReader.java   
static String getJunitClsUrl(final boolean version4) {
  String url = version4 ? JavaSdkUtil.getJunit4JarPath() : JavaSdkUtil.getJunit3JarPath();
  final VirtualFile localFile = VirtualFileManager.getInstance().findFileByUrl(pathToUrl(url));
  if (localFile != null) {
    final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(localFile);
    url = jarFile != null ? jarFile.getUrl() : localFile.getUrl();
  }

  return url;
}
项目:tools-idea    文件:EclipseClasspathReader.java   
static String getJunitClsUrl(final boolean version4) {
  String url = version4 ? JavaSdkUtil.getJunit4JarPath() : JavaSdkUtil.getJunit3JarPath();
  final VirtualFile localFile = VirtualFileManager.getInstance().findFileByUrl(pathToUrl(url));
  if (localFile != null) {
    final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(localFile);
    url = jarFile != null ? jarFile.getUrl() : localFile.getUrl();
  }

  return url;
}
项目:consulo-java    文件:ApplicationConfiguration.java   
private static void setupModulePath(OwnJavaParameters params, JavaRunConfigurationModule module)
{
    if(JavaSdkUtil.isJdkAtLeast(params.getJdk(), JavaSdkVersion.JDK_1_9))
    {
        PsiJavaModule mainModule = DumbService.getInstance(module.getProject()).computeWithAlternativeResolveEnabled(() -> JavaModuleGraphUtil.findDescriptorByElement(module.findClass(params
                .getMainClass())));
        if(mainModule != null)
        {
            params.setModuleName(mainModule.getName());
            PathsList classPath = params.getClassPath(), modulePath = params.getModulePath();
            modulePath.addAll(classPath.getPathList());
            classPath.clear();
        }
    }
}
项目:consulo-java    文件:IdeaProjectModelModifier.java   
@Override
@RequiredReadAction
public AsyncResult<Void> changeLanguageLevel(@NotNull Module module, @NotNull LanguageLevel level)
{
    if(JavaSdkUtil.isLanguageLevelAcceptable(myProject, module, level))
    {
        final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
        rootModel.getExtension(JavaMutableModuleExtension.class).getInheritableLanguageLevel().set(null, level);
        rootModel.commit();
    }
    return AsyncResult.done(null);
}
项目:intellij-ce-playground    文件:JUnitExternalLibraryDescriptor.java   
@NotNull
@Override
public List<String> getLibraryClassesRoots() {
  return Collections.singletonList(JavaSdkUtil.getJunit3JarPath());
}
项目:intellij-ce-playground    文件:JUnitExternalLibraryDescriptor.java   
@NotNull
@Override
public List<String> getLibraryClassesRoots() {
  return JavaSdkUtil.getJUnit4JarPaths();
}
项目:tools-idea    文件:JUnit4Framework.java   
@NotNull
public String getLibraryPath() {
  return JavaSdkUtil.getJunit4JarPath();
}
项目:tools-idea    文件:JUnit3Framework.java   
@NotNull
public String getLibraryPath() {
  return JavaSdkUtil.getJunit3JarPath();
}
项目:tools-idea    文件:GroovyTestFramework.java   
@NotNull
@Override
public String getLibraryPath() {
  return JavaSdkUtil.getJunit3JarPath();
}
项目:consulo-java    文件:JavaTestFrameworkRunnableState.java   
@Override
protected OwnJavaParameters createJavaParameters() throws ExecutionException
{
    final OwnJavaParameters javaParameters = new OwnJavaParameters();
    Project project = getConfiguration().getProject();
    javaParameters.setShortenCommandLine(getConfiguration().getShortenCommandLine(), project);
    final Module module = getConfiguration().getConfigurationModule().getModule();

    Sdk jdk = module == null ? null : ModuleUtilCore.getSdk(module, JavaModuleExtension.class);
    javaParameters.setJdk(jdk);

    final String parameters = getConfiguration().getProgramParameters();
    getConfiguration().setProgramParameters(null);
    try
    {
        JavaParametersUtil.configureConfiguration(javaParameters, getConfiguration());
    }
    finally
    {
        getConfiguration().setProgramParameters(parameters);
    }
    javaParameters.getClassPath().addFirst(JavaSdkUtil.getJavaRtJarPath());
    configureClasspath(javaParameters);

    final JavaTestPatcher[] patchers = JavaTestPatcher.EP_NAME.getExtensions();
    for(JavaTestPatcher patcher : patchers)
    {
        patcher.patchJavaParameters(module, javaParameters);
    }

    // Append coverage parameters if appropriate
    for(RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME))
    {
        ext.updateJavaParameters(getConfiguration(), javaParameters, getRunnerSettings());
    }

    if(!StringUtil.isEmptyOrSpaces(parameters))
    {
        javaParameters.getProgramParametersList().addAll(getNamedParams(parameters));
    }

    if(ConsoleBuffer.useCycleBuffer())
    {
        javaParameters.getVMParametersList().addProperty("idea.test.cyclic.buffer.size", String.valueOf(ConsoleBuffer.getCycleBufferSize()));
    }

    return javaParameters;
}
项目:consulo-java    文件:JavaTestFrameworkRunnableState.java   
protected void writeClassesPerModule(String packageName,
        OwnJavaParameters javaParameters,
        Map<Module, List<String>> perModule) throws FileNotFoundException, UnsupportedEncodingException, CantRunException
{
    if(perModule != null)
    {
        final String classpath = getScope() == TestSearchScope.WHOLE_PROJECT ? null : javaParameters.getClassPath().getPathsString();

        final PrintWriter wWriter = new PrintWriter(myWorkingDirsFile, CharsetToolkit.UTF8);
        try
        {
            wWriter.println(packageName);
            for(Module module : perModule.keySet())
            {
                wWriter.println(module.getModuleDirPath());
                wWriter.println(module.getName());

                if(classpath == null)
                {
                    final OwnJavaParameters parameters = new OwnJavaParameters();
                    parameters.getClassPath().add(JavaSdkUtil.getJavaRtJarPath());
                    configureRTClasspath(parameters);
                    JavaParametersUtil.configureModule(module, parameters, OwnJavaParameters.JDK_AND_CLASSES_AND_TESTS, getConfiguration().isAlternativeJrePathEnabled() ? getConfiguration()
                            .getAlternativeJrePath() : null);
                    wWriter.println(parameters.getClassPath().getPathsString());
                }
                else
                {
                    wWriter.println(classpath);
                }

                final List<String> classNames = perModule.get(module);
                wWriter.println(classNames.size());
                for(String className : classNames)
                {
                    wWriter.println(className);
                }
            }
        }
        finally
        {
            wWriter.close();
        }
    }
}
项目:consulo-java    文件:ProcessProxyFactoryImpl.java   
@Override
public ProcessProxy createCommandLineProxy(JavaCommandLine javaCmdLine) throws ExecutionException
{
    OwnJavaParameters javaParameters = javaCmdLine.getJavaParameters();
    String mainClass = javaParameters.getMainClass();

    if(ourMayUseLauncher && mainClass != null)
    {
        String rtJarPath = JavaSdkUtil.getJavaRtJarPath();
        boolean runtimeJarFile = new File(rtJarPath).isFile();

        if(runtimeJarFile || javaParameters.getModuleName() == null)
        {
            try
            {
                ProcessProxyImpl proxy = new ProcessProxyImpl(StringUtil.getShortName(mainClass));
                String port = String.valueOf(proxy.getPortNumber());
                String binPath = new File(PluginManager.getPluginPath(JavaClassNames.class), "breakgen").getPath();

                if(runtimeJarFile && JavaSdkUtil.isJdkAtLeast(javaParameters.getJdk(), JavaSdkVersion.JDK_1_5))
                {
                    javaParameters.getVMParametersList().add("-javaagent:" + rtJarPath + '=' + port + ':' + binPath);
                }
                else
                {
                    JavaSdkUtil.addRtJar(javaParameters.getClassPath());

                    ParametersList vmParametersList = javaParameters.getVMParametersList();
                    vmParametersList.defineProperty(AppMainV2.LAUNCHER_PORT_NUMBER, port);
                    vmParametersList.defineProperty(AppMainV2.LAUNCHER_BIN_PATH, binPath);

                    javaParameters.getProgramParametersList().prepend(mainClass);
                    javaParameters.setMainClass(AppMainV2.class.getName());
                }

                return proxy;
            }
            catch(Exception e)
            {
                Logger.getInstance(ProcessProxy.class).warn(e);
            }
        }
    }

    return null;
}