@NotNull public static Map<GroupDescriptor, Set<UsageDescriptor>> getAllUsages( @Nullable Project project, @NotNull Set<String> disabledGroups) { Map<GroupDescriptor, Set<UsageDescriptor>> usageDescriptors = new LinkedHashMap<GroupDescriptor, Set<UsageDescriptor>>(); for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) { final GroupDescriptor groupDescriptor = usagesCollector.getGroupId(); if (!disabledGroups.contains(groupDescriptor.getId())) { usageDescriptors.put(groupDescriptor, usagesCollector.getUsages(project)); } } return usageDescriptors; }
public void loadState(final Element element) { List groups = element.getChildren(GROUP_TAG); for (Object group : groups) { Element groupElement = (Element) group; String groupName = groupElement.getAttributeValue(GROUP_NAME_ATTR); final GroupDescriptor groupDescriptor = GroupDescriptor.create(groupName); List projectsList = groupElement.getChildren(PROJECT_TAG); for (Object project : projectsList) { Element projectElement = (Element) project; String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR); String frameworks = projectElement.getAttributeValue(VALUES_ATTR); if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) { Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>(); for (String key : StringUtil.split(frameworks, TOKENIZER)) { final UsageDescriptor descriptor = getUsageDescriptor(key); if (descriptor != null) frameworkDescriptors.add(descriptor); } getApplicationData(groupDescriptor).put(projectId, frameworkDescriptors); } } } }
@NotNull public static Map<GroupDescriptor, Set<UsageDescriptor>> getAllUsages( @NotNull Set<String> disabledGroups) { Map<GroupDescriptor, Set<UsageDescriptor>> usageDescriptors = new LinkedHashMap<GroupDescriptor, Set<UsageDescriptor>>(); for (UsagesCollector usagesCollector : UsagesCollector.EP_NAME.getExtensions()) { GroupDescriptor groupDescriptor = usagesCollector.getGroupId(); if (!disabledGroups.contains(groupDescriptor.getId())) { try { usageDescriptors.put(groupDescriptor, usagesCollector.getUsages()); } catch (CollectUsagesException e) { LOG.info(e); } } } return usageDescriptors; }
@NotNull @Override public GroupDescriptor getGroupId() { return GroupDescriptor.create("Project Category"); }
@NotNull @Override public GroupDescriptor getGroupId() { return GroupDescriptor.create(GROUP_ID); }
/** @author Ivan Chirkov */ public class LibraryJarUsagesCollector extends AbstractApplicationUsagesCollector { private static final GroupDescriptor GROUP = GroupDescriptor.create("Libraries by jars", GroupDescriptor.LOWER_PRIORITY); private static final String DIGIT_VERSION_PATTERN_PART = "(\\d+.\\d+|\\d+)"; private static final Pattern JAR_FILE_NAME_PATTERN = Pattern.compile("[\\w|\\-|\\.]+-(" + DIGIT_VERSION_PATTERN_PART + "[\\w|\\.]*)jar"); @NotNull @Override public Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) throws CollectUsagesException { final LibraryJarDescriptor[] descriptors = LibraryJarStatisticsService.getInstance().getTechnologyDescriptors(); final Set<UsageDescriptor> result = new HashSet<>(descriptors.length); ApplicationManager.getApplication() .runReadAction( () -> { for (LibraryJarDescriptor descriptor : descriptors) { String className = descriptor.myClass; if (className == null) continue; PsiClass[] psiClasses = JavaPsiFacade.getInstance(project) .findClasses(className, ProjectScope.getLibrariesScope(project)); for (PsiClass psiClass : psiClasses) { if (psiClass == null) continue; VirtualFile jarFile = JarFileSystem.getInstance() .getLocalVirtualFileFor(psiClass.getContainingFile().getVirtualFile()); if (jarFile == null) continue; String version = getVersionByJarManifest(jarFile); if (version == null) { version = getVersionByJarFileName(jarFile.getName()); } if (version == null || !StringUtil.containsChar(version, '.')) { continue; } result.add(new UsageDescriptor(descriptor.myName + "_" + version, 1)); } } }); return result; } @Nullable private static String getVersionByJarManifest(@NotNull VirtualFile file) { return JarUtil.getJarAttribute( VfsUtilCore.virtualToIoFile(file), Attributes.Name.IMPLEMENTATION_VERSION); } @Nullable private static String getVersionByJarFileName(@NotNull String fileName) { Matcher fileNameMatcher = JAR_FILE_NAME_PATTERN.matcher(fileName); if (!fileNameMatcher.matches()) return null; return StringUtil.trimTrailing(fileNameMatcher.group(1), '.'); } @NotNull @Override public GroupDescriptor getGroupId() { return GROUP; } }
@NotNull @Override public GroupDescriptor getGroupId() { return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY); }