Java 类com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl 实例源码

项目:intellij-ce-playground    文件:CompilerTester.java   
public CompilerTester(Project project, List<Module> modules) throws Exception {
  myProject = project;
  myModules = modules;
  myMainOutput = new TempDirTestFixtureImpl();
  myMainOutput.setUp();

  CompilerTestUtil.enableExternalCompiler();
  new WriteCommandAction(getProject()) {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      //noinspection ConstantConditions
      CompilerProjectExtension.getInstance(getProject()).setCompilerOutputUrl(myMainOutput.findOrCreateDir("out").getUrl());
      for (Module module : myModules) {
        ModuleRootModificationUtil.setModuleSdk(module, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
      }
    }
  }.execute();
}
项目:intellij-ce-playground    文件:MavenServerManager.java   
@NotNull
private Sdk getJdk() {
  if (myState.embedderJdk.equals(MavenRunnerSettings.USE_JAVA_HOME)) {
    final String javaHome = System.getenv("JAVA_HOME");
    if (!StringUtil.isEmptyOrSpaces(javaHome)) {
      Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
      if (jdk != null) {
        return jdk;
      }
    }
  }

  for (Sdk projectJdk : ProjectJdkTable.getInstance().getAllJdks()) {
    if (projectJdk.getName().equals(myState.embedderJdk)) {
      return projectJdk;
    }
  }

  // By default use internal jdk
  return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
}
项目:tools-idea    文件:CompilerTester.java   
public CompilerTester(boolean externalMake, Module module) throws Exception {
  myExternalMake = externalMake;
  myModule = module;
  myMainOutput = new TempDirTestFixtureImpl();
  myMainOutput.setUp();

  CompilerManagerImpl.testSetup();
  new WriteCommandAction(getProject()) {
    @Override
    protected void run(Result result) throws Throwable {
      //noinspection ConstantConditions
      CompilerProjectExtension.getInstance(getProject()).setCompilerOutputUrl(myMainOutput.findOrCreateDir("out").getUrl());
      if (myExternalMake) {
        CompilerTestUtil.enableExternalCompiler(getProject());
        ModuleRootModificationUtil.setModuleSdk(myModule, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
      }
      else {
        CompilerTestUtil.disableExternalCompiler(getProject());
      }
    }
  }.execute();

}
项目:tools-idea    文件:EclipseCompiler.java   
private void createStartupCommand(final ModuleChunk chunk,
                                  @NonNls final ArrayList<String> commandLine,
                                  final String outputPath,
                                  final boolean useTempFile) throws IOException {
  final EclipseCompilerOptions options = EclipseCompilerConfiguration.getOptions(myProject, EclipseCompilerConfiguration.class);

  final Sdk projectJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  final String vmExePath = ((JavaSdkType)projectJdk.getSdkType()).getVMExecutablePath(projectJdk);
  commandLine.add(vmExePath);
  commandLine.add("-Xmx" + options.MAXIMUM_HEAP_SIZE + "m");

  CompilerUtil.addLocaleOptions(commandLine, false);

  commandLine.add("-classpath");
  commandLine.add(PATH_TO_COMPILER_JAR);
  commandLine.add(getCompilerClass());

  addCommandLineOptions(commandLine, chunk, outputPath, options, useTempFile, true);
}
项目:jgiven-intellij-plugin    文件:BaseTestCase.java   
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
    return new LightProjectDescriptor() {
        @Nullable
        @Override
        public Sdk getSdk() {
            return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
        }
    };
}
项目:intellij-ce-playground    文件:ExecutionTestCase.java   
protected JavaParameters createJavaParameters(String mainClass) {
  JavaParameters parameters = new JavaParameters();
  parameters.getClassPath().add(getAppOutputPath());
  parameters.setMainClass(mainClass);
  parameters.setJdk(JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
  parameters.setWorkingDirectory(getTestAppPath());
  return parameters;
}
项目:intellij-ce-playground    文件:CompilerTestUtil.java   
public static void enableExternalCompiler() {
  ApplicationManagerEx.getApplicationEx().doNotSave(false);
  final JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx();
  new WriteAction() {
    @Override
    protected void run(@NotNull final Result result) {
      table.addJdk(table.getInternalJdk());
    }
  }.execute();
}
项目:intellij-ce-playground    文件:JavaTestUtil.java   
public static Sdk getTestJdk() {
  try {
    ProjectJdkImpl jdk = (ProjectJdkImpl)JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().clone();
    jdk.setName(TEST_JDK_NAME);
    return jdk;
  }
  catch (CloneNotSupportedException e) {
    throw new RuntimeException(e);
  }
}
项目:intellij-ce-playground    文件:JavaCommandLineTest.java   
public void testClasspath() throws CantRunException {
  JavaParameters javaParameters;
  String commandLineString;

  javaParameters = new JavaParameters();
  final Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  javaParameters.setJdk(internalJdk);
  javaParameters.getClassPath().add("my-jar-file.jar");
  javaParameters.setMainClass("Main");
  commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
  assertTrue(containsClassPath(commandLineString));

  javaParameters = new JavaParameters();
  javaParameters.setJdk(internalJdk);
  javaParameters.getClassPath().add("my-jar-file.jar");
  javaParameters.setMainClass("Main");
  javaParameters.getVMParametersList().add("-cp");
  javaParameters.getVMParametersList().add("..");
  commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
  commandLineString = removeClassPath(commandLineString, "-cp ..");
  assertTrue(!containsClassPath(commandLineString));

  javaParameters = new JavaParameters();
  javaParameters.setJdk(internalJdk);
  javaParameters.getClassPath().add("my-jar-file.jar");
  javaParameters.setMainClass("Main");
  javaParameters.getVMParametersList().add("-classpath");
  javaParameters.getVMParametersList().add("..");
  commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
  commandLineString = removeClassPath(commandLineString, "-classpath ..");
  assertTrue(!containsClassPath(commandLineString));
}
项目:eddy    文件:Tests.java   
@Override
public Sdk getSdk() {
  try {
    ProjectJdkImpl jdk = (ProjectJdkImpl) JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().clone();
    jdk.setName("JDK");
    return jdk;
  } catch (CloneNotSupportedException e) {
    log("cloning not supported: " + e);
    return null;
  }
}
项目:intellij-pants-plugin    文件:PantsUtil.java   
/**
 * @return Path to IDEA Project JDK if exists, else null
 */
@Nullable
public static String getJdkPathFromIntelliJCore() {
  // Followed example in com.twitter.intellij.pants.testFramework.PantsIntegrationTestCase.setUpInWriteAction()
  final Sdk sdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  String javaHome = null;
  if (sdk.getHomeDirectory() != null) {
    javaHome = sdk.getHomeDirectory().getParent().getPath();
  }
  return javaHome;
}
项目:tools-idea    文件:ExecutionWithDebuggerToolsTestCase.java   
private Sdk getTestJdk() {
  try {
    ProjectJdkImpl jdk = (ProjectJdkImpl)JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().clone();
    jdk.setName("JDK");
    return jdk;
  }
  catch (CloneNotSupportedException e) {
    LOG.error(e);
    return null;
  }
}
项目:tools-idea    文件:ExecutionTestCase.java   
protected JavaParameters createJavaParameters(String mainClass) {
  JavaParameters parameters = new JavaParameters();
  parameters.getClassPath().add(getAppClassesPath());
  parameters.setMainClass(mainClass);
  parameters.setJdk(JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
  return parameters;
}
项目:tools-idea    文件:CompilerTestUtil.java   
public static void enableExternalCompiler(final Project project) {
  new WriteAction() {
    protected void run(final Result result) {
      CompilerWorkspaceConfiguration.getInstance(project).USE_COMPILE_SERVER = true;
      ApplicationManagerEx.getApplicationEx().doNotSave(false);
      JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx();
      table.addJdk(table.getInternalJdk());
    }
  }.execute();
}
项目:tools-idea    文件:CompilerTestUtil.java   
public static void disableExternalCompiler(final Project project) {
  new WriteAction() {
    protected void run(final Result result) {
      CompilerWorkspaceConfiguration.getInstance(project).USE_COMPILE_SERVER = false;
      ApplicationManagerEx.getApplicationEx().doNotSave(true);
      JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx();
      table.removeJdk(table.getInternalJdk());
      BuildManager.getInstance().stopWatchingProject(project);
    }
  }.execute();
}
项目:tools-idea    文件:JavaCommandLineTest.java   
public void testClasspath() throws CantRunException {
  JavaParameters javaParameters;
  String commandLineString;

  javaParameters = new JavaParameters();
  final Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  javaParameters.setJdk(internalJdk);
  javaParameters.setMainClass("Main");
  commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
  assertTrue(containsClassPath(commandLineString));

  javaParameters = new JavaParameters();
  javaParameters.setJdk(internalJdk);
  javaParameters.setMainClass("Main");
  javaParameters.getVMParametersList().add("-cp");
  javaParameters.getVMParametersList().add("..");
  commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
  commandLineString = removeClassPath(commandLineString, "-cp ..");
  assertTrue(!containsClassPath(commandLineString));

  javaParameters = new JavaParameters();
  javaParameters.setJdk(internalJdk);
  javaParameters.setMainClass("Main");
  javaParameters.getVMParametersList().add("-classpath");
  javaParameters.getVMParametersList().add("..");
  commandLineString = CommandLineBuilder.createFromJavaParameters(javaParameters).getCommandLineString();
  commandLineString = removeClassPath(commandLineString, "-classpath ..");
  assertTrue(!containsClassPath(commandLineString));
}
项目:tools-idea    文件:JavaTestUtil.java   
private static Sdk getTestJdk() {
  try {
    ProjectJdkImpl jdk = (ProjectJdkImpl)JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().clone();
    jdk.setName("JDK");
    return jdk;
  }
  catch (CloneNotSupportedException e) {
    //LOG.error(e);
    return null;
  }
}
项目:tools-idea    文件:BaseCompilerTestCase.java   
@Override
protected Sdk getTestProjectJdk() {
  if (useExternalCompiler()) {
    return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  }
  return super.getTestProjectJdk();
}
项目:Rearranger    文件:RearrangerTest.java   
protected Sdk getProjectJDK()
    {
//        return ProjectJdkTable.getInstance().getInternalJdk();  -- pre-IDEA 8.0 syntax
        ProjectJdkTable projectJdkTable = ProjectJdkTable.getInstance();
        return ((JavaAwareProjectJdkTableImpl)projectJdkTable).getInternalJdk();
    }
项目:intellij-ce-playground    文件:ExecutionTestCase.java   
@Override
protected Sdk getTestProjectJdk() {
  return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
}
项目:intellij-ce-playground    文件:BuildManager.java   
@NotNull
public static Pair<Sdk, JavaSdkVersion> getBuildProcessRuntimeSdk(Project project) {
  Sdk projectJdk = null;
  int sdkMinorVersion = 0;
  JavaSdkVersion sdkVersion = null;

  final Set<Sdk> candidates = new LinkedHashSet<Sdk>();
  final Sdk defaultSdk = ProjectRootManager.getInstance(project).getProjectSdk();
  if (defaultSdk != null && defaultSdk.getSdkType() instanceof JavaSdkType) {
    candidates.add(defaultSdk);
  }

  for (Module module : ModuleManager.getInstance(project).getModules()) {
    final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
      candidates.add(sdk);
    }
  }

  // now select the latest version from the sdks that are used in the project, but not older than the internal sdk version
  final JavaSdk javaSdkType = JavaSdk.getInstance();
  for (Sdk candidate : candidates) {
    final String vs = candidate.getVersionString();
    if (vs != null) {
      final JavaSdkVersion candidateVersion = javaSdkType.getVersion(vs);
      if (candidateVersion != null) {
        final int candidateMinorVersion = getMinorVersion(vs);
        if (projectJdk == null) {
          sdkVersion = candidateVersion;
          sdkMinorVersion = candidateMinorVersion;
          projectJdk = candidate;
        }
        else {
          final int result = candidateVersion.compareTo(sdkVersion);
          if (result > 0 || (result == 0 && candidateMinorVersion > sdkMinorVersion)) {
            sdkVersion = candidateVersion;
            sdkMinorVersion = candidateMinorVersion;
            projectJdk = candidate;
          }
        }
      }
    }
  }

  final Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  if (projectJdk == null || sdkVersion == null || !sdkVersion.isAtLeast(JavaSdkVersion.JDK_1_6)) {
    projectJdk = internalJdk;
    sdkVersion = javaSdkType.getVersion(internalJdk);
  }
  return Pair.create(projectJdk, sdkVersion);
}
项目:intellij-ce-playground    文件:BaseCompilerTestCase.java   
@Override
protected Sdk getTestProjectJdk() {
  return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
}
项目:intellij-ce-playground    文件:ExternalSystemJdkUtil.java   
@Nullable
public static Sdk getJdk(@Nullable Project project, @Nullable String jdkName) throws ExternalSystemJdkException {
  if (jdkName == null) return null;

  if (USE_INTERNAL_JAVA.equals(jdkName)) {
    return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  }

  if (USE_PROJECT_JDK.equals(jdkName)) {
    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 ProjectJdkNotFoundException();
  }

  if (USE_JAVA_HOME.equals(jdkName)) {
    final String javaHome = System.getenv("JAVA_HOME");
    if (StringUtil.isEmptyOrSpaces(javaHome)) {
      throw new UndefinedJavaHomeException();
    }

    if (JdkUtil.checkForJdk(new File(javaHome)) || JdkUtil.checkForJre(javaHome)) {
      final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
      if (jdk == null) {
        throw new InvalidJavaHomeException(javaHome);
      }
      return jdk;
    }
    else {
      throw new InvalidJavaHomeException(javaHome);
    }
  }

  for (Sdk projectJdk : ProjectJdkTable.getInstance().getAllJdks()) {
    if (projectJdk.getName().equals(jdkName)) {
      if (projectJdk.getHomePath() != null &&
          (JdkUtil.checkForJdk(new File(projectJdk.getHomePath())) || JdkUtil.checkForJre(projectJdk.getHomePath()))) {
        return projectJdk;
      }
      else {
        throw new InvalidSdkException(projectJdk.getHomePath());
      }
    }
  }

  return null;
}
项目:intellij-ce-playground    文件:ExternalSystemTestCase.java   
protected Sdk setupJdkForModule(final String moduleName) {
  final Sdk sdk = true ? JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk() : createJdk("Java 1.5");
  ModuleRootModificationUtil.setModuleSdk(getModule(moduleName), sdk);
  return sdk;
}
项目:intellij-ce-playground    文件:ExternalSystemImportingTestCase.java   
protected Sdk setupJdkForModule(final String moduleName) {
  final Sdk sdk = true ? JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk() : createJdk("Java 1.5");
  ModuleRootModificationUtil.setModuleSdk(getModule(moduleName), sdk);
  return sdk;
}
项目:intellij-ce-playground    文件:MavenExternalParameters.java   
@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));
  }
}
项目:intellij-ce-playground    文件:MavenImportingTestCase.java   
protected Sdk setupJdkForModule(final String moduleName) {
  final Sdk sdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  ModuleRootModificationUtil.setModuleSdk(getModule(moduleName), sdk);
  return sdk;
}
项目:tools-idea    文件:MavenExternalParameters.java   
@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));
  }
}
项目:tools-idea    文件:MavenImportingTestCase.java   
protected Sdk setupJdkForModule(final String moduleName) {
  final Sdk sdk = useJps()? JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk() : createJdk("Java 1.5");
  ModuleRootModificationUtil.setModuleSdk(getModule(moduleName), sdk);
  return sdk;
}