Java Code Examples for com.intellij.openapi.projectRoots.Sdk

The following are top voted examples for showing how to use com.intellij.openapi.projectRoots.Sdk. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: green-cat   File: Utils.java   Source Code and License 6 votes vote down vote up
public static String getAndroidSdkPath(Project project) {
    ModuleManager manager = ModuleManager.getInstance(project);
    String androidSdkPath = null;

    for (Module module : manager.getModules()) {
        if (androidSdkPath != null) {
            break;
        }
        Sdk sdk = ModuleRootManager.getInstance(module).getSdk();

        if (sdk != null && sdk.getHomePath() != null) {
            File file = new File(sdk.getHomePath());
            String[] contents = file.list();

            if (contents != null) {
                for (String path : contents) {
                    if (path.equals("build-tools")) {
                        androidSdkPath = sdk.getHomePath();
                        break;
                    }
                }
            }
        }
    }
    return androidSdkPath;
}
 
Example 2
Project: hybris-integration-intellij-idea-plugin   File: ImportProjectProgressModalWindow.java   Source Code and License 6 votes vote down vote up
private void selectSdk(@NotNull final Project project) {
    Validate.notNull(project);

    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);

    final Sdk projectSdk = projectRootManager.getProjectSdk();

    if (null == projectSdk) {
        return;
    }

    if (StringUtils.isNotBlank(projectSdk.getVersionString())) {
        final JavaSdkVersion sdkVersion = JdkVersionUtil.getVersion(projectSdk.getVersionString());
        final LanguageLevelProjectExtension languageLevelExt = LanguageLevelProjectExtension.getInstance(project);

        if (sdkVersion.getMaxLanguageLevel() != languageLevelExt.getLanguageLevel()) {
            languageLevelExt.setLanguageLevel(sdkVersion.getMaxLanguageLevel());
        }
    }
}
 
Example 3
Project: hybris-integration-intellij-idea-plugin   File: ProjectRefreshAction.java   Source Code and License 6 votes vote down vote up
private AddModuleWizard getWizard(final Project project) throws ConfigurationException {
    final HybrisProjectImportProvider provider = getHybrisProjectImportProvider();
    final String basePath = project.getBasePath();
    final String projectName = project.getName();
    final Sdk jdk = ProjectRootManager.getInstance(project).getProjectSdk();
    final String compilerOutputUrl = CompilerProjectExtension.getInstance(project).getCompilerOutputUrl();
    final HybrisProjectSettings settings = HybrisProjectSettingsComponent.getInstance(project).getState();

    final AddModuleWizard wizard = new AddModuleWizard(null, basePath, provider) {

        protected void init() {
            // non GUI mode
        }
    };
    final WizardContext wizardContext = wizard.getWizardContext();
    wizardContext.setProjectJdk(jdk);
    wizardContext.setProjectName(projectName);
    wizardContext.setCompilerOutputDirectory(compilerOutputUrl);
    final StepSequence stepSequence = wizard.getSequence();
    for (ModuleWizardStep step : stepSequence.getAllSteps()) {
        if (step instanceof NonGuiSupport) {
            ((NonGuiSupport) step).nonGuiModeImport(settings);
        }
    }
    return wizard;
}
 
Example 4
Project: educational-plugin   File: PyStudyDirectoryProjectGenerator.java   Source Code and License 6 votes vote down vote up
private static Sdk addDetectedSdk(@NotNull Sdk sdk, @NotNull Project project) {
  final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
  final String name = sdk.getName();
  VirtualFile sdkHome = WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByPath(name));
  sdk = SdkConfigurationUtil.createAndAddSDK(sdkHome.getPath(), PythonSdkType.getInstance());
  if (sdk != null) {
    PythonSdkUpdater.updateOrShowError(sdk, null, project, null);
  }

  model.addSdk(sdk);
  try {
    model.apply();
  }
  catch (ConfigurationException exception) {
    LOG.error("Error adding detected python interpreter " + exception.getMessage());
  }
  return sdk;
}
 
Example 5
Project: educational-plugin   File: PyStudyDirectoryProjectGenerator.java   Source Code and License 6 votes vote down vote up
@Nullable
@Override
public BooleanFunction<PythonProjectGenerator> beforeProjectGenerated(@Nullable Sdk sdk) {
  return generator -> {
    final List<Integer> enrolledCoursesIds = myGenerator.getEnrolledCoursesIds();
    final Course course = myGenerator.getSelectedCourse();
    if (course == null || !(course instanceof RemoteCourse)) return true;
    if (((RemoteCourse)course).getId() > 0 && !enrolledCoursesIds.contains(((RemoteCourse)course).getId())) {
      ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
        return StudyUtils.execCancelable(() -> EduStepicConnector.enrollToCourse(((RemoteCourse)course).getId(),
                                                                                 StudySettings.getInstance().getUser()));
      }, "Creating Course", true, ProjectManager.getInstance().getDefaultProject());
    }
    return true;
  };
}
 
Example 6
Project: lua-for-idea   File: GenerateLuaListingAction.java   Source Code and License 6 votes vote down vote up
@Override
public void update(AnActionEvent e) {
    e.getPresentation().setVisible(false);
    e.getPresentation().setEnabled(false);
    Project project = e.getData(LangDataKeys.PROJECT);
    if (project != null) {
        for (Module module : ModuleManager.getInstance(project).getModules()) {
            e.getPresentation().setVisible(true);
            Sdk luaSdk = LuaSdkType.findLuaSdk(module);
            if (luaSdk == null) continue;

            final String homePath = luaSdk.getHomePath();
            if (homePath == null) continue;

            if (LuaSdkType.getByteCodeCompilerExecutable(homePath).exists()) {
                e.getPresentation().setEnabled(true);
                break;
            }
        }
    }
}
 
Example 7
Project: intellij-ce-playground   File: PyStudyIntroductionCourseAction.java   Source Code and License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final File projectDir = new File(ProjectUtil.getBaseDir(), INTRODUCTION_FOLDER);
  if (projectDir.exists()) {
    ProjectUtil.openProject(projectDir.getPath(), null, false);
  }
  else {
    final PyStudyDirectoryProjectGenerator generator = new PyStudyDirectoryProjectGenerator();
    CourseInfo introCourse = getIntroCourseInfo(generator.getCourses());
    if (introCourse == null) {
      return;
    }
    final GenerateProjectCallback callback = new GenerateProjectCallback();
    final ProjectSpecificSettingsStep step = new ProjectSpecificSettingsStep(generator, callback);
    step.createPanel(); // initialize panel to set location
    step.setLocation(projectDir.toString());
    generator.setSelectedCourse(introCourse);

    final Project project = ProjectManager.getInstance().getDefaultProject();
    final List<Sdk> sdks = PyConfigurableInterpreterList.getInstance(project).getAllPythonSdks();
    Sdk sdk = sdks.isEmpty() ? null : sdks.iterator().next();
    step.setSdk(sdk);
    callback.consume(step);
  }
}
 
Example 8
Project: intellij-ce-playground   File: ProjectRootManagerImpl.java   Source Code and License 6 votes vote down vote up
@Override
public void jdkNameChanged(final Sdk jdk, final String previousName) {
  mergeRootsChangesDuring(new Runnable() {
    @Override
    public void run() {
      for (ProjectJdkTable.Listener listener : getListeners()) {
        listener.jdkNameChanged(jdk, previousName);
      }
    }
  });
  String currentName = getProjectSdkName();
  if (previousName != null && previousName.equals(currentName)) {
    // if already had jdk name and that name was the name of the jdk just changed
    myProjectSdkName = jdk.getName();
    myProjectSdkType = jdk.getSdkType().getName();
  }
}
 
Example 9
Project: intellij-ce-playground   File: PyRemoteProcessStarter.java   Source Code and License 6 votes vote down vote up
protected PyRemoteProcessHandlerBase doStartRemoteProcess(@NotNull Sdk sdk,
                                                          @NotNull final GeneralCommandLine commandLine,
                                                          @NotNull final PythonRemoteInterpreterManager manager,
                                                          @Nullable final Project project,
                                                          @Nullable PyRemotePathMapper pathMapper)
  throws ExecutionException {
  SdkAdditionalData data = sdk.getSdkAdditionalData();
  assert data instanceof PyRemoteSdkAdditionalDataBase;
  final PyRemoteSdkAdditionalDataBase pyRemoteSdkAdditionalDataBase = (PyRemoteSdkAdditionalDataBase)data;

  final PyRemotePathMapper extendedPathMapper = manager.setupMappings(project, pyRemoteSdkAdditionalDataBase, pathMapper);

  try {
    return PyRemoteProcessStarterManagerUtil
      .getManager(pyRemoteSdkAdditionalDataBase).startRemoteProcess(project, commandLine, manager, pyRemoteSdkAdditionalDataBase,
                                                   extendedPathMapper);
  }
  catch (InterruptedException e) {
    throw new ExecutionException(e);
  }
}
 
Example 10
Project: intellij-ce-playground   File: JavaFxChunkBuildExtension.java   Source Code and License 6 votes vote down vote up
@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);
  }
}
 
Example 11
Project: intellij-ce-playground   File: PythonSdkUpdater.java   Source Code and License 6 votes vote down vote up
public static void updateActiveSdks(@NotNull final Project project, final int delay) {
  final Set<Sdk> sdksToUpdate = new HashSet<Sdk>();
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    final Sdk sdk = PythonSdkType.findPythonSdk(module);
    if (sdk != null) {
      final SdkTypeId sdkType = sdk.getSdkType();
      if (sdkType instanceof PythonSdkType) {
        sdksToUpdate.add(sdk);
      }
    }
  }

  // NOTE: everything is run later on the AWT thread
  if (!sdksToUpdate.isEmpty()) {
    updateSdks(project, delay, sdksToUpdate);
  }
}
 
Example 12
Project: intellij-ce-playground   File: LightProjectDescriptor.java   Source Code and License 6 votes vote down vote up
protected void createContentEntry(@NotNull final Module module, @NotNull final VirtualFile srcRoot) {
  updateModel(module, new Consumer<ModifiableRootModel>() {
    @Override
    public void consume(ModifiableRootModel model) {
      Sdk sdk = getSdk();
      if (sdk != null) {
        model.setSdk(sdk);
      }

      ContentEntry contentEntry = model.addContentEntry(srcRoot);
      contentEntry.addSourceFolder(srcRoot, false);

      configureModule(module, model, contentEntry);
    }
  });
}
 
Example 13
Project: intellij-ce-playground   File: RootsChangedTest.java   Source Code and License 6 votes vote down vote up
public void testEditLibraryForModuleLoadFromXml() throws IOException {
  final File tempDirectory = createTempDirectory();
  ApplicationManager.getApplication().runWriteAction(() -> {
    Module a = loadModule(PathManagerEx.getHomePath(getClass()) + "/java/java-tests/testData/moduleRootManager/rootsChanged/emptyModule/a.iml");
    assertEventsCount(1);

    final Sdk jdk = IdeaTestUtil.getMockJdk17();
    ProjectJdkTable.getInstance().addJdk(jdk);
    assertEventsCount(0);

    ModuleRootModificationUtil.setModuleSdk(a, jdk);
    assertEventsCount(1);

    final SdkModificator sdkModificator = jdk.getSdkModificator();
    sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
    sdkModificator.commitChanges();
  });

  assertEventsCount(1);
}
 
Example 14
Project: intellij-ce-playground   File: SphinxDirectiveCompletionContributor.java   Source Code and License 6 votes vote down vote up
public SphinxDirectiveCompletionContributor() {
  extend(CompletionType.BASIC, DIRECTIVE_PATTERN,
     new CompletionProvider<CompletionParameters>() {
       @Override
       protected void addCompletions(@NotNull CompletionParameters parameters,
                                     ProcessingContext context,
                                     @NotNull CompletionResultSet result) {
         Sdk sdk = ProjectRootManager.getInstance(parameters.getPosition().getProject()).getProjectSdk();
         if (sdk != null) {
           for (String tag : RestUtil.SPHINX_DIRECTIVES) {
             result.addElement(LookupElementBuilder.create(tag));
           }
         }
       }
     }
     );
}
 
Example 15
Project: intellij-ce-playground   File: PythonSdkTableListener.java   Source Code and License 6 votes vote down vote up
private static void renameLibrary(final Sdk sdk, final String previousName) {
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        public void run() {
          final LibraryTable.ModifiableModel libraryTableModel =
            ModifiableModelsProvider.SERVICE.getInstance().getLibraryTableModifiableModel();
          final Library library = libraryTableModel.getLibraryByName(PythonFacet.getFacetLibraryName(previousName));
          if (library != null) {
            final Library.ModifiableModel model = library.getModifiableModel();
            model.setName(PythonFacet.getFacetLibraryName(sdk.getName()));
            model.commit();
          }
          libraryTableModel.commit();
        }
      });
    }
  }, ModalityState.NON_MODAL);
}
 
Example 16
Project: jgiven-intellij-plugin   File: BaseTestCase.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
    return new LightProjectDescriptor() {
        @Nullable
        @Override
        public Sdk getSdk() {
            return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
        }
    };
}
 
Example 17
Project: SmartTomcat   File: PluginUtils.java   Source Code and License 5 votes vote down vote up
public static Sdk getDefaultJDK(){
    Sdk[] allJdks = ProjectJdkTable.getInstance().getAllJdks();
    if (allJdks == null || allJdks.length == 0) {
        throw new RuntimeException("Please setup your project JDK first");
    }
    Sdk jdk = allJdks[0];
    return jdk;
}
 
Example 18
Project: CopyCurrentActivity   File: CopyCurrentActivityAction.java   Source Code and License 5 votes vote down vote up
@Nullable
private String getAndroidSdkPath() {
    Sdk[] allSdks = ProjectJdkTable.getInstance().getAllJdks();
    for (Sdk sdk : allSdks) {
        String sdkTypeName = sdk.getSdkType().getName();
        if (ANDROID_SDK_TYPE_NAME.equals(sdkTypeName)) {
            return sdk.getHomePath();
        }
    }
    return null;
}
 
Example 19
Project: educational-plugin   File: PyStudyDirectoryProjectGenerator.java   Source Code and License 5 votes vote down vote up
@Override
public void afterProjectGenerated(@NotNull Project project) {
  Sdk sdk = mySettings.getSdk();

  if (sdk == PLACEHOLDER_SDK) {
    createAndAddVirtualEnv(project, mySettings);
    sdk = mySettings.getSdk();
  }
  if (sdk instanceof PyDetectedSdk) {
    sdk = addDetectedSdk(sdk, project);
  }
  SdkConfigurationUtil.setDirectoryProjectSdk(project, sdk);
}
 
Example 20
Project: educational-plugin   File: PyStudyDirectoryProjectGenerator.java   Source Code and License 5 votes vote down vote up
@Nullable
@Override
public LabeledComponent<JComponent> getLanguageSettingsComponent(@NotNull Course selectedCourse) {
  final Project project = ProjectManager.getInstance().getDefaultProject();
  PyConfigurableInterpreterList instance = PyConfigurableInterpreterList.getInstance(project);
  if (instance == null) {
    return null;
  }
  final List<Sdk> sdks = instance.getAllPythonSdks();
  VirtualEnvProjectFilter.removeAllAssociated(sdks);
  // by default we create new virtual env in project, we need to add this non-existing sdk to sdk list
  ProjectJdkImpl fakeSdk = createFakeSdk(selectedCourse);
  if (fakeSdk != null) {
    sdks.add(0, fakeSdk);
  }
  PythonSdkChooserCombo combo = new PythonSdkChooserCombo(project, sdks, sdk -> true);
  if (fakeSdk != null) {
    patchRenderer(fakeSdk, combo);
    combo.getComboBox().setSelectedItem(fakeSdk);
  }
  if (SystemInfo.isMac && !UIUtil.isUnderDarcula()) {
    combo.putClientProperty("JButton.buttonType", null);
  }
  combo.setButtonIcon(PythonIcons.Python.InterpreterGear);
  combo.addChangedListener(e -> {
    Sdk selectedSdk = (Sdk)combo.getComboBox().getSelectedItem();
    mySettings.setSdk(selectedSdk == fakeSdk ? null : selectedSdk);
  });
  return LabeledComponent.create(combo, "Interpreter", BorderLayout.WEST);
}
 
Example 21
Project: educational-plugin   File: PyStudyDirectoryProjectGenerator.java   Source Code and License 5 votes vote down vote up
public void createAndAddVirtualEnv(Project project, PyNewProjectSettings settings) {
  final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
  Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course == null) {
    return;
  }
  final String baseSdk = getBaseSdk(course);

  if (baseSdk != null) {
    final PyPackageManager packageManager = PyPackageManager.getInstance(new PyDetectedSdk(baseSdk));
    try {
      final String path = packageManager.createVirtualEnv(project.getBasePath() + "/.idea/VirtualEnvironment", false);
      AbstractCreateVirtualEnvDialog.setupVirtualEnvSdk(path, true, new AbstractCreateVirtualEnvDialog.VirtualEnvCallback() {
        @Override
        public void virtualEnvCreated(Sdk createdSdk, boolean associateWithProject) {
          settings.setSdk(createdSdk);
          model.addSdk(createdSdk);
          try {
            model.apply();
          }
          catch (ConfigurationException exception) {
            LOG.error("Error adding created virtual env " + exception.getMessage());
          }
          if (associateWithProject) {
            SdkAdditionalData additionalData = createdSdk.getSdkAdditionalData();
            if (additionalData == null) {
              additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(createdSdk.getHomePath()));
              ((ProjectJdkImpl)createdSdk).setSdkAdditionalData(additionalData);
            }
            ((PythonSdkAdditionalData)additionalData).associateWithNewProject();
          }
        }
      });
    }
    catch (ExecutionException e) {
      LOG.warn("Failed to create virtual env " + e.getMessage());
    }
  }
}
 
Example 22
Project: educational-plugin   File: PyStudyTestRunner.java   Source Code and License 5 votes vote down vote up
Process createCheckProcess(@NotNull final Project project, @NotNull final String executablePath) throws ExecutionException {
  final Sdk sdk = PythonSdkType.findPythonSdk(ModuleManager.getInstance(project).getModules()[0]);
  PyEduPluginConfigurator configurator = new PyEduPluginConfigurator();
  String testsFileName = configurator.getTestFileName();
  if (myTask instanceof TaskWithSubtasks) {
    testsFileName = FileUtil.getNameWithoutExtension(testsFileName);
    int index = ((TaskWithSubtasks)myTask).getActiveSubtaskIndex();
    testsFileName += EduNames.SUBTASK_MARKER + index + "." + FileUtilRt.getExtension(configurator.getTestFileName());
  }
  final File testRunner = new File(myTaskDir.getPath(), testsFileName);
  myCommandLine = new GeneralCommandLine();
  myCommandLine.withWorkDirectory(myTaskDir.getPath());
  final Map<String, String> env = myCommandLine.getEnvironment();

  final VirtualFile courseDir = project.getBaseDir();
  if (courseDir != null) {
    env.put(PYTHONPATH, courseDir.getPath());
  }
  if (sdk != null) {
    String pythonPath = sdk.getHomePath();
    if (pythonPath != null) {
      myCommandLine.setExePath(pythonPath);
      myCommandLine.addParameter(testRunner.getPath());
      myCommandLine.addParameter(FileUtil.toSystemDependentName(executablePath));
      return myCommandLine.createProcess();
    }
  }
  return null;
}
 
Example 23
Project: manifold-ij   File: ManProject.java   Source Code and License 5 votes vote down vote up
private int findJdkVersion()
{
  Sdk projectSdk = ProjectRootManager.getInstance( _ijProject ).getProjectSdk();
  if( projectSdk == null )
  {
    return -1;
  }

  // expected format:
  // 'java version "1.8.1"'
  // 'java version "9.0.1"'
  // 'java version "10.0.1"'
  // etc.
  String version = projectSdk.getVersionString();
  int iQuote = version.indexOf( '"' );
  if( iQuote < 0 )
  {
    return -1;
  }

  String verNum = version.substring( iQuote+1 );
  int iDot = verNum.indexOf( '.' );
  if( iDot < 0 )
  {
    return -1;
  }

  verNum = verNum.substring( 0, iDot );
  if( verNum.equals( "1" ) )
  {
    return 8;
  }
  else
  {
    return Integer.parseInt( verNum );
  }
}
 
Example 24
Project: manifold-ij   File: AbstractManifoldCodeInsightTest.java   Source Code and License 5 votes vote down vote up
@Override
public Sdk getSdk()
{
  return _sdk == null
         ? _sdk = JavaSdk.getInstance().createJdk( getJdkVersion(), getPath_JdkRoot() + File.separatorChar + getJdkVersion(), false )
         : _sdk;
}
 
Example 25
Project: lua-for-idea   File: LuaSdkChooserPanel.java   Source Code and License 5 votes vote down vote up
public LuaSdkChooserPanel(final Project project) {
    myJdkChooser = new JdkChooserPanel(project);

    setLayout(new GridBagLayout());
    setBorder(BorderFactory.createEtchedBorder());

    final JLabel label = new JLabel(LuaBundle.message("sdk.chooser.luabinaries.prompt"));
    label.setUI(new MultiLineLabelUI());
    add(label, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL, new Insets(8, 10, 8, 10), 0, 0));

    final JLabel jdkLabel = new JLabel(LuaBundle.message("sdk.chooser.select.sdk.prompt"));
    jdkLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
    add(jdkLabel,
            new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST,
                    GridBagConstraints.NONE, new Insets(8, 10, 0, 10), 0, 0));

    add(myJdkChooser,
            new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
                    GridBagConstraints.BOTH, new Insets(2, 10, 10, 5), 0, 0));
    JButton configureButton = new JButton(LuaBundle.message("sdk.chooser.configure.button"));
    add(configureButton,
            new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST,
                    GridBagConstraints.NONE, new Insets(2, 0, 10, 5), 0, 0));

    configureButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myJdkChooser.editJdkTable();
        }
    });

    myJdkChooser.setAllowedJdkTypes(new SdkType[]{LuaSdkType.getInstance()});

    final Sdk selectedJdk = project == null ? null : ProjectRootManager.getInstance(project).getProjectSdk();

    myJdkChooser.fillList(LuaSdkType.getInstance(), null);
    if (selectedJdk != null) {
        myJdkChooser.selectJdk(selectedJdk);
    }
}
 
Example 26
Project: intellij-ce-playground   File: NamedLibraryElementNode.java   Source Code and License 5 votes vote down vote up
private static Icon getJdkIcon(JdkOrderEntry entry) {
  final Sdk sdk = entry.getJdk();
  if (sdk == null) {
    return AllIcons.General.Jdk;
  }
  final SdkType sdkType = (SdkType) sdk.getSdkType();
  return sdkType.getIcon();
}
 
Example 27
Project: intellij-ce-playground   File: SdkConfigurationUtil.java   Source Code and License 5 votes vote down vote up
public static void addSdk(@NotNull final Sdk sdk) {
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      ProjectJdkTable.getInstance().addJdk(sdk);
    }
  });
}
 
Example 28
Project: intellij-ce-playground   File: AndroidSdkUtils.java   Source Code and License 5 votes vote down vote up
@VisibleForTesting
static boolean tryToCreateAndSetAndroidSdk(@NotNull Module module, @NotNull String sdkPath, @NotNull String targetHashString) {
  File path = new File(toSystemDependentName(sdkPath));
  Sdk sdk = tryToCreateAndroidSdk(path, targetHashString);
  if (sdk != null) {
    setModuleSdk(module, sdk);
    return true;
  }
  return false;
}
 
Example 29
Project: intellij-ce-playground   File: PythonSdkUpdater.java   Source Code and License 5 votes vote down vote up
private static void updateSdks(final Project project, final int delay, final Set<Sdk> sdksToUpdate) {
  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    public void run() {
      if (delay > 0) {
        try {
          Thread.sleep(delay); // wait until all short-term disk-hitting activity ceases
        }
        catch (InterruptedException ignore) {
        }
      }
      // update skeletons
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          ProgressManager.getInstance().run(new Task.Backgroundable(project, PyBundle.message("sdk.gen.updating.skels"), false) {
            @Override
            public void run(@NotNull ProgressIndicator indicator) {
              for (final Sdk sdk : sdksToUpdate) {
                updateSdk(sdk, project);
              }
            }
          });
        }
      });
    }
  });
}
 
Example 30
Project: lua-for-idea   File: LuaRunConfiguration.java   Source Code and License 5 votes vote down vote up
public Sdk getSdk() {
    RunConfigurationModule runConfigurationModule = getConfigurationModule();
    Module currentModule = runConfigurationModule.getModule();
    if (currentModule != null)
        return LuaSdkType.findLuaSdk(currentModule);
    Project currentProject = runConfigurationModule.getProject();
    return ProjectRootManager.getInstance(currentProject).getProjectSdk();
}
 
Example 31
Project: intellij-ce-playground   File: PythonSdkDetailsDialog.java   Source Code and License 5 votes vote down vote up
private void editRemoteSdk(Sdk currentSdk) {
  PythonRemoteInterpreterManager remoteInterpreterManager = PythonRemoteInterpreterManager.getInstance();
  if (remoteInterpreterManager != null) {
    final SdkModificator modificator = myModificators.get(currentSdk);
    Set<Sdk> existingSdks = Sets.newHashSet(myProjectSdksModel.getSdks());
    existingSdks.remove(currentSdk);
    if (remoteInterpreterManager.editSdk(myProject, modificator, existingSdks)) {
      myModifiedModificators.add(modificator);
    }
  }
}
 
Example 32
Project: intellij-ce-playground   File: PlatformTestCase.java   Source Code and License 5 votes vote down vote up
protected void setUpJdk() {
    //final ProjectJdkEx jdk = ProjectJdkUtil.getDefaultJdk("java 1.4");
    final Sdk jdk = getTestProjectJdk();
//    ProjectJdkImpl jdk = ProjectJdkTable.getInstance().addJdk(defaultJdk);
    Module[] modules = ModuleManager.getInstance(myProject).getModules();
    for (Module module : modules) {
      ModuleRootModificationUtil.setModuleSdk(module, jdk);
    }
  }
 
Example 33
Project: intellij   File: BlazeAndroidSyncPlugin.java   Source Code and License 5 votes vote down vote up
@Override
public void updateProjectSdk(
    Project project,
    BlazeContext context,
    ProjectViewSet projectViewSet,
    BlazeVersionData blazeVersionData,
    BlazeProjectData blazeProjectData) {
  if (!isAndroidWorkspace(blazeProjectData.workspaceLanguageSettings)) {
    return;
  }
  BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
  if (syncData == null) {
    return;
  }
  AndroidSdkPlatform androidSdkPlatform = syncData.androidSdkPlatform;
  if (androidSdkPlatform == null) {
    return;
  }
  Sdk sdk = BlazeSdkProvider.getInstance().findSdk(androidSdkPlatform.androidSdk);
  if (sdk == null) {
    IssueOutput.error(
            String.format("Android platform '%s' not found.", androidSdkPlatform.androidSdk))
        .submit(context);
    return;
  }

  LanguageLevel defaultLanguageLevel =
      BuildSystemAndroidJdkProvider.languageLevel(
          Blaze.getBuildSystem(project), blazeVersionData);
  LanguageLevel javaLanguageLevel =
      JavaLanguageLevelSection.getLanguageLevel(projectViewSet, defaultLanguageLevel);
  setProjectSdkAndLanguageLevel(project, sdk, javaLanguageLevel);
}
 
Example 34
Project: intellij-ce-playground   File: JavaCommandLineTest.java   Source Code and License 5 votes vote down vote up
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));
}
 
Example 35
Project: intellij-ce-playground   File: PyActiveSdkConfigurable.java   Source Code and License 5 votes vote down vote up
private void rehighlightVersionSpecific(@Nullable final Sdk newSdk, @Nullable final Sdk prevSdk) {
  if (prevSdk != null && newSdk != null) {
    final PythonSdkFlavor flavor1 = PythonSdkFlavor.getFlavor(newSdk);
    final PythonSdkFlavor flavor2 = PythonSdkFlavor.getFlavor(prevSdk);
    if (flavor1 != null && flavor2 != null) {
      final LanguageLevel languageLevel1 = flavor1.getLanguageLevel(newSdk);
      final LanguageLevel languageLevel2 = flavor2.getLanguageLevel(prevSdk);
      if ((languageLevel1.isPy3K() && !languageLevel2.isPy3K()) ||
          (!languageLevel1.isPy3K()) && languageLevel2.isPy3K()) {
        PyUtil.rehighlightOpenEditors(myProject);
      }
    }
  }
}
 
Example 36
Project: intellij-ce-playground   File: PythonConsoleView.java   Source Code and License 5 votes vote down vote up
public PythonConsoleView(final Project project, final String title, final Sdk sdk) {
  super(project, title, PythonLanguage.getInstance());

  getVirtualFile().putUserData(LanguageLevel.KEY, PythonSdkType.getLanguageLevelForSdk(sdk));
  // Mark editor as console one, to prevent autopopup completion
  getConsoleEditor().putUserData(PythonConsoleAutopopupBlockingHandler.REPL_KEY, new Object());

  setPrompt(PyConsoleUtil.ORDINARY_PROMPT);
  setUpdateFoldingsEnabled(false);
  //noinspection ConstantConditions
  myPyHighlighter = new PyHighlighter(
    sdk != null && sdk.getVersionString() != null ? LanguageLevel.fromPythonVersion(sdk.getVersionString()) : LanguageLevel.getDefault());
  myScheme = getConsoleEditor().getColorsScheme();
}
 
Example 37
Project: intellij-ce-playground   File: AndroidSdkModuleCustomizer.java   Source Code and License 5 votes vote down vote up
/**
 * Sets an Android SDK to the given module only if:
 * <ol>
 * <li>the given module was created by importing an {@code AndroidProject}</li>
 * <li>there is a matching Android SDK already defined in IDEA</li>
 * </ol>
 * @param project         project that owns the module to customize.
 * @param ideaModuleModel modifiable root module of the module to customize.
 * @param androidProject  the imported Android-Gradle project.
 */
@Override
public void customizeModule(@NotNull Project project,
                            @NotNull Module module,
                            @NotNull IdeModifiableModelsProvider modelsProvider,
                            @Nullable IdeaAndroidProject androidProject) {
  if (androidProject == null) {
    return;
  }
  File androidSdkHomePath = IdeSdks.getAndroidSdkPath();
  // Android SDK may be not configured in IntelliJ
  if (androidSdkHomePath == null) {
    return;
  }

  final ModifiableRootModel ideaModuleModel = modelsProvider.getModifiableRootModel(module);
  LanguageLevel languageLevel = androidProject.getJavaLanguageLevel();
  if (languageLevel != null) {
    ideaModuleModel.getModuleExtension(LanguageLevelModuleExtensionImpl.class).setLanguageLevel(languageLevel);
  }

  String compileTarget = androidProject.getDelegate().getCompileTarget();

  Sdk sdk = findSuitableAndroidSdk(compileTarget);
  if (sdk == null) {
    sdk = tryToCreateAndroidSdk(androidSdkHomePath, compileTarget);
  }

  if (sdk != null) {
    ideaModuleModel.setSdk(sdk);
    return;
  }

  String text = String.format("Module '%1$s': platform '%2$s' not found.", module.getName(), compileTarget);
  LOG.info(text);

  Message msg = new Message(FAILED_TO_SET_UP_SDK, Message.Type.ERROR, text);
  ProjectSyncMessages.getInstance(project).add(msg);
}
 
Example 38
Project: intellij-ce-playground   File: JavaParameters.java   Source Code and License 5 votes vote down vote up
private static OrderRootsEnumerator configureEnumerator(OrderEnumerator enumerator, @MagicConstant(valuesFromClass = JavaParameters.class) int classPathType, Sdk jdk) {
  if ((classPathType & JDK_ONLY) == 0) {
    enumerator = enumerator.withoutSdk();
  }
  if ((classPathType & TESTS_ONLY) == 0) {
    enumerator = enumerator.productionOnly();
  }
  OrderRootsEnumerator rootsEnumerator = enumerator.classes();
  final NotNullFunction<OrderEntry, VirtualFile[]> provider = computeRootProvider(classPathType, jdk);
  if (provider != null) {
    rootsEnumerator = rootsEnumerator.usingCustomRootProvider(provider);
  }
  return rootsEnumerator;
}
 
Example 39
Project: intellij-ce-playground   File: AndroidSdkUtils.java   Source Code and License 5 votes vote down vote up
public static void clearLocalPkgInfo(@NotNull Sdk sdk) {
  AndroidSdkAdditionalData data = getAndroidSdkAdditionalData(sdk);
  if (data == null) {
    return;
  }

  if (data.getAndroidPlatform() != null) {
    data.getAndroidPlatform().getSdkData().getLocalSdk().clearLocalPkg(PkgType.PKG_ALL);
  }
  data.clearAndroidPlatform();
}
 
Example 40
Project: intellij-ce-playground   File: PyPackageManagementService.java   Source Code and License 5 votes vote down vote up
@Nullable
public static ErrorDescription toErrorDescription(@Nullable List<ExecutionException> exceptions, @Nullable Sdk sdk) {
  if (exceptions != null && !exceptions.isEmpty() && !isCancelled(exceptions)) {
    return createDescription(exceptions.get(0), sdk);
  }
  return null;
}