Java Code Examples for com.intellij.openapi.vfs.VirtualFile#createChildDirectory()

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#createChildDirectory() . 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: IFolder.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public void create(boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
    VirtualFile parentFolder;
    String folderName;
    if(virtualFile == null) {
        File parentFile = file.getParentFile();
        parentFolder = module.getProject().getProjectFile().getFileSystem().findFileByPath(parentFile.getPath());
        folderName = file.getName();
    } else {
        parentFolder = virtualFile.getParent();
        folderName = virtualFile.getName();
    }
    if(parentFolder != null) {
        try {
            parentFolder.createChildDirectory(module, folderName);
            if(virtualFile == null) {
                virtualFile = parentFolder.findChild(folderName);
            }
        } catch(IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to create file: " + file, e));
        }
    } else {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to create folder: " + file + " because parent could not be found"));
    }
}
 
Example 2
Source File: DifferenceReverterTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testDirDeletion() throws Exception {
  VirtualFile dir = myRoot.createChildDirectory(this, "dir");
  VirtualFile subdir = dir.createChildDirectory(this, "subdir");
  VirtualFile f = subdir.createChildData(this, "foo.txt");
  f.setBinaryContent(new byte[]{123}, -1, 4000);

  dir.delete(this);

  revertLastChange();

  dir = myRoot.findChild("dir");
  subdir = dir.findChild("subdir");
  f = subdir.findChild("foo.txt");
  assertNotNull(f);
  assertEquals(123, f.contentsToByteArray()[0]);
  assertEquals(4000, f.getTimeStamp());
}
 
Example 3
Source File: ProjectHelper.java    From android-codegenerator-plugin-intellij with Apache License 2.0 5 votes vote down vote up
private VirtualFile createFolderIfNotExist(Project project, String folder) throws IOException {
    VirtualFile directory = project.getBaseDir();
    String[] folders = folder.split("/");
    for (String childFolder : folders) {
        VirtualFile childDirectory = directory.findChild(childFolder);
        if (childDirectory != null && childDirectory.isDirectory()) {
            directory = childDirectory;
        } else {
            directory = directory.createChildDirectory(project, childFolder);
        }
    }
    return directory;
}
 
Example 4
Source File: IntellijFolder.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the folder in the local filesystem.
 *
 * @throws FileAlreadyExistsException if a resource with the same name already exists
 * @throws FileNotFoundException if the parent directory of the folder does not exist
 */
private void createInternal() throws IOException {
  IResource parent = getParent();

  VirtualFile parentFile = referencePoint.findVirtualFile(parent.getReferencePointRelativePath());

  if (parentFile == null || !parentFile.exists()) {
    throw new FileNotFoundException(
        "Could not create "
            + this
            + " as its parent folder "
            + parent
            + " does not exist or is not valid");
  }

  VirtualFile virtualFile = parentFile.findChild(getName());

  if (virtualFile != null && virtualFile.exists()) {
    throw new FileAlreadyExistsException(
        "Could not create "
            + this
            + " as a resource with the same name already exists: "
            + virtualFile);
  }

  parentFile.createChildDirectory(this, getName());
}
 
Example 5
Source File: ApplyFilePatchBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private static VirtualFile findFileToPatchByComponents(ApplyPatchContext context,
                                                       final String[] pathNameComponents,
                                                       final int lastComponentToFind) {
  VirtualFile patchedDir = context.getBaseDir();
  for(int i=context.getSkipTopDirs(); i<lastComponentToFind; i++) {
    VirtualFile nextChild;
    if (pathNameComponents [i].equals("..")) {
      nextChild = patchedDir.getParent();
    }
    else {
      nextChild = patchedDir.findChild(pathNameComponents [i]);
    }
    if (nextChild == null) {
      if (context.isCreateDirectories()) {
        try {
          nextChild = patchedDir.createChildDirectory(null, pathNameComponents [i]);
        }
        catch (IOException e) {
          return null;
        }
      }
      else {
        return null;
      }
    }
    patchedDir = nextChild;
  }
  return patchedDir;
}