public static void addModuleLibrary( final Module module, final String libName, final List<String> classesRoots, final List<String> sourceRoots, final DependencyScope scope) { addModuleLibrary( module, libName, classesRoots, sourceRoots, Collections.<String>emptyList(), scope); }
public static void addModuleLibrary( final Module module, final String libName, final List<String> classesRoots, final List<String> sourceRoots, final List<String> excludedRoots, final DependencyScope scope) { addModuleLibrary(module, libName, classesRoots, sourceRoots, excludedRoots, scope, false); }
public static void addLibrary( Module module, String libName, String libDir, String[] classRoots, String[] sourceRoots) { String proto = (classRoots.length > 0 ? classRoots[0] : sourceRoots[0]).endsWith(".jar!/") ? JarFileSystem.PROTOCOL : LocalFileSystem.PROTOCOL; String parentUrl = VirtualFileManager.constructUrl(proto, libDir); List<String> classesUrls = new ArrayList<>(); List<String> sourceUrls = new ArrayList<>(); for (String classRoot : classRoots) { classesUrls.add(parentUrl + classRoot); } for (String sourceRoot : sourceRoots) { sourceUrls.add(parentUrl + sourceRoot); } ModuleRootModificationUtil.addModuleLibrary(module, libName, classesUrls, sourceUrls); }
public static void addJarsToRoots( @NotNull final List<String> jarPaths, @Nullable final String libraryName, @NotNull final Module module, @Nullable final PsiElement location) { final Boolean isAdded = provideFix( new Function<MissingDependencyFixProvider, Boolean>() { @Override public Boolean fun(MissingDependencyFixProvider provider) { return provider.addJarsToRoots(jarPaths, libraryName, module, location); } }); if (Boolean.TRUE.equals(isAdded)) return; List<String> urls = ContainerUtil.map( jarPaths, new Function<String, String>() { @Override public String fun(String path) { return refreshAndConvertToUrl(path); } }); boolean inTests = false; if (location != null) { final VirtualFile vFile = location.getContainingFile().getVirtualFile(); if (vFile != null && ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(vFile)) { inTests = true; } } ModuleRootModificationUtil.addModuleLibrary( module, libraryName, urls, Collections.<String>emptyList(), inTests ? DependencyScope.TEST : DependencyScope.COMPILE); }
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; }
public static void addModuleLibrary( Module module, String libName, List<String> classesRoots, List<String> sourceRoots) { addModuleLibrary(module, libName, classesRoots, sourceRoots, DependencyScope.COMPILE); }
public static void addModuleLibrary(Module module, String classesRootUrl) { addModuleLibrary( module, null, Collections.singletonList(classesRootUrl), Collections.<String>emptyList()); }