Index: AntStarTeamCheckOut.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java,v
retrieving revision 1.2
diff -w -b -B -d -u -r1.2 AntStarTeamCheckOut.java
--- AntStarTeamCheckOut.java	2000/08/22 15:54:16	1.2
+++ AntStarTeamCheckOut.java	2000/11/06 20:03:58
@@ -73,16 +73,15 @@
  * out only if appropriate.
  * <BR><BR>
  * Checked out files go to a directory you specify under the subfolder
- * named for the default StarTeam path to the view.  That is, if you
- * entered /home/cpovirk/work as the target folder, your project was named
- * "OurProject," the given view was named "TestView," and that view is
- * stored by default at "C:\projects\Test," your files would be checked
- * out to /home/cpovirk/work/Test."  I avoided using the project name in
+ * named for the the view.  That is, if you entered /home/cpovirk/work
+ * as the target folder, your project was named "OurProject," the given
+ * view was named "TestView," your files would be checked out to
+ * /home/cpovirk/work/TestView."  I avoided using the project name in
  * the path because you may want to keep several versions of the same
- * project on your computer, and I didn't want to use the view name, as
- * there may be many "Test" or "Version 1.0" views, for example.  This
- * system's success, of course, depends on what you set the default path
- * to in StarTeam.
+ * project on your computer. The view name does not have to be appended
+ * by setting the <CODE>appendViewName</CODE> attribute to false.  This is
+ * in case you have many "Test" or "Version 1.0" views that you need to
+ * checkout.
  * <BR><BR>
  * You can set AntStarTeamCheckOut to verbose or quiet mode.  Also, it has
  * a safeguard against overwriting the files on your computer:  If the
@@ -249,6 +248,12 @@
 	 * and not in its subfolders.
 	 */
 	private String recursion = DEFAULT_RECURSIONSETTING;
+	/**
+	 * Set appendViewName to false to check out files without adding
+        * a directory for view name between targetFolder and path to
+        * file in Starteam. (Under view)
+	 */
+	private boolean appendViewName = true;
 
 	// These fields deal with includes and excludes
 
@@ -268,6 +273,26 @@
 	private String delim = Platform.getFilePathDelim();
 
 	/**
+        * The allowed Statuses to check out.
+        */
+   	private String statusFilter = null;
+   	private Vector statusToCheckout = null;
+
+    private static Hashtable statusMap = null;
+
+    static
+    {
+        statusMap = new Hashtable(10);
+        statusMap.put("c", new Integer(0)); //Current
+        statusMap.put("g", new Integer(1)); //Merge
+        statusMap.put("i", new Integer(2)); //Missing
+        statusMap.put("m", new Integer(3)); //Modified
+        statusMap.put("o", new Integer(4));	//out-of-date
+        statusMap.put("n", new Integer(5)); //Not in view
+        statusMap.put("u", new Integer(6)); //Unknown
+    }
+
+	/**
 	 * Do the execution.
 	 * 
 	 * @exception BuildException
@@ -443,6 +468,21 @@
 
 		// This is ugly; checking for the root folder.
 		Folder f = v.getRootFolder();
+
+  		try
+        {
+  			if(!getAppendViewName())
+         	{
+     			f.setAlternatePathFragment( (new java.io.File(getTargetFolder())).getCanonicalPath() );
+        	}
+         	else
+          	{
+     			f.setAlternatePathFragment( (new java.io.File(getTargetFolder()+delim+viewName)).getCanonicalPath() );
+		}
+     	 }catch(Exception e)
+      	 {
+          	//pass
+        }
 		if (!(getFolderName()==null))
 		{
 			if (getFolderName().equals("\\") || getFolderName().equals("/"))
@@ -584,7 +624,14 @@
 		{
 			return;
 		}
-
+		// Change the item to be checked out to a StarTeam File.
+		com.starbase.starteam.File remote = (com.starbase.starteam.File)item;
+        int stat = 6;
+        try{
+            stat = remote.getStatus();
+        }catch(Exception e){
+            //pass
+        }
 		// VERBOSE MODE ONLY
 		if (getVerboseAsBoolean())
 		{
@@ -613,13 +660,14 @@
 			if (bShowHeader)
 			{
 				System.out.print("                Item");
-				System.out.print(",\t" + p1.getDisplayName());
-				if (p2 != null)
+				System.out.print(",  " + p1.getDisplayName());
+				if (p2 != null && !p2.equals(""))
 				{
-					System.out.print(",\t" + p2.getDisplayName());
+					System.out.print(",  " + p2.getDisplayName());
 				}
 				System.out.println("");
 			}
+            System.out.println("\n     Abs Path is " + remote.getFullName());
 
 			// Finally, show the Item properties ...
 
@@ -628,74 +676,49 @@
 
 			// Show the primary descriptor.
 			// There should always be one.
-			System.out.print(",\t" + formatForDisplay(p1, item.get(p1.getName())));
+			System.out.print(",  " + formatForDisplay(p1, item.get(p1.getName())));
 
 			// Show the secondary descriptor, if there is one.
 			// Some item types have one, some don't.
-			if (p2 != null)
+			if (p2 != null && !p2.equals(""))
 			{
-				System.out.print(",\t" + formatForDisplay(p2, item.get(p2.getName())));
+				System.out.print(",  " + formatForDisplay(p2, item.get(p2.getName())));
 			}
 
 			// Show if the file is locked.
 			int locker = item.getLocker();
 			if (locker>-1)
 			{
-				System.out.println(",\tLocked by " + locker);
+				System.out.print(",  Locked by " + locker);
 			}
 			else
 			{
-				System.out.println(",\tNot locked");
+				System.out.print(",  Not locked");
 			}
+   			try{
+   				System.out.println(",  " + com.starbase.starteam.Status.name(stat));
+       		}catch(Exception e){
+             	System.out.println("Failed to get status");
+            }
 		}
 		// END VERBOSE ONLY
 
 		// Check it out; also ugly.
 
-		// Change the item to be checked out to a StarTeam File.
-		com.starbase.starteam.File remote = (com.starbase.starteam.File)item;
 
-		// Create a variable dirName that contains the name of the StarTeam folder that is the root folder in this view.
-		// Get the default path to the current view.
-		String dirName = v.getDefaultPath();
-		// Settle on "/" as the default path separator for this purpose only.
-		dirName = dirName.replace('\\', '/');
-                // Take the StarTeam folder name furthest down in the hierarchy.
-                int endDirIndex = dirName.length();
-                // If it ends with separator then strip it off
-                if (dirName.endsWith("/"))
-                {
-                    // This should be the SunOS and Linux case
-                    endDirIndex--;
-                }
-		dirName = dirName.substring(dirName.lastIndexOf("/", dirName.length() - 2) + 1, endDirIndex);
                 
-		// Replace the projectName in the file's absolute path to the viewName.
-		// This eventually makes the target of a checkout operation equal to:
-		// targetFolder + dirName + [subfolders] + itemName
-		StringTokenizer pathTokenizer = new StringTokenizer(item.getParentFolder().getFolderHierarchy(), delim);
-		String localName = delim;
-		String currentToken = null;
-		while (pathTokenizer.hasMoreTokens())
-		{
-			currentToken = pathTokenizer.nextToken();
-			if (currentToken.equals(getProjectName()))
-			{
-				currentToken = dirName;
-			}
-			localName += currentToken + delim;
-		}
-		// Create a reference to the local target file using the format listed above.
-		java.io.File local = new java.io.File(getTargetFolder() + localName + item.get(p1.getName()));
 		try
 		{
-			remote.checkoutTo(local, Item.LockType.UNCHANGED, false, true, true);
+      		if(statusToCheckout == null || statusToCheckout.indexOf(new Integer(stat)) != -1){
+            	project.log("Checking file " + remote.getName() + " out to " + remote.getFullName(), project.MSG_VERBOSE);
+				remote.checkout(Item.LockType.UNCHANGED, false, true, true);
+				checkedOut++;
+    		}
 		}
 		catch (Throwable e)
 		{
 			project.log("    " + e.getMessage());
 		}
-		checkedOut++;
 	}
 
 	/**
@@ -1286,6 +1309,39 @@
 	{
 		return project.toBoolean(verbose);
 	}
+	/**
+	 * Sets the <CODE>appendViewName</CODE> attribute to the given value.
+	 *
+	 * @param append A boolean containing telling AntStarTeamCheckOut
+     *                whether to add the view name to
+  	 * 				  the checkout directory.  By default it is
+     * 				  true, so the program adds the extra directory which
+     *                is named the same as the View.
+	 * @see #getAppendViewName()
+	 */
+
+	public void setAppendViewName(boolean append)
+	{
+		this.appendViewName = append;
+	}
+
+	public void setAppendViewName(String append)
+	{
+		this.appendViewName = project.toBoolean(append);
+	}
+
+	/**
+	 * Gets the <CODE>appendViewName</CODE> attribute.
+	 *
+	 * @return A boolean telling the application
+	 * 		to add the view name to the checkout path or not.
+	 * @see #setAppendViewName(String appendViewName)
+	 */
+
+	public boolean getAppendViewName()
+	{
+		return appendViewName;
+	}
 
 	// Begin filter getters and setters
 
@@ -1407,5 +1463,52 @@
 	{
 		return excludes;
 	}
+	/**
+	 * Sets the <CODE>statusFilter</CODE> attribute.
+  	 *
+  	 * Sets the Filter of what statuses are acceptable to checkout.  It is a
+        * String which gets parsed.  An example of a Status filter is "MUGI"
+        * without spaces and other delimiters.  This example would check out
+        * files only if thier status was Modified, Unknown, Merge, or Missing.
+        * Any other status and the file would not be checked out.
+        *
+        * Values can be any combination of the following:
+        * <pre>
+        * 		'C':  Current
+        * 		'G':  Merge
+        * 		'I':  Missing
+        * 		'M':  Modified
+        * 		'O':  Out-of-Date
+        * 		'N':  Not-in-View
+        * 		'U':  Unknown
+        * </pre>
+        *
+        * These statuses are defined in the Starteam documentation.
+        * @param stats A String defining the statuses acceptable to be checked out.
+        *
+  	 */
+	public void setStatusFilter(String stats)
+	{
+	        this.statusFilter = stats;
+  		statusToCheckout = new Vector();
+  		char letters[] = stats.toCharArray();
+    	        for(int i=0; i<letters.length ; i++){
+        	       Object o = statusMap.get(String.valueOf(letters[i]).toLowerCase());
+		       if(o != null){
+   		               statusToCheckout.addElement(o);
+       	       }
+     	        }
+      	        project.log("Status Filter " + statusFilter + " equates " +statusToCheckout, project.MSG_DEBUG);
+	}
+	/**
+	 * Gets the <CODE>statusFilter</CODE> attribute.
+	 *
+	 * @return A string containing a list of statuses to check out.
+	 * @see #setStatusFilter(String stats)
+	 */
+
+ 	public String getStatusFilter(){
+      	        return statusFilter;
+       }
 
 }
