Java Code Examples for com.intellij.openapi.projectRoots.Sdk#getHomePath()
The following examples show how to use
com.intellij.openapi.projectRoots.Sdk#getHomePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginUtils.java From SmartTomcat with Apache License 2.0 | 5 votes |
public static String getJavaHome() { Sdk sdk = getProjectJDK(); String javahome; if (sdk == null) { JdkBundle jdkBundle = JdkBundle.createBoot(); javahome = jdkBundle.getLocation().getAbsolutePath(); } else { javahome = sdk.getHomePath(); } return javahome; }
Example 2
Source File: AndroidSyncTest.java From intellij with Apache License 2.0 | 5 votes |
@Test public void testSimpleSync_invalidSdkAndSReInstall() { TestProjectArguments testEnvArgument = createTestProjectArguments(); MockSdkUtil.registerSdk(workspace, "28", "5", MultiMap.create(), true); setProjectView( "directories:", " java/com/google", "targets:", " //java/com/google:lib", "android_sdk_platform: android-28"); setTargetMap(testEnvArgument.targetMap); // When IDE re-add local SDK into {link @ProjectJdkTable}, it need access to embedded jdk. Set // path to mock jdk as embedded jdk path to avoid NPE. Sdk jdk = IdeaTestUtil.getMockJdk18(); File jdkFile = new File(jdk.getHomePath()); if (!jdkFile.exists()) { jdkFile.mkdirs(); jdkFile.deleteOnExit(); TestUtils.setSystemProperties( getTestRootDisposable(), "android.test.embedded.jdk", jdkFile.getPath()); } runBlazeSync( BlazeSyncParams.builder() .setTitle("Sync") .setSyncMode(SyncMode.INCREMENTAL) .setSyncOrigin("test") .setBlazeBuildParams(BlazeBuildParams.fromProject(getProject())) .setAddProjectViewTargets(true) .build()); assertSyncSuccess(testEnvArgument.targetMap, testEnvArgument.javaRoot); assertThat(SdkUtil.containsJarAndRes(BlazeSdkProvider.getInstance().findSdk(ANDROID_28))) .isTrue(); }
Example 3
Source File: IntellijWithPluginClasspathHelper.java From intellij with Apache License 2.0 | 5 votes |
private static void addIntellijLibraries(JavaParameters params, Sdk ideaJdk) { String libPath = ideaJdk.getHomePath() + File.separator + "lib"; PathsList list = params.getClassPath(); for (String lib : IJ_LIBRARIES) { list.addFirst(libPath + File.separator + lib); } list.addFirst(((JavaSdkType) ideaJdk.getSdkType()).getToolsPath(ideaJdk)); }
Example 4
Source File: IntellijWithPluginClasspathHelper.java From intellij with Apache License 2.0 | 5 votes |
public static void addRequiredVmParams( JavaParameters params, Sdk ideaJdk, ImmutableSet<File> javaAgents) { String canonicalSandbox = IdeaJdkHelper.getSandboxHome(ideaJdk); ParametersList vm = params.getVMParametersList(); String libPath = ideaJdk.getHomePath() + File.separator + "lib"; vm.add("-Xbootclasspath/a:" + libPath + File.separator + "boot.jar"); vm.defineProperty("idea.config.path", canonicalSandbox + File.separator + "config"); vm.defineProperty("idea.system.path", canonicalSandbox + File.separator + "system"); vm.defineProperty("idea.plugins.path", canonicalSandbox + File.separator + "plugins"); vm.defineProperty("idea.classpath.index.enabled", "false"); if (SystemInfo.isMac) { vm.defineProperty("idea.smooth.progress", "false"); vm.defineProperty("apple.laf.useScreenMenuBar", "true"); } if (SystemInfo.isXWindow) { if (!vm.hasProperty("sun.awt.disablegrab")) { vm.defineProperty( "sun.awt.disablegrab", "true"); // See http://devnet.jetbrains.net/docs/DOC-1142 } } for (File javaAgent : javaAgents) { vm.add("-javaagent:" + javaAgent.getAbsolutePath()); } params.setWorkingDirectory(ideaJdk.getHomePath() + File.separator + "bin" + File.separator); params.setJdk(ideaJdk); addIntellijLibraries(params, ideaJdk); params.setMainClass("com.intellij.idea.Main"); }
Example 5
Source File: Jdks.java From intellij with Apache License 2.0 | 5 votes |
private static boolean jdkPathMatches(Sdk jdk, String homePath) { String jdkPath = jdk.getHomePath(); if (jdkPath == null) { return false; } try { return Objects.equals( new File(homePath).getCanonicalPath(), new File(jdkPath).getCanonicalPath()); } catch (IOException e) { // ignore these exceptions return false; } }
Example 6
Source File: BlazePythonSyncPlugin.java From intellij with Apache License 2.0 | 5 votes |
private static boolean isValidPythonSdk(@Nullable Sdk sdk) { if (sdk == null) { return false; } if (!(sdk.getSdkType() instanceof PythonSdkType)) { return false; } // facets aren't properly updated when SDKs change (e.g. when they're deleted), so we need to // manually check against the full list. if (!PythonSdkType.getAllSdks().contains(sdk)) { return false; } // If an SDK exists with a home path that doesn't exist anymore, it's not valid String sdkHome = sdk.getHomePath(); if (sdkHome == null) { return false; } File sdkHomeFile = new File(sdkHome); if (!sdkHomeFile.exists()) { return false; } // Allow PySdkSuggester extensions the ability to veto an SDK as deprecated return !isDeprecatedPythonSdk(sdk); }
Example 7
Source File: RoboVmPlugin.java From robovm-idea with GNU General Public License v2.0 | 5 votes |
public static File getBestAndroidSdkDir() { Sdk bestSdk = null; for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) { if (sdk.getSdkType().getName().equals("Android SDK")) { if(sdk.getHomePath().contains("/Library/RoboVM/")) { return new File(sdk.getHomePath()); } else { bestSdk = sdk; } } } return new File(bestSdk.getHomePath()); }
Example 8
Source File: OSSSdkRefreshActionTest.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
public void testRefreshPantsSdk() { ProjectRootManager rootManager = ProjectRootManager.getInstance(myProject); Sdk sdk = createDummySdk("1.8_from_" + pantsExecutable()); String originalSdkPath = sdk.getHomePath(); doImport("examples/src/java/org/pantsbuild/example/hello"); assertEquals(originalSdkPath, rootManager.getProjectSdk().getHomePath()); refreshProjectSdk(); // the SDK gets updated assertSame(sdk, rootManager.getProjectSdk()); assertNotEquals(originalSdkPath, sdk.getHomePath()); }
Example 9
Source File: Unity3dRootModuleExtension.java From consulo-unity3d with Apache License 2.0 | 5 votes |
@Nonnull @Override public File[] getFilesForLibraries() { Sdk sdk = getSdk(); if(sdk == null) { return EMPTY_FILE_ARRAY; } String homePath = sdk.getHomePath(); if(homePath == null) { return EMPTY_FILE_ARRAY; } List<String> pathsForLibraries = getPathsForLibraries(homePath, sdk); File[] array = EMPTY_FILE_ARRAY; for(String pathsForLibrary : pathsForLibraries) { File dir = new File(pathsForLibrary); if(dir.exists()) { File[] files = dir.listFiles(); if(files != null) { array = ArrayUtil.mergeArrays(array, files); } } } return array; }
Example 10
Source File: NamedLibraryElementNode.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(PresentationData presentation) { presentation.setPresentableText(getValue().getName()); final OrderEntry orderEntry = getValue().getOrderEntry(); if (orderEntry instanceof ModuleExtensionWithSdkOrderEntry) { final ModuleExtensionWithSdkOrderEntry sdkOrderEntry = (ModuleExtensionWithSdkOrderEntry)orderEntry; final Sdk sdk = sdkOrderEntry.getSdk(); presentation.setIcon(SdkUtil.getIcon(((ModuleExtensionWithSdkOrderEntry)orderEntry).getSdk())); if (sdk != null) { //jdk not specified final String path = sdk.getHomePath(); if (path != null) { presentation.setLocationString(FileUtil.toSystemDependentName(path)); } } presentation.setTooltip(null); } else if (orderEntry instanceof LibraryOrderEntry) { presentation.setIcon(getIconForLibrary(orderEntry)); presentation.setTooltip(StringUtil.capitalize(IdeBundle.message("node.projectview.library", ((LibraryOrderEntry)orderEntry).getLibraryLevel()))); } else if(orderEntry instanceof OrderEntryWithTracking) { Image icon = null; CellAppearanceEx cellAppearance = OrderEntryAppearanceService.getInstance().forOrderEntry(orderEntry); if(cellAppearance instanceof ModifiableCellAppearanceEx) { icon = ((ModifiableCellAppearanceEx)cellAppearance).getIcon(); } presentation.setIcon(icon == null ? AllIcons.Toolbar.Unknown : icon); } }
Example 11
Source File: BlazeIntellijPluginConfiguration.java From intellij with Apache License 2.0 | 4 votes |
/** * Plugin jar has been previously created via blaze build. This method: - copies jar to sandbox * environment - cracks open jar and finds plugin.xml (with ID, etc., needed for JVM args) - sets * up the SDK, etc. (use project SDK?) - sets up the JVM, and returns a JavaCommandLineState */ @Nullable @Override public RunProfileState getState(Executor executor, ExecutionEnvironment env) throws ExecutionException { final Sdk ideaJdk = pluginSdk; if (!IdeaJdkHelper.isIdeaJdk(ideaJdk)) { throw new ExecutionException("Choose an IntelliJ Platform Plugin SDK"); } String sandboxHome = IdeaJdkHelper.getSandboxHome(ideaJdk); if (sandboxHome == null) { throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK"); } try { sandboxHome = new File(sandboxHome).getCanonicalPath(); } catch (IOException e) { throw new ExecutionException("No sandbox specified for IntelliJ Platform Plugin SDK", e); } String buildNumber = IdeaJdkHelper.getBuildNumber(ideaJdk); final BlazeIntellijPluginDeployer deployer = new BlazeIntellijPluginDeployer(sandboxHome, buildNumber, target); env.putUserData(BlazeIntellijPluginDeployer.USER_DATA_KEY, deployer); // copy license from running instance of idea IdeaJdkHelper.copyIDEALicense(sandboxHome); return new JavaCommandLineState(env) { @Override protected JavaParameters createJavaParameters() throws ExecutionException { DeployedPluginInfo deployedPluginInfo = deployer.deployNonBlocking(); final JavaParameters params = new JavaParameters(); ParametersList vm = params.getVMParametersList(); fillParameterList(vm, vmParameters); fillParameterList(params.getProgramParametersList(), programParameters); IntellijWithPluginClasspathHelper.addRequiredVmParams( params, ideaJdk, deployedPluginInfo.javaAgents); vm.defineProperty( JetBrainsProtocolHandler.REQUIRED_PLUGINS_KEY, Joiner.on(',').join(deployedPluginInfo.pluginIds)); if (!vm.hasProperty(PlatformUtils.PLATFORM_PREFIX_KEY) && buildNumber != null) { String prefix = IdeaJdkHelper.getPlatformPrefix(buildNumber); if (prefix != null) { vm.defineProperty(PlatformUtils.PLATFORM_PREFIX_KEY, prefix); } } return params; } /** https://youtrack.jetbrains.com/issue/IDEA-201733 */ @Override protected GeneralCommandLine createCommandLine() throws ExecutionException { GeneralCommandLine commandLine = super.createCommandLine(); for (String jreName : new String[] {"jbr", "jre64", "jre"}) { File bundledJre = new File(ideaJdk.getHomePath(), jreName); if (bundledJre.isDirectory()) { File bundledJava = new File(bundledJre, "bin/java"); if (bundledJava.canExecute()) { commandLine.setExePath(bundledJava.getAbsolutePath()); break; } } } return commandLine; } @Override protected OSProcessHandler startProcess() throws ExecutionException { deployer.blockUntilDeployComplete(); final OSProcessHandler handler = super.startProcess(); handler.addProcessListener( new ProcessAdapter() { @Override public void processTerminated(ProcessEvent event) { deployer.deleteDeployment(); } }); return handler; } }; }
Example 12
Source File: Unity3dPackageOrderEntry.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@Nonnull @Override @RequiredReadAction public String[] getUrls(@Nonnull OrderRootType rootType) { List<String> urls = new SmartList<>(); if(rootType == BinariesOrderRootType.getInstance() || rootType == SourcesOrderRootType.getInstance()) { // moved to project files String projectPackageCache = getProjectPackageCache(); if(new File(projectPackageCache, myNameWithVersion).exists()) { urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(projectPackageCache + "/" + myNameWithVersion)); } if(urls.isEmpty()) { Unity3dPackageWatcher watcher = Unity3dPackageWatcher.getInstance(); for(String path : watcher.getPackageDirPaths()) { if(new File(path, myNameWithVersion).exists()) { urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(path + "/" + myNameWithVersion)); } } } } if(urls.isEmpty()) { Sdk sdk = getSdk(); if(sdk != null) { String builtInPath = sdk.getHomePath() + "/" + getBuiltInPackagesRelativePath(); String packageName = getPackageName(); if(new File(builtInPath, packageName).exists()) { urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(builtInPath + "/" + packageName)); } } } return ArrayUtil.toStringArray(urls); }
Example 13
Source File: MSBaseDotNetCompilerOptionsBuilder.java From consulo-csharp with Apache License 2.0 | 4 votes |
public void setExecutableFromSdk(@Nonnull Sdk sdk, @Nonnull String executableFromSdk) { myExecutable = sdk.getHomePath() + File.separatorChar + executableFromSdk; }
Example 14
Source File: AlternativeJREPanel.java From intellij-xquery with Apache License 2.0 | 4 votes |
public AlternativeJREPanel() { myCbEnabled = new JBCheckBox(ExecutionBundle.message("run.configuration.use.alternate.jre.checkbox")); myFieldWithHistory = new TextFieldWithHistory(); myFieldWithHistory.setHistorySize(-1); final List<String> foundJDKs = new ArrayList<>(); final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks(); String javaHomeOfCurrentProcess = System.getProperty("java.home"); if (javaHomeOfCurrentProcess != null && !javaHomeOfCurrentProcess.isEmpty()) { foundJDKs.add(javaHomeOfCurrentProcess); } for (Sdk sdk : allJDKs) { String name = sdk.getName(); if (!foundJDKs.contains(name)) { foundJDKs.add(name); } } for (Sdk jdk : allJDKs) { String homePath = jdk.getHomePath(); if (!SystemInfo.isMac) { final File jre = new File(jdk.getHomePath(), "jre"); if (jre.isDirectory()) { homePath = jre.getPath(); } } if (!foundJDKs.contains(homePath)) { foundJDKs.add(homePath); } } myFieldWithHistory.setHistory(foundJDKs); myPathField = new ComponentWithBrowseButton<>(myFieldWithHistory, null); myPathField.addBrowseFolderListener(ExecutionBundle.message("run.configuration.select.alternate.jre.label"), ExecutionBundle.message("run.configuration.select.jre.dir.label"), null, BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); setLayout(new MigLayout("ins 0, gap 10, fill, flowx")); add(myCbEnabled, "shrinkx"); add(myPathField, "growx, pushx"); InsertPathAction.addTo(myFieldWithHistory.getTextEditor()); myCbEnabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { enabledChanged(); } }); enabledChanged(); setAnchor(myCbEnabled); updateUI(); }