@NotNull private static List<VirtualFile> findClasses(File file, boolean isJre) { List<VirtualFile> result = ContainerUtil.newArrayList(); VirtualFileManager fileManager = VirtualFileManager.getInstance(); String path = file.getPath(); if (JrtFileSystem.isModularJdk(path)) { String url = VirtualFileManager.constructUrl( JrtFileSystem.PROTOCOL, FileUtil.toSystemIndependentName(path) + JrtFileSystem.SEPARATOR); for (String module : JrtFileSystem.listModules(path)) { ContainerUtil.addIfNotNull(result, fileManager.findFileByUrl(url + module)); } } for (File root : JavaSdkUtil.getJdkClassesRoots(file, isJre)) { String url = VfsUtil.getUrlForLibraryRoot(root); ContainerUtil.addIfNotNull(result, fileManager.findFileByUrl(url)); } Collections.sort(result, (o1, o2) -> o1.getPath().compareTo(o2.getPath())); return result; }
@Override public void configureModule( @NotNull Module module, @NotNull ModifiableRootModel model, @Nullable ContentEntry contentEntry) { Library library = model.getModuleLibraryTable().createLibrary(libraryName); Library.ModifiableModel modifiableModel = library.getModifiableModel(); modifiableModel.addRoot(VfsUtil.getUrlForLibraryRoot(libraryFile), libraryRootType); modifiableModel.commit(); }
protected Module createModule(final String name) { final Module module = super.createModule(name); final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); final LibraryTable.ModifiableModel modifiableModel = model.getModuleLibraryTable().getModifiableModel(); final Library library = modifiableModel.createLibrary("junit"); final Library.ModifiableModel libModel = library.getModifiableModel(); libModel.addRoot( VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Before.class))), OrderRootType.CLASSES); libModel.commit(); model.commit(); return module; }
public static boolean checkTestNGInClasspath(PsiElement psiElement) { final Project project = psiElement.getProject(); final PsiManager manager = PsiManager.getInstance(project); if (JavaPsiFacade.getInstance(manager.getProject()) .findClass(TestNG.class.getName(), psiElement.getResolveScope()) == null) { if (!ApplicationManager.getApplication().isUnitTestMode()) { if (Messages.showOkCancelDialog( psiElement.getProject(), "TestNG will be added to module classpath", "Unable to convert.", Messages.getWarningIcon()) != Messages.OK) { return false; } } final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement); if (module == null) return false; String url = VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Assert.class))); ModuleRootModificationUtil.addModuleLibrary(module, url); } return true; }
@NotNull private static String refreshAndConvertToUrl(String jarPath) { final File libraryRoot = new File(jarPath); LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libraryRoot); return VfsUtil.getUrlForLibraryRoot(libraryRoot); }