Eclipseplugins
FileSystemUtils.java
1 package com.proalpha.pds.templates.helper;
2 
3 import org.eclipse.core.resources.IFile;
4 import org.eclipse.core.resources.IFolder;
5 import org.eclipse.core.runtime.CoreException;
6 import org.eclipse.core.runtime.NullProgressMonitor;
7 
8 public final class FileSystemUtils {
9 
10 
11  private FileSystemUtils() {
12  super();
13  }
14 
15 
24  private static void createFolderRecursively(final IFolder path) throws CoreException {
25 
26  if (!path.exists()) {
27  if (!path.getParent().exists())
28  createFolderRecursively((IFolder) path.getParent());
29 
30  path.create(true, true, new NullProgressMonitor());
31  }
32 
33  }
34 
35  public static IFolder createNewFoldersInWorkingDirectory(
36  IFolder workingDirectory, String path) throws Exception {
37 
38  IFolder fullPath = workingDirectory.getFolder(path);
39 
40  if (!fullPath.exists()) {
41  createFolderRecursively(fullPath);
42  }
43 
44  return fullPath;
45  }
46 
47  public static IFile createFileInWorkingDirectory(IFolder workingDirectory, String relativePath,
48  String fileName) throws Exception {
49 
50  workingDirectory = createNewFoldersInWorkingDirectory(workingDirectory
51  , relativePath);
52 
53  return workingDirectory.getFile(fileName);
54 
55  }
56 
57 }