Search in sources :

Example 1 with PathMacroManager

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

the class SaveProjectAsTemplateAction method collectStructure.

@NotNull
private static List<LocalArchivedTemplate.RootDescription> collectStructure(Project project, Module moduleToSave) {
    List<LocalArchivedTemplate.RootDescription> result = new ArrayList<>();
    if (moduleToSave != null) {
        PathMacroManager macroManager = PathMacroManager.getInstance(moduleToSave);
        ModuleRootManager rootManager = ModuleRootManager.getInstance(moduleToSave);
        int i = 0;
        for (VirtualFile file : rootManager.getContentRoots()) {
            result.add(i, describeRoot(file, i, macroManager));
            i++;
        }
    } else {
        PathMacroManager macroManager = PathMacroManager.getInstance(project);
        ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
        int i = 0;
        for (VirtualFile file : rootManager.getContentRoots()) {
            result.add(i, describeRoot(file, i, macroManager));
            i++;
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) PathMacroManager(com.intellij.openapi.components.PathMacroManager) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PathMacroManager

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

the class DuplocatorHashCallback method writeFragments.

@SuppressWarnings({ "HardCodedStringLiteral" })
private static void writeFragments(final List<PsiFragment> psiFragments, final PrettyPrintWriter writer, Project project, final boolean shouldWriteOffsets) {
    final PathMacroManager macroManager = PathMacroManager.getInstance(project);
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    for (PsiFragment fragment : psiFragments) {
        final PsiFile psiFile = fragment.getFile();
        final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() : null;
        if (virtualFile != null) {
            writer.startNode("fragment");
            writer.addAttribute("file", macroManager.collapsePath(virtualFile.getUrl()));
            if (shouldWriteOffsets) {
                final Document document = documentManager.getDocument(psiFile);
                LOG.assertTrue(document != null);
                int startOffset = fragment.getStartOffset();
                final int line = document.getLineNumber(startOffset);
                writer.addAttribute("line", String.valueOf(line));
                final int lineStartOffset = document.getLineStartOffset(line);
                if (StringUtil.isEmptyOrSpaces(document.getText().substring(lineStartOffset, startOffset))) {
                    startOffset = lineStartOffset;
                }
                writer.addAttribute("start", String.valueOf(startOffset));
                writer.addAttribute("end", String.valueOf(fragment.getEndOffset()));
                if (fragment.containsMultipleFragments()) {
                    final int[][] offsets = fragment.getOffsets();
                    for (int[] offset : offsets) {
                        writer.startNode("offset");
                        writer.addAttribute("start", String.valueOf(offset[0]));
                        writer.addAttribute("end", String.valueOf(offset[1]));
                        writer.endNode();
                    }
                }
            }
            writer.endNode();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFragment(com.intellij.dupLocator.util.PsiFragment) PsiFile(com.intellij.psi.PsiFile) PathMacroManager(com.intellij.openapi.components.PathMacroManager) Document(com.intellij.openapi.editor.Document) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 3 with PathMacroManager

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

the class ToolsProcessor method saveTool.

private void saveTool(T tool, Element groupElement) {
    Element element = new Element(TOOL);
    if (tool.getName() != null) {
        element.setAttribute(NAME, tool.getName());
    }
    if (tool.getDescription() != null) {
        element.setAttribute(DESCRIPTION, tool.getDescription());
    }
    saveToolAttributes(tool, element);
    Element taskElement = new Element(EXEC);
    final PathMacroManager macroManager = PathMacroManager.getInstance(ApplicationManager.getApplication());
    Element option = new Element(ELEMENT_OPTION);
    taskElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, COMMAND);
    if (tool.getProgram() != null) {
        option.setAttribute(ATTRIBUTE_VALUE, macroManager.collapsePath(tool.getProgram()));
    }
    option = new Element(ELEMENT_OPTION);
    taskElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, PARAMETERS);
    if (tool.getParameters() != null) {
        option.setAttribute(ATTRIBUTE_VALUE, macroManager.collapsePath(tool.getParameters()));
    }
    option = new Element(ELEMENT_OPTION);
    taskElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, WORKING_DIRECTORY);
    if (tool.getWorkingDirectory() != null) {
        option.setAttribute(ATTRIBUTE_VALUE, macroManager.collapsePath(tool.getWorkingDirectory()).replace(File.separatorChar, '/'));
    }
    element.addContent(taskElement);
    FilterInfo[] filters = tool.getOutputFilters();
    for (FilterInfo filter : filters) {
        Element filterElement = new Element(FILTER);
        filter.writeExternal(filterElement);
        element.addContent(filterElement);
    }
    groupElement.addContent(element);
}
Also used : Element(org.jdom.Element) PathMacroManager(com.intellij.openapi.components.PathMacroManager)

Example 4 with PathMacroManager

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

the class ToolsProcessor method readScheme.

@NotNull
@Override
public ToolsGroup<T> readScheme(@NotNull Element root, boolean duringLoad) throws InvalidDataException, IOException, JDOMException {
    if (!TOOL_SET.equals(root.getName())) {
        throw new InvalidDataException();
    }
    String attrName = root.getAttributeValue(ATTRIBUTE_NAME);
    String groupName = StringUtil.isEmpty(attrName) ? Tool.DEFAULT_GROUP_NAME : attrName;
    ToolsGroup<T> result = createToolsGroup(groupName);
    final PathMacroManager macroManager = PathMacroManager.getInstance(ApplicationManager.getApplication());
    for (Element element : root.getChildren(TOOL)) {
        T tool = createTool();
        readToolAttributes(element, tool);
        Element exec = element.getChild(EXEC);
        if (exec != null) {
            for (final Object o1 : exec.getChildren(ELEMENT_OPTION)) {
                Element optionElement = (Element) o1;
                String name = optionElement.getAttributeValue(ATTRIBUTE_NAME);
                String value = optionElement.getAttributeValue(ATTRIBUTE_VALUE);
                if (WORKING_DIRECTORY.equals(name)) {
                    if (value != null) {
                        final String replace = macroManager.expandPath(value).replace('/', File.separatorChar);
                        tool.setWorkingDirectory(replace);
                    }
                }
                if (COMMAND.equals(name)) {
                    tool.setProgram(macroManager.expandPath(BaseToolManager.convertString(value)));
                }
                if (PARAMETERS.equals(name)) {
                    tool.setParameters(macroManager.expandPath(BaseToolManager.convertString(value)));
                }
            }
        }
        for (final Object o2 : element.getChildren(FILTER)) {
            Element childNode = (Element) o2;
            FilterInfo filterInfo = new FilterInfo();
            filterInfo.readExternal(childNode);
            tool.addOutputFilter(filterInfo);
        }
        tool.setGroup(groupName);
        result.addElement(tool);
    }
    return result;
}
Also used : Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) PathMacroManager(com.intellij.openapi.components.PathMacroManager) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PathMacroManager

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

the class OsmorcFacetConfiguration method writeExternal.

@Override
public void writeExternal(Element element) throws WriteExternalException {
    element.setAttribute(MANIFEST_GENERATION_MODE, getManifestGenerationMode().name());
    element.setAttribute(MANIFEST_LOCATION, getManifestLocation());
    element.setAttribute(JAR_FILE_LOCATION, myJarFileLocation != null ? myJarFileLocation : "");
    element.setAttribute(OUTPUT_PATH_TYPE, getOutputPathType().name());
    element.setAttribute(BND_FILE_LOCATION, getBndFileLocation());
    element.setAttribute(BUNDLOR_FILE_LOCATION, getBundlorFileLocation());
    element.setAttribute(BUNDLE_ACTIVATOR, getBundleActivator());
    element.setAttribute(BUNDLE_SYMBOLIC_NAME, getBundleSymbolicName());
    element.setAttribute(BUNDLE_VERSION, getBundleVersion());
    element.setAttribute(IGNORE_FILE_PATTERN, getIgnoreFilePattern());
    element.setAttribute(USE_PROJECT_DEFAULT_MANIFEST_FILE_LOCATION, String.valueOf(isUseProjectDefaultManifestFileLocation()));
    element.setAttribute(ALWAYS_REBUILD_BUNDLE_JAR, String.valueOf(isAlwaysRebuildBundleJAR()));
    element.setAttribute(DO_NOT_SYNCHRONIZE_WITH_MAVEN, String.valueOf(myDoNotSynchronizeWithMaven));
    Element props = new Element(ADDITIONAL_PROPERTIES);
    Map<String, String> map = getAdditionalPropertiesAsMap();
    for (String key : map.keySet()) {
        String value = map.get(key);
        if (key.equals(INCLUDE_RESOURCE)) {
            // there are paths in there, collapse these so the IML files don't get mixed up on every machine. The built in macro manager
            // does not recognize these, so we have to do this manually here.
            Parameters parameters = OSGiHeader.parseHeader(value);
            PathMacroManager macroManager = PathMacroManager.getInstance(myFacet.getModule());
            StringBuilder result = new StringBuilder(value.length());
            int last = 0;
            for (String pair : parameters.keySet()) {
                if (StringUtil.startsWithChar(pair, '{') && StringUtil.endsWithChar(pair, '}')) {
                    pair = pair.substring(1, pair.length() - 1).trim();
                }
                int p = pair.indexOf('=');
                String source = (p < 0 ? pair : pair.substring(p + 1)).trim();
                if (StringUtil.startsWithChar(source, '@')) {
                    source = source.substring(1);
                }
                String collapsedSource = macroManager.collapsePath(source);
                int sourceStart = value.indexOf(source, last);
                result.append(value, last, sourceStart).append(collapsedSource);
                last = sourceStart + source.length();
            }
            result.append(value, last, value.length());
            value = result.toString();
        }
        Element prop = new Element(PROPERTY);
        prop.setAttribute(KEY, key);
        prop.setAttribute(VALUE, value);
        props.addContent(prop);
    }
    element.addContent(props);
    Element additionalJARContentsElement = new Element("additionalJARContents");
    List<Pair<String, String>> additionalJARContents = getAdditionalJARContents();
    for (Pair<String, String> additionalJARContent : additionalJARContents) {
        Element entry = new Element("entry");
        entry.setAttribute("source", additionalJARContent.getFirst());
        entry.setAttribute("dest", additionalJARContent.getSecond());
        additionalJARContentsElement.addContent(entry);
    }
    element.addContent(additionalJARContentsElement);
}
Also used : Parameters(aQute.bnd.header.Parameters) Element(org.jdom.Element) PathMacroManager(com.intellij.openapi.components.PathMacroManager) Pair(com.intellij.openapi.util.Pair)

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