com.intellij.openapi.components.PathMacroManager Java Examples

The following examples show how to use com.intellij.openapi.components.PathMacroManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BashRunConfiguration.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Override
public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);

    // common config
    JDOMExternalizerUtil.writeField(element, "INTERPRETER_OPTIONS", interpreterOptions);
    JDOMExternalizerUtil.writeField(element, "INTERPRETER_PATH", interpreterPath);
    JDOMExternalizerUtil.writeField(element, "PROJECT_INTERPRETER", Boolean.toString(useProjectInterpreter));
    JDOMExternalizerUtil.writeField(element, "WORKING_DIRECTORY", workingDirectory);
    JDOMExternalizerUtil.writeField(element, "PARENT_ENVS", Boolean.toString(isPassParentEnvs()));

    // run config
    JDOMExternalizerUtil.writeField(element, "SCRIPT_NAME", scriptName);
    JDOMExternalizerUtil.writeField(element, "PARAMETERS", getProgramParameters());

    //JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element);
    DefaultJDOMExternalizer.writeExternal(this, element);
    writeModule(element);
    EnvironmentVariablesComponent.writeExternal(element, getEnvs());

    PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
}
 
Example #2
Source File: MacroAwareTextBrowseFolderListener.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected String expandPath(@Nonnull String path) {
  Project project = getProject();
  if (project != null) {
    path = PathMacroManager.getInstance(project).expandPath(path);
  }

  Module module = myFileChooserDescriptor.getUserData(LangDataKeys.MODULE_CONTEXT);
  if (module == null) {
    module = myFileChooserDescriptor.getUserData(LangDataKeys.MODULE);
  }
  if (module != null) {
    path = PathMacroManager.getInstance(module).expandPath(path);
  }

  return super.expandPath(path);
}
 
Example #3
Source File: RefManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public RefEntity getReference(final String type, final String fqName) {
  for (RefManagerExtension extension : myExtensions.values()) {
    final RefEntity refEntity = extension.getReference(type, fqName);
    if (refEntity != null) return refEntity;
  }
  if (SmartRefElementPointer.FILE.equals(type)) {
    return RefFileImpl.fileFromExternalName(this, fqName);
  }
  if (SmartRefElementPointer.MODULE.equals(type)) {
    return RefModuleImpl.moduleFromName(this, fqName);
  }
  if (SmartRefElementPointer.PROJECT.equals(type)) {
    return getRefProject();
  }
  if (SmartRefElementPointer.DIR.equals(type)) {
    String url = VfsUtilCore.pathToUrl(PathMacroManager.getInstance(getProject()).expandPath(fqName));
    VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(url);
    if (vFile != null) {
      final PsiDirectory dir = PsiManager.getInstance(getProject()).findDirectory(vFile);
      return getReference(dir);
    }
  }
  return null;
}
 
Example #4
Source File: DuplocatorHashCallback.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"HardCodedStringLiteral"})
private static void writeFragments(final List<? extends PsiFragment> psiFragments, Element duplicateElement, 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) {
      Element fragmentElement = new Element("fragment");
      fragmentElement.setAttribute("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);
        fragmentElement.setAttribute("line", String.valueOf(line));
        final int lineStartOffset = document.getLineStartOffset(line);
        if (StringUtil.isEmptyOrSpaces(document.getText().substring(lineStartOffset, startOffset))) {
          startOffset = lineStartOffset;
        }
        fragmentElement.setAttribute("start", String.valueOf(startOffset));
        fragmentElement.setAttribute("end", String.valueOf(fragment.getEndOffset()));
        if (fragment.containsMultipleFragments()) {
          final int[][] offsets = fragment.getOffsets();
          for (int[] offset : offsets) {
            Element offsetElement = new Element("offset");
            offsetElement.setAttribute("start", String.valueOf(offset[0]));
            offsetElement.setAttribute("end", String.valueOf(offset[1]));
            fragmentElement.addContent(offsetElement);
          }
        }
      }
      duplicateElement.addContent(fragmentElement);
    }
  }
}
 
Example #5
Source File: BashRunConfiguration.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
public void readExternal(Element element) throws InvalidDataException {
    PathMacroManager.getInstance(getProject()).expandPaths(element);
    super.readExternal(element);

    DefaultJDOMExternalizer.readExternal(this, element);
    readModule(element);
    EnvironmentVariablesComponent.readExternal(element, getEnvs());

    // common config
    interpreterOptions = JDOMExternalizerUtil.readField(element, "INTERPRETER_OPTIONS");
    interpreterPath = JDOMExternalizerUtil.readField(element, "INTERPRETER_PATH");
    workingDirectory = JDOMExternalizerUtil.readField(element, "WORKING_DIRECTORY");

    // 1.7.0 to 1.7.2 broke the run configs by defaulting to useProjectInterpreter, using field USE_PROJECT_INTERPRETER
    // we try to workaround for config saved by these versions by using another field and a smart fallback
    String useProjectInterpreterValue = JDOMExternalizerUtil.readField(element, "PROJECT_INTERPRETER");
    String oldUseProjectInterpreterValue = JDOMExternalizerUtil.readField(element, "USE_PROJECT_INTERPRETER");
    if (useProjectInterpreterValue != null) {
        useProjectInterpreter = Boolean.parseBoolean(useProjectInterpreterValue);
    } else if (StringUtils.isEmpty(interpreterPath) && oldUseProjectInterpreterValue != null) {
        // only use old "use project interpreter" setting when there's no interpreter in the run config and a configured project interpreter
        Project project = getProject();
        if (!BashProjectSettings.storedSettings(project).getProjectInterpreter().isEmpty()) {
            useProjectInterpreter = Boolean.parseBoolean(oldUseProjectInterpreterValue);
        }
    }

    String parentEnvValue = JDOMExternalizerUtil.readField(element, "PARENT_ENVS");
    if (parentEnvValue != null) {
        setPassParentEnvs(Boolean.parseBoolean(parentEnvValue));
    }

    // run config
    scriptName = JDOMExternalizerUtil.readField(element, "SCRIPT_NAME");
    setProgramParameters(JDOMExternalizerUtil.readField(element, "PARAMETERS"));
}
 
Example #6
Source File: DependenciesPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getReportText() {
  final Element rootElement = new Element("root");
  rootElement.setAttribute("isBackward", String.valueOf(!myForward));
  final List<PsiFile> files = new ArrayList<PsiFile>(myDependencies.keySet());
  Collections.sort(files, new Comparator<PsiFile>() {
    @Override
    public int compare(PsiFile f1, PsiFile f2) {
      final VirtualFile virtualFile1 = f1.getVirtualFile();
      final VirtualFile virtualFile2 = f2.getVirtualFile();
      if (virtualFile1 != null && virtualFile2 != null) {
        return virtualFile1.getPath().compareToIgnoreCase(virtualFile2.getPath());
      }
      return 0;
    }
  });
  for (PsiFile file : files) {
    final Element fileElement = new Element("file");
    fileElement.setAttribute("path", file.getVirtualFile().getPath());
    for (PsiFile dep : myDependencies.get(file)) {
      Element depElement = new Element("dependency");
      depElement.setAttribute("path", dep.getVirtualFile().getPath());
      fileElement.addContent(depElement);
    }
    rootElement.addContent(fileElement);
  }
  PathMacroManager.getInstance(myProject).collapsePaths(rootElement);
  return JDOMUtil.writeDocument(new Document(rootElement), SystemProperties.getLineSeparator());
}
 
Example #7
Source File: ProgramParametersConfigurator.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected String expandPath(@Nullable String path, Module module, Project project) {
  path = PathMacroManager.getInstance(project).expandPath(path);
  if (module != null) {
    path = PathMacroManager.getInstance(module).expandPath(path);
  }
  return path;
}
 
Example #8
Source File: DefaultInspectionToolPresentation.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void writeOutput(@Nonnull final CommonProblemDescriptor[] descriptions, @Nonnull RefEntity refElement) {
  final Element parentNode = new Element(InspectionsBundle.message("inspection.problems"));
  exportResults(descriptions, refElement, parentNode);
  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(" " + GlobalInspectionContextImpl.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), "UTF-8")));
    printWriter.append("\n");
    printWriter.append(writer.toString());
  }
  catch (IOException e) {
    LOG.error(e);
  }
  finally {
    if (printWriter != null) {
      printWriter.close();
    }
  }
}
 
Example #9
Source File: ExportToFileUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected JPanel createFilePanel(JTextField textField, JButton button) {
  JPanel panel = new JPanel();
  panel.setLayout(new GridBagLayout());
  GridBagConstraints gbConstraints = new GridBagConstraints();
  gbConstraints.fill = GridBagConstraints.HORIZONTAL;
  JLabel promptLabel = new JLabel(IdeBundle.message("editbox.export.to.file"));
  gbConstraints.weightx = 0;
  panel.add(promptLabel, gbConstraints);
  gbConstraints.weightx = 1;
  panel.add(textField, gbConstraints);
  gbConstraints.fill = 0;
  gbConstraints.weightx = 0;
  gbConstraints.insets = new Insets(0, 0, 0, 0);
  panel.add(button, gbConstraints);

  String defaultFilePath = myExporter.getDefaultFilePath();
  if (! new File(defaultFilePath).isAbsolute()) {
    defaultFilePath = PathMacroManager.getInstance(myProject).collapsePath(defaultFilePath).replace('/', File.separatorChar);
  } else {
    defaultFilePath = defaultFilePath.replace('/', File.separatorChar);
  }
  textField.setText(defaultFilePath);

  button.addActionListener(
      new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        browseFile();
      }
    }
  );

  return panel;
}
 
Example #10
Source File: RefFileImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
static RefElement fileFromExternalName(final RefManager manager, final String fqName) {
  final VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(PathMacroManager.getInstance(manager.getProject()).expandPath(fqName));
  if (virtualFile != null) {
    final PsiFile psiFile = PsiManager.getInstance(manager.getProject()).findFile(virtualFile);
    if (psiFile != null) {
      return manager.getReference(psiFile);
    }
  }
  return null;
}
 
Example #11
Source File: ModuleManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Method expand or collapse element children.  This is need because PathMacroManager affected to attributes to.
 * If dirurl equals file://$PROJECT_DIR$ it ill replace to  file://$MODULE_DIR$, and after restart it ill throw error directory not found
 */
private static void collapseOrExpandMacros(Module module, Element element, boolean collapse) {
  final PathMacroManager pathMacroManager = PathMacroManager.getInstance(module);
  for (Element child : element.getChildren()) {
    if (collapse) {
      pathMacroManager.collapsePaths(child);
    }
    else {
      pathMacroManager.expandPaths(child);
    }
  }
}
 
Example #12
Source File: BuckCellManagerImplTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  Project project = getProject();
  virtualFileManager = VirtualFileManager.getInstance();
  pathMacroManager = PathMacroManager.getInstance(project);
  buckCellSettingsProvider = BuckCellSettingsProvider.getInstance(project);
}
 
Example #13
Source File: BuckCellManagerImpl.java    From buck with Apache License 2.0 5 votes vote down vote up
public BuckCellManagerImpl(
    BuckCellSettingsProvider buckCellSettingsProvider,
    VirtualFileManager virtualFileManager,
    PathMacroManager pathMacroManager) {
  mBuckCellSettingsProvider = buckCellSettingsProvider;
  mVirtualFileManager = virtualFileManager;
  mPathMacroManager = pathMacroManager;
}
 
Example #14
Source File: ANTLRv4GrammarProperties.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public String resolveLibDir(Project project, String defaultValue) {
    String libDir = getLibDir();

    if ( libDir==null || libDir.equals("") ) {
        libDir = defaultValue;
    }

    return PathMacroManager.getInstance(project).expandPath(libDir);
}
 
Example #15
Source File: ANTLRv4GrammarProperties.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public String resolveOutputDirName(Project project, VirtualFile contentRoot, String package_) {
    String outputDirName = outputDir.isEmpty() ? RunANTLROnGrammarFile.OUTPUT_DIR_NAME : outputDir;

    outputDirName = PathMacroManager.getInstance(project).expandPath(outputDirName);

    File f = new File(outputDirName);
    if (!f.isAbsolute()) { // if not absolute file spec, it's relative to project root
        outputDirName = contentRoot.getPath() + File.separator + outputDirName;
    }
    // add package if any
    if ( isNotBlank(package_) ) {
        outputDirName += File.separator + package_.replace('.', File.separatorChar);
    }
    return outputDirName;
}
 
Example #16
Source File: XQueryRunProfileState.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private String expandPath(String path, Module module, Project project) {
    path = PathMacroManager.getInstance(project).expandPath(path);
    if (module != null) {
        path = PathMacroManager.getInstance(module).expandPath(path);
    }

    return path;
}
 
Example #17
Source File: XQueryRunConfiguration.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public void writeExternal(final Element element) throws WriteExternalException {
    super.writeExternal(element);
    xmlConfigurationAccessor.writeConfiguration(this, element);
    writeModule(element);
    EnvironmentVariablesComponent.writeExternal(element, getEnvs());
    PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
    variablesAccessor.writeVariables(this, element);
}
 
Example #18
Source File: XQueryRunConfiguration.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public void readExternal(final Element element) throws InvalidDataException {
    PathMacroManager.getInstance(getProject()).expandPaths(element);
    super.readExternal(element);
    xmlConfigurationAccessor.readConfiguration(element, this);
    readModule(element);
    EnvironmentVariablesComponent.readExternal(element, getEnvs());
    variablesAccessor.readVariables(element, this);
}
 
Example #19
Source File: MongoRunConfiguration.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
@Override
    public void writeExternal(Element element) throws WriteExternalException {
        super.writeExternal(element);
        JDOMExternalizer.write(element, "path", scriptPath);
        JDOMExternalizer.write(element, "shellParams", shellParameters);
//        JDOMExternalizer.write(element, "serverConfiguration", serverConfiguration);

        PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
    }
 
Example #20
Source File: MongoRunConfiguration.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
@Override
    public void readExternal(Element element) throws InvalidDataException {
        PathMacroManager.getInstance(getProject()).expandPaths(element);
        super.readExternal(element);
        scriptPath = JDOMExternalizer.readString(element, "path");
        shellParameters = JDOMExternalizer.readString(element, "shellParams");
//        serverConfiguration = JDOMExternalizer.readBoolean(element, "serverConfiguration");
    }
 
Example #21
Source File: BaseFileConfigurableStoreImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected BaseFileConfigurableStoreImpl(@Nonnull Provider<ApplicationDefaultStoreCache> applicationDefaultStoreCache, @Nonnull PathMacroManager pathMacroManager) {
  super(applicationDefaultStoreCache);
  myPathMacroManager = pathMacroManager;
}
 
Example #22
Source File: BaseFileConfigurableStoreImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected final PathMacroManager getPathMacroManagerForDefaults() {
  return myPathMacroManager;
}
 
Example #23
Source File: HaskellApplicationRunConfiguration.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
@Override
public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);
    JDOMExternalizerUtil.writeField(element, PROGRAM_ARGUMENTS, programArguments);
    PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
}
 
Example #24
Source File: HaskellApplicationRunConfiguration.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
@Override
public void readExternal(Element element) throws InvalidDataException {
    PathMacroManager.getInstance(getProject()).expandPaths(element);
    super.readExternal(element);
    programArguments = JDOMExternalizerUtil.readField(element, PROGRAM_ARGUMENTS);
}
 
Example #25
Source File: ToolsProcessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public ToolsGroup<T> readScheme(@Nonnull final Document document) throws InvalidDataException, IOException, JDOMException {
  Element root = document.getRootElement();
  if (root == null || !TOOL_SET.equals(root.getName())) {
    throw new InvalidDataException();
  }

  String groupName = root.getAttributeValue(ATTRIBUTE_NAME);
  ToolsGroup<T> result = createToolsGroup(groupName);

  final PathMacroManager macroManager = PathMacroManager.getInstance(ApplicationManager.getApplication());

  for (final Object o : root.getChildren(TOOL)) {
    Element element = (Element)o;

    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(ToolManager.convertString(value)));
        }
        if (PARAMETERS.equals(name)) {
          tool.setParameters(macroManager.expandPath(ToolManager.convertString(value)));
        }
      }
    }

    for (final Element childNode : element.getChildren(FILTER)) {
      FilterInfo filterInfo = new FilterInfo();
      filterInfo.readExternal(childNode);
      tool.addOutputFilter(filterInfo);
    }

    tool.setGroup(groupName);
    result.addElement(tool);
  }

  return result;
}
 
Example #26
Source File: HaskellTestRunConfiguration.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
@Override
public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);
    JDOMExternalizerUtil.writeField(element, PROGRAM_ARGUMENTS, programArguments);
    PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
}
 
Example #27
Source File: HaskellTestRunConfiguration.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
@Override
public void readExternal(Element element) throws InvalidDataException {
    PathMacroManager.getInstance(getProject()).expandPaths(element);
    super.readExternal(element);
    programArguments = JDOMExternalizerUtil.readField(element, PROGRAM_ARGUMENTS);
}