IDEADEV-41995
[fedora-idea.git] / plugins / cvs / cvs-plugin / src / com / intellij / cvsSupport2 / util / CvsVfsUtil.java
blob49f85f527893b6b823e91ef35221505038fe2525
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.cvsSupport2.util;
18 import com.intellij.openapi.diagnostic.Logger;
19 import com.intellij.openapi.vfs.LocalFileSystem;
20 import com.intellij.openapi.vfs.VirtualFile;
21 import org.jetbrains.annotations.NotNull;
23 import java.io.File;
25 /**
26 * author: lesya
28 public class CvsVfsUtil {
30 private static final Logger LOG = Logger.getInstance("#com.intellij.cvsSupport2.util.CvsVfsUtil");
32 public static VirtualFile findFileByPath(final String path) {
33 return LocalFileSystem.getInstance().findFileByPath(path);
36 public static VirtualFile findChild(final VirtualFile file, final String name) {
37 if (file == null) {
38 return LocalFileSystem.getInstance().findFileByIoFile(new File(name));
40 else {
41 return file.findChild(name);
45 public static VirtualFile getParentFor(final File file) {
46 return findFileByIoFile(file.getParentFile());
49 public static File getFileFor(final VirtualFile file) {
50 if (file == null) return null;
51 return new File(file.getPath());
54 public static File getFileFor(final VirtualFile parent, String name) {
55 if (parent == null) {
56 return new File(name);
58 else {
59 return new File(parent.getPath(), name);
63 public static VirtualFile findFileByIoFile(final File file) {
64 if (file == null) return null;
65 return LocalFileSystem.getInstance().findFileByIoFile(file);
68 public static VirtualFile refreshAndFindFileByIoFile(@NotNull final File file) {
69 return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
72 public static VirtualFile[] getChildrenOf(final VirtualFile directory) {
73 return directory.isValid() ? directory.getChildren() : null;
76 public static long getTimeStamp(final VirtualFile file) {
77 return file.getTimeStamp();
80 public static boolean isWritable(final VirtualFile virtualFile) {
81 return virtualFile.isWritable();
84 public static String getPresentablePathFor(final VirtualFile root) {
85 return root.getPresentableUrl();
88 public static VirtualFile refreshAndfFindChild(VirtualFile parent, String fileName) {
89 return refreshAndFindFileByIoFile(new File(CvsVfsUtil.getFileFor(parent), fileName));