public static IdeaPluginDescriptorImpl[] loadDescriptors(@Nullable StartupProgress progress) { if (ClassUtilCore.isLoadingOfExternalPluginsDisabled()) { return IdeaPluginDescriptorImpl.EMPTY_ARRAY; } final List<IdeaPluginDescriptorImpl> result = new ArrayList<IdeaPluginDescriptorImpl>(); int pluginsCount = countPlugins(PathManager.getPluginsPath()) + countPlugins(PathManager.getPreinstalledPluginsPath()); loadDescriptors(PathManager.getPluginsPath(), result, progress, pluginsCount); Application application = ApplicationManager.getApplication(); boolean fromSources = false; if (application == null || !application.isUnitTestMode()) { int size = result.size(); loadDescriptors(PathManager.getPreinstalledPluginsPath(), result, progress, pluginsCount); fromSources = size == result.size(); } loadDescriptorsFromProperty(result); loadDescriptorsFromClassPath(result, fromSources ? progress : null); IdeaPluginDescriptorImpl[] pluginDescriptors = result.toArray(new IdeaPluginDescriptorImpl[result.size()]); try { Arrays.sort(pluginDescriptors, new PluginDescriptorComparator(pluginDescriptors)); } catch (Exception e) { prepareLoadingPluginsErrorMessage( IdeBundle.message("error.plugins.were.not.loaded", e.getMessage())); getLogger().info(e); return findCorePlugin(pluginDescriptors); } return pluginDescriptors; }
@Override public void writeExternal(Element rootElement) throws WriteExternalException { LOG.assertTrue(!isDisposed(), "Already disposed!"); Element element = new Element(ELEMENT); if (myName != null) { element.setAttribute(LIBRARY_NAME_ATTR, myName); } if (myKind != null) { element.setAttribute(LIBRARY_TYPE_ATTR, myKind.getKindId()); final Object state = myProperties.getState(); if (state != null) { final Element propertiesElement = XmlSerializer.serialize(state, SERIALIZATION_FILTERS); if (propertiesElement != null && (!propertiesElement.getContent().isEmpty() || !propertiesElement.getAttributes().isEmpty())) { element.addContent(propertiesElement.setName(PROPERTIES_ELEMENT)); } } } ArrayList<OrderRootType> storableRootTypes = new ArrayList<OrderRootType>(); storableRootTypes.addAll(Arrays.asList(OrderRootType.getAllTypes())); if (myKind != null) { storableRootTypes.addAll(Arrays.asList(myKind.getAdditionalRootTypes())); } for (OrderRootType rootType : sortRootTypes(storableRootTypes)) { final VirtualFilePointerContainer roots = myRoots.get(rootType); if (roots.size() == 0 && rootType.skipWriteIfEmpty()) continue; // compatibility iml/ipr final Element rootTypeElement = new Element(rootType.name()); roots.writeExternal(rootTypeElement, ROOT_PATH_ELEMENT); element.addContent(rootTypeElement); } myJarDirectories.writeExternal(element); rootElement.addContent(element); }
@Override @NotNull public Project[] getOpenProjects() { synchronized (myOpenProjects) { if (myOpenProjectsArrayCache.length != myOpenProjects.size()) { LOG.error( "Open projects: " + myOpenProjects + "; cache: " + Arrays.asList(myOpenProjectsArrayCache)); } if (myOpenProjectsArrayCache.length > 0 && myOpenProjectsArrayCache[0] != myOpenProjects.get(0)) { LOG.error( "Open projects cache corrupted. Open projects: " + myOpenProjects + "; cache: " + Arrays.asList(myOpenProjectsArrayCache)); } if (ApplicationManager.getApplication().isUnitTestMode()) { Project[] testProjects = myTestProjects.toArray(new Project[myTestProjects.size()]); for (Project testProject : testProjects) { assert !testProject.isDisposed() : testProject; } return ArrayUtil.mergeArrays(myOpenProjectsArrayCache, testProjects); } return myOpenProjectsArrayCache; } }
private Set<OrderRootType> getAllRootTypes() { Set<OrderRootType> rootTypes = new HashSet<OrderRootType>(); rootTypes.addAll(Arrays.asList(OrderRootType.getAllTypes())); if (myKind != null) { rootTypes.addAll(Arrays.asList(myKind.getAdditionalRootTypes())); } return rootTypes; }
public Collection<Module> getValidModules() { if (TEST_PACKAGE.equals(myData.TEST_OBJECT) || TEST_PATTERN.equals(myData.TEST_OBJECT)) { return Arrays.asList(ModuleManager.getInstance(getProject()).getModules()); } try { myData.getTestObject(getProject(), this).checkConfiguration(); } catch (RuntimeConfigurationError e) { return Arrays.asList(ModuleManager.getInstance(getProject()).getModules()); } catch (RuntimeConfigurationException e) { // ignore } return JavaRunConfigurationModule.getModulesForClass(getProject(), myData.getMainClassName()); }
private static HighlightVisitor[] filterVisitors( HighlightVisitor[] highlightVisitors, final PsiFile file) { final List<HighlightVisitor> visitors = new ArrayList<HighlightVisitor>(highlightVisitors.length); List<HighlightVisitor> list = Arrays.asList(highlightVisitors); for (HighlightVisitor visitor : DumbService.getInstance(file.getProject()).filterByDumbAwareness(list)) { if (visitor.suitableForFile(file)) visitors.add(visitor); } LOG.assertTrue(!visitors.isEmpty(), list); HighlightVisitor[] visitorArray = visitors.toArray(new HighlightVisitor[visitors.size()]); Arrays.sort(visitorArray, VISITOR_ORDER_COMPARATOR); return visitorArray; }
private static boolean checkDependants( final IdeaPluginDescriptor pluginDescriptor, final Function<PluginId, IdeaPluginDescriptor> pluginId2Descriptor, final Condition<PluginId> check, final Set<PluginId> processed) { processed.add(pluginDescriptor.getPluginId()); final PluginId[] dependentPluginIds = pluginDescriptor.getDependentPluginIds(); final Set<PluginId> optionalDependencies = new HashSet<PluginId>(Arrays.asList(pluginDescriptor.getOptionalDependentPluginIds())); for (final PluginId dependentPluginId : dependentPluginIds) { if (processed.contains(dependentPluginId)) continue; // TODO[yole] should this condition be a parameter? if (isModuleDependency(dependentPluginId) && (ourAvailableModules.isEmpty() || ourAvailableModules.contains(dependentPluginId.getIdString()))) { continue; } if (!optionalDependencies.contains(dependentPluginId)) { if (!check.value(dependentPluginId)) { return false; } final IdeaPluginDescriptor dependantPluginDescriptor = pluginId2Descriptor.fun(dependentPluginId); if (dependantPluginDescriptor != null && !checkDependants(dependantPluginDescriptor, pluginId2Descriptor, check, processed)) { return false; } } } return true; }
public static <T> void assertUnorderedCollection( Collection<? extends T> collection, Consumer<T>... checkers) { Assert.assertNotNull(collection); if (collection.size() != checkers.length) { Assert.fail(toString(collection)); } Set<Consumer<T>> checkerSet = new HashSet<Consumer<T>>(Arrays.asList(checkers)); int i = 0; Throwable lastError = null; for (final T actual : collection) { boolean flag = true; for (final Consumer<T> condition : checkerSet) { Throwable error = accepts(condition, actual); if (error == null) { checkerSet.remove(condition); flag = false; break; } else { lastError = error; } } if (flag) { lastError.printStackTrace(); Assert.fail("Incorrect element(" + i + "): " + actual); } i++; } }
public static <T> void assertOneOf(T value, T... values) { boolean found = false; for (T v : values) { if (value == v || value != null && value.equals(v)) { found = true; } } Assert.assertTrue(value + " should be equal to one of " + Arrays.toString(values), found); }
@Override @NotNull public String[] getUrls(@NotNull OrderRootType rootType) { Set<String> originalUrls = new LinkedHashSet<String>(Arrays.asList(LibraryImpl.this.getUrls(rootType))); for (VirtualFile file : getFiles(rootType)) { // Add those expanded with jar directories. originalUrls.add(file.getUrl()); } return ArrayUtil.toStringArray(originalUrls); }
@NotNull public VirtualFile[] getOpenFiles() { final ArrayListSet<VirtualFile> files = new ArrayListSet<VirtualFile>(); for (final EditorWindow myWindow : myWindows) { final EditorWithProviderComposite[] editors = myWindow.getEditors(); for (final EditorWithProviderComposite editor : editors) { final VirtualFile file = editor.getFile(); LOG.assertTrue(file.isValid(), Arrays.toString(editor.getProviders())); files.add(file); } } return VfsUtil.toVirtualFileArray(files); }
@Override public void writeExternal(Element element) throws WriteExternalException { final CodeStyleSettings parentSettings = new CodeStyleSettings(); DefaultJDOMExternalizer.writeExternal( this, element, new DifferenceFilter<CodeStyleSettings>(this, parentSettings)); List<CustomCodeStyleSettings> customSettings = new ArrayList<CustomCodeStyleSettings>(getCustomSettingsValues()); Collections.sort( customSettings, new Comparator<CustomCodeStyleSettings>() { @Override public int compare(final CustomCodeStyleSettings o1, final CustomCodeStyleSettings o2) { return o1.getTagName().compareTo(o2.getTagName()); } }); for (final CustomCodeStyleSettings settings : customSettings) { final CustomCodeStyleSettings parentCustomSettings = parentSettings.getCustomSettings(settings.getClass()); if (parentCustomSettings == null) { throw new WriteExternalException("Custom settings are null for " + settings.getClass()); } settings.writeExternal(element, parentCustomSettings); } final FileType[] fileTypes = myAdditionalIndentOptions .keySet() .toArray(new FileType[myAdditionalIndentOptions.keySet().size()]); Arrays.sort( fileTypes, new Comparator<FileType>() { @Override public int compare(final FileType o1, final FileType o2) { return o1.getDefaultExtension().compareTo(o2.getDefaultExtension()); } }); for (FileType fileType : fileTypes) { final IndentOptions indentOptions = myAdditionalIndentOptions.get(fileType); Element additionalIndentOptions = new Element(ADDITIONAL_INDENT_OPTIONS); indentOptions.serialize(additionalIndentOptions, getDefaultIndentOptions(fileType)); additionalIndentOptions.setAttribute(FILETYPE, fileType.getDefaultExtension()); if (!additionalIndentOptions.getChildren().isEmpty()) { element.addContent(additionalIndentOptions); } } myCommonSettingsManager.writeExternal(element); }
public static void renameNonCodeUsages( @NotNull Project project, @NotNull NonCodeUsageInfo[] usages) { PsiDocumentManager.getInstance(project).commitAllDocuments(); Map<Document, List<UsageOffset>> docsToOffsetsMap = new HashMap<Document, List<UsageOffset>>(); final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); for (NonCodeUsageInfo usage : usages) { PsiElement element = usage.getElement(); if (element == null) continue; element = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(element, true); if (element == null) continue; final ProperTextRange rangeInElement = usage.getRangeInElement(); if (rangeInElement == null) continue; final PsiFile containingFile = element.getContainingFile(); final Document document = psiDocumentManager.getDocument(containingFile); final Segment segment = usage.getSegment(); LOG.assertTrue(segment != null); int fileOffset = segment.getStartOffset(); List<UsageOffset> list = docsToOffsetsMap.get(document); if (list == null) { list = new ArrayList<UsageOffset>(); docsToOffsetsMap.put(document, list); } list.add(new UsageOffset(fileOffset, fileOffset + rangeInElement.getLength(), usage.newText)); } for (Document document : docsToOffsetsMap.keySet()) { List<UsageOffset> list = docsToOffsetsMap.get(document); LOG.assertTrue(list != null, document); UsageOffset[] offsets = list.toArray(new UsageOffset[list.size()]); Arrays.sort(offsets); for (int i = offsets.length - 1; i >= 0; i--) { UsageOffset usageOffset = offsets[i]; document.replaceString(usageOffset.startOffset, usageOffset.endOffset, usageOffset.newText); } PsiDocumentManager.getInstance(project).commitDocument(document); } PsiDocumentManager.getInstance(project).commitAllDocuments(); }
static Collection<URL> getClassLoaderUrls() { final ClassLoader classLoader = PluginManagerCore.class.getClassLoader(); final Class<? extends ClassLoader> aClass = classLoader.getClass(); try { @SuppressWarnings("unchecked") List<URL> urls = (List<URL>) aClass.getMethod("getUrls").invoke(classLoader); return urls; } catch (IllegalAccessException ignored) { } catch (InvocationTargetException ignored) { } catch (NoSuchMethodException ignored) { } if (classLoader instanceof URLClassLoader) { return Arrays.asList(((URLClassLoader) classLoader).getURLs()); } return Collections.emptyList(); }
public List<VirtualFile> gatherPatchFiles(final Collection<VirtualFile> files) { final List<VirtualFile> result = new ArrayList<VirtualFile>(); final LinkedList<VirtualFile> filesQueue = new LinkedList<VirtualFile>(files); while (!filesQueue.isEmpty()) { ProgressManager.checkCanceled(); final VirtualFile file = filesQueue.removeFirst(); if (file.isDirectory()) { filesQueue.addAll(Arrays.asList(file.getChildren())); continue; } if (PatchFileType.NAME.equals(file.getFileType().getName())) { result.add(file); } } return result; }
private static GitCommit createCommit( Project project, SymbolicRefsI refs, VirtualFile root, GitLogRecord record) throws VcsException { GitCommit gitCommit; final Collection<String> currentRefs = record.getRefs(); List<String> locals = new ArrayList<String>(); List<String> remotes = new ArrayList<String>(); List<String> tags = new ArrayList<String>(); final String s = parseRefs(refs, currentRefs, locals, remotes, tags); gitCommit = new GitCommit( root, AbstractHash.create(record.getShortHash()), new SHAHash(record.getHash()), record.getAuthorName(), record.getCommitterName(), record.getDate(), record.getSubject(), record.getFullMessage(), new HashSet<String>(Arrays.asList(record.getParentsShortHashes())), record.getFilePaths(root), record.getAuthorEmail(), record.getCommitterEmail(), tags, locals, remotes, record.parseChanges(project, root), record.getAuthorTimeStamp() * 1000); gitCommit.setCurrentBranch(s); /*final String current = refs.getCurrent().getName(); gitCommit.setOnLocal((current != null) && (! current.startsWith(GitBranch.REFS_REMOTES_PREFIX)) && (! current.startsWith("remotes/")) && branches.contains(current)); String remoteName = refs.getTrackedRemoteName(); if (".".equals(remoteName)) { gitCommit.setOnTracked(gitCommit.isOnLocal()); } else { remoteName = remoteName.startsWith("refs/") ? remoteName.substring("refs/".length()) : remoteName; gitCommit.setOnTracked(remoteName != null && branches.contains(remoteName)); }*/ return gitCommit; }
@Override public boolean isReferenceTo(PsiElement element) { PsiElement baseTarget = resolve(); if (getManager().areElementsEquivalent(element, baseTarget)) { return true; } PsiElement target = GroovyTargetElementEvaluator.correctSearchTargets(baseTarget); if (target != baseTarget && getManager().areElementsEquivalent(element, target)) { return true; } if (element instanceof PsiMethod && target instanceof PsiMethod) { PsiMethod[] superMethods = ((PsiMethod) target).findSuperMethods(false); //noinspection SuspiciousMethodCalls if (Arrays.asList(superMethods).contains(element)) { return true; } } return false; }
public static <T> T assertOneElement(T[] ts) { Assert.assertNotNull(ts); Assert.assertEquals(Arrays.asList(ts).toString(), 1, ts.length); return ts[0]; }
public static <T> void assertUnorderedCollection(T[] collection, Consumer<T>... checkers) { assertUnorderedCollection(Arrays.asList(collection), checkers); }
public <T> void assertDoesntContain(Collection<? extends T> collection, T... notExpected) { assertDoesntContain(collection, Arrays.asList(notExpected)); }
public static String toString(Object[] collection, String separator) { return toString(Arrays.asList(collection), separator); }
public <T> void assertContainsElements(Collection<? extends T> collection, T... expected) { assertContainsElements(collection, Arrays.asList(expected)); }
public static <T> void assertSameElements(Collection<? extends T> collection, T... expected) { assertSameElements(collection, Arrays.asList(expected)); }
public static <T> void assertSameElements(T[] collection, T... expected) { assertSameElements(Arrays.asList(collection), expected); }
public static <T> void assertOrderedCollection(T[] collection, @NotNull Consumer<T>... checkers) { Assert.assertNotNull(collection); assertOrderedCollection(Arrays.asList(collection), checkers); }
public static <T> void assertOrderedEquals( final String errorMsg, @NotNull Iterable<T> actual, @NotNull T... expected) { Assert.assertNotNull(actual); Assert.assertNotNull(expected); assertOrderedEquals(errorMsg, actual, Arrays.asList(expected)); }
public static <T> void assertOrderedEquals(T[] actual, T... expected) { assertOrderedEquals(Arrays.asList(actual), expected); }
public static boolean isFiltered(@NotNull String qName, ClassFilter[] classFilters) { return isFiltered(qName, Arrays.asList(classFilters)); }
public static void assertSize(int expectedSize, final Object[] array) { assertEquals(toString(Arrays.asList(array)), expectedSize, array.length); }
@SuppressWarnings({"HardCodedStringLiteral"}) @Nullable public static IdeaPluginDescriptorImpl loadDescriptor( final File file, @NonNls final String fileName) { IdeaPluginDescriptorImpl descriptor = null; if (file.isDirectory()) { descriptor = loadDescriptorFromDir(file, fileName); if (descriptor == null) { File libDir = new File(file, "lib"); if (!libDir.isDirectory()) { return null; } final File[] files = libDir.listFiles(); if (files == null || files.length == 0) { return null; } Arrays.sort( files, new Comparator<File>() { @Override public int compare(File o1, File o2) { if (o2.getName().startsWith(file.getName())) return Integer.MAX_VALUE; if (o1.getName().startsWith(file.getName())) return -Integer.MAX_VALUE; if (o2.getName().startsWith("resources")) return -Integer.MAX_VALUE; if (o1.getName().startsWith("resources")) return Integer.MAX_VALUE; return 0; } }); for (final File f : files) { if (FileUtil.isJarOrZip(f)) { descriptor = loadDescriptorFromJar(f, fileName); if (descriptor != null) { descriptor.setPath(file); break; } // getLogger().warn("Cannot load descriptor from " + f.getName() + ""); } else if (f.isDirectory()) { IdeaPluginDescriptorImpl descriptor1 = loadDescriptorFromDir(f, fileName); if (descriptor1 != null) { if (descriptor != null) { getLogger() .info("Cannot load " + file + " because two or more plugin.xml's detected"); return null; } descriptor = descriptor1; descriptor.setPath(file); } } } } } else if (StringUtil.endsWithIgnoreCase(file.getName(), ".jar") && file.exists()) { descriptor = loadDescriptorFromJar(file, fileName); } if (descriptor != null && !descriptor.getOptionalConfigs().isEmpty()) { final Map<PluginId, IdeaPluginDescriptorImpl> descriptors = new HashMap<PluginId, IdeaPluginDescriptorImpl>(descriptor.getOptionalConfigs().size()); for (Map.Entry<PluginId, String> entry : descriptor.getOptionalConfigs().entrySet()) { String optionalDescriptorName = entry.getValue(); assert !Comparing.equal(fileName, optionalDescriptorName) : "recursive dependency: " + fileName; IdeaPluginDescriptorImpl optionalDescriptor = loadDescriptor(file, optionalDescriptorName); if (optionalDescriptor == null && !FileUtil.isJarOrZip(file)) { for (URL url : getClassLoaderUrls()) { if ("file".equals(url.getProtocol())) { optionalDescriptor = loadDescriptor(new File(decodeUrl(url.getFile())), optionalDescriptorName); if (optionalDescriptor != null) { break; } } } } if (optionalDescriptor != null) { descriptors.put(entry.getKey(), optionalDescriptor); } else { getLogger().info("Cannot find optional descriptor " + optionalDescriptorName); } } descriptor.setOptionalDescriptors(descriptors); } return descriptor; }