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