Java Code Examples for com.intellij.openapi.util.io.FileUtil#toSystemDependentName()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#toSystemDependentName() . 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: FlutterProjectCreator.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private VirtualFile getLocationFromModel(@Nullable Project projectToClose, boolean saveLocation) {
  final File location = new File(FileUtil.toSystemDependentName(myModel.projectLocation().get()));
  if (!location.exists() && !location.mkdirs()) {
    String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir", location.getAbsolutePath());
    Messages.showErrorDialog(projectToClose, message, ActionsBundle.message("action.NewDirectoryProject.title"));
    return null;
  }
  final File baseFile = new File(location, myModel.projectName().get());
  //noinspection ResultOfMethodCallIgnored
  baseFile.mkdirs();
  final VirtualFile baseDir = ApplicationManager.getApplication().runWriteAction(
    (Computable<VirtualFile>)() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(baseFile));
  if (baseDir == null) {
    FlutterUtils.warn(LOG, "Couldn't find '" + location + "' in VFS");
    return null;
  }
  if (saveLocation) {
    RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getPath());
  }
  return baseDir;
}
 
Example 2
Source File: ArchivesBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void copyJars(final Set<String> writtenPaths) throws IOException {
  for (Map.Entry<ArchivePackageInfo, File> entry : myBuiltArchives.entrySet()) {
    File fromFile = entry.getValue();
    boolean first = true;
    for (DestinationInfo destination : entry.getKey().getAllDestinations()) {
      if (destination instanceof ExplodedDestinationInfo) {
        File toFile = new File(FileUtil.toSystemDependentName(destination.getOutputPath()));

        if (first) {
          first = false;
          renameFile(fromFile, toFile, writtenPaths);
          fromFile = toFile;
        }
        else {
          DeploymentUtilImpl.copyFile(fromFile, toFile, myContext, writtenPaths, myFileFilter);
        }

      }
    }
  }
}
 
Example 3
Source File: FlutterDartAnalysisServer.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
public CompletableFuture<List<FlutterWidgetProperty>> getWidgetDescription(@NotNull VirtualFile file, int _offset) {
  final CompletableFuture<List<FlutterWidgetProperty>> result = new CompletableFuture<>();
  final String filePath = FileUtil.toSystemDependentName(file.getPath());
  final int offset = analysisService.getOriginalOffset(file, _offset);

  final String id = analysisService.generateUniqueId();
  synchronized (responseConsumers) {
    responseConsumers.put(id, (resultObject) -> {
      try {
        final JsonArray propertiesObject = resultObject.getAsJsonArray("properties");
        final ArrayList<FlutterWidgetProperty> properties = new ArrayList<>();
        for (JsonElement propertyObject : propertiesObject) {
          properties.add(FlutterWidgetProperty.fromJson(propertyObject.getAsJsonObject()));
        }
        result.complete(properties);
      }
      catch (Throwable ignored) {
      }
    });
  }

  final JsonObject request = FlutterRequestUtilities.generateFlutterGetWidgetDescription(id, filePath, offset);
  analysisService.sendRequest(id, request);

  return result;
}
 
Example 4
Source File: FilePromptMacro.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected String promptUser(DataContext dataContext) {
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
  final VirtualFile[] result = FileChooser.chooseFiles(descriptor, project, null);
  return result.length == 1? FileUtil.toSystemDependentName(result[0].getPath()) : null;
}
 
Example 5
Source File: HaxeFormatterTest.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private void doTest() throws Exception {
  myFixture.configureByFile(getTestName(false) + ".hx");
    /*CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
        @Override
        public void run() {
            CodeStyleManager.getInstance(myFixture.getProject()).reformat(myFixture.getFile());

        }
    }, null, null);*/
  WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
    @Override
    public void run() {
      CodeStyleManager.getInstance(myFixture.getProject()).reformat(myFixture.getFile());
    }
  });
  try {
    myFixture.checkResultByFile(getTestName(false) + ".txt");
  }
  catch (RuntimeException e) {
    if (!(e.getCause() instanceof FileNotFoundException)) {
      throw e;
    }
    final String path = getTestDataPath() + getTestName(false) + ".txt";
    FileWriter writer = new FileWriter(FileUtil.toSystemDependentName(path));
    try {
      writer.write(myFixture.getFile().getText().trim());
    }
    finally {
      writer.close();
    }
    fail("No output text found. File " + path + " created.");
  }
}
 
Example 6
Source File: UsefulTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  ensureConfigFolderExists();

  if (shouldContainTempFiles()) {
    String testName = getTestName(true);
    if (StringUtil.isEmptyOrSpaces(testName)) testName = "";
    testName = new File(testName).getName(); // in case the test name contains file separators
    myTempDir = FileUtil.toSystemDependentName(ORIGINAL_TEMP_DIR + "/" + TEMP_DIR_MARKER + testName + "_"+ RNG.nextInt(1000));
    FileUtil.resetCanonicalTempPathCache(myTempDir);
  }
  ApplicationInfoImpl.setInPerformanceTest(isPerformanceTest());
}
 
Example 7
Source File: WSLDistributionLegacy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String getWindowsPath(@Nonnull String wslPath) {
  String windowsPath = super.getWindowsPath(wslPath);
  if (windowsPath != null) {
    return windowsPath;
  }

  String wslRootInHost = WSL_ROOT_IN_WINDOWS_PROVIDER.getValue();
  if (wslRootInHost == null) {
    return null;
  }
  return FileUtil.toSystemDependentName(wslRootInHost + wslPath);
}
 
Example 8
Source File: ProjectStoreImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getPresentableUrl() {
  if (myProject.isDefault()) {
    return null;
  }
  if (myPresentableUrl == null) {
    String url = !myProject.isDefault() ? getProjectBasePath() : getProjectFilePath();
    if (url != null) {
      myPresentableUrl = FileUtil.toSystemDependentName(url);
    }
  }
  return myPresentableUrl;
}
 
Example 9
Source File: UpdateBreakpointsAfterRenameTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private VirtualFile createFile(String path) {
  final File ioFile = new File(myTempFiles.createTempDir(), FileUtil.toSystemDependentName(path));
  FileUtil.createIfDoesntExist(ioFile);
  final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile);
  assertNotNull(virtualFile);
  return virtualFile;
}
 
Example 10
Source File: ArtifactDeploymentSourceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getFilePath() {
  final Artifact artifact = getArtifact();
  if (artifact != null) {
    String outputPath = artifact.getOutputPath();
    if (outputPath != null) {
      final CompositePackagingElement<?> rootElement = artifact.getRootElement();
      if (!(rootElement instanceof ArtifactRootElement<?>)) {
        outputPath += "/" + rootElement.getName();
      }
      return FileUtil.toSystemDependentName(outputPath);
    }
  }
  return null;
}
 
Example 11
Source File: InstallSdkAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
GeneralCommandLine getCommandLine() {
  final String flutterTool = FileUtil.toSystemDependentName(mySdkDir + "/bin/" + FlutterSdkUtil.flutterScriptName());
  return new GeneralCommandLine().withParentEnvironmentType(
    GeneralCommandLine.ParentEnvironmentType.CONSOLE).withWorkDirectory(mySdkDir)
    .withExePath(flutterTool)
    .withParameters("precache");
}
 
Example 12
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setSelectedFile(VirtualFile newFile) {
  if (currentFile.getValue() != null) {
    flutterAnalysisServer.removeOutlineListener(currentFilePath, outlineListener);
    currentFile.setValue(null);
    currentFilePath = null;
  }

  // If not a Dart file, ignore it.
  if (newFile != null && !FlutterUtils.isDartFile(newFile)) {
    newFile = null;
  }

  // Show the toolbar if the new file is a Dart file, or hide otherwise.
  if (windowPanel != null) {
    if (newFile != null) {
      windowPanel.setToolbar(widgetEditToolbar.getToolbar().getComponent());
    }
    else if (windowPanel.isToolbarVisible()) {
      windowPanel.setToolbar(null);
    }
  }

  // If the tree is already created, clear it now, until the outline for the new file is received.
  if (tree != null) {
    final DefaultMutableTreeNode rootNode = getRootNode();
    rootNode.removeAllChildren();
    getTreeModel().reload(rootNode);
  }

  // Subscribe for the outline for the new file.
  if (newFile != null) {
    currentFile.setValue(newFile);
    currentFilePath = FileUtil.toSystemDependentName(newFile.getPath());
    flutterAnalysisServer.addOutlineListener(currentFilePath, outlineListener);
  }
}
 
Example 13
Source File: LocalFileSystemImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static WatchRequestImpl watch(String rootPath, boolean recursively) {
  int index = rootPath.indexOf(URLUtil.ARCHIVE_SEPARATOR);
  if (index >= 0) rootPath = rootPath.substring(0, index);

  File rootFile = new File(FileUtil.toSystemDependentName(rootPath));
  if (!rootFile.isAbsolute()) {
    LOG.warn(new IllegalArgumentException("Invalid path: " + rootPath));
    return null;
  }

  return new WatchRequestImpl(rootFile.getAbsolutePath(), recursively);
}
 
Example 14
Source File: InstallSdkAction.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
GeneralCommandLine getCommandLine() {
  final String flutterTool = FileUtil.toSystemDependentName(mySdkDir + "/bin/" + FlutterSdkUtil.flutterScriptName());
  return new GeneralCommandLine().withParentEnvironmentType(
    GeneralCommandLine.ParentEnvironmentType.CONSOLE).withWorkDirectory(mySdkDir)
    .withExePath(flutterTool)
    .withParameters("precache");
}
 
Example 15
Source File: FirefoxSettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public File getProfilesIniFile() {
  if (myProfilesIniPath != null) {
    return new File(FileUtil.toSystemDependentName(myProfilesIniPath));
  }
  return FirefoxUtil.getDefaultProfileIniPath();
}
 
Example 16
Source File: XLineBreakpointImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getPresentableFilePath() {
  String url = getFileUrl();
  if (url != null && LocalFileSystem.PROTOCOL.equals(VirtualFileManager.extractProtocol(url))) {
    return FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(url));
  }
  return url != null ? url : "";
}
 
Example 17
Source File: ChangesBrowserFilePathNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return FileUtil.toSystemDependentName(getUserObject().getPath());
}
 
Example 18
Source File: DiffShelvedChangesAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String getName() {
  return FileUtil.toSystemDependentName(getFilePath().getPath());
}
 
Example 19
Source File: ImportSettingsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String presentableFileName(final File file) {
  return "'" + FileUtil.toSystemDependentName(file.getPath()) + "'";
}
 
Example 20
Source File: MockSdkWrapper.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String getHomePath() {
  final String homePath = FileUtil.toSystemDependentName(myHomePath == null ? myDelegate.getHomePath() : myHomePath);
  return StringUtil.trimEnd(homePath, File.separator);
}