Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.starteam;
  
  import  com.starbase.starteam.Folder;
  import  com.starbase.starteam.View;
  import  com.starbase.starteam.File;
  import  com.starbase.starteam.Item;
  
 import java.util.Map;
 
 
 public class StarTeamFunctions {

Find the given folder in the given view.

Parameters:
view The view to look in.
foldername The view-relative path of the folder to look for.
Returns:
The folder or null if a folder by the given name was not found.
Throws:
StarTeamSCMException
 
 	public static Folder findFolderInView(final View viewfinal String foldername)
 		// Check the root folder of the view
 		if (view.getName().equalsIgnoreCase(foldername)) {
 			return view.getRootFolder();
 		}
 
 		// Create a File object with the folder name for system-
 		// independent matching
 		java.io.File thefolder = new java.io.File(foldername.toLowerCase());
 
 		// Search for the folder in subfolders
 		Folder result = findFolderInView(view.getRootFolder(), thefolder);
 		if (result == null) {
 			throw new StarTeamSCMException("Couldn't find folder " + foldername
 					+ " in view " + view.getName());
 		}
 		return result;
 	}

Do a breadth-first search for a folder with the given name, starting with children of the provided folder.

Parameters:
folder the folder whose children to check
thefolder the folder to look for
Returns:
 
 	private static Folder findFolderInView(Folder folderjava.io.File thefolder) {
 		// Check subfolders, breadth first. checkLater is a collection
 		// of folders that didn't match, therefore their children
 		// will be checked next.
 		Collection<Folder> checkLater = new ArrayList<Folder>();
 		for (Folder f : folder.getSubFolders()) {
 			// Compare pathnames. The getFolderHierarchy call returns
 			// the full folder name (including root folder name which
 			// is the same as the view name) terminated by the
 			// platform-specific separator.
 			if (f.getFolderHierarchy().equalsIgnoreCase(
 					thefolder.getPath() + ...)) {
 				return f;
 			} else {
 				// add to list of folders whose children will be checked
 				checkLater.add(f);
 			}
 		}
 		// recurse unto children
 		for (Folder f : checkLater) {
 			Folder result = findFolderInView(fthefolder);
 			if (result != null) {
 				return result;
 			}
 		}
 		return null;
 	}
 
   public static Collection<File> listAllFiles(Map<String,Folder> rootFolderMapjava.io.File workspace) {
 		Collection<File> result = new ArrayList<File>();
 
     for (Map.Entry<String,Folder> f:rootFolderMap.entrySet()) {
       result.addAll(listAllFiles(f.getValue(),workspace));
     }
 
 		return result;
 	}
 
   public static Collection<File> listAllFiles(Folder rootFolderjava.io.File workspace) {
 		Collection<File> result = new ArrayList<File>();
     // set root folder
 		String alternatePath = rootFolder.getAlternatePathFragment();
		if (alternatePath == null)
		{
			alternatePath = "";
		}
		java.io.File actualPlace = new java.io.File(workspace,alternatePath);
		rootFolder.setAlternatePathFragment(actualPlace.getAbsolutePath());
		// Get a list of all files
		listAllFiles(resultrootFolder);
		return result;
	}
  private static void listAllFiles(Collection<File> result, Folder folder) {
    for (Folder f : folder.getSubFolders()) {
      listAllFiles(resultf);
    }
    // find items in this folder
    for (Item i : folder.getItems(folder.getView().getProject().getServer()
        .getTypeNames().FILE)) {
      File f = (com.starbase.starteam.File) i;
      try {
        // This sometimes throws... deep inside starteam =(
        result.add(f);
      } catch (RuntimeException e) {
        //todo logger.println("Exception in listAllFiles: "
        // + e.getLocalizedMessage());
      }
    }
    folder.discard();
  }
  public static Map<String,StringsplitCsvString(String multiplefolder) {
    Map<String,StringfolderMap = new HashMap<String,String>();
    if (multiplefolder != null) {
      for (String folderLine:multiplefolder.split("\n")) {
        String folderLineNullable = StringUtils.trimToNull(folderLine);
        if (folderLineNullable != null) {
          String[] starteamWorkspace = folderLineNullable.split(",");
          String starteamFolder = starteamWorkspace.length>0?StringUtils.trimToNull(starteamWorkspace[0]):null;
          String workspacePath = starteamWorkspace.length>1?StringUtils.trimToNull(starteamWorkspace[1]):null;
          if (workspacePath == null) {
            workspacePath = ".";
          }
          if (starteamFolder != null && workspacePath != null) {
            folderMap.put(starteamFolder,workspacePath);
          }
        }
      }
    }
    return folderMap;
  }
public static Map<java.io.File,com.starbase.starteam.File> convertToFileMap(final Collection<com.starbase.starteam.File> collection) {
    Map<java.io.File,com.starbase.starteam.File> result = new TreeMap<java.io.File,com.starbase.starteam.File>();
    for (com.starbase.starteam.File f:collection) {
      result.put(new java.io.File(f.getFullName()),f);
    }
    return result;
  }
New to GrepCode? Check out our FAQ X