OPENIDE set default jdk for new java project

(cherry picked from commit 1205baa4bc)
This commit is contained in:
Dmitry Lyubin
2025-06-05 16:56:01 +04:00
committed by Nikita Iarychenko
parent 13dc8596e2
commit 49ed84c71f
5 changed files with 94 additions and 20 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.execution.wsl.WslPath
@@ -70,6 +74,7 @@ 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
fun NewProjectWizardStep.projectWizardJdkComboBox(
@@ -326,6 +331,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
@@ -336,10 +348,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)
}
@@ -347,11 +359,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))
}
}
}
@@ -360,7 +372,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)
}
}
@@ -534,7 +546,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> {
@@ -546,6 +569,7 @@ private fun computeRegisteredSdks(key: EelDescriptor?): List<ExistingJdk> {
(key == null || ProjectSdksModel.sdkMatchesEel(key, jdk))
}
.map { ExistingJdk(it) }
.sortedWith(Comparator { o1, o2 -> compareJdkStrings(o1?.jdk?.versionString, o2?.jdk?.versionString) })
}
private fun computeHelperJdks(registered: List<ExistingJdk>): List<ProjectWizardJdkIntent> {
@@ -563,7 +587,7 @@ private fun computeHelperJdks(registered: List<ExistingJdk>): List<ProjectWizard
return helperJdks
}
// Suggests to download OpenJDK if nothing else is available in the IDE
// 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
@@ -580,7 +604,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 }
.maxByOrNull { it.jdkMajorVersion }
@@ -623,7 +647,7 @@ private fun CoroutineScope.findExistingJdks(descriptor: EelDescriptor?, comboBox
}
withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) {
comboBox.addExistingJdks(detected)
comboBox.addExistingJdks(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;
@@ -185,7 +189,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;
@@ -27,6 +31,7 @@ import javax.accessibility.AccessibleContext;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.util.Locale;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -116,6 +121,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,
@@ -148,7 +162,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
@@ -73,7 +77,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)
@@ -90,7 +102,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.*;
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;
}
}
}