private void editSdk(final Sdk currentSdk) { final SdkModificator modificator = myModificators.get(currentSdk); final EditSdkDialog dialog = new EditSdkDialog( myProject, modificator, s -> { if (isDuplicateSdkName(s, currentSdk)) { return PyBundle.message("sdk.details.dialog.error.duplicate.name"); } return null; }); if (dialog.showAndGet()) { mySdkList.repaint(); final boolean pathChanged = !Comparing.equal(currentSdk.getHomePath(), dialog.getHomePath()); if (!modificator.getName().equals(dialog.getName()) || pathChanged || dialog.isAssociateChanged()) { myModifiedModificators.add(modificator); modificator.setName(dialog.getName()); modificator.setHomePath(dialog.getHomePath()); if (dialog.isAssociateChanged()) { setSdkAssociated(modificator, dialog.associateWithProject()); } if (pathChanged) { reloadSdk(currentSdk); } } } }
private static void attachJdkAnnotations(Sdk jdk) { LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile root = null; if (root == null) { // community idea under idea root = lfs.findFileByPath( FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/java/jdkAnnotations"); } if (root == null) { // idea under idea root = lfs.findFileByPath( FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/community/java/jdkAnnotations"); } if (root == null) { // build root = VirtualFileManager.getInstance() .findFileByUrl( "jar://" + FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar!/"); } if (root == null) { LOG.error( "jdk annotations not found in: " + FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar!/"); return; } SdkModificator modificator = jdk.getSdkModificator(); modificator.removeRoot(root, AnnotationOrderRootType.getInstance()); modificator.addRoot(root, AnnotationOrderRootType.getInstance()); modificator.commitChanges(); }
private void appendChosenAnnotationsRoot( @NotNull final OrderEntry entry, @NotNull final VirtualFile vFile) { if (entry instanceof LibraryOrderEntry) { Library library = ((LibraryOrderEntry) entry).getLibrary(); LOG.assertTrue(library != null); final ModifiableRootModel rootModel = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel(); final Library.ModifiableModel model = library.getModifiableModel(); model.addRoot(vFile, AnnotationOrderRootType.getInstance()); model.commit(); rootModel.commit(); } else if (entry instanceof ModuleSourceOrderEntry) { final ModifiableRootModel model = ModuleRootManager.getInstance(entry.getOwnerModule()).getModifiableModel(); final JavaModuleExternalPaths extension = model.getModuleExtension(JavaModuleExternalPaths.class); extension.setExternalAnnotationUrls( ArrayUtil.mergeArrays(extension.getExternalAnnotationsUrls(), vFile.getUrl())); model.commit(); } else if (entry instanceof JdkOrderEntry) { final SdkModificator sdkModificator = ((JdkOrderEntry) entry).getJdk().getSdkModificator(); sdkModificator.addRoot(vFile, AnnotationOrderRootType.getInstance()); sdkModificator.commitChanges(); } myExternalAnnotations.clear(); }
@Override public void apply(SdkModificator sdkModificator) { if (sdkModificator.getSdkAdditionalData() instanceof PyRemoteSdkAdditionalDataBase) { for (PathMappingSettings.PathMapping mapping : myNewMappings) { ((PyRemoteSdkAdditionalDataBase) sdkModificator.getSdkAdditionalData()) .getPathMappings() .addMappingCheckUnique(mapping.getLocalRoot(), mapping.getRemoteRoot()); } } super.apply(sdkModificator); }
public static Sdk addJdkAnnotations(Sdk sdk) { String path = FileUtil.toSystemIndependentName(PlatformTestUtil.getCommunityPath()) + "/java/jdkAnnotations"; VirtualFile root = LocalFileSystem.getInstance().findFileByPath(path); if (root != null) { SdkModificator sdkModificator = sdk.getSdkModificator(); sdkModificator.addRoot(root, AnnotationOrderRootType.getInstance()); sdkModificator.commitChanges(); } return sdk; }
/** Removes duplicate roots that have been added as the result of a bug with *.egg handling. */ private static boolean removeDuplicateClassRoots( @NotNull Sdk sdk, @NotNull SdkModificator modificator) { final List<VirtualFile> sourceRoots = Arrays.asList(sdk.getRootProvider().getFiles(OrderRootType.CLASSES)); final LinkedHashSet<VirtualFile> uniqueRoots = new LinkedHashSet<VirtualFile>(sourceRoots); if (uniqueRoots.size() != sourceRoots.size()) { modificator.removeRoots(OrderRootType.CLASSES); for (VirtualFile root : uniqueRoots) { modificator.addRoot(root, OrderRootType.CLASSES); } return true; } return false; }
private void setSdkAssociated(SdkModificator modificator, boolean isAssociated) { PythonSdkAdditionalData additionalData = (PythonSdkAdditionalData) modificator.getSdkAdditionalData(); if (additionalData == null) { additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(modificator.getHomePath())); modificator.setSdkAdditionalData(additionalData); } if (isAssociated) { additionalData.associateWithProject(myProject); } else { additionalData.setAssociatedProjectPath(null); } }
@Override public void setupSdkPaths(Sdk sdk) { final SdkModificator modificator = sdk.getSdkModificator(); SdkAdditionalData data = sdk.getSdkAdditionalData(); if (data == null) { data = DartSdkUtil.testDartSdk(sdk.getHomePath()); modificator.setSdkAdditionalData(data); } DartSdkUtil.setupSdkPaths(sdk.getHomeDirectory(), modificator); modificator.commitChanges(); super.setupSdkPaths(sdk); }
@SuppressWarnings("HardCodedStringLiteral") private static void addDocs(File file, SdkModificator rootContainer) { VirtualFile vFile = findDocs(file, "docs/api"); if (vFile != null) { rootContainer.addRoot(vFile, JavadocOrderRootType.getInstance()); } }
public static void attachJdkAnnotations(@NotNull SdkModificator modificator) { LocalFileSystem lfs = LocalFileSystem.getInstance(); List<String> pathsChecked = new ArrayList<>(); // community idea under idea String path = FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/java/jdkAnnotations"; VirtualFile root = lfs.findFileByPath(path); pathsChecked.add(path); if (root == null) { // idea under idea path = FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/community/java/jdkAnnotations"; root = lfs.findFileByPath(path); pathsChecked.add(path); } if (root == null) { // build String url = "jar://" + FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar!/"; root = VirtualFileManager.getInstance().findFileByUrl(url); pathsChecked.add( FileUtil.toSystemIndependentName(PathManager.getHomePath()) + "/lib/jdkAnnotations.jar"); } if (root == null) { String msg = "Paths checked:\n"; for (String p : pathsChecked) { File file = new File(p); msg += "Path: '" + p + "' " + (file.exists() ? "Found" : "Not found") + "; directory children: " + Arrays.toString(file.getParentFile().listFiles()) + "\n"; } LOG.error("JDK annotations not found", msg); return; } OrderRootType annoType = AnnotationOrderRootType.getInstance(); modificator.removeRoot(root, annoType); modificator.addRoot(root, annoType); }
/** Removes legacy SOURCES entries in Python SDK tables (PY-2891). */ private static boolean removeSourceRoots(@NotNull Sdk sdk, @NotNull SdkModificator modificator) { final VirtualFile[] sourceRoots = sdk.getRootProvider().getFiles(OrderRootType.SOURCES); if (sourceRoots.length > 0) { modificator.removeRoots(OrderRootType.SOURCES); return true; } return false; }
public void apply() throws ConfigurationException { if (!myModifiedModificators.isEmpty()) { mySdkSettingsWereModified.run(); } for (SdkModificator modificator : myModifiedModificators) { /* This should always be true barring bug elsewhere, log error on else? */ if (modificator.isWritable()) { modificator.commitChanges(); } } myModificators.clear(); myModifiedModificators.clear(); mySdkListChanged = false; final Sdk sdk = getSelectedSdk(); myShowMoreCallback.consume(sdk); PyPackageManagers.getInstance().clearCache(sdk); Disposer.dispose(getDisposable()); }
@NotNull @Override public Sdk createJdk(@NotNull String jdkName, @NotNull String home, boolean isJre) { ProjectJdkImpl jdk = new ProjectJdkImpl(jdkName, this); SdkModificator sdkModificator = jdk.getSdkModificator(); String path = home.replace(File.separatorChar, '/'); sdkModificator.setHomePath(path); sdkModificator.setVersionString( jdkName); // must be set after home path, otherwise setting home path clears the version // string File jdkHomeFile = new File(home); addClasses(jdkHomeFile, sdkModificator, isJre); addSources(jdkHomeFile, sdkModificator); addDocs(jdkHomeFile, sdkModificator); sdkModificator.commitChanges(); return jdk; }
public static void addWebJarsTo(@NotNull Sdk jdk) { SdkModificator sdkModificator = jdk.getSdkModificator(); sdkModificator.addRoot(findJar("lib/jsp-api.jar"), OrderRootType.CLASSES); sdkModificator.addRoot(findJar("lib/servlet-api.jar"), OrderRootType.CLASSES); sdkModificator.commitChanges(); }
@Override public void setupSdkPaths(@NotNull Sdk sdk) { VirtualFile homeDirectory = sdk.getHomeDirectory(); if (sdk.getSdkType() != this || homeDirectory == null) { return; } String path = homeDirectory.getPath(); GoSdkData sdkData = GoSdkUtil.testGoogleGoSdk(path); if (sdkData == null) return; final VirtualFile sdkSourcesRoot = homeDirectory.findFileByRelativePath("src/pkg/"); if (sdkSourcesRoot != null) { sdkSourcesRoot.refresh(false, false); } String goPathFirst = System.getenv("GOPATH"); VirtualFile goPathDirectory; VirtualFile pathSourcesRoot = null; if (goPathFirst != null && !goPathFirst.equals("") && goPathFirst.contains(File.pathSeparator)) { // If there are multiple directories under GOPATH then we extract only the first one if (goPathFirst.contains(File.pathSeparator)) { goPathFirst = goPathFirst.split(File.pathSeparator)[0]; } if ((new File(goPathFirst).exists())) { goPathDirectory = StandardFileSystems.local().findFileByPath(goPathFirst); if (goPathDirectory != null) { pathSourcesRoot = goPathDirectory.findFileByRelativePath("src/"); } } } final SdkModificator sdkModificator = sdk.getSdkModificator(); final VirtualFile finalPathSourcesRoot = pathSourcesRoot; ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { sdkModificator.addRoot(sdkSourcesRoot, OrderRootType.CLASSES); sdkModificator.addRoot(sdkSourcesRoot, OrderRootType.SOURCES); // If we could detect the GOPATH properly, automatically add the first directory to // the autocompletion path if (finalPathSourcesRoot != null) { sdkModificator.addRoot(finalPathSourcesRoot, OrderRootType.CLASSES); sdkModificator.addRoot(finalPathSourcesRoot, OrderRootType.SOURCES); } } }); sdkModificator.setVersionString(sdkData.VERSION_MAJOR); sdkModificator.setSdkAdditionalData(sdkData); sdkModificator.commitChanges(); }
@Override public void initComponent() { ProjectJdkTable jdkTable = ProjectJdkTable.getInstance(); List<Sdk> sdkList = new ArrayList<Sdk>(); sdkList.addAll(GoSdkUtil.getSdkOfType(GoSdkType.getInstance(), jdkTable)); for (Sdk sdk : sdkList) { GoSdkData sdkData = (GoSdkData) sdk.getSdkAdditionalData(); boolean needsUpgrade = sdkData == null; try { if (!needsUpgrade) { sdkData.checkValid(); } } catch (ConfigurationException ex) { needsUpgrade = true; } if (!needsUpgrade) continue; needsUpgrade = false; GoSdkData data = GoSdkUtil.testGoogleGoSdk(sdk.getHomePath()); if (data == null) needsUpgrade = true; try { if (data != null) { data.checkValid(); } } catch (ConfigurationException ex) { needsUpgrade = true; } if (needsUpgrade) { Notifications.Bus.notify( new Notification( "Go SDK validator", "Corrupt Go SDK", getContent("Go", sdk.getName()), NotificationType.WARNING), myProject); } SdkModificator sdkModificator = sdk.getSdkModificator(); sdkModificator.setSdkAdditionalData(data); sdkModificator.commitChanges(); } sdkList.clear(); sdkList.addAll(GoSdkUtil.getSdkOfType(GoAppEngineSdkType.getInstance(), jdkTable)); Boolean hasGAESdk = sdkList.size() > 0; for (Sdk sdk : sdkList) { GoAppEngineSdkData sdkData = (GoAppEngineSdkData) sdk.getSdkAdditionalData(); if (sdkData == null || sdkData.TARGET_ARCH == null || sdkData.TARGET_OS == null) { Notifications.Bus.notify( new Notification( "Go AppEngine SDK validator", "Corrupt Go App Engine SDK", getContent("Go App Engine", sdk.getName()), NotificationType.WARNING), myProject); continue; } boolean needsUpgrade = false; try { sdkData.checkValid(); } catch (ConfigurationException ex) { needsUpgrade = true; } if (!needsUpgrade) continue; needsUpgrade = false; GoAppEngineSdkData data = GoSdkUtil.testGoAppEngineSdk(sdk.getHomePath()); if (data == null) needsUpgrade = true; try { if (data != null) { data.checkValid(); } } catch (ConfigurationException ex) { needsUpgrade = true; } // GAE SDK auto-update needs a bit more love if (data != null && !(new File(data.GOAPP_BIN_PATH)).exists()) { needsUpgrade = true; } if (needsUpgrade) { Notifications.Bus.notify( new Notification( "Go AppEngine SDK validator", "Corrupt Go App Engine SDK", getContent("Go AppEngine", sdk.getName()), NotificationType.WARNING), myProject); } SdkModificator sdkModificator = sdk.getSdkModificator(); sdkModificator.setSdkAdditionalData(data); sdkModificator.commitChanges(); } if (hasGAESdk) { String sysAppEngineDevServerPath = GoSdkUtil.getAppEngineDevServer(); if (sysAppEngineDevServerPath.isEmpty()) Notifications.Bus.notify( new Notification( "Go AppEngine SDK validator", "Problem with env variables", getInvalidAPPENGINE_DEV_APPSERVEREnvMessage(), NotificationType.WARNING, NotificationListener.URL_OPENING_LISTENER), myProject); } PluginDescriptor pluginDescriptor = PluginManager.getPlugin(PluginId.getId("ro.redeul.google.go")); if (pluginDescriptor != null) { String version = ((IdeaPluginDescriptorImpl) pluginDescriptor).getVersion(); if (version.endsWith("-dev") && !System.getProperty("go.skip.dev.warn", "false").equals("true")) { Notifications.Bus.notify( new Notification( "Go plugin notice", "Development version detected", getDevVersionMessage(), NotificationType.WARNING, null), myProject); } } super.initComponent(); }
@Override @SuppressWarnings("HardCodedStringLiteral") public void setupSdkPaths(@NotNull Sdk sdk) { String homePath = sdk.getHomePath(); assert homePath != null : sdk; File jdkHome = new File(homePath); List<VirtualFile> classes = findClasses(jdkHome, false); VirtualFile sources = findSources(jdkHome); VirtualFile docs = findDocs(jdkHome, "docs/api"); SdkModificator sdkModificator = sdk.getSdkModificator(); Set<VirtualFile> previousRoots = new LinkedHashSet<>(Arrays.asList(sdkModificator.getRoots(OrderRootType.CLASSES))); sdkModificator.removeRoots(OrderRootType.CLASSES); previousRoots.removeAll(new HashSet<>(classes)); for (VirtualFile aClass : classes) { sdkModificator.addRoot(aClass, OrderRootType.CLASSES); } for (VirtualFile root : previousRoots) { sdkModificator.addRoot(root, OrderRootType.CLASSES); } if (sources != null) { sdkModificator.addRoot(sources, OrderRootType.SOURCES); } VirtualFile javaFxSources = findSources(jdkHome, "javafx-src"); if (javaFxSources != null) { sdkModificator.addRoot(javaFxSources, OrderRootType.SOURCES); } if (docs != null) { sdkModificator.addRoot(docs, JavadocOrderRootType.getInstance()); } else if (SystemInfo.isMac) { VirtualFile commonDocs = findDocs(jdkHome, "docs"); if (commonDocs == null) { commonDocs = findInJar(new File(jdkHome, "docs.jar"), "doc/api"); if (commonDocs == null) { commonDocs = findInJar(new File(jdkHome, "docs.jar"), "docs/api"); } } if (commonDocs != null) { sdkModificator.addRoot(commonDocs, JavadocOrderRootType.getInstance()); } VirtualFile appleDocs = findDocs(jdkHome, "appledocs"); if (appleDocs == null) { appleDocs = findInJar(new File(jdkHome, "appledocs.jar"), "appledoc/api"); } if (appleDocs != null) { sdkModificator.addRoot(appleDocs, JavadocOrderRootType.getInstance()); } if (commonDocs == null && appleDocs == null && sources == null) { String url = getDefaultDocumentationUrl(sdk); if (url != null) { sdkModificator.addRoot( VirtualFileManager.getInstance().findFileByUrl(url), JavadocOrderRootType.getInstance()); } } } else if (getVersion(sdk) == JavaSdkVersion.JDK_1_7) { VirtualFile url = VirtualFileManager.getInstance().findFileByUrl("http://docs.oracle.com/javafx/2/api/"); sdkModificator.addRoot(url, JavadocOrderRootType.getInstance()); } attachJdkAnnotations(sdkModificator); sdkModificator.commitChanges(); }
private static void addClasses(File file, SdkModificator sdkModificator, boolean isJre) { for (VirtualFile virtualFile : findClasses(file, isJre)) { sdkModificator.addRoot(virtualFile, OrderRootType.CLASSES); } }
private static void addSources(@NotNull File file, @NotNull SdkModificator sdkModificator) { VirtualFile vFile = findSources(file); if (vFile != null) { sdkModificator.addRoot(vFile, OrderRootType.SOURCES); } }