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;
}
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;
}
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);
}
Aggregations