Exemplo n.º 1
0
 /**
  * Returns the existing WebProject corresponding to the provided path, or <code>null</code> if no
  * such project exists.
  *
  * @param path path in the form /file/{workspaceId}/{projectName}/[filePath]
  * @return the web project, or <code>null</code>
  */
 public static ProjectInfo projectFromPath(IPath path) {
   if (path == null || path.segmentCount() < 3) return null;
   String workspaceId = path.segment(1);
   String projectName = path.segment(2);
   try {
     return OrionConfiguration.getMetaStore().readProject(workspaceId, projectName);
   } catch (CoreException e) {
     return null;
   }
 }
Exemplo n.º 2
0
 /**
  * Returns the existing git repositories for the given file path, following the given traversal
  * rule.
  *
  * @param path expected format /file/{Workspace}/{projectName}[/{path}]
  * @return a map of all git repositories found, or <code>null</code> if the provided path format
  *     doesn't match the expected format.
  * @throws CoreException
  */
 public static Map<IPath, File> getGitDirs(IPath path, Traverse traverse) throws CoreException {
   IPath p = path.removeFirstSegments(1); // remove /file
   IFileStore fileStore = NewFileServlet.getFileStore(null, p);
   if (fileStore == null) return null;
   Map<IPath, File> result = new HashMap<IPath, File>();
   File file = fileStore.toLocalFile(EFS.NONE, null);
   // jgit can only handle a local file
   if (file == null) return result;
   switch (traverse) {
     case CURRENT:
       if (RepositoryCache.FileKey.isGitRepository(file, FS.DETECTED)) {
         result.put(new Path(""), file); // $NON-NLS-1$
       } else if (RepositoryCache.FileKey.isGitRepository(
           new File(file, Constants.DOT_GIT), FS.DETECTED)) {
         result.put(new Path(""), new File(file, Constants.DOT_GIT)); // $NON-NLS-1$
       }
       break;
     case GO_UP:
       getGitDirsInParents(file, result);
       break;
     case GO_DOWN:
       getGitDirsInChildren(file, p, result);
       break;
   }
   return result;
 }
Exemplo n.º 3
0
 public static String getRelativePath(IPath filePath, IPath pathToGitRoot) {
   StringBuilder sb = new StringBuilder();
   String file = null;
   if (!filePath.hasTrailingSeparator()) {
     file = filePath.lastSegment();
     filePath = filePath.removeLastSegments(1);
   }
   for (int i = 0; i < pathToGitRoot.segments().length; i++) {
     if (pathToGitRoot.segments()[i].equals(".."))
       sb.append(
               filePath.segment(filePath.segments().length - pathToGitRoot.segments().length + i))
           .append("/");
     // else TODO
   }
   if (file != null) sb.append(file);
   return sb.toString();
 }
Exemplo n.º 4
0
 /** Recursively walks down a directory tree and collects the paths of all git repositories. */
 private static void getGitDirsInChildren(File localFile, IPath path, Map<IPath, File> gitDirs)
     throws CoreException {
   if (localFile.exists() && localFile.isDirectory()) {
     if (RepositoryCache.FileKey.isGitRepository(localFile, FS.DETECTED)) {
       gitDirs.put(path.addTrailingSeparator(), localFile);
       return;
     } else if (RepositoryCache.FileKey.isGitRepository(
         new File(localFile, Constants.DOT_GIT), FS.DETECTED)) {
       gitDirs.put(path.addTrailingSeparator(), new File(localFile, Constants.DOT_GIT));
       return;
     }
     File[] folders =
         localFile.listFiles(
             new FileFilter() {
               public boolean accept(File file) {
                 return file.isDirectory() && !file.getName().equals(Constants.DOT_GIT);
               }
             });
     for (File folder : folders) {
       getGitDirsInChildren(folder, path.append(folder.getName()), gitDirs);
     }
     return;
   }
 }