1. /*
  2. * Copyright 2000-2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.optional.scm;
  18. import com.starbase.starteam.Folder;
  19. import com.starbase.starteam.Item;
  20. import com.starbase.starteam.Property;
  21. import com.starbase.starteam.Server;
  22. import com.starbase.starteam.StarTeamFinder;
  23. import com.starbase.starteam.Type;
  24. import com.starbase.starteam.View;
  25. import com.starbase.util.Platform;
  26. import java.util.StringTokenizer;
  27. import org.apache.tools.ant.BuildException;
  28. import org.apache.tools.ant.DirectoryScanner;
  29. import org.apache.tools.ant.Project;
  30. /**
  31. * Checks out files from a specific StarTeam server, project, view, and
  32. * folder.
  33. * <BR><BR>
  34. * This program logs in to a StarTeam server and opens up the specified
  35. * project and view. Then, it searches through that view for the given
  36. * folder (or, if you prefer, it uses the root folder). Beginning with
  37. * that folder and optionally continuing recursivesly, AntStarTeamCheckOut
  38. * compares each file with your include and exclude filters and checks it
  39. * out only if appropriate.
  40. * <BR><BR>
  41. * Checked out files go to a directory you specify under the subfolder
  42. * named for the default StarTeam path to the view. That is, if you
  43. * entered /home/cpovirk/work as the target folder, your project was named
  44. * "OurProject," the given view was named "TestView," and that view is
  45. * stored by default at "C:\projects\Test," your files would be checked
  46. * out to /home/cpovirk/work/Test." I avoided using the project name in
  47. * the path because you may want to keep several versions of the same
  48. * project on your computer, and I didn't want to use the view name, as
  49. * there may be many "Test" or "Version 1.0" views, for example. This
  50. * system's success, of course, depends on what you set the default path
  51. * to in StarTeam.
  52. * <BR><BR>
  53. * You can set AntStarTeamCheckOut to verbose or quiet mode. Also, it has
  54. * a safeguard against overwriting the files on your computer: If the
  55. * target directory you specify already exists, the program will throw a
  56. * BuildException. To override the exception, set <CODE>force</CODE> to
  57. * true.
  58. * <BR><BR>
  59. * <B>This program makes use of functions from the StarTeam API. As a result
  60. * AntStarTeamCheckOut is available only to licensed users of StarTeam and
  61. * requires the StarTeam SDK to function. You must have
  62. * <CODE>starteam-sdk.jar</CODE> in your classpath to run this program.
  63. * For more information about the StarTeam API and how to license it, see
  64. * the link below.</B>
  65. *
  66. * @version 1.0
  67. * @see <A HREF="http://www.starbase.com/">StarBase Web Site</A>
  68. *
  69. * @ant.task name="starteam" category="scm" ignore="true"
  70. */
  71. public class AntStarTeamCheckOut extends org.apache.tools.ant.Task {
  72. /**
  73. * This constant sets the filter to include all files. This default has
  74. * the same result as <CODE>setIncludes("*")</CODE>.
  75. *
  76. * @see #getIncludes()
  77. * @see #setIncludes(String includes)
  78. */
  79. public static final String DEFAULT_INCLUDESETTING = "*";
  80. /**
  81. * This disables the exclude filter by default. In other words, no files
  82. * are excluded. This setting is equivalent to <CODE>setExcludes(null)</CODE>
  83. * .
  84. *
  85. * @see #getExcludes()
  86. * @see #setExcludes(String excludes)
  87. */
  88. public static final String DEFAULT_EXCLUDESETTING = null;
  89. /**
  90. * The default folder to search; the root folder. Since
  91. * AntStarTeamCheckOut searches subfolders, by default it processes an
  92. * entire view.
  93. *
  94. * @see #getFolderName()
  95. * @see #setFolderName(String folderName)
  96. */
  97. public static final String DEFAULT_FOLDERSETTING = null;
  98. /**
  99. * This is used when formatting the output. The directory name is
  100. * displayed only when it changes.
  101. */
  102. private Folder prevFolder = null;
  103. /** This field keeps count of the number of files checked out. */
  104. private int checkedOut = 0;
  105. // Change these through their GET and SET methods.
  106. /** The name of the server you wish to connect to. */
  107. private String serverName = null;
  108. /** The port on the server used for StarTeam. */
  109. private int serverPort = -1;
  110. /** The name of your project. */
  111. private String projectName = null;
  112. /**
  113. * The name of the folder you want to check out files from. All subfolders
  114. * will be searched, as well.
  115. */
  116. private String folderName = DEFAULT_FOLDERSETTING;
  117. /** The view that the files you want are in. */
  118. private String viewName = null;
  119. /** Your username on the StarTeam server. */
  120. private String username = null;
  121. /** Your StarTeam password. */
  122. private String password = null;
  123. /**
  124. * The path to the root folder you want to check out to. This is a local
  125. * directory.
  126. */
  127. private String targetFolder = null;
  128. /**
  129. * If force set to true, AntStarTeamCheckOut will overwrite files in the
  130. * target directory.
  131. */
  132. private boolean force = false;
  133. /**
  134. * When verbose is true, the program will display all files and
  135. * directories as they are checked out.
  136. */
  137. private boolean verbose = false;
  138. /**
  139. * Set recursion to false to check out files in only the given folder and
  140. * not in its subfolders.
  141. */
  142. private boolean recursion = true;
  143. // These fields deal with includes and excludes
  144. /** All files that fit this pattern are checked out. */
  145. private String includes = DEFAULT_INCLUDESETTING;
  146. /** All files fitting this pattern are ignored. */
  147. private String excludes = DEFAULT_EXCLUDESETTING;
  148. /** The file delimitor on the user's system. */
  149. private String delim = Platform.getFilePathDelim();
  150. /**
  151. * whether to use the Starteam "default folder" when calculating the
  152. * target paths to which files are checked out (false) or if targetFolder
  153. * represents an absolute mapping to folderName.
  154. */
  155. private boolean targetFolderAbsolute = false;
  156. /** convenient method to check for conditions */
  157. private static void assertTrue(boolean value, String msg) throws BuildException {
  158. if (!value) {
  159. throw new BuildException(msg);
  160. }
  161. }
  162. protected void checkParameters() throws BuildException {
  163. // Check all of the properties that are required.
  164. assertTrue(getServerName() != null, "ServerName must be set.");
  165. assertTrue(getServerPort() != -1, "ServerPort must be set.");
  166. assertTrue(getProjectName() != null, "ProjectName must be set.");
  167. assertTrue(getViewName() != null, "ViewName must be set.");
  168. assertTrue(getUsername() != null, "Username must be set.");
  169. assertTrue(getPassword() != null, "Password must be set.");
  170. assertTrue(getTargetFolder() != null, "TargetFolder must be set.");
  171. // Because of the way I create the full target path, there
  172. // must be NO slash at the end of targetFolder and folderName
  173. // However, if the slash or backslash is the only character, leave it alone
  174. if ((getTargetFolder().endsWith("/")
  175. || getTargetFolder().endsWith("\\"))
  176. && getTargetFolder().length() > 1) {
  177. setTargetFolder(getTargetFolder().substring(0, getTargetFolder().length() - 1));
  178. }
  179. // Check to see if the target directory exists.
  180. java.io.File dirExist = new java.io.File(getTargetFolder());
  181. if (dirExist.isDirectory() && !getForce()) {
  182. throw new BuildException("Target directory exists. Set \"force\" "
  183. + "to \"true\" to continue anyway.");
  184. }
  185. }
  186. /**
  187. * Do the execution.
  188. *
  189. * @exception BuildException
  190. */
  191. public void execute() throws BuildException {
  192. log("DEPRECATED - The starteam task is deprecated. Use stcheckout instead.",
  193. Project.MSG_WARN);
  194. // Connect to the StarTeam server, and log on.
  195. Server s = getServer();
  196. try {
  197. // Search the items on this server.
  198. runServer(s);
  199. } finally {
  200. // Disconnect from the server.
  201. s.disconnect();
  202. }
  203. // after you are all of the properties are ok, do your thing
  204. // with StarTeam. If there are any kind of exceptions then
  205. // send the message to the project log.
  206. // Tell how many files were checked out.
  207. log(checkedOut + " files checked out.");
  208. }
  209. /**
  210. * Creates and logs in to a StarTeam server.
  211. *
  212. * @return A StarTeam server.
  213. */
  214. protected Server getServer() {
  215. // Simplest constructor, uses default encryption algorithm and compression level.
  216. Server s = new Server(getServerName(), getServerPort());
  217. // Optional; logOn() connects if necessary.
  218. s.connect();
  219. // Logon using specified user name and password.
  220. s.logOn(getUsername(), getPassword());
  221. return s;
  222. }
  223. /**
  224. * Searches for the specified project on the server.
  225. *
  226. * @param s A StarTeam server.
  227. */
  228. protected void runServer(Server s) {
  229. com.starbase.starteam.Project[] projects = s.getProjects();
  230. for (int i = 0; i < projects.length; i++) {
  231. com.starbase.starteam.Project p = projects[i];
  232. if (p.getName().equals(getProjectName())) {
  233. if (getVerbose()) {
  234. log("Found " + getProjectName() + delim);
  235. }
  236. runProject(s, p);
  237. break;
  238. }
  239. }
  240. }
  241. /**
  242. * Searches for the given view in the project.
  243. *
  244. * @param s A StarTeam server.
  245. * @param p A valid project on the given server.
  246. */
  247. protected void runProject(Server s, com.starbase.starteam.Project p) {
  248. View[] views = p.getViews();
  249. for (int i = 0; i < views.length; i++) {
  250. View v = views[i];
  251. if (v.getName().equals(getViewName())) {
  252. if (getVerbose()) {
  253. log("Found " + getProjectName() + delim + getViewName() + delim);
  254. }
  255. runType(s, p, v, s.typeForName(s.getTypeNames().FILE));
  256. break;
  257. }
  258. }
  259. }
  260. /**
  261. * Searches for folders in the given view.
  262. *
  263. * @param s A StarTeam server.
  264. * @param p A valid project on the server.
  265. * @param v A view name from the specified project.
  266. * @param t An item type which is currently always "file".
  267. */
  268. protected void runType(Server s, com.starbase.starteam.Project p, View v, Type t) {
  269. // This is ugly; checking for the root folder.
  270. Folder f = v.getRootFolder();
  271. if (getFolderName() != null) {
  272. if (getFolderName().equals("\\") || getFolderName().equals("/")) {
  273. setFolderName(null);
  274. } else {
  275. f = StarTeamFinder.findFolder(v.getRootFolder(), getFolderName());
  276. assertTrue(null != f, "ERROR: " + getProjectName() + delim
  277. + getViewName() + delim + v.getRootFolder() + delim
  278. + getFolderName() + delim
  279. + " does not exist.");
  280. }
  281. }
  282. if (getVerbose() && getFolderName() != null) {
  283. log("Found " + getProjectName() + delim + getViewName()
  284. + delim + getFolderName() + delim + "\n");
  285. }
  286. // For performance reasons, it is important to pre-fetch all the
  287. // properties we'll need for all the items we'll be searching.
  288. // We always display the ItemID (OBJECT_ID) and primary descriptor.
  289. int nProperties = 2;
  290. // We'll need this item type's primary descriptor.
  291. Property p1 = getPrimaryDescriptor(t);
  292. // Does this item type have a secondary descriptor?
  293. // If so, we'll need it.
  294. Property p2 = getSecondaryDescriptor(t);
  295. if (p2 != null) {
  296. nProperties++;
  297. }
  298. // Now, build an array of the property names.
  299. String[] strNames = new String[nProperties];
  300. int iProperty = 0;
  301. strNames[iProperty++] = s.getPropertyNames().OBJECT_ID;
  302. strNames[iProperty++] = p1.getName();
  303. if (p2 != null) {
  304. strNames[iProperty++] = p2.getName();
  305. }
  306. // Pre-fetch the item properties and cache them.
  307. f.populateNow(t.getName(), strNames, -1);
  308. // Now, search for items in the selected folder.
  309. runFolder(s, p, v, t, f, calcTargetFolder(v, f));
  310. // Free up the memory used by the cached items.
  311. f.discardItems(t.getName(), -1);
  312. }
  313. /**
  314. * Returns a file object that defines the root of the local checkout tree.
  315. * Depending on the value of targetFolderAbsolute, this will be either the
  316. * targetFolder exactly as set by the user or the path formed by appending
  317. * the default folder onto the specified target folder.
  318. *
  319. * @param v view from which the file is checked out, supplies the "default
  320. * folder"
  321. * @param rootSourceFolder root folder of the checkout operation in Star
  322. * Team
  323. * @return an object referencing the local file
  324. * @see #getTargetFolderAbsolute()
  325. */
  326. private java.io.File calcTargetFolder(View v, Folder rootSourceFolder) {
  327. java.io.File root = new java.io.File(getTargetFolder());
  328. if (!getTargetFolderAbsolute()) {
  329. // Create a variable dir that contains the name of
  330. // the StarTeam folder that is the root folder in this view.
  331. // Get the default path to the current view.
  332. String defaultPath = v.getDefaultPath();
  333. // convert whatever separator char is in starteam to that of the target system.
  334. defaultPath = defaultPath.replace('/', java.io.File.separatorChar);
  335. defaultPath = defaultPath.replace('\\', java.io.File.separatorChar);
  336. java.io.File dir = new java.io.File(defaultPath);
  337. String dirName = dir.getName();
  338. // If it ends with separator then strip it off
  339. if (dirName.endsWith(delim)) {
  340. dirName = dirName.substring(0, dirName.length() - 1);
  341. }
  342. // Replace the projectName in the file's absolute path to the viewName.
  343. // This makes the root target of a checkout operation equal to:
  344. // targetFolder + dirName
  345. StringTokenizer pathTokenizer
  346. = new StringTokenizer(rootSourceFolder.getFolderHierarchy(), delim);
  347. String currentToken = null;
  348. boolean foundRoot = false;
  349. while (pathTokenizer.hasMoreTokens()) {
  350. currentToken = pathTokenizer.nextToken();
  351. if (currentToken.equals(getProjectName()) && !foundRoot) {
  352. currentToken = dirName;
  353. foundRoot = true; // only want to do this the first time
  354. }
  355. root = new java.io.File(root, currentToken);
  356. }
  357. }
  358. return root;
  359. }
  360. /**
  361. * Searches for files in the given folder. This method is recursive and
  362. * thus searches all subfolders.
  363. *
  364. * @param s A StarTeam server.
  365. * @param p A valid project on the server.
  366. * @param v A view name from the specified project.
  367. * @param t An item type which is currently always "file".
  368. * @param f The folder to search.
  369. * @param tgt Target folder on local machine
  370. */
  371. protected void runFolder(Server s,
  372. com.starbase.starteam.Project p,
  373. View v,
  374. Type t,
  375. Folder f,
  376. java.io.File tgt) {
  377. // Process all items in this folder.
  378. Item[] items = f.getItems(t.getName());
  379. for (int i = 0; i < items.length; i++) {
  380. runItem(s, p, v, t, f, items[i], tgt);
  381. }
  382. // Process all subfolders recursively if recursion is on.
  383. if (getRecursion()) {
  384. Folder[] subfolders = f.getSubFolders();
  385. for (int i = 0; i < subfolders.length; i++) {
  386. runFolder(s, p, v, t, subfolders[i],
  387. new java.io.File(tgt, subfolders[i].getName()));
  388. }
  389. }
  390. }
  391. /**
  392. * Check out one file if it matches the include filter but not the exclude
  393. * filter.
  394. *
  395. * @param s A StarTeam server.
  396. * @param p A valid project on the server.
  397. * @param v A view name from the specified project.
  398. * @param t An item type which is currently always "file".
  399. * @param f The folder the file is localed in.
  400. * @param item The file to check out.
  401. * @param tgt target folder on local machine
  402. */
  403. protected void runItem(Server s,
  404. com.starbase.starteam.Project p,
  405. View v,
  406. Type t,
  407. Folder f,
  408. Item item,
  409. java.io.File tgt) {
  410. // Get descriptors for this item type.
  411. Property p1 = getPrimaryDescriptor(t);
  412. Property p2 = getSecondaryDescriptor(t);
  413. String pName = (String) item.get(p1.getName());
  414. if (!shouldCheckout(pName)) {
  415. return;
  416. }
  417. // VERBOSE MODE ONLY
  418. if (getVerbose()) {
  419. // Show folder only if changed.
  420. boolean bShowHeader = (f != prevFolder);
  421. if (bShowHeader) {
  422. // We want to display the folder the same way you would
  423. // enter it on the command line ... so we remove the
  424. // View name (which is also the name of the root folder,
  425. // and therefore shows up at the start of the path).
  426. String strFolder = f.getFolderHierarchy();
  427. int i = strFolder.indexOf(delim);
  428. if (i >= 0) {
  429. strFolder = strFolder.substring(i + 1);
  430. }
  431. log(" Folder: \"" + strFolder + "\"");
  432. prevFolder = f;
  433. // If we displayed the project, view, item type, or folder,
  434. // then show the list of relevant item properties.
  435. StringBuffer header = new StringBuffer(" Item");
  436. header.append(",\t").append(p1.getDisplayName());
  437. if (p2 != null) {
  438. header.append(",\t").append(p2.getDisplayName());
  439. }
  440. log(header.toString());
  441. }
  442. // Finally, show the Item properties ...
  443. // Always show the ItemID.
  444. StringBuffer itemLine = new StringBuffer(" ");
  445. itemLine.append(item.getItemID());
  446. // Show the primary descriptor.
  447. // There should always be one.
  448. itemLine.append(",\t").append(formatForDisplay(p1, item.get(p1.getName())));
  449. // Show the secondary descriptor, if there is one.
  450. // Some item types have one, some don't.
  451. if (p2 != null) {
  452. itemLine.append(",\t").append(formatForDisplay(p2, item.get(p2.getName())));
  453. }
  454. // Show if the file is locked.
  455. int locker = item.getLocker();
  456. if (locker > -1) {
  457. itemLine.append(",\tLocked by ").append(locker);
  458. } else {
  459. itemLine.append(",\tNot locked");
  460. }
  461. log(itemLine.toString());
  462. }
  463. // END VERBOSE ONLY
  464. // Check it out; also ugly.
  465. // Change the item to be checked out to a StarTeam File.
  466. com.starbase.starteam.File remote = (com.starbase.starteam.File) item;
  467. // The local file name is simply the local target path (tgt) which has
  468. // been passed recursively down from the top of the tree, with the item's name appended.
  469. java.io.File local = new java.io.File(tgt, (String) item.get(p1.getName()));
  470. try {
  471. remote.checkoutTo(local, Item.LockType.UNCHANGED, false, true, true);
  472. checkedOut++;
  473. } catch (Exception e) {
  474. throw new BuildException("Failed to checkout '" + local + "'", e);
  475. }
  476. }
  477. /**
  478. * Look if the file should be checked out. Don't check it out if It fits
  479. * no include filters and It fits an exclude filter.
  480. *
  481. * @param pName the item name to look for being included.
  482. * @return whether the file should be checked out or not.
  483. */
  484. protected boolean shouldCheckout(String pName) {
  485. boolean includeIt = matchPatterns(getIncludes(), pName);
  486. boolean excludeIt = matchPatterns(getExcludes(), pName);
  487. return (includeIt && !excludeIt);
  488. }
  489. /**
  490. * Convenient method to see if a string match a one pattern in given set
  491. * of space-separated patterns.
  492. *
  493. * @param patterns the space-separated list of patterns.
  494. * @param pName the name to look for matching.
  495. * @return whether the name match at least one pattern.
  496. */
  497. protected boolean matchPatterns(String patterns, String pName) {
  498. if (patterns == null) {
  499. return false;
  500. }
  501. StringTokenizer exStr = new StringTokenizer(patterns, " ");
  502. while (exStr.hasMoreTokens()) {
  503. if (DirectoryScanner.match(exStr.nextToken(), pName)) {
  504. return true;
  505. }
  506. }
  507. return false;
  508. }
  509. /**
  510. * Get the primary descriptor of the given item type. Returns null if
  511. * there isn't one. In practice, all item types have a primary descriptor.
  512. *
  513. * @param t An item type. At this point it will always be "file".
  514. * @return The specified item's primary descriptor.
  515. */
  516. protected Property getPrimaryDescriptor(Type t) {
  517. Property[] properties = t.getProperties();
  518. for (int i = 0; i < properties.length; i++) {
  519. Property p = properties[i];
  520. if (p.isPrimaryDescriptor()) {
  521. return p;
  522. }
  523. }
  524. return null;
  525. }
  526. /**
  527. * Get the secondary descriptor of the given item type. Returns null if
  528. * there isn't one.
  529. *
  530. * @param t An item type. At this point it will always be "file".
  531. * @return The specified item's secondary descriptor. There may not be one
  532. * for every file.
  533. */
  534. protected Property getSecondaryDescriptor(Type t) {
  535. Property[] properties = t.getProperties();
  536. for (int i = 0; i < properties.length; i++) {
  537. Property p = properties[i];
  538. if (p.isDescriptor() && !p.isPrimaryDescriptor()) {
  539. return p;
  540. }
  541. }
  542. return null;
  543. }
  544. /**
  545. * Formats a property value for display to the user.
  546. *
  547. * @param p An item property to format.
  548. * @param value
  549. * @return A string containing the property, which is truncated to 35
  550. * characters for display.
  551. */
  552. protected String formatForDisplay(Property p, Object value) {
  553. if (p.getTypeCode() == Property.Types.TEXT) {
  554. String str = value.toString();
  555. if (str.length() > 35) {
  556. str = str.substring(0, 32) + "...";
  557. }
  558. return "\"" + str + "\"";
  559. } else {
  560. if (p.getTypeCode() == Property.Types.ENUMERATED) {
  561. return "\"" + p.getEnumDisplayName(((Integer) value).intValue()) + "\"";
  562. } else {
  563. return value.toString();
  564. }
  565. }
  566. }
  567. // Begin SET and GET methods
  568. /**
  569. * Sets the <CODE>serverName</CODE> attribute to the given value.
  570. *
  571. * @param serverName The name of the server you wish to connect to.
  572. * @see #getServerName()
  573. */
  574. public void setServerName(String serverName) {
  575. this.serverName = serverName;
  576. }
  577. /**
  578. * Gets the <CODE>serverName</CODE> attribute.
  579. *
  580. * @return The StarTeam server to log in to.
  581. * @see #setServerName(String serverName)
  582. */
  583. public String getServerName() {
  584. return serverName;
  585. }
  586. /**
  587. * Sets the <CODE>serverPort</CODE> attribute to the given value. The
  588. * given value must be a valid integer, but it must be a string object.
  589. *
  590. * @param serverPort A string containing the port on the StarTeam server
  591. * to use.
  592. * @see #getServerPort()
  593. */
  594. public void setServerPort(int serverPort) {
  595. this.serverPort = serverPort;
  596. }
  597. /**
  598. * Gets the <CODE>serverPort</CODE> attribute.
  599. *
  600. * @return A string containing the port on the StarTeam server to use.
  601. * @see #setServerPort(int)
  602. */
  603. public int getServerPort() {
  604. return serverPort;
  605. }
  606. /**
  607. * Sets the <CODE>projectName</CODE> attribute to the given value.
  608. *
  609. * @param projectName The StarTeam project to search.
  610. * @see #getProjectName()
  611. */
  612. public void setProjectName(String projectName) {
  613. this.projectName = projectName;
  614. }
  615. /**
  616. * Gets the <CODE>projectName</CODE> attribute.
  617. *
  618. * @return The StarTeam project to search.
  619. * @see #setProjectName(String projectName)
  620. */
  621. public String getProjectName() {
  622. return projectName;
  623. }
  624. /**
  625. * Sets the <CODE>viewName</CODE> attribute to the given value.
  626. *
  627. * @param viewName The view to find the specified folder in.
  628. * @see #getViewName()
  629. */
  630. public void setViewName(String viewName) {
  631. this.viewName = viewName;
  632. }
  633. /**
  634. * Gets the <CODE>viewName</CODE> attribute.
  635. *
  636. * @return The view to find the specified folder in.
  637. * @see #setViewName(String viewName)
  638. */
  639. public String getViewName() {
  640. return viewName;
  641. }
  642. /**
  643. * Sets the <CODE>folderName</CODE> attribute to the given value. To
  644. * search the root folder, use a slash or backslash, or simply don't set a
  645. * folder at all.
  646. *
  647. * @param folderName The subfolder from which to check out files.
  648. * @see #getFolderName()
  649. */
  650. public void setFolderName(String folderName) {
  651. this.folderName = folderName;
  652. }
  653. /**
  654. * Gets the <CODE>folderName</CODE> attribute.
  655. *
  656. * @return The subfolder from which to check out files. All subfolders
  657. * will be searched, as well.
  658. * @see #setFolderName(String folderName)
  659. */
  660. public String getFolderName() {
  661. return folderName;
  662. }
  663. /**
  664. * Sets the <CODE>username</CODE> attribute to the given value.
  665. *
  666. * @param username Your username for the specified StarTeam server.
  667. * @see #getUsername()
  668. */
  669. public void setUsername(String username) {
  670. this.username = username;
  671. }
  672. /**
  673. * Gets the <CODE>username</CODE> attribute.
  674. *
  675. * @return The username given by the user.
  676. * @see #setUsername(String username)
  677. */
  678. public String getUsername() {
  679. return username;
  680. }
  681. /**
  682. * Sets the <CODE>password</CODE> attribute to the given value.
  683. *
  684. * @param password Your password for the specified StarTeam server.
  685. * @see #getPassword()
  686. */
  687. public void setPassword(String password) {
  688. this.password = password;
  689. }
  690. /**
  691. * Gets the <CODE>password</CODE> attribute.
  692. *
  693. * @return The password given by the user.
  694. * @see #setPassword(String password)
  695. */
  696. public String getPassword() {
  697. return password;
  698. }
  699. /**
  700. * Sets the <CODE>targetFolder</CODE> attribute to the given value.
  701. *
  702. * @param targetFolder The target path on the local machine to check out to.
  703. * @see #getTargetFolder()
  704. */
  705. public void setTargetFolder(String targetFolder) {
  706. this.targetFolder = targetFolder;
  707. }
  708. /**
  709. * Gets the <CODE>targetFolder</CODE> attribute.
  710. *
  711. * @return The target path on the local machine to check out to.
  712. * @see #setTargetFolder(String targetFolder)
  713. */
  714. public String getTargetFolder() {
  715. return targetFolder;
  716. }
  717. /**
  718. * Sets the <CODE>force</CODE> attribute to the given value.
  719. *
  720. * @param force if true, it overwrites files in the target directory. By
  721. * default it set to false as a safeguard. Note that if the target
  722. * directory does not exist, this setting has no effect.
  723. * @see #getForce()
  724. */
  725. public void setForce(boolean force) {
  726. this.force = force;
  727. }
  728. /**
  729. * Gets the <CODE>force</CODE> attribute.
  730. *
  731. * @return whether to continue if the target directory exists.
  732. * @see #setForce(boolean)
  733. */
  734. public boolean getForce() {
  735. return force;
  736. }
  737. /**
  738. * Turns recursion on or off.
  739. *
  740. * @param recursion if it is true, the default, subfolders are searched
  741. * recursively for files to check out. Otherwise, only files
  742. * specified by <CODE>folderName</CODE> are scanned.
  743. * @see #getRecursion()
  744. */
  745. public void setRecursion(boolean recursion) {
  746. this.recursion = recursion;
  747. }
  748. /**
  749. * Gets the <CODE>recursion</CODE> attribute, which tells
  750. * AntStarTeamCheckOut whether to search subfolders when checking out
  751. * files.
  752. *
  753. * @return whether to search subfolders when checking out files.
  754. * @see #setRecursion(boolean)
  755. */
  756. public boolean getRecursion() {
  757. return recursion;
  758. }
  759. /**
  760. * Sets the <CODE>verbose</CODE> attribute to the given value.
  761. *
  762. * @param verbose whether to display all files as it checks them out. By
  763. * default it is false, so the program only displays the total number
  764. * of files unless you override this default.
  765. * @see #getVerbose()
  766. */
  767. public void setVerbose(boolean verbose) {
  768. this.verbose = verbose;
  769. }
  770. /**
  771. * Gets the <CODE>verbose</CODE> attribute.
  772. *
  773. * @return whether to display all files as it checks them out.
  774. * @see #setVerbose(boolean verbose)
  775. */
  776. public boolean getVerbose() {
  777. return verbose;
  778. }
  779. // Begin filter getters and setters
  780. /**
  781. * Sets the include filter. When filtering files, AntStarTeamCheckOut uses
  782. * an unmodified version of <CODE>DirectoryScanner</CODE>'s <CODE>match</CODE>
  783. * method, so here are the patterns straight from the Ant source code:
  784. * <BR>
  785. * <BR>
  786. * Matches a string against a pattern. The pattern contains two special
  787. * characters: <BR>
  788. * '*' which means zero or more characters, <BR>
  789. * '?' which means one and only one character. <BR>
  790. * <BR>
  791. * Separate multiple inlcude filters by <I>spaces</I> , not commas as Ant
  792. * uses. For example, if you want to check out all .java and .class\
  793. * files, you would put the following line in your program:
  794. * <CODE>setIncludes("*.java *.class");</CODE>
  795. * Finally, note that filters have no effect on the <B>directories</B>
  796. * that are scanned; you could not check out files from directories with
  797. * names beginning only with "build," for instance. Of course, you could
  798. * limit AntStarTeamCheckOut to a particular folder and its subfolders
  799. * with the <CODE>setFolderName(String folderName)</CODE> command. <BR>
  800. * <BR>
  801. * Treatment of overlapping inlcudes and excludes: To give a simplistic
  802. * example suppose that you set your include filter to "*.htm *.html" and
  803. * your exclude filter to "index.*". What happens to index.html?
  804. * AntStarTeamCheckOut will not check out index.html, as it matches an
  805. * exclude filter ("index.*"), even though it matches the include filter,
  806. * as well. <BR>
  807. * <BR>
  808. * Please also read the following sections before using filters:
  809. *
  810. * @param includes A string of filter patterns to include. Separate the
  811. * patterns by spaces.
  812. * @see #getIncludes()
  813. * @see #setExcludes(String excludes)
  814. * @see #getExcludes()
  815. */
  816. public void setIncludes(String includes) {
  817. this.includes = includes;
  818. }
  819. /**
  820. * Gets the patterns from the include filter. Rather that duplicate the
  821. * details of AntStarTeanCheckOut's filtering here, refer to these links:
  822. *
  823. * @return A string of filter patterns separated by spaces.
  824. * @see #setIncludes(String includes)
  825. * @see #setExcludes(String excludes)
  826. * @see #getExcludes()
  827. */
  828. public String getIncludes() {
  829. return includes;
  830. }
  831. /**
  832. * Sets the exclude filter. When filtering files, AntStarTeamCheckOut uses
  833. * an unmodified version of <CODE>DirectoryScanner</CODE>'s <CODE>match</CODE>
  834. * method, so here are the patterns straight from the Ant source code:
  835. * <BR>
  836. * <BR>
  837. * Matches a string against a pattern. The pattern contains two special
  838. * characters: <BR>
  839. * '*' which means zero or more characters, <BR>
  840. * '?' which means one and only one character. <BR>
  841. * <BR>
  842. * Separate multiple exlcude filters by <I>spaces</I> , not commas as Ant
  843. * uses. For example, if you want to check out all files except .XML and
  844. * .HTML files, you would put the following line in your program:
  845. * <CODE>setExcludes("*.XML *.HTML");</CODE>
  846. * Finally, note that filters have no effect on the <B>directories</B>
  847. * that are scanned; you could not skip over all files in directories
  848. * whose names begin with "project," for instance. <BR>
  849. * <BR>
  850. * Treatment of overlapping inlcudes and excludes: To give a simplistic
  851. * example suppose that you set your include filter to "*.htm *.html" and
  852. * your exclude filter to "index.*". What happens to index.html?
  853. * AntStarTeamCheckOut will not check out index.html, as it matches an
  854. * exclude filter ("index.*"), even though it matches the include filter,
  855. * as well. <BR>
  856. * <BR>
  857. * Please also read the following sections before using filters:
  858. *
  859. * @param excludes A string of filter patterns to exclude. Separate the
  860. * patterns by spaces.
  861. * @see #setIncludes(String includes)
  862. * @see #getIncludes()
  863. * @see #getExcludes()
  864. */
  865. public void setExcludes(String excludes) {
  866. this.excludes = excludes;
  867. }
  868. /**
  869. * Gets the patterns from the exclude filter. Rather that duplicate the
  870. * details of AntStarTeanCheckOut's filtering here, refer to these links:
  871. *
  872. * @return A string of filter patterns separated by spaces.
  873. * @see #setExcludes(String excludes)
  874. * @see #setIncludes(String includes)
  875. * @see #getIncludes()
  876. */
  877. public String getExcludes() {
  878. return excludes;
  879. }
  880. /**
  881. * returns whether the StarTeam default path is factored into calculated
  882. * target path locations (false) or whether targetFolder is an absolute
  883. * mapping to the root folder named by folderName
  884. *
  885. * @return returns true if absolute mapping is used, false if it is not
  886. * used.
  887. * @see #setTargetFolderAbsolute(boolean)
  888. */
  889. public boolean getTargetFolderAbsolute() {
  890. return this.targetFolderAbsolute;
  891. }
  892. /**
  893. * sets the property that indicates whether or not the Star Team "default
  894. * folder" is to be used when calculation paths for items on the target
  895. * (false) or if targetFolder is an absolute mapping to the root folder
  896. * named by foldername.
  897. *
  898. * @param targetFolderAbsolute <tt>true</tt> if the absolute mapping is to
  899. * be used. <tt>false</tt> (the default) if the "default folder" is
  900. * to be factored in.
  901. * @see #getTargetFolderAbsolute()
  902. */
  903. public void setTargetFolderAbsolute(boolean targetFolderAbsolute) {
  904. this.targetFolderAbsolute = targetFolderAbsolute;
  905. }
  906. }