Search in sources :

Example 6 with PathMacroManager

use of com.intellij.openapi.components.PathMacroManager in project intellij-plugins by JetBrains.

the class FlexBuildConfigurationImpl method collapsePaths.

static String collapsePaths(@Nullable final ComponentManager componentManager, final String value) {
    if (componentManager == null)
        return value;
    if (!value.contains(CompilerOptionInfo.LIST_ENTRIES_SEPARATOR) && !value.contains(CompilerOptionInfo.LIST_ENTRY_PARTS_SEPARATOR)) {
        return value;
    }
    final StringBuilder result = new StringBuilder();
    final PathMacroManager pathMacroManager = PathMacroManager.getInstance(componentManager);
    final String delimiters = CompilerOptionInfo.LIST_ENTRIES_SEPARATOR + CompilerOptionInfo.LIST_ENTRY_PARTS_SEPARATOR;
    for (StringTokenizer tokenizer = new StringTokenizer(value, delimiters, true); tokenizer.hasMoreTokens(); ) {
        String token = tokenizer.nextToken();
        if (token.length() > 1) {
            token = pathMacroManager.collapsePath(token);
        }
        result.append(token);
    }
    return result.toString();
}
Also used : PathMacroManager(com.intellij.openapi.components.PathMacroManager)

Example 7 with PathMacroManager

use of com.intellij.openapi.components.PathMacroManager in project Perl5-IDEA by Camelcade.

the class PerlModuleExtension method loadState.

@Override
public void loadState(Element state) {
    state = state.getChild(PERL_CONFIG);
    myRoots.clear();
    if (state == null) {
        return;
    }
    PathMacroManager macroManager = ModulePathMacroManager.getInstance(myModule);
    for (Element pathElement : state.getChildren(ELEMENT_PATH)) {
        JpsModuleSourceRootPropertiesSerializer serializer = SERIALIZER_BY_ID_MAP.get(pathElement.getAttributeValue(ATTRIBUTE_TYPE));
        if (serializer == null) {
            continue;
        }
        String expandedPath = macroManager.expandPath(pathElement.getAttributeValue(ATTRIBUTE_VALUE));
        VirtualFile libRoot = VfsUtil.findFileByIoFile(new File(expandedPath), true);
        if (libRoot != null && libRoot.isValid() && libRoot.isDirectory()) {
            myRoots.put(libRoot, (PerlSourceRootType) serializer.getType());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JpsModuleSourceRootPropertiesSerializer(org.jetbrains.jps.model.serialization.module.JpsModuleSourceRootPropertiesSerializer) Element(org.jdom.Element) PathMacroManager(com.intellij.openapi.components.PathMacroManager) ModulePathMacroManager(com.intellij.openapi.components.impl.ModulePathMacroManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with PathMacroManager

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

the class DefaultInspectionToolPresentation method writeOutput.

private synchronized void writeOutput(@NotNull final CommonProblemDescriptor[] descriptions, @NotNull RefEntity refElement) {
    final Element parentNode = new Element(InspectionsBundle.message("inspection.problems"));
    exportResults(descriptions, refElement, parentNode, d -> false);
    final List list = parentNode.getChildren();
    @NonNls final String ext = ".xml";
    final String fileName = ourOutputPath + File.separator + myToolWrapper.getShortName() + ext;
    final PathMacroManager pathMacroManager = PathMacroManager.getInstance(getContext().getProject());
    PrintWriter printWriter = null;
    try {
        new File(ourOutputPath).mkdirs();
        final File file = new File(fileName);
        final CharArrayWriter writer = new CharArrayWriter();
        if (!file.exists()) {
            writer.append("<").append(InspectionsBundle.message("inspection.problems")).append(" " + GlobalInspectionContextBase.LOCAL_TOOL_ATTRIBUTE + "=\"").append(Boolean.toString(myToolWrapper instanceof LocalInspectionToolWrapper)).append("\">\n");
        }
        for (Object o : list) {
            final Element element = (Element) o;
            pathMacroManager.collapsePaths(element);
            JDOMUtil.writeElement(element, writer, "\n");
        }
        printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName, true), CharsetToolkit.UTF8_CHARSET)));
        printWriter.append("\n");
        printWriter.append(writer.toString());
    } catch (IOException e) {
        LOG.error(e);
    } finally {
        if (printWriter != null) {
            printWriter.close();
        }
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) PathMacroManager(com.intellij.openapi.components.PathMacroManager) PsiFile(com.intellij.psi.PsiFile)

Example 9 with PathMacroManager

use of com.intellij.openapi.components.PathMacroManager in project Perl5-IDEA by Camelcade.

the class PerlModuleExtension method getState.

@Nullable
@Override
public Element getState() {
    Element perlConfig = new Element(PERL_CONFIG);
    PathMacroManager macroManager = ModulePathMacroManager.getInstance(myModule);
    for (VirtualFile root : myRoots.keySet()) {
        if (!root.isValid() || !root.isDirectory()) {
            continue;
        }
        JpsModuleSourceRootPropertiesSerializer serializer = SERIALIZER_BY_TYPE_MAP.get(myRoots.get(root));
        if (serializer == null) {
            continue;
        }
        String collapsedPath = macroManager.collapsePath(root.getCanonicalPath());
        if (StringUtil.isEmpty(collapsedPath)) {
            continue;
        }
        Element pathElement = new Element(ELEMENT_PATH);
        pathElement.setAttribute(ATTRIBUTE_VALUE, collapsedPath);
        pathElement.setAttribute(ATTRIBUTE_TYPE, serializer.getTypeId());
        perlConfig.addContent(pathElement);
    }
    Element root = new Element("root");
    if (!perlConfig.getChildren().isEmpty()) {
        root.addContent(perlConfig);
    }
    return root;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JpsModuleSourceRootPropertiesSerializer(org.jetbrains.jps.model.serialization.module.JpsModuleSourceRootPropertiesSerializer) Element(org.jdom.Element) PathMacroManager(com.intellij.openapi.components.PathMacroManager) ModulePathMacroManager(com.intellij.openapi.components.impl.ModulePathMacroManager) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PathMacroManager (com.intellij.openapi.components.PathMacroManager)9 Element (org.jdom.Element)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ModulePathMacroManager (com.intellij.openapi.components.impl.ModulePathMacroManager)2 PsiFile (com.intellij.psi.PsiFile)2 NotNull (org.jetbrains.annotations.NotNull)2 JpsModuleSourceRootPropertiesSerializer (org.jetbrains.jps.model.serialization.module.JpsModuleSourceRootPropertiesSerializer)2 Parameters (aQute.bnd.header.Parameters)1 PsiFragment (com.intellij.dupLocator.util.PsiFragment)1 Document (com.intellij.openapi.editor.Document)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 InvalidDataException (com.intellij.openapi.util.InvalidDataException)1 Pair (com.intellij.openapi.util.Pair)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 PsiElement (com.intellij.psi.PsiElement)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 NonNls (org.jetbrains.annotations.NonNls)1 Nullable (org.jetbrains.annotations.Nullable)1