Search in sources :

Example 1 with TrackingPathMacroSubstitutor

use of com.intellij.openapi.components.TrackingPathMacroSubstitutor in project intellij-community by JetBrains.

the class DirectoryStorageUtil method loadFrom.

@NotNull
public static Map<String, Element> loadFrom(@Nullable VirtualFile dir, @Nullable PathMacroSubstitutor pathMacroSubstitutor) {
    if (dir == null || !dir.exists()) {
        return Collections.emptyMap();
    }
    StringInterner interner = new StringInterner();
    Map<String, Element> fileToState = new THashMap<>();
    for (VirtualFile file : dir.getChildren()) {
        // ignore system files like .DS_Store on Mac
        if (!StringUtilRt.endsWithIgnoreCase(file.getNameSequence(), FileStorageCoreUtil.DEFAULT_EXT)) {
            continue;
        }
        try {
            if (file.getLength() == 0) {
                LOG.warn("Ignore empty file " + file.getPath());
                continue;
            }
            Element element = JDOMUtil.load(file.getInputStream());
            String componentName = FileStorageCoreUtil.getComponentNameIfValid(element);
            if (componentName == null) {
                continue;
            }
            if (!element.getName().equals(FileStorageCoreUtil.COMPONENT)) {
                LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPresentableUrl());
                continue;
            }
            List<Element> elementChildren = element.getChildren();
            if (elementChildren.isEmpty()) {
                continue;
            }
            Element state = (Element) elementChildren.get(0).detach();
            if (JDOMUtil.isEmpty(state)) {
                continue;
            }
            JDOMUtil.internElement(state, interner);
            if (pathMacroSubstitutor != null) {
                pathMacroSubstitutor.expandPaths(state);
                if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) {
                    ((TrackingPathMacroSubstitutor) pathMacroSubstitutor).addUnknownMacros(componentName, PathMacrosCollector.getMacroNames(state));
                }
            }
            fileToState.put(file.getName(), state);
        } catch (Throwable e) {
            LOG.warn("Unable to load state", e);
        }
    }
    return fileToState;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringInterner(com.intellij.util.containers.StringInterner) THashMap(gnu.trove.THashMap) Element(org.jdom.Element) TrackingPathMacroSubstitutor(com.intellij.openapi.components.TrackingPathMacroSubstitutor) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TrackingPathMacroSubstitutor

use of com.intellij.openapi.components.TrackingPathMacroSubstitutor in project intellij-community by JetBrains.

the class FileStorageCoreUtil method load.

@NotNull
public static TreeMap<String, Element> load(@NotNull Element rootElement, @Nullable PathMacroSubstitutor pathMacroSubstitutor, boolean intern) {
    if (pathMacroSubstitutor != null) {
        pathMacroSubstitutor.expandPaths(rootElement);
    }
    StringInterner interner = intern ? new StringInterner() : null;
    List<Element> children = rootElement.getChildren(COMPONENT);
    if (children.isEmpty() && rootElement.getName().equals(COMPONENT) && rootElement.getAttributeValue(NAME) != null) {
        // exclusive component data
        // singleton must be not used here - later we modify list
        children = new SmartList<>(rootElement);
    }
    CompositePathMacroFilter filter = null;
    TreeMap<String, Element> map = new TreeMap<>();
    for (Iterator<Element> iterator = children.iterator(); iterator.hasNext(); ) {
        Element element = iterator.next();
        String name = getComponentNameIfValid(element);
        if (name == null || !(element.getAttributes().size() > 1 || !element.getChildren().isEmpty())) {
            continue;
        }
        // so, PathMacroFilter can easily find component name (null parent)
        iterator.remove();
        if (interner != null) {
            JDOMUtil.internElement(element, interner);
        }
        map.put(name, element);
        if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) {
            if (filter == null) {
                filter = new CompositePathMacroFilter(PathMacrosCollector.MACRO_FILTER_EXTENSION_POINT_NAME.getExtensions());
            }
            ((TrackingPathMacroSubstitutor) pathMacroSubstitutor).addUnknownMacros(name, PathMacrosCollector.getMacroNames(element, filter, PathMacros.getInstance()));
        }
        // remove only after "getMacroNames" - some PathMacroFilter requires element name attribute
        element.removeAttribute(NAME);
    }
    return map;
}
Also used : StringInterner(com.intellij.util.containers.StringInterner) Element(org.jdom.Element) TrackingPathMacroSubstitutor(com.intellij.openapi.components.TrackingPathMacroSubstitutor) TreeMap(java.util.TreeMap) CompositePathMacroFilter(com.intellij.openapi.components.CompositePathMacroFilter) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with TrackingPathMacroSubstitutor

use of com.intellij.openapi.components.TrackingPathMacroSubstitutor in project intellij-community by JetBrains.

the class CommitToIcsDialog method commitChanges.

private void commitChanges(List<Change> changes) {
    StateStorageManager storageManager = ServiceKt.getStateStore(project).getStateStorageManager();
    TrackingPathMacroSubstitutor macroSubstitutor = storageManager.getMacroSubstitutor();
    assert macroSubstitutor != null;
    IcsManager icsManager = IcsManagerKt.getIcsManager();
    SmartList<String> addToIcs = new SmartList<>();
    for (Change change : changes) {
        VirtualFile file = change.getVirtualFile();
        assert file != null;
        String fileSpec = macroSubstitutor.collapsePath(file.getPath());
        String repoPath = IcsUrlBuilderKt.toRepositoryPath(fileSpec, RoamingType.DEFAULT, projectId);
        addToIcs.add(repoPath);
        if (!icsManager.getRepositoryManager().has(repoPath)) {
        // new, revert local
        // todo
        }
    }
//icsManager.getRepositoryManager().commit(addToIcs);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StateStorageManager(com.intellij.configurationStore.StateStorageManager) TrackingPathMacroSubstitutor(com.intellij.openapi.components.TrackingPathMacroSubstitutor) Change(com.intellij.openapi.vcs.changes.Change) SmartList(com.intellij.util.SmartList)

Aggregations

TrackingPathMacroSubstitutor (com.intellij.openapi.components.TrackingPathMacroSubstitutor)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 StringInterner (com.intellij.util.containers.StringInterner)2 Element (org.jdom.Element)2 NotNull (org.jetbrains.annotations.NotNull)2 StateStorageManager (com.intellij.configurationStore.StateStorageManager)1 CompositePathMacroFilter (com.intellij.openapi.components.CompositePathMacroFilter)1 Change (com.intellij.openapi.vcs.changes.Change)1 SmartList (com.intellij.util.SmartList)1 THashMap (gnu.trove.THashMap)1 TreeMap (java.util.TreeMap)1