本文整理了Java中com.intellij.openapi.util.io.FileUtil
类的一些代码示例,展示了FileUtil
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil
类的具体详情如下:
包路径:com.intellij.openapi.util.io.FileUtil
类名称:FileUtil
暂无
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Nullable
public static VirtualFile findByImportPath(@NotNull String importPath, @NotNull Project project, @Nullable Module module) {
if (importPath.isEmpty()) {
return null;
}
importPath = FileUtil.toSystemIndependentName(importPath);
for (VirtualFile root : GoSdkUtil.getSourcesPathsToLookup(project, module)) {
VirtualFile file = root.findFileByRelativePath(importPath);
if (file != null) {
return file;
}
}
return null;
}
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
private void doTest() {
try {
String text = FileUtil.loadFile(new File("./" + PATH + "/" + getTestName(true) + ".s"));
String actual = printTokens(StringUtil.convertLineSeparators(text.trim()), 0);
assertSameLinesWithFile(new File(PATH + "/" + getTestName(true) + ".txt").getAbsolutePath(), actual);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: KronicDeth/intellij-elixir
public String createFile(String relativePath, String text){
try{
File file = new File(getOrCreateProjectDir(), relativePath);
FileUtil.writeToFile(file, text);
return FileUtil.toSystemIndependentName(file.getAbsolutePath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: KronicDeth/intellij-elixir
private static void assertRelativePaths(File[] baseDirs, Collection<File> files, String[] expected){
List<String> relativePaths = new ArrayList<String>();
for (File file: files){
String path = file.getAbsolutePath();
for(File baseDir:baseDirs){
if(baseDir != null && FileUtil.isAncestor(baseDir, file, false)){
path = FileUtil.getRelativePath(baseDir, file);
break;
}
}
relativePaths.add(FileUtil.toSystemIndependentName(path));
}
UsefulTestCase.assertSameElements(relativePaths, expected);
}
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
private static File createDir(String... children) {
try {
File dir = FileUtil.createTempDirectory("goSdk", "test");
for (String child : children) {
File file = new File(dir, child);
FileUtil.createParentDirs(file);
if (StringUtil.endsWithChar(child, '/')) {
assertTrue(file.mkdir());
}
else {
assertTrue(file.createNewFile());
}
}
return dir;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: Camelcade/Perl5-IDEA
@Nullable
@Override
protected String doGetLocalPath(@NotNull String remotePath) {
File remoteFile = new File(remotePath);
if (FileUtil.isAncestor(CONTAINER_ROOT_FILE, remoteFile, false)) {
return PerlFileUtil.unLinuxisePath('/' + FileUtil.getRelativePath(CONTAINER_ROOT_FILE, remoteFile));
}
return FileUtil.toSystemIndependentName(FileUtil.join(getLocalCacheRoot(), remotePath));
}
代码示例来源:origin: Camelcade/Perl5-IDEA
/**
* Reverse operation for {@link #linuxisePath(String)}
*/
@NotNull
public static String unLinuxisePath(@NotNull String linuxisedPath) {
if (!SystemInfo.isWindows || linuxisedPath.length() < 2) {
return linuxisedPath;
}
String normalizedPath = FileUtil.toSystemIndependentName(linuxisedPath);
if (normalizedPath.charAt(0) != '/') {
throw new RuntimeException("Badly formatted path: " + linuxisedPath);
}
char driveLetter = normalizedPath.charAt(1);
if (!Character.isLetter(driveLetter)) {
throw new RuntimeException("Unexpected drive letter: " + linuxisedPath);
}
return FileUtil.toSystemDependentName(driveLetter + ":" + (linuxisedPath.length() > 2 ? linuxisedPath.substring(2) : ""));
}
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@Nullable
private static String getGaeExecutablePath(@NotNull String sdkHomePath) {
String goExecutablePath = PathUtil.toSystemIndependentName(sdkHomePath);
goExecutablePath = StringUtil.trimEnd(goExecutablePath, GoConstants.APP_ENGINE_GO_ROOT_DIRECTORY_PATH);
boolean gcloudInstallation = goExecutablePath.endsWith(GoConstants.GCLOUD_APP_ENGINE_DIRECTORY_PATH);
if (gcloudInstallation) {
LOG.debug("Detected gcloud GAE installation at " + goExecutablePath);
goExecutablePath = FileUtil.join(StringUtil.trimEnd(goExecutablePath, GoConstants.GCLOUD_APP_ENGINE_DIRECTORY_PATH), "bin");
}
String executablePath = FileUtil.join(goExecutablePath, GoEnvironmentUtil.getGaeExecutableFileName(gcloudInstallation));
return new File(executablePath).exists() ? executablePath : null;
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
private static boolean prepareFile(@NotNull File file) {
try {
FileUtil.writeToFile(file, new byte[]{0x7F, 'E', 'L', 'F'});
}
catch (IOException e) {
return false;
}
return file.setExecutable(true);
}
代码示例来源:origin: KronicDeth/intellij-elixir
protected void loadProject(String projectPath, Map<String, String> pathVariables){
try{
String testDataRootPath = getTestDataRootPath();
String fullProjectPath = FileUtil.toSystemDependentName(testDataRootPath != null ? testDataRootPath + "/" + projectPath : projectPath);
Map<String, String> allPathVariables = new HashMap<String, String>(pathVariables.size() + 1);
allPathVariables.putAll(pathVariables);
allPathVariables.put(PathMacroUtil.APPLICATION_HOME_DIR, PathManager.getHomePath());
JpsProjectLoader.loadProject(myProject, allPathVariables, fullProjectPath);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: liias/monkey
boolean releaseBuild) throws ProjectBuildException {
final File projectRoot = new File(FileUtil.toSystemIndependentName(projectRootPath));
final List<File> mcFiles = FileUtil.findFilesByMask(sourcePattern, projectRoot);
final List<File> xmlFiles = FileUtil.findFilesByMask(resourcePattern, projectRoot);
final List<String> resourceFilePaths = xmlFiles.stream()
.filter(file -> file != null && file.getParentFile().getAbsolutePath().contains("resource"))
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@NotNull
public static String getBinaryFileNameForPath(@NotNull String path) {
String resultBinaryName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(path));
return SystemInfo.isWindows ? resultBinaryName + ".exe" : resultBinaryName;
}
代码示例来源:origin: KronicDeth/intellij-elixir
protected static void change(String filePath, @Nullable String newContent){
try{
File file = new File(FileUtil.toSystemDependentName(filePath));
assertTrue("File " + file.getAbsolutePath() + " doesn't exist", file.exists());
if(newContent != null){
FileUtil.writeToFile(file, newContent);
}
long oldTimeStamp = FileSystemUtil.lastModified(file);
long time = System.currentTimeMillis();
setLastModified(file, time);
if(FileSystemUtil.lastModified(file) <= oldTimeStamp){
setLastModified(file, time + 1);
long newTimeStamp = FileSystemUtil.lastModified(file);
if(newTimeStamp <= oldTimeStamp){
// Mac OS and som versions of Linux truncates timestamp to nearest second
setLastModified(file, time + 1000);
newTimeStamp = FileSystemUtil.lastModified(file);
assertTrue("Failed to change timestamp for " + file.getAbsolutePath(), newTimeStamp > oldTimeStamp);
}
sleepUntil(newTimeStamp);
}
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
String directoryPath = FileUtil.isAbsolutePlatformIndependent(myDirectoryPath)
? myDirectoryPath
: FileUtil.join(getWorkingDirectory(), myDirectoryPath);
if (!FileUtil.isAncestor(getWorkingDirectory(), directoryPath, false)) {
throw new RuntimeConfigurationError("Working directory should be ancestor of testing directory");
代码示例来源:origin: Camelcade/Perl5-IDEA
/**
* @return perl5 dir in the ide's {@code system} dir
*/
@NotNull
public static String getPerlSystemPath() {
String systemPath = PathManager.getSystemPath();
String perlDirectory = FileUtil.join(systemPath, PERL_DIR);
FileUtil.createDirectory(new File(perlDirectory));
return perlDirectory;
}
代码示例来源:origin: Camelcade/Perl5-IDEA
@NotNull
@Override
public String mapPathToLocal(@NotNull String remotePathName) {
File remotePath = new File(remotePathName);
if (FileUtil.isAncestor(myRemoteProjectPath, remotePath, false)) {
return FileUtil.toSystemDependentName(
new File(myLocalProjectPath, Objects.requireNonNull(FileUtil.getRelativePath(myRemoteProjectPath, remotePath))).getPath()
);
}
else {
return remotePathName;
}
}
}
代码示例来源:origin: cheptsov/AdvancedExpressionFolding
try {
verificationFile = new File(verificationFileName);
expectedContent = FileUtil.loadFile(verificationFile);
FileUtil.writeToFile(new File(destinationFileName), cleanContent);
VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(destinationFileName);
assertNotNull(file);
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
@NotNull
@Override
public DirectoryProcessingResult detectRoots(@NotNull File dir,
@NotNull File[] children,
@NotNull File base,
@NotNull List<DetectedProjectRoot> result) {
Pattern pattern = Pattern.compile(".*\\.go");
List<File> filesByMask = FileUtil.findFilesByMask(pattern, base);
if (!filesByMask.isEmpty()) {
result.add(new DetectedProjectRoot(dir) {
@NotNull
@Override
public String getRootTypeName() {
return GoConstants.GO;
}
});
}
return DirectoryProcessingResult.SKIP_CHILDREN;
}
代码示例来源:origin: GoogleCloudPlatform/google-cloud-intellij
/**
* Creates all {@link File files} annotated with {@link TestFile} in the given directory name.
*
* @param directoryName the name of the directory to create the test files in
*/
private void createTestFiles(String directoryName) throws IllegalAccessException, IOException {
for (Field field : getFieldsWithAnnotation(testInstance.getClass(), TestFile.class)) {
field.setAccessible(true);
if (!field.getType().equals(File.class)) {
throw new IllegalArgumentException(
"@TestFile can only annotate fields of type java.io.File");
}
TestFile annotation = field.getAnnotation(TestFile.class);
File directory = FileUtil.createTempDirectory(directoryName, null);
File file = new File(directory, annotation.name());
if (!file.createNewFile()) {
throw new IOException("Can't create file: " + file);
}
if (!annotation.contents().isEmpty()) {
FileUtil.writeToFile(file, annotation.contents());
}
filesToDelete.add(file);
field.set(testInstance, file);
}
}
代码示例来源:origin: JetBrains/Grammar-Kit
public void doGenTest(final boolean generatePsi) throws Exception {
final String name = getTestName(false);
String text = loadFile(name + "." + myFileExt);
myFile = createPsiFile(name, text.replaceAll("generatePsi=[^\n]*", "generatePsi=" + generatePsi));
List<File> filesToCheck = ContainerUtil.newArrayList();
filesToCheck.add(new File(FileUtilRt.getTempDirectory(), name + ".java"));
if (generatePsi) {
filesToCheck.add(new File(FileUtilRt.getTempDirectory(), name + ".PSI.java"));
}
for (File file : filesToCheck) {
if (file.exists()) {
assertTrue(file.delete());
}
}
ParserGenerator parserGenerator = newTestGenerator();
if (generatePsi) parserGenerator.generate();
else parserGenerator.generateParser();
for (File file : filesToCheck) {
assertTrue("Generated file not found: " + file, file.exists());
final String expectedName = FileUtil.getNameWithoutExtension(file) + ".expected.java";
String result = FileUtil.loadFile(file, CharsetToolkit.UTF8, true);
doCheckResult(myFullDataPath, expectedName, result);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!