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

The following examples show how to use com.intellij.openapi.util.io.FileUtil#sanitizeFileName() . 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: EditorDocOps.java    From KodeBeagle with Apache License 2.0 6 votes vote down vote up
public final VirtualFile getVirtualFile(final String fileName,
                                        final String displayFileName,
                                        final String contents)
        throws IOException, NoSuchAlgorithmException {

    final String tempDir = System.getProperty(JAVA_IO_TMP_DIR);
    final String trimmedFileName =
            FileUtil.sanitizeFileName(StringUtil.trimEnd(fileName, displayFileName));
    final String digest = Utils.getInstance().getDigestAsString(trimmedFileName);
    final String fullFilePath = Utils.getInstance()
            .createFileWithContents(displayFileName, contents, tempDir, digest);
    // Refreshing File System is required so that it is aware of newly created files
    final VirtualFile virtualFile = LocalFileSystem.getInstance()
            .refreshAndFindFileByIoFile(new File(fullFilePath));
    if (virtualFile == null) {
        throw new IllegalArgumentException("Virtual file should not be null."
                + " Can be an issue with FileSystem.");
    }
    windowEditorOps.setWriteStatus(virtualFile, false);
    return virtualFile;
}
 
Example 2
Source File: CoverageEnabledConfiguration.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@NonNls
protected String createCoverageFile() {
  if (myCoverageRunner == null) {
    return null;
  }

  @NonNls final String coverageRootPath = ContainerPathManager.get().getSystemPath() + File.separator + "coverage";
  final String path = coverageRootPath + File.separator + myProject.getName() + coverageFileNameSeparator()
                      + FileUtil.sanitizeFileName(myConfiguration.getName()) + ".coverage";

  new File(coverageRootPath).mkdirs();
  return path;
}
 
Example 3
Source File: ArtifactUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static String getDefaultArtifactOutputPath(@Nonnull String artifactName, final @Nonnull Project project) {
  final CompilerConfiguration extension = CompilerConfiguration.getInstance(project);
  String outputUrl = extension.getCompilerOutputUrl();
  if (outputUrl == null || outputUrl.length() == 0) {
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null) return null;
    outputUrl = baseDir.getUrl() + "/out";
  }
  return VfsUtil.urlToPath(outputUrl) + "/artifacts/" + FileUtil.sanitizeFileName(artifactName);
}
 
Example 4
Source File: ShelveChangesManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String shortenAndSanitize(@Nonnull String commitMessage) {
  @NonNls String defaultPath = FileUtil.sanitizeFileName(commitMessage);
  if (defaultPath.isEmpty()) {
    defaultPath = "unnamed";
  }
  if (defaultPath.length() > PatchNameChecker.MAX - 10) {
    defaultPath = defaultPath.substring(0, PatchNameChecker.MAX - 10);
  }
  return defaultPath;
}
 
Example 5
Source File: GradleImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String getName() {
  return name.getMethodName() == null ? super.getName() : FileUtil.sanitizeFileName(name.getMethodName());
}