KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > scm > AntStarTeamCheckOut


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs.optional.scm;
19
20 import com.starbase.starteam.Folder;
21 import com.starbase.starteam.Item;
22 import com.starbase.starteam.Property;
23 import com.starbase.starteam.Server;
24 import com.starbase.starteam.StarTeamFinder;
25 import com.starbase.starteam.Type;
26 import com.starbase.starteam.View;
27 import com.starbase.util.Platform;
28 import java.util.StringTokenizer JavaDoc;
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.DirectoryScanner;
31 import org.apache.tools.ant.Project;
32
33 /**
34  * Checks out files from a specific StarTeam server, project, view, and
35  * folder.
36  * <BR><BR>
37  * This program logs in to a StarTeam server and opens up the specified
38  * project and view. Then, it searches through that view for the given
39  * folder (or, if you prefer, it uses the root folder). Beginning with
40  * that folder and optionally continuing recursivesly, AntStarTeamCheckOut
41  * compares each file with your include and exclude filters and checks it
42  * out only if appropriate.
43  * <BR><BR>
44  * Checked out files go to a directory you specify under the subfolder
45  * named for the default StarTeam path to the view. That is, if you
46  * entered /home/cpovirk/work as the target folder, your project was named
47  * "OurProject," the given view was named "TestView," and that view is
48  * stored by default at "C:\projects\Test," your files would be checked
49  * out to /home/cpovirk/work/Test." I avoided using the project name in
50  * the path because you may want to keep several versions of the same
51  * project on your computer, and I didn't want to use the view name, as
52  * there may be many "Test" or "Version 1.0" views, for example. This
53  * system's success, of course, depends on what you set the default path
54  * to in StarTeam.
55  * <BR><BR>
56  * You can set AntStarTeamCheckOut to verbose or quiet mode. Also, it has
57  * a safeguard against overwriting the files on your computer: If the
58  * target directory you specify already exists, the program will throw a
59  * BuildException. To override the exception, set <CODE>force</CODE> to
60  * true.
61  * <BR><BR>
62  * <B>This program makes use of functions from the StarTeam API. As a result
63  * AntStarTeamCheckOut is available only to licensed users of StarTeam and
64  * requires the StarTeam SDK to function. You must have
65  * <CODE>starteam-sdk.jar</CODE> in your classpath to run this program.
66  * For more information about the StarTeam API and how to license it, see
67  * the link below.</B>
68  *
69  * @version 1.0
70  * @see <A HREF="http://www.starbase.com/">StarBase Web Site</A>
71  *
72  * @ant.task name="starteam" category="scm" ignore="true"
73  */

74 public class AntStarTeamCheckOut extends org.apache.tools.ant.Task {
75
76     /**
77      * This constant sets the filter to include all files. This default has
78      * the same result as <CODE>setIncludes("*")</CODE>.
79      *
80      * @see #getIncludes()
81      * @see #setIncludes(String includes)
82      */

83     public static final String JavaDoc DEFAULT_INCLUDESETTING = "*";
84
85     /**
86      * This disables the exclude filter by default. In other words, no files
87      * are excluded. This setting is equivalent to <CODE>setExcludes(null)</CODE>
88      * .
89      *
90      * @see #getExcludes()
91      * @see #setExcludes(String excludes)
92      */

93     public static final String JavaDoc DEFAULT_EXCLUDESETTING = null;
94
95     /**
96      * The default folder to search; the root folder. Since
97      * AntStarTeamCheckOut searches subfolders, by default it processes an
98      * entire view.
99      *
100      * @see #getFolderName()
101      * @see #setFolderName(String folderName)
102      */

103     public static final String JavaDoc DEFAULT_FOLDERSETTING = null;
104
105     /**
106      * This is used when formatting the output. The directory name is
107      * displayed only when it changes.
108      */

109     private Folder prevFolder = null;
110
111     /** This field keeps count of the number of files checked out. */
112     private int checkedOut = 0;
113
114     // Change these through their GET and SET methods.
115

116     /** The name of the server you wish to connect to. */
117     private String JavaDoc serverName = null;
118
119     /** The port on the server used for StarTeam. */
120     private int serverPort = -1;
121
122     /** The name of your project. */
123     private String JavaDoc projectName = null;
124
125     /**
126      * The name of the folder you want to check out files from. All subfolders
127      * will be searched, as well.
128      */

129     private String JavaDoc folderName = DEFAULT_FOLDERSETTING;
130
131     /** The view that the files you want are in. */
132     private String JavaDoc viewName = null;
133
134     /** Your username on the StarTeam server. */
135     private String JavaDoc username = null;
136
137     /** Your StarTeam password. */
138     private String JavaDoc password = null;
139
140     /**
141      * The path to the root folder you want to check out to. This is a local
142      * directory.
143      */

144     private String JavaDoc targetFolder = null;
145
146     /**
147      * If force set to true, AntStarTeamCheckOut will overwrite files in the
148      * target directory.
149      */

150     private boolean force = false;
151
152     /**
153      * When verbose is true, the program will display all files and
154      * directories as they are checked out.
155      */

156     private boolean verbose = false;
157
158     /**
159      * Set recursion to false to check out files in only the given folder and
160      * not in its subfolders.
161      */

162     private boolean recursion = true;
163
164     // These fields deal with includes and excludes
165

166     /** All files that fit this pattern are checked out. */
167     private String JavaDoc includes = DEFAULT_INCLUDESETTING;
168
169     /** All files fitting this pattern are ignored. */
170     private String JavaDoc excludes = DEFAULT_EXCLUDESETTING;
171
172     /** The file delimitor on the user's system. */
173     private String JavaDoc delim = Platform.getFilePathDelim();
174
175     /**
176      * whether to use the Starteam "default folder" when calculating the
177      * target paths to which files are checked out (false) or if targetFolder
178      * represents an absolute mapping to folderName.
179      */

180     private boolean targetFolderAbsolute = false;
181
182
183     /** convenient method to check for conditions */
184     private static void assertTrue(boolean value, String JavaDoc msg) throws BuildException {
185         if (!value) {
186             throw new BuildException(msg);
187         }
188     }
189
190     /**
191      * Check if the attributes/elements are correct.
192      * @throws BuildException if there was a problem.
193      */

194     protected void checkParameters() throws BuildException {
195         // Check all of the properties that are required.
196
assertTrue(getServerName() != null, "ServerName must be set.");
197         assertTrue(getServerPort() != -1, "ServerPort must be set.");
198         assertTrue(getProjectName() != null, "ProjectName must be set.");
199         assertTrue(getViewName() != null, "ViewName must be set.");
200         assertTrue(getUsername() != null, "Username must be set.");
201         assertTrue(getPassword() != null, "Password must be set.");
202         assertTrue(getTargetFolder() != null, "TargetFolder must be set.");
203
204         // Because of the way I create the full target path, there
205
// must be NO slash at the end of targetFolder and folderName
206
// However, if the slash or backslash is the only character, leave it alone
207
if ((getTargetFolder().endsWith("/")
208                 || getTargetFolder().endsWith("\\"))
209              && getTargetFolder().length() > 1) {
210             setTargetFolder(getTargetFolder().substring(0, getTargetFolder().length() - 1));
211         }
212
213         // Check to see if the target directory exists.
214
java.io.File JavaDoc dirExist = new java.io.File JavaDoc(getTargetFolder());
215
216         if (dirExist.isDirectory() && !getForce()) {
217             throw new BuildException("Target directory exists. Set \"force\" "
218                  + "to \"true\" to continue anyway.");
219         }
220     }
221
222
223     /**
224      * Do the execution.
225      *
226      * @throws BuildException if there was a problem.
227      */

228     public void execute() throws BuildException {
229         log("DEPRECATED - The starteam task is deprecated. Use stcheckout instead.",
230             Project.MSG_WARN);
231
232         // Connect to the StarTeam server, and log on.
233
Server s = getServer();
234
235         try {
236             // Search the items on this server.
237
runServer(s);
238         } finally {
239             // Disconnect from the server.
240
s.disconnect();
241         }
242         // after you are all of the properties are ok, do your thing
243
// with StarTeam. If there are any kind of exceptions then
244
// send the message to the project log.
245

246         // Tell how many files were checked out.
247
log(checkedOut + " files checked out.");
248     }
249
250
251     /**
252      * Creates and logs in to a StarTeam server.
253      *
254      * @return A StarTeam server.
255      */

256     protected Server getServer() {
257         // Simplest constructor, uses default encryption algorithm and compression level.
258
Server s = new Server(getServerName(), getServerPort());
259
260         // Optional; logOn() connects if necessary.
261
s.connect();
262
263         // Logon using specified user name and password.
264
s.logOn(getUsername(), getPassword());
265
266         return s;
267     }
268
269
270     /**
271      * Searches for the specified project on the server.
272      *
273      * @param s A StarTeam server.
274      */

275     protected void runServer(Server s) {
276         com.starbase.starteam.Project[] projects = s.getProjects();
277
278         for (int i = 0; i < projects.length; i++) {
279             com.starbase.starteam.Project p = projects[i];
280
281             if (p.getName().equals(getProjectName())) {
282                 if (getVerbose()) {
283                     log("Found " + getProjectName() + delim);
284                 }
285                 runProject(s, p);
286                 break;
287             }
288         }
289     }
290
291
292     /**
293      * Searches for the given view in the project.
294      *
295      * @param s A StarTeam server.
296      * @param p A valid project on the given server.
297      */

298     protected void runProject(Server s, com.starbase.starteam.Project p) {
299         View[] views = p.getViews();
300
301         for (int i = 0; i < views.length; i++) {
302             View v = views[i];
303
304             if (v.getName().equals(getViewName())) {
305                 if (getVerbose()) {
306                     log("Found " + getProjectName() + delim + getViewName() + delim);
307                 }
308                 runType(s, p, v, s.typeForName(s.getTypeNames().FILE));
309                 break;
310             }
311         }
312     }
313
314
315     /**
316      * Searches for folders in the given view.
317      *
318      * @param s A StarTeam server.
319      * @param p A valid project on the server.
320      * @param v A view name from the specified project.
321      * @param t An item type which is currently always "file".
322      */

323     protected void runType(Server s, com.starbase.starteam.Project p, View v, Type t) {
324         // This is ugly; checking for the root folder.
325
Folder f = v.getRootFolder();
326
327         if (getFolderName() != null) {
328             if (getFolderName().equals("\\") || getFolderName().equals("/")) {
329                 setFolderName(null);
330             } else {
331                 f = StarTeamFinder.findFolder(v.getRootFolder(), getFolderName());
332                 assertTrue(null != f, "ERROR: " + getProjectName() + delim
333                     + getViewName() + delim + v.getRootFolder() + delim
334                     + getFolderName() + delim
335                     + " does not exist.");
336             }
337         }
338
339         if (getVerbose() && getFolderName() != null) {
340             log("Found " + getProjectName() + delim + getViewName()
341                 + delim + getFolderName() + delim + "\n");
342         }
343
344         // For performance reasons, it is important to pre-fetch all the
345
// properties we'll need for all the items we'll be searching.
346

347         // We always display the ItemID (OBJECT_ID) and primary descriptor.
348
int nProperties = 2;
349
350         // We'll need this item type's primary descriptor.
351
Property p1 = getPrimaryDescriptor(t);
352
353         // Does this item type have a secondary descriptor?
354
// If so, we'll need it.
355
Property p2 = getSecondaryDescriptor(t);
356
357         if (p2 != null) {
358             nProperties++;
359         }
360
361         // Now, build an array of the property names.
362
String JavaDoc[] strNames = new String JavaDoc[nProperties];
363         int iProperty = 0;
364
365         strNames[iProperty++] = s.getPropertyNames().OBJECT_ID;
366         strNames[iProperty++] = p1.getName();
367         if (p2 != null) {
368             strNames[iProperty++] = p2.getName();
369         }
370
371         // Pre-fetch the item properties and cache them.
372
f.populateNow(t.getName(), strNames, -1);
373
374         // Now, search for items in the selected folder.
375
runFolder(s, p, v, t, f, calcTargetFolder(v, f));
376
377         // Free up the memory used by the cached items.
378
f.discardItems(t.getName(), -1);
379     }
380
381
382     /**
383      * Returns a file object that defines the root of the local checkout tree.
384      * Depending on the value of targetFolderAbsolute, this will be either the
385      * targetFolder exactly as set by the user or the path formed by appending
386      * the default folder onto the specified target folder.
387      *
388      * @param v view from which the file is checked out, supplies the "default
389      * folder"
390      * @param rootSourceFolder root folder of the checkout operation in Star
391      * Team
392      * @return an object referencing the local file
393      * @see #getTargetFolderAbsolute()
394      */

395     private java.io.File JavaDoc calcTargetFolder(View v, Folder rootSourceFolder) {
396         java.io.File JavaDoc root = new java.io.File JavaDoc(getTargetFolder());
397
398         if (!getTargetFolderAbsolute()) {
399             // Create a variable dir that contains the name of
400
// the StarTeam folder that is the root folder in this view.
401
// Get the default path to the current view.
402
String JavaDoc defaultPath = v.getDefaultPath();
403
404             // convert whatever separator char is in starteam to that of the target system.
405
defaultPath = defaultPath.replace('/', java.io.File.separatorChar);
406             defaultPath = defaultPath.replace('\\', java.io.File.separatorChar);
407
408             java.io.File JavaDoc dir = new java.io.File JavaDoc(defaultPath);
409             String JavaDoc dirName = dir.getName();
410
411             // If it ends with separator then strip it off
412
if (dirName.endsWith(delim)) {
413                 dirName = dirName.substring(0, dirName.length() - 1);
414             }
415
416             // Replace the projectName in the file's absolute path to the viewName.
417
// This makes the root target of a checkout operation equal to:
418
// targetFolder + dirName
419
StringTokenizer JavaDoc pathTokenizer
420                 = new StringTokenizer JavaDoc(rootSourceFolder.getFolderHierarchy(), delim);
421             String JavaDoc currentToken = null;
422             boolean foundRoot = false;
423
424             while (pathTokenizer.hasMoreTokens()) {
425                 currentToken = pathTokenizer.nextToken();
426                 if (currentToken.equals(getProjectName()) && !foundRoot) {
427                     currentToken = dirName;
428                     foundRoot = true; // only want to do this the first time
429
}
430                 root = new java.io.File JavaDoc(root, currentToken);
431             }
432         }
433
434         return root;
435     }
436
437
438     /**
439      * Searches for files in the given folder. This method is recursive and
440      * thus searches all subfolders.
441      *
442      * @param s A StarTeam server.
443      * @param p A valid project on the server.
444      * @param v A view name from the specified project.
445      * @param t An item type which is currently always "file".
446      * @param f The folder to search.
447      * @param tgt Target folder on local machine
448      */

449     protected void runFolder(Server s,
450                              com.starbase.starteam.Project p,
451                              View v,
452                              Type t,
453                              Folder f,
454                              java.io.File JavaDoc tgt) {
455         // Process all items in this folder.
456
Item[] items = f.getItems(t.getName());
457
458         for (int i = 0; i < items.length; i++) {
459             runItem(s, p, v, t, f, items[i], tgt);
460         }
461
462         // Process all subfolders recursively if recursion is on.
463
if (getRecursion()) {
464             Folder[] subfolders = f.getSubFolders();
465
466             for (int i = 0; i < subfolders.length; i++) {
467                 runFolder(s, p, v, t, subfolders[i],
468                           new java.io.File JavaDoc(tgt, subfolders[i].getName()));
469             }
470         }
471     }
472
473
474     /**
475      * Check out one file if it matches the include filter but not the exclude
476      * filter.
477      *
478      * @param s A StarTeam server.
479      * @param p A valid project on the server.
480      * @param v A view name from the specified project.
481      * @param t An item type which is currently always "file".
482      * @param f The folder the file is localed in.
483      * @param item The file to check out.
484      * @param tgt target folder on local machine
485      */

486     protected void runItem(Server s,
487                            com.starbase.starteam.Project p,
488                            View v,
489                            Type t,
490                            Folder f,
491                            Item item,
492                            java.io.File JavaDoc tgt) {
493         // Get descriptors for this item type.
494
Property p1 = getPrimaryDescriptor(t);
495         Property p2 = getSecondaryDescriptor(t);
496
497         String JavaDoc pName = (String JavaDoc) item.get(p1.getName());
498
499         if (!shouldCheckout(pName)) {
500             return;
501         }
502
503         // VERBOSE MODE ONLY
504
if (getVerbose()) {
505             // Show folder only if changed.
506
boolean bShowHeader = (f != prevFolder);
507
508             if (bShowHeader) {
509                 // We want to display the folder the same way you would
510
// enter it on the command line ... so we remove the
511
// View name (which is also the name of the root folder,
512
// and therefore shows up at the start of the path).
513
String JavaDoc strFolder = f.getFolderHierarchy();
514                 int i = strFolder.indexOf(delim);
515
516                 if (i >= 0) {
517                     strFolder = strFolder.substring(i + 1);
518                 }
519                 log(" Folder: \"" + strFolder + "\"");
520                 prevFolder = f;
521
522                 // If we displayed the project, view, item type, or folder,
523
// then show the list of relevant item properties.
524
StringBuffer JavaDoc header = new StringBuffer JavaDoc(" Item");
525
526                 header.append(",\t").append(p1.getDisplayName());
527                 if (p2 != null) {
528                     header.append(",\t").append(p2.getDisplayName());
529                 }
530                 log(header.toString());
531             }
532
533             // Finally, show the Item properties ...
534
// Always show the ItemID.
535
StringBuffer JavaDoc itemLine = new StringBuffer JavaDoc(" ");
536
537             itemLine.append(item.getItemID());
538
539             // Show the primary descriptor.
540
// There should always be one.
541
itemLine.append(",\t").append(formatForDisplay(p1, item.get(p1.getName())));
542
543             // Show the secondary descriptor, if there is one.
544
// Some item types have one, some don't.
545
if (p2 != null) {
546                 itemLine.append(",\t").append(formatForDisplay(p2, item.get(p2.getName())));
547             }
548
549             // Show if the file is locked.
550
int locker = item.getLocker();
551
552             if (locker > -1) {
553                 itemLine.append(",\tLocked by ").append(locker);
554             } else {
555                 itemLine.append(",\tNot locked");
556             }
557             log(itemLine.toString());
558         }
559         // END VERBOSE ONLY
560

561         // Check it out; also ugly.
562

563         // Change the item to be checked out to a StarTeam File.
564
com.starbase.starteam.File remote = (com.starbase.starteam.File) item;
565
566         // The local file name is simply the local target path (tgt) which has
567
// been passed recursively down from the top of the tree, with the item's name appended.
568
java.io.File JavaDoc local = new java.io.File JavaDoc(tgt, (String JavaDoc) item.get(p1.getName()));
569
570         try {
571             remote.checkoutTo(local, Item.LockType.UNCHANGED, false, true, true);
572             checkedOut++;
573         } catch (Exception JavaDoc e) {
574             throw new BuildException("Failed to checkout '" + local + "'", e);
575         }
576     }
577
578
579     /**
580      * Look if the file should be checked out. Don't check it out if It fits
581      * no include filters and It fits an exclude filter.
582      *
583      * @param pName the item name to look for being included.
584      * @return whether the file should be checked out or not.
585      */

586     protected boolean shouldCheckout(String JavaDoc pName) {
587         boolean includeIt = matchPatterns(getIncludes(), pName);
588         boolean excludeIt = matchPatterns(getExcludes(), pName);
589
590         return (includeIt && !excludeIt);
591     }
592
593
594     /**
595      * Convenient method to see if a string match a one pattern in given set
596      * of space-separated patterns.
597      *
598      * @param patterns the space-separated list of patterns.
599      * @param pName the name to look for matching.
600      * @return whether the name match at least one pattern.
601      */

602     protected boolean matchPatterns(String JavaDoc patterns, String JavaDoc pName) {
603         if (patterns == null) {
604             return false;
605         }
606         StringTokenizer JavaDoc exStr = new StringTokenizer JavaDoc(patterns, " ");
607
608         while (exStr.hasMoreTokens()) {
609             if (DirectoryScanner.match(exStr.nextToken(), pName)) {
610                 return true;
611             }
612         }
613         return false;
614     }
615
616
617     /**
618      * Get the primary descriptor of the given item type. Returns null if
619      * there isn't one. In practice, all item types have a primary descriptor.
620      *
621      * @param t An item type. At this point it will always be "file".
622      * @return The specified item's primary descriptor.
623      */

624     protected Property getPrimaryDescriptor(Type t) {
625         Property[] properties = t.getProperties();
626
627         for (int i = 0; i < properties.length; i++) {
628             Property p = properties[i];
629
630             if (p.isPrimaryDescriptor()) {
631                 return p;
632             }
633         }
634         return null;
635     }
636
637
638     /**
639      * Get the secondary descriptor of the given item type. Returns null if
640      * there isn't one.
641      *
642      * @param t An item type. At this point it will always be "file".
643      * @return The specified item's secondary descriptor. There may not be one
644      * for every file.
645      */

646     protected Property getSecondaryDescriptor(Type t) {
647         Property[] properties = t.getProperties();
648
649         for (int i = 0; i < properties.length; i++) {
650             Property p = properties[i];
651
652             if (p.isDescriptor() && !p.isPrimaryDescriptor()) {
653                 return p;
654             }
655         }
656         return null;
657     }
658
659
660     /**
661      * Formats a property value for display to the user.
662      *
663      * @param p An item property to format.
664      * @param value the object to format.
665      * @return A string containing the property, which is truncated to 35
666      * characters for display.
667      */

668     protected String JavaDoc formatForDisplay(Property p, Object JavaDoc value) {
669         if (p.getTypeCode() == Property.Types.TEXT) {
670             String JavaDoc str = value.toString();
671
672             if (str.length() > 35) {
673                 str = str.substring(0, 32) + "...";
674             }
675             return "\"" + str + "\"";
676         } else {
677             if (p.getTypeCode() == Property.Types.ENUMERATED) {
678                 return "\"" + p.getEnumDisplayName(((Integer JavaDoc) value).intValue()) + "\"";
679             } else {
680                 return value.toString();
681             }
682         }
683     }
684
685     // Begin SET and GET methods
686

687     /**
688      * Sets the <CODE>serverName</CODE> attribute to the given value.
689      *
690      * @param serverName The name of the server you wish to connect to.
691      * @see #getServerName()
692      */

693     public void setServerName(String JavaDoc serverName) {
694         this.serverName = serverName;
695     }
696
697
698     /**
699      * Gets the <CODE>serverName</CODE> attribute.
700      *
701      * @return The StarTeam server to log in to.
702      * @see #setServerName(String serverName)
703      */

704     public String JavaDoc getServerName() {
705         return serverName;
706     }
707
708
709     /**
710      * Sets the <CODE>serverPort</CODE> attribute to the given value. The
711      * given value must be a valid integer, but it must be a string object.
712      *
713      * @param serverPort A string containing the port on the StarTeam server
714      * to use.
715      * @see #getServerPort()
716      */

717     public void setServerPort(int serverPort) {
718         this.serverPort = serverPort;
719     }
720
721
722     /**
723      * Gets the <CODE>serverPort</CODE> attribute.
724      *
725      * @return A string containing the port on the StarTeam server to use.
726      * @see #setServerPort(int)
727      */

728     public int getServerPort() {
729         return serverPort;
730     }
731
732
733     /**
734      * Sets the <CODE>projectName</CODE> attribute to the given value.
735      *
736      * @param projectName The StarTeam project to search.
737      * @see #getProjectName()
738      */

739     public void setProjectName(String JavaDoc projectName) {
740         this.projectName = projectName;
741     }
742
743
744     /**
745      * Gets the <CODE>projectName</CODE> attribute.
746      *
747      * @return The StarTeam project to search.
748      * @see #setProjectName(String projectName)
749      */

750     public String JavaDoc getProjectName() {
751         return projectName;
752     }
753
754
755     /**
756      * Sets the <CODE>viewName</CODE> attribute to the given value.
757      *
758      * @param viewName The view to find the specified folder in.
759      * @see #getViewName()
760      */

761     public void setViewName(String JavaDoc viewName) {
762         this.viewName = viewName;
763     }
764
765
766     /**
767      * Gets the <CODE>viewName</CODE> attribute.
768      *
769      * @return The view to find the specified folder in.
770      * @see #setViewName(String viewName)
771      */

772     public String JavaDoc getViewName() {
773         return viewName;
774     }
775
776
777     /**
778      * Sets the <CODE>folderName</CODE> attribute to the given value. To
779      * search the root folder, use a slash or backslash, or simply don't set a
780      * folder at all.
781      *
782      * @param folderName The subfolder from which to check out files.
783      * @see #getFolderName()
784      */

785     public void setFolderName(String JavaDoc folderName) {
786         this.folderName = folderName;
787     }
788
789
790     /**
791      * Gets the <CODE>folderName</CODE> attribute.
792      *
793      * @return The subfolder from which to check out files. All subfolders
794      * will be searched, as well.
795      * @see #setFolderName(String folderName)
796      */

797     public String JavaDoc getFolderName() {
798         return folderName;
799     }
800
801
802     /**
803      * Sets the <CODE>username</CODE> attribute to the given value.
804      *
805      * @param username Your username for the specified StarTeam server.
806      * @see #getUsername()
807      */

808     public void setUsername(String JavaDoc username) {
809         this.username = username;
810     }
811
812
813     /**
814      * Gets the <CODE>username</CODE> attribute.
815      *
816      * @return The username given by the user.
817      * @see #setUsername(String username)
818      */

819     public String JavaDoc getUsername() {
820         return username;
821     }
822
823
824     /**
825      * Sets the <CODE>password</CODE> attribute to the given value.
826      *
827      * @param password Your password for the specified StarTeam server.
828      * @see #getPassword()
829      */

830     public void setPassword(String JavaDoc password) {
831         this.password = password;
832     }
833
834
835     /**
836      * Gets the <CODE>password</CODE> attribute.
837      *
838      * @return The password given by the user.
839      * @see #setPassword(String password)
840      */

841     public String JavaDoc getPassword() {
842         return password;
843     }
844
845
846     /**
847      * Sets the <CODE>targetFolder</CODE> attribute to the given value.
848      *
849      * @param targetFolder The target path on the local machine to check out to.
850      * @see #getTargetFolder()
851      */

852     public void setTargetFolder(String JavaDoc targetFolder) {
853         this.targetFolder = targetFolder;
854     }
855
856
857     /**
858      * Gets the <CODE>targetFolder</CODE> attribute.
859      *
860      * @return The target path on the local machine to check out to.
861      * @see #setTargetFolder(String targetFolder)
862      */

863     public String JavaDoc getTargetFolder() {
864         return targetFolder;
865     }
866
867
868     /**
869      * Sets the <CODE>force</CODE> attribute to the given value.
870      *
871      * @param force if true, it overwrites files in the target directory. By
872      * default it set to false as a safeguard. Note that if the target
873      * directory does not exist, this setting has no effect.
874      * @see #getForce()
875      */

876     public void setForce(boolean force) {
877         this.force = force;
878     }
879
880
881     /**
882      * Gets the <CODE>force</CODE> attribute.
883      *
884      * @return whether to continue if the target directory exists.
885      * @see #setForce(boolean)
886      */

887     public boolean getForce() {
888         return force;
889     }
890
891
892     /**
893      * Turns recursion on or off.
894      *
895      * @param recursion if it is true, the default, subfolders are searched
896      * recursively for files to check out. Otherwise, only files
897      * specified by <CODE>folderName</CODE> are scanned.
898      * @see #getRecursion()
899      */

900     public void setRecursion(boolean recursion) {
901         this.recursion = recursion;
902     }
903
904
905     /**
906      * Gets the <CODE>recursion</CODE> attribute, which tells
907      * AntStarTeamCheckOut whether to search subfolders when checking out
908      * files.
909      *
910      * @return whether to search subfolders when checking out files.
911      * @see #setRecursion(boolean)
912      */

913     public boolean getRecursion() {
914         return recursion;
915     }
916
917
918     /**
919      * Sets the <CODE>verbose</CODE> attribute to the given value.
920      *
921      * @param verbose whether to display all files as it checks them out. By
922      * default it is false, so the program only displays the total number
923      * of files unless you override this default.
924      * @see #getVerbose()
925      */

926     public void setVerbose(boolean verbose) {
927         this.verbose = verbose;
928     }
929
930
931     /**
932      * Gets the <CODE>verbose</CODE> attribute.
933      *
934      * @return whether to display all files as it checks them out.
935      * @see #setVerbose(boolean verbose)
936      */

937     public boolean getVerbose() {
938         return verbose;
939     }
940
941     // Begin filter getters and setters
942

943     /**
944      * Sets the include filter. When filtering files, AntStarTeamCheckOut uses
945      * an unmodified version of <CODE>DirectoryScanner</CODE>'s <CODE>match</CODE>
946      * method, so here are the patterns straight from the Ant source code:
947      * <BR>
948      * <BR>
949      * Matches a string against a pattern. The pattern contains two special
950      * characters: <BR>
951      * '*' which means zero or more characters, <BR>
952      * '?' which means one and only one character. <BR>
953      * <BR>
954      * Separate multiple inlcude filters by <I>spaces</I> , not commas as Ant
955      * uses. For example, if you want to check out all .java and .class\
956      * files, you would put the following line in your program:
957      * <CODE>setIncludes("*.java *.class");</CODE>
958      * Finally, note that filters have no effect on the <B>directories</B>
959      * that are scanned; you could not check out files from directories with
960      * names beginning only with "build," for instance. Of course, you could
961      * limit AntStarTeamCheckOut to a particular folder and its subfolders
962      * with the <CODE>setFolderName(String folderName)</CODE> command. <BR>
963      * <BR>
964      * Treatment of overlapping inlcudes and excludes: To give a simplistic
965      * example suppose that you set your include filter to "*.htm *.html" and
966      * your exclude filter to "index.*". What happens to index.html?
967      * AntStarTeamCheckOut will not check out index.html, as it matches an
968      * exclude filter ("index.*"), even though it matches the include filter,
969      * as well. <BR>
970      * <BR>
971      * Please also read the following sections before using filters:
972      *
973      * @param includes A string of filter patterns to include. Separate the
974      * patterns by spaces.
975      * @see #getIncludes()
976      * @see #setExcludes(String excludes)
977      * @see #getExcludes()
978      */

979     public void setIncludes(String JavaDoc includes) {
980         this.includes = includes;
981     }
982
983
984     /**
985      * Gets the patterns from the include filter. Rather that duplicate the
986      * details of AntStarTeanCheckOut's filtering here, refer to these links:
987      *
988      * @return A string of filter patterns separated by spaces.
989      * @see #setIncludes(String includes)
990      * @see #setExcludes(String excludes)
991      * @see #getExcludes()
992      */

993     public String JavaDoc getIncludes() {
994         return includes;
995     }
996
997
998     /**
999      * Sets the exclude filter. When filtering files, AntStarTeamCheckOut uses
1000     * an unmodified version of <CODE>DirectoryScanner</CODE>'s <CODE>match</CODE>
1001     * method, so here are the patterns straight from the Ant source code:
1002     * <BR>
1003     * <BR>
1004     * Matches a string against a pattern. The pattern contains two special
1005     * characters: <BR>
1006     * '*' which means zero or more characters, <BR>
1007     * '?' which means one and only one character. <BR>
1008     * <BR>
1009     * Separate multiple exlcude filters by <I>spaces</I> , not commas as Ant
1010     * uses. For example, if you want to check out all files except .XML and
1011     * .HTML files, you would put the following line in your program:
1012     * <CODE>setExcludes("*.XML *.HTML");</CODE>
1013     * Finally, note that filters have no effect on the <B>directories</B>
1014     * that are scanned; you could not skip over all files in directories
1015     * whose names begin with "project," for instance. <BR>
1016     * <BR>
1017     * Treatment of overlapping inlcudes and excludes: To give a simplistic
1018     * example suppose that you set your include filter to "*.htm *.html" and
1019     * your exclude filter to "index.*". What happens to index.html?
1020     * AntStarTeamCheckOut will not check out index.html, as it matches an
1021     * exclude filter ("index.*"), even though it matches the include filter,
1022     * as well. <BR>
1023     * <BR>
1024     * Please also read the following sections before using filters:
1025     *
1026     * @param excludes A string of filter patterns to exclude. Separate the
1027     * patterns by spaces.
1028     * @see #setIncludes(String includes)
1029     * @see #getIncludes()
1030     * @see #getExcludes()
1031     */

1032    public void setExcludes(String JavaDoc excludes) {
1033        this.excludes = excludes;
1034    }
1035
1036
1037    /**
1038     * Gets the patterns from the exclude filter. Rather that duplicate the
1039     * details of AntStarTeanCheckOut's filtering here, refer to these links:
1040     *
1041     * @return A string of filter patterns separated by spaces.
1042     * @see #setExcludes(String excludes)
1043     * @see #setIncludes(String includes)
1044     * @see #getIncludes()
1045     */

1046    public String JavaDoc getExcludes() {
1047        return excludes;
1048    }
1049
1050
1051    /**
1052     * returns whether the StarTeam default path is factored into calculated
1053     * target path locations (false) or whether targetFolder is an absolute
1054     * mapping to the root folder named by folderName
1055     *
1056     * @return returns true if absolute mapping is used, false if it is not
1057     * used.
1058     * @see #setTargetFolderAbsolute(boolean)
1059     */

1060    public boolean getTargetFolderAbsolute() {
1061        return this.targetFolderAbsolute;
1062    }
1063
1064
1065    /**
1066     * sets the property that indicates whether or not the Star Team "default
1067     * folder" is to be used when calculation paths for items on the target
1068     * (false) or if targetFolder is an absolute mapping to the root folder
1069     * named by foldername.
1070     *
1071     * @param targetFolderAbsolute <tt>true</tt> if the absolute mapping is to
1072     * be used. <tt>false</tt> (the default) if the "default folder" is
1073     * to be factored in.
1074     * @see #getTargetFolderAbsolute()
1075     */

1076    public void setTargetFolderAbsolute(boolean targetFolderAbsolute) {
1077        this.targetFolderAbsolute = targetFolderAbsolute;
1078    }
1079}
1080
1081
Popular Tags