use of com.intellij.openapi.projectRoots.SdkType in project intellij-community by JetBrains.
the class SdkConfigurationUtil method findOrCreateSdk.
@Nullable
public static Sdk findOrCreateSdk(@Nullable Comparator<Sdk> comparator, final SdkType... sdkTypes) {
final Project defaultProject = ProjectManager.getInstance().getDefaultProject();
final Sdk sdk = ProjectRootManager.getInstance(defaultProject).getProjectSdk();
if (sdk != null) {
for (SdkType type : sdkTypes) {
if (sdk.getSdkType() == type) {
return sdk;
}
}
}
for (SdkType type : sdkTypes) {
List<Sdk> sdks = ProjectJdkTable.getInstance().getSdksOfType(type);
if (!sdks.isEmpty()) {
if (comparator != null) {
Collections.sort(sdks, comparator);
}
return sdks.get(0);
}
}
for (SdkType sdkType : sdkTypes) {
final String suggestedHomePath = sdkType.suggestHomePath();
if (suggestedHomePath != null && sdkType.isValidSdkHome(suggestedHomePath)) {
Sdk an_sdk = createAndAddSDK(suggestedHomePath, sdkType);
if (an_sdk != null)
return an_sdk;
}
}
return null;
}
use of com.intellij.openapi.projectRoots.SdkType in project intellij-community by JetBrains.
the class SdkSettingsStep method validate.
@Override
public boolean validate() throws ConfigurationException {
JdkComboBox.JdkComboBoxItem item = myJdkComboBox.getSelectedItem();
if (myJdkComboBox.getSelectedJdk() == null && !(item instanceof JdkComboBox.ProjectJdkComboBoxItem) && !(item instanceof JdkComboBox.SuggestedJdkItem)) {
if (Messages.showDialog(getNoSdkMessage(), IdeBundle.message("title.no.jdk.specified"), new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 1, Messages.getWarningIcon()) != Messages.YES) {
return false;
}
}
try {
if (item instanceof JdkComboBox.SuggestedJdkItem) {
SdkType type = ((JdkComboBox.SuggestedJdkItem) item).getSdkType();
String path = ((JdkComboBox.SuggestedJdkItem) item).getPath();
myModel.addSdk(type, path, sdk -> {
myJdkComboBox.reloadModel(new JdkComboBox.ActualJdkComboBoxItem(sdk), myWizardContext.getProject());
myJdkComboBox.setSelectedJdk(sdk);
});
}
myModel.apply(null, true);
} catch (ConfigurationException e) {
//IDEA-98382 We should allow Next step if user has wrong SDK
if (Messages.showDialog(e.getMessage() + "/nDo you want to proceed?", e.getTitle(), new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 1, Messages.getWarningIcon()) != Messages.YES) {
return false;
}
}
return true;
}
use of com.intellij.openapi.projectRoots.SdkType in project intellij-plugins by JetBrains.
the class LibraryCollector method collect.
/**
* We don't use BuildConfigurationEntry as source of libraries. If reference to component declared in such build configuration is resolved, so, we register such bc's module
*/
public void collect(Module module) {
final FlexBuildConfiguration bc = FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration();
final Sdk sdk = bc.getSdk();
assert sdk != null;
final SdkType sdkType;
try {
sdkType = (SdkType) sdk.getClass().getMethod("getSdkType").invoke(sdk);
} catch (Exception e) {
throw new RuntimeException(e);
}
final boolean isFlexmojosSdk = sdkType instanceof FlexmojosSdkType;
if (!isFlexmojosSdk) {
collectSdkLibraries(bc, sdk);
} else {
final String sdkHomePath = sdk.getHomePath();
LogMessageUtil.LOG.assertTrue(sdkHomePath != null && sdkHomePath.contains("flex"), sdkHomePath + " must be path to maven repo and contains 'flex'");
flexmojosSdkHomePath = sdkHomePath.substring(0, sdkHomePath.indexOf("flex"));
}
flexSdkVersion = sdk.getVersionString();
assert flexSdkVersion != null;
if (StringUtil.compareVersionNumbers(flexSdkVersion, "4.5.1") >= 0) {
flexSdkVersion = "4.6";
} else {
flexSdkVersion = flexSdkVersion.substring(0, 3);
}
globalCatalogForTests(bc);
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
for (DependencyEntry entry : bc.getDependencies().getEntries()) {
if (entry instanceof ModuleLibraryEntry) {
LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, moduleRootManager);
if (orderEntry != null) {
collectFromLibraryOrderEntry(orderEntry.getRootFiles(OrderRootType.CLASSES));
}
} else if (entry instanceof SharedLibraryEntry) {
com.intellij.openapi.roots.libraries.Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
if (library != null) {
collectFromLibraryOrderEntry(library.getFiles(OrderRootType.CLASSES));
}
}
}
// IDEA-71055
// todo css-based themes
final List<String> themes = BCUtils.getThemes(module, bc);
for (String theme : themes) {
if (theme.endsWith(DOT_SWC)) {
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(theme);
if (file != null && uniqueGuard.add(file)) {
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(file);
if (jarFile != null) {
addLibrary(jarFile, true);
}
}
}
}
}
use of com.intellij.openapi.projectRoots.SdkType in project intellij-community by JetBrains.
the class OrderEntryAppearanceServiceImpl method forJdk.
@NotNull
@Override
public CellAppearanceEx forJdk(@Nullable final Sdk jdk, final boolean isInComboBox, final boolean selected, final boolean showVersion) {
if (jdk == null) {
return FileAppearanceService.getInstance().forInvalidUrl(NO_JDK);
}
String name = jdk.getName();
CompositeAppearance appearance = new CompositeAppearance();
SdkType sdkType = (SdkType) jdk.getSdkType();
appearance.setIcon(sdkType.getIcon());
SimpleTextAttributes attributes = getTextAttributes(sdkType.sdkHasValidPath(jdk), selected);
CompositeAppearance.DequeEnd ending = appearance.getEnding();
ending.addText(name, attributes);
if (showVersion) {
String versionString = jdk.getVersionString();
if (versionString != null && !versionString.equals(name)) {
SimpleTextAttributes textAttributes = isInComboBox && !selected ? SimpleTextAttributes.SYNTHETIC_ATTRIBUTES : SystemInfo.isMac && selected ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, Color.WHITE) : SimpleTextAttributes.GRAY_ATTRIBUTES;
ending.addComment(versionString, textAttributes);
}
}
return ending.getAppearance();
}
use of com.intellij.openapi.projectRoots.SdkType in project intellij-community by JetBrains.
the class SdkConfigurationUtil method createSdk.
public static void createSdk(@Nullable final Project project, final Sdk[] existingSdks, final NullableConsumer<Sdk> onSdkCreatedCallBack, final boolean createIfExists, final boolean followSymLinks, final SdkType... sdkTypes) {
if (sdkTypes.length == 0) {
onSdkCreatedCallBack.consume(null);
return;
}
FileChooserDescriptor descriptor = createCompositeDescriptor(sdkTypes);
// XXX: Workaround for PY-21787 since the native macOS dialog always follows symlinks
if (!followSymLinks) {
descriptor.setForcedToUseIdeaFileChooser(true);
}
VirtualFile suggestedDir = getSuggestedSdkRoot(sdkTypes[0]);
FileChooser.chooseFiles(descriptor, project, suggestedDir, new FileChooser.FileChooserConsumer() {
@Override
public void consume(List<VirtualFile> selectedFiles) {
for (SdkType sdkType : sdkTypes) {
final String path = selectedFiles.get(0).getPath();
if (sdkType.isValidSdkHome(path)) {
Sdk newSdk = null;
if (!createIfExists) {
for (Sdk sdk : existingSdks) {
if (path.equals(sdk.getHomePath())) {
newSdk = sdk;
break;
}
}
}
if (newSdk == null) {
newSdk = setupSdk(existingSdks, selectedFiles.get(0), sdkType, false, null, null);
}
onSdkCreatedCallBack.consume(newSdk);
return;
}
}
onSdkCreatedCallBack.consume(null);
}
@Override
public void cancelled() {
onSdkCreatedCallBack.consume(null);
}
});
}
Aggregations