@Nullable private static Sdk moduleSdk(@NotNull Module module) { return sdk(ModuleRootManager.getInstance(module).getSdk()); }
private Map<Module, Sdk> sdkByModule(@NotNull Project project) { final Map<Module, Sdk> sdkByModule = new LinkedHashMap<>(); final Module[] modules = ModuleManager.getInstance(project).getModules(); for (Module module : modules) { ModuleType moduleType = ModuleType.get(module); if (moduleType instanceof ElixirModuleType) { Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk != null && sdk.getSdkType() instanceof Type) { sdkByModule.put(module, sdk); } } } return sdkByModule; }
private Sdk getGoSdk(@Nullable Module module) { if (module != null) { Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk != null && sdk.getSdkType() instanceof GoSdkType) { return sdk; } } Sdk sdk = ProjectRootManager.getInstance(myProject).getProjectSdk(); return sdk != null && sdk.getSdkType() instanceof GoSdkType ? sdk : null; } }
private Sdk getBallerinaSdk(@Nullable Module module) { if (module != null) { Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk != null && sdk.getSdkType() instanceof BallerinaSdkType) { return sdk; } } Sdk sdk = ProjectRootManager.getInstance(myProject).getProjectSdk(); return sdk != null && sdk.getSdkType() instanceof BallerinaSdkType ? sdk : null; }
/** * Finds a file in the module SDK. * * @param element a PsiElement * @param path relative file path in the SDK * @return {@code null} if the file cannot be found, otherwise returns the corresponding {@link VirtualFile}. */ @Nullable public static VirtualFile findFileInModuleSDK(@NotNull PsiElement element, @NotNull String path) { Module module = ModuleUtilCore.findModuleForPsiElement(element); if (module == null) { return null; } Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk(); if (moduleSdk == null) { return null; } VirtualFile[] roots = moduleSdk.getSdkModificator().getRoots(OrderRootType.SOURCES); VirtualFile file; for (VirtualFile root : roots) { file = VfsUtilCore.findRelativeFile(path, root); if (file != null) { return file; } } return null; }
@NotNull public static Level level(@NotNull Project project) { Level level; final ModuleManager moduleManager = ModuleManager.getInstance(project); Level projectLevel = MAXIMUM; if (moduleManager != null) { Level maxLevel = null; for (Module module : moduleManager.getModules()) { final Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk(); if (moduleSdk != null) { final Level sdkLevel = level(moduleSdk); if (maxLevel == null || maxLevel.ordinal() < sdkLevel.ordinal()) { maxLevel = sdkLevel; } } } if (maxLevel != null) { projectLevel = maxLevel; } else { Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk(); projectLevel = level(projectSdk); } } level = projectLevel; return level; }
Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk(); if (moduleSdk != null) { VirtualFile homeDirectory = moduleSdk.getHomeDirectory();
public static String getSdkHome(Project project, Module module) { // Get the module SDK. Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk(); // If the SDK is Ballerina SDK, return the home path. if (moduleSdk != null && moduleSdk.getSdkType() == BallerinaSdkType.getInstance()) { return moduleSdk.getHomePath(); } // Ge the project SDK. Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk(); // If the SDK is Ballerina SDK, return the home path. if (projectSdk != null && projectSdk.getSdkType() == BallerinaSdkType.getInstance()) { return projectSdk.getHomePath(); } return ""; }
public boolean isValidModule(@NotNull final Module module) { final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); final Sdk sdk = moduleRootManager.getSdk(); return sdk!=null && (sdk.getSdkType() instanceof DlangSdkType); }
public List<TargetDevice> getAllDevices(Module module) { Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk == null) { return new ArrayList<>(); } String sdkBinPath = MonkeySdkType.getBinPath(sdk); DevicesReader devicesReader = new DevicesReader(sdkBinPath); return devicesReader.parseDevicesXml(); }
public SimulatorCommunication(@NotNull Module module) { this.module = module; this.sdk = checkNotNull(ModuleRootManager.getInstance(module).getSdk()); Project project = module.getProject(); VirtualFile moduleRootDir = project.getBaseDir(); final Manifest manifest = MonkeyModuleUtil.getManifest(project, moduleRootDir); this.manifestApplicationId = manifest.getApplication().getId().getStringValue(); }
private List<String> getCompilerSourcePaths() { final ArrayList<String> compilerSourcePaths = new ArrayList<>(); final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); final Sdk sdk = moduleRootManager.getSdk(); if (sdk != null && (sdk.getSdkType() instanceof DlangSdkType)) { for (VirtualFile f: sdk.getSdkModificator().getRoots(OrderRootType.SOURCES)) { if (f.exists() && f.isDirectory()) { compilerSourcePaths.add(f.getPath()); } } } return compilerSourcePaths; }
@Override protected void addAdditionalSettingsToPanel(JPanel mainPanel) { Sdk sdk = ModuleRootManager.getInstance(getModule()).getSdk(); String binPath = sdk == null ? null : MonkeySdkType.getBinPath(sdk); targetDeviceConfigurable = new TargetDeviceConfigurable(myProject, binPath) { // overriding is needed because it would fail when Applying changes in module settings // though I guess I could give 'this' to TargetDeviceConfigurable so I could have getModule() reference instead of value @NotNull @Override public TargetDeviceModuleExtension getTargetDeviceModuleExtension() { return getModel().getModuleExtension(TargetDeviceModuleExtension.class); } }; mainPanel.add(targetDeviceConfigurable.createComponent(), BorderLayout.NORTH); targetDeviceConfigurable.reset(); }
public static Sdk getModuleSdk(final Module module) throws CantRunException { final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk == null) { throw new CantRunException("No SDK for module " + module.getName()); } final VirtualFile homeDirectory = sdk.getHomeDirectory(); if (homeDirectory == null || !homeDirectory.isValid()) { throw CantRunException.jdkMisconfigured(sdk, module); } return sdk; }
private List<String> getCompilerSourcePaths(final PsiFile file) { Module module = ProjectRootManager.getInstance(file.getProject()).getFileIndex().getModuleForFile(file.getVirtualFile()); final ArrayList<String> compilerSourcePaths = new ArrayList<>(); final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); final Sdk sdk = moduleRootManager.getSdk(); if (sdk != null && (sdk.getSdkType() instanceof DlangSdkType)) { for (VirtualFile f: sdk.getSdkModificator().getRoots(OrderRootType.SOURCES)) { if (f.exists() && f.isDirectory()) { compilerSourcePaths.add(f.getPath()); } } } return compilerSourcePaths; }
final Sdk sdk = moduleRootManager.getSdk();
private Sdk findAndSetSdk(Module module, MonkeySdkType sdkType) { Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk == null) { sdk = ProjectRootManager.getInstance(module.getProject()).getProjectSdk(); } if (sdk == null) { Comparator<Sdk> preferredSdkComparator = (o1, o2) -> { if (o1.getSdkType() instanceof MonkeySdkType) { return 1; } else if (o2.getSdkType() instanceof MonkeySdkType) { return -1; } return 0; }; SdkConfigurationUtil.configureDirectoryProjectSdk(module.getProject(), preferredSdkComparator, sdkType); sdk = ProjectRootManager.getInstance(module.getProject()).getProjectSdk(); } return sdk; }
public GeneralCommandLine getExecutableCommandLine(final DlangRunAppConfiguration config) throws ModuleNotFoundException, NoValidDlangSdkFound { final Module module = config.getConfigurationModule().getModule(); if (module == null) { throw new ModuleNotFoundException(); } final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module); final Sdk sdk = moduleRootManager.getSdk(); if (sdk == null || !(sdk.getSdkType() instanceof DlangSdkType)) { throw new NoValidDlangSdkFound(); } final VirtualFile sourcesRoot = getSourceRoot(module); final GeneralCommandLine cmd = new GeneralCommandLine(); cmd.setExePath(getOutputFilePath(module)); if (StringUtil.isNotEmpty(config.getWorkDir())) { cmd.withWorkDirectory(config.getWorkDir()); } else { cmd.withWorkDirectory(sourcesRoot.getPath()); } if (StringUtil.isNotEmpty(config.getAdditionalParams())) { cmd.addParameters(splitArguments(config.getAdditionalParams())); } return cmd; }