OPENIDE set default jdk for new java project

(cherry picked from commit 1205baa4bc)

(cherry picked from commit 49ed84c71f)
(cherry picked from commit 7a18287175)
(cherry picked from commit d1561f5f73)
This commit is contained in:
Dmitry Lyubin
2025-06-05 16:56:01 +04:00
committed by Nikita Iarychenko
parent f06966ae55
commit 59d694d82b
5 changed files with 96 additions and 26 deletions

View File

@@ -1,4 +1,8 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Dmitry Lyubin at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
//
package com.intellij.ide.projectWizard
import com.intellij.icons.AllIcons
@@ -100,6 +104,8 @@ import java.nio.file.Paths
import javax.accessibility.AccessibleContext
import javax.swing.Icon
import javax.swing.JList
import kotlin.Comparator
import kotlin.io.path.Path
import kotlin.reflect.KFunction1
private val selectedJdkProperty = "jdk.selected.JAVA_MODULE"
@@ -276,6 +282,13 @@ class ProjectWizardJdkComboBox(
}
}
private fun appendJdkText(item: SimpleColoredComponent, text: String) {
if (text.contains("axiom", ignoreCase = true))
item.append(text, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES)
else
item.append(text)
}
override fun customize(item: SimpleColoredComponent, value: ProjectWizardJdkIntent, index: Int, isSelected: Boolean, cellHasFocus: Boolean) {
item.icon = when {
value is NoJdk && index == -1 -> null
@@ -286,10 +299,10 @@ class ProjectWizardJdkComboBox(
is NoJdk -> item.append(JavaUiBundle.message("jdk.missing.item"), SimpleTextAttributes.ERROR_ATTRIBUTES)
is ExistingJdk -> {
if (value.jdk == projectJdk) {
item.append(JavaUiBundle.message("jdk.project.item"))
appendJdkText(item, JavaUiBundle.message("jdk.project.item"))
item.append(" ${projectJdk.name}", SimpleTextAttributes.GRAYED_ATTRIBUTES)
} else {
item.append(value.jdk.name)
appendJdkText(item, value.jdk.name)
val version = value.jdk.versionString ?: (value.jdk.sdkType as SdkType).presentableName
item.append(" $version", SimpleTextAttributes.GRAYED_ATTRIBUTES)
}
@@ -297,11 +310,11 @@ class ProjectWizardJdkComboBox(
is DownloadJdk -> {
when (value.task.productName) {
null -> {
item.append(JavaUiBundle.message("jdk.download.predefined.item", value.task.suggestedSdkName))
appendJdkText(item, JavaUiBundle.message("jdk.download.predefined.item", value.task.suggestedSdkName))
item.append(" ${value.task.plannedVersion}", SimpleTextAttributes.GRAYED_ATTRIBUTES)
}
else -> {
item.append(JavaUiBundle.message("jdk.download.predefined.item", value.task.productName))
appendJdkText(item, JavaUiBundle.message("jdk.download.predefined.item", value.task.productName))
}
}
}
@@ -310,7 +323,7 @@ class ProjectWizardJdkComboBox(
is AddJdkFromPath -> item.append(JavaUiBundle.message("action.AddJdkAction.text"))
is DetectedJdk -> {
item.append(value.version)
appendJdkText(item, value.version)
item.append(" ${value.home}", SimpleTextAttributes.GRAYED_ATTRIBUTES)
}
}
@@ -532,7 +545,18 @@ private fun selectAndAddJdk(combo: ProjectWizardJdkComboBox) {
private fun containsSymbolicLink(path: String): Boolean {
val p = Paths.get(path)
return try { p.toRealPath() != p }
catch (_: IOException) { false }
catch (_: IOException) { false }
}
private fun compareJdkStrings(s1: String?, s2: String?): Int {
val b1 = s1?.contains("axiom", ignoreCase = true) ?: false
val b2 = s2?.contains("axiom", ignoreCase = true) ?: false
if (b1 && b2)
return 0
else if (b2)
return 1
else
return -1
}
private fun computeRegisteredSdks(key: EelDescriptor?): List<ExistingJdk> {
@@ -544,6 +568,7 @@ private fun computeRegisteredSdks(key: EelDescriptor?): List<ExistingJdk> {
(key == null || ProjectSdksModel.sdkMatchesEel(key.getResolvedEelMachine() ?: LocalEelMachine, jdk))
}
.map { ExistingJdk(it) }
.sortedWith(Comparator { o1, o2 -> compareJdkStrings(o1?.jdk?.versionString, o2?.jdk?.versionString) })
}
private fun computeHelperJdks(registered: List<ExistingJdk>): List<ProjectWizardJdkIntent> {
@@ -561,10 +586,7 @@ private fun computeHelperJdks(registered: List<ExistingJdk>): List<ProjectWizard
return helperJdks
}
/**
* Adds an option to download the latest OpenJDK to the combo box.
* This is called if no JDKs were found in the ProjectJdkTable and on the disk.
*/
// Suggests to download AxiomJDK if nothing else is available in the IDE
private fun CoroutineScope.getDownloadOpenJdkIntent(comboBox: ProjectWizardJdkComboBox): Job = launch {
val eel = if (Registry.`is`("java.home.finder.use.eel")) {
comboBox.currentEelDescriptor?.toEelApi() ?: localEel
@@ -581,7 +603,7 @@ private fun CoroutineScope.getDownloadOpenJdkIntent(comboBox: ProjectWizardJdkCo
val item = JdkListDownloader.getInstance()
.downloadModelForJdkInstaller(null, predicate)
.filter { it.isDefaultItem }
.filter { it.matchesVendor("Axiom JSC") }
.filter { CpuArch.fromString(it.arch) == CpuArch.CURRENT }
.filter { comboBox.jdkPredicate?.showJdkItem(it) ?: true }
.maxByOrNull { it.jdkMajorVersion }
@@ -627,7 +649,7 @@ private fun CoroutineScope.findDetectedJdks(descriptor: EelDescriptor?, comboBox
}
withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) {
comboBox.addDetectedJdks(detected)
comboBox.addDetectedJdks(detected.sortedWith(Comparator { o1, o2 -> compareJdkStrings(o1?.version, o2?.version) }))
}
}

View File

@@ -1,4 +1,8 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Dmitry Lyubin at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
//
package com.intellij.openapi.roots.ui.configuration;
import com.google.common.collect.ImmutableList;
@@ -198,7 +202,19 @@ public final class SdkListModelBuilder {
newModel.addAll(subItems);
}
for (SuggestedItem item : mySuggestions) {
List<SuggestedItem> mySortedSuggestions = new ArrayList<>(mySuggestions);
mySortedSuggestions.sort((o1, o2) -> {
boolean b1 = o1 != null && o1.version.toLowerCase(Locale.ROOT).contains("axiom");
boolean b2 = o2 != null && o2.version.toLowerCase(Locale.ROOT).contains("axiom");
if (b1 && b2)
return 0;
else if (b2)
return 1;
else
return -1;
});
for (SuggestedItem item : mySortedSuggestions) {
if (!isApplicableSuggestedItem(item)) continue;
newModel.add(item);
}

View File

@@ -1,4 +1,8 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Dmitry Lyubin at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
//
package com.intellij.openapi.roots.ui.configuration;
import com.intellij.icons.AllIcons;
@@ -34,9 +38,8 @@ import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.*;
import java.util.Locale;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -133,6 +136,15 @@ public class SdkListPresenter extends ColoredListCellRenderer<SdkListItem> {
return panel;
}
private void appendJdkText(String text) {
if (text != null) {
if (text.toLowerCase(Locale.ROOT).contains("axiom"))
append(text, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
else
append(text);
}
}
@Override
protected void customizeCellRenderer(@NotNull JList<? extends SdkListItem> list,
@Nullable SdkListItem value,
@@ -165,7 +177,7 @@ public class SdkListPresenter extends ColoredListCellRenderer<SdkListItem> {
Icon icon = type.getIcon();
if (icon == null) icon = IconUtil.getAddIcon();
setIcon(icon);
append(presentDetectedSdkPath(home));
appendJdkText(presentDetectedSdkPath(home));
append(" ");
append(version, SimpleTextAttributes.GRAYED_ATTRIBUTES);
}

View File

@@ -1,4 +1,8 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Dmitry Lyubin at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
//
package com.intellij.openapi.roots.ui.configuration
import com.intellij.icons.AllIcons
@@ -77,7 +81,15 @@ internal class SdkListPresenter2<T>(
return component
}
private fun appendJdkText(item: SimpleColoredComponent, text: String) {
if (text.contains("axiom", ignoreCase = true))
item.append(text, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES)
else
item.append(text)
}
override fun customize(item: SimpleColoredComponent, value: T, index: Int, isSelected: Boolean, cellHasFocus: Boolean) {
when (val sdkListItem = listItemProducer.apply(value)) {
is SdkListItem.InvalidSdkItem -> {
item.append(ProjectBundle.message("jdk.combo.box.invalid.item", sdkListItem.sdkName), SimpleTextAttributes.ERROR_ATTRIBUTES)
@@ -94,7 +106,7 @@ internal class SdkListPresenter2<T>(
}
item.icon = icon ?: IconUtil.addIcon
item.append(sdkListItem.version)
appendJdkText(item, sdkListItem.version)
item.append(" ${SdkListPresenter.presentDetectedSdkPath(sdkListItem.homePath)}", SimpleTextAttributes.GRAYED_ATTRIBUTES)
}

View File

@@ -1,4 +1,8 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//
// Modified by Dmitry Lyubin at 2025 as part of the OpenIDE project(https://openide.ru).
// Any modifications are available on the same license terms as the original source code.
//
package com.intellij.openapi.roots.ui;
import com.intellij.openapi.project.ProjectBundle;
@@ -18,6 +22,8 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.UIManager;
import java.util.Locale;
import static com.intellij.ui.SimpleTextAttributes.GRAY_ATTRIBUTES;
import static com.intellij.ui.SimpleTextAttributes.STYLE_PLAIN;
@@ -53,7 +59,9 @@ public final class SdkAppearanceServiceImpl extends SdkAppearanceService {
appearance.setIcon(((SdkType)sdkType).getIcon());
}
SimpleTextAttributes attributes = getTextAttributes(hasValidPath, selected);
boolean bold = name.toLowerCase(Locale.ROOT).contains("axiom");
SimpleTextAttributes attributes = getTextAttributes(hasValidPath, selected, bold);
CompositeAppearance.DequeEnd ending = appearance.getEnding();
ending.addText(StringUtil.shortenTextWithEllipsis(name, 50, 0), attributes);
@@ -71,15 +79,15 @@ public final class SdkAppearanceServiceImpl extends SdkAppearanceService {
return ending.getAppearance();
}
private static SimpleTextAttributes getTextAttributes(final boolean valid, final boolean selected) {
private static SimpleTextAttributes getTextAttributes(final boolean valid, final boolean selected, final boolean bold) {
if (!valid) {
return SimpleTextAttributes.ERROR_ATTRIBUTES;
}
else if (selected && !(SystemInfoRt.isWindows && UIManager.getLookAndFeel().getName().contains("Windows"))) {
return SimpleTextAttributes.SELECTED_SIMPLE_CELL_ATTRIBUTES;
return bold ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.SELECTED_SIMPLE_CELL_ATTRIBUTES;
}
else {
return SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES;
return bold ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES;
}
}
}