📄 antstarteamcheckout.java
字号:
String[] strNames = new String[nProperties]; int iProperty = 0; strNames[iProperty++] = s.getPropertyNames().OBJECT_ID; strNames[iProperty++] = p1.getName(); if (p2 != null) { strNames[iProperty++] = p2.getName(); } // Pre-fetch the item properties and cache them. f.populateNow(t.getName(), strNames, -1); // Now, search for items in the selected folder. runFolder(s, p, v, t, f, calcTargetFolder(v, f)); // Free up the memory used by the cached items. f.discardItems(t.getName(), -1); } /** * Returns a file object that defines the root of the local checkout tree. * Depending on the value of targetFolderAbsolute, this will be either the * targetFolder exactly as set by the user or the path formed by appending * the default folder onto the specified target folder. * * @param v view from which the file is checked out, supplies the "default * folder" * @param rootSourceFolder root folder of the checkout operation in Star * Team * @return an object referencing the local file * @see #getTargetFolderAbsolute() */ private java.io.File calcTargetFolder(View v, Folder rootSourceFolder) { java.io.File root = new java.io.File(getTargetFolder()); if (!getTargetFolderAbsolute()) { // Create a variable dir 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 defaultPath = v.getDefaultPath(); // convert whatever separator char is in starteam to that of the target system. defaultPath = defaultPath.replace('/', java.io.File.separatorChar); defaultPath = defaultPath.replace('\\', java.io.File.separatorChar); java.io.File dir = new java.io.File(defaultPath); String dirName = dir.getName(); // If it ends with separator then strip it off if (dirName.endsWith(delim)) { dirName = dirName.substring(0, dirName.length() - 1); } // Replace the projectName in the file's absolute path to the viewName. // This makes the root target of a checkout operation equal to: // targetFolder + dirName StringTokenizer pathTokenizer = new StringTokenizer(rootSourceFolder.getFolderHierarchy(), delim); String currentToken = null; boolean foundRoot = false; while (pathTokenizer.hasMoreTokens()) { currentToken = pathTokenizer.nextToken(); if (currentToken.equals(getProjectName()) && !foundRoot) { currentToken = dirName; foundRoot = true; // only want to do this the first time } root = new java.io.File(root, currentToken); } } return root; } /** * Searches for files in the given folder. This method is recursive and * thus searches all subfolders. * * @param s A StarTeam server. * @param p A valid project on the server. * @param v A view name from the specified project. * @param t An item type which is currently always "file". * @param f The folder to search. * @param tgt Target folder on local machine */ protected void runFolder(Server s, com.starbase.starteam.Project p, View v, Type t, Folder f, java.io.File tgt) { // Process all items in this folder. Item[] items = f.getItems(t.getName()); for (int i = 0; i < items.length; i++) { runItem(s, p, v, t, f, items[i], tgt); } // Process all subfolders recursively if recursion is on. if (getRecursion()) { Folder[] subfolders = f.getSubFolders(); for (int i = 0; i < subfolders.length; i++) { runFolder(s, p, v, t, subfolders[i], new java.io.File(tgt, subfolders[i].getName())); } } } /** * Check out one file if it matches the include filter but not the exclude * filter. * * @param s A StarTeam server. * @param p A valid project on the server. * @param v A view name from the specified project. * @param t An item type which is currently always "file". * @param f The folder the file is localed in. * @param item The file to check out. * @param tgt target folder on local machine */ protected void runItem(Server s, com.starbase.starteam.Project p, View v, Type t, Folder f, Item item, java.io.File tgt) { // Get descriptors for this item type. Property p1 = getPrimaryDescriptor(t); Property p2 = getSecondaryDescriptor(t); String pName = (String) item.get(p1.getName()); if (!shouldCheckout(pName)) { return; } // VERBOSE MODE ONLY if (getVerbose()) { // Show folder only if changed. boolean bShowHeader = (f != prevFolder); if (bShowHeader) { // We want to display the folder the same way you would // enter it on the command line ... so we remove the // View name (which is also the name of the root folder, // and therefore shows up at the start of the path). String strFolder = f.getFolderHierarchy(); int i = strFolder.indexOf(delim); if (i >= 0) { strFolder = strFolder.substring(i + 1); } log(" Folder: \"" + strFolder + "\""); prevFolder = f; // If we displayed the project, view, item type, or folder, // then show the list of relevant item properties. StringBuffer header = new StringBuffer(" Item"); header.append(",\t").append(p1.getDisplayName()); if (p2 != null) { header.append(",\t").append(p2.getDisplayName()); } log(header.toString()); } // Finally, show the Item properties ... // Always show the ItemID. StringBuffer itemLine = new StringBuffer(" "); itemLine.append(item.getItemID()); // Show the primary descriptor. // There should always be one. itemLine.append(",\t").append(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) { itemLine.append(",\t").append(formatForDisplay(p2, item.get(p2.getName()))); } // Show if the file is locked. int locker = item.getLocker(); if (locker > -1) { itemLine.append(",\tLocked by ").append(locker); } else { itemLine.append(",\tNot locked"); } log(itemLine.toString()); } // 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; // The local file name is simply the local target path (tgt) which has // been passed recursively down from the top of the tree, with the item's name appended. java.io.File local = new java.io.File(tgt, (String) item.get(p1.getName())); try { remote.checkoutTo(local, Item.LockType.UNCHANGED, false, true, true); checkedOut++; } catch (Exception e) { throw new BuildException("Failed to checkout '" + local + "'", e); } } /** * Look if the file should be checked out. Don't check it out if It fits * no include filters and It fits an exclude filter. * * @param pName the item name to look for being included. * @return whether the file should be checked out or not. */ protected boolean shouldCheckout(String pName) { boolean includeIt = matchPatterns(getIncludes(), pName); boolean excludeIt = matchPatterns(getExcludes(), pName); return (includeIt && !excludeIt); } /** * Convenient method to see if a string match a one pattern in given set * of space-separated patterns. * * @param patterns the space-separated list of patterns. * @param pName the name to look for matching. * @return whether the name match at least one pattern. */ protected boolean matchPatterns(String patterns, String pName) { if (patterns == null) { return false; } StringTokenizer exStr = new StringTokenizer(patterns, " "); while (exStr.hasMoreTokens()) { if (DirectoryScanner.match(exStr.nextToken(), pName)) { return true; } } return false; } /** * Get the primary descriptor of the given item type. Returns null if * there isn't one. In practice, all item types have a primary descriptor. * * @param t An item type. At this point it will always be "file". * @return The specified item's primary descriptor. */ protected Property getPrimaryDescriptor(Type t) { Property[] properties = t.getProperties(); for (int i = 0; i < properties.length; i++) { Property p = properties[i]; if (p.isPrimaryDescriptor()) { return p; } } return null; } /** * Get the secondary descriptor of the given item type. Returns null if * there isn't one. * * @param t An item type. At this point it will always be "file". * @return The specified item's secondary descriptor. There may not be one * for every file. */ protected Property getSecondaryDescriptor(Type t) { Property[] properties = t.getProperties(); for (int i = 0; i < properties.length; i++) { Property p = properties[i]; if (p.isDescriptor() && !p.isPrimaryDescriptor()) { return p; } } return null; } /** * Formats a property value for display to the user. * * @param p An item property to format. * @param value the object to format. * @return A string containing the property, which is truncated to 35 * characters for display. */ protected String formatForDisplay(Property p, Object value) { if (p.getTypeCode() == Property.Types.TEXT) { String str = value.toString(); if (str.length() > 35) { str = str.substring(0, 32) + "..."; } return "\"" + str + "\""; } else { if (p.getTypeCode() == Property.Types.ENUMERATED) { return "\"" + p.getEnumDisplayName(((Integer) value).intValue()) + "\""; } else { return value.toString(); } } } // Begin SET and GET methods /** * Sets the <CODE>serverName</CODE> attribute to the given value. * * @param serverName The name of the server you wish to connect to. * @see #getServerName() */ public void setServerName(String serverName) { this.serverName = serverName; } /** * Gets the <CODE>serverName</CODE> attribute. * * @return The StarTeam server to log in to. * @see #setServerName(String serverName) */ public String getServerName() { return serverName; } /** * Sets the <CODE>serverPort</CODE> attribute to the given value. The * given value must be a valid integer, but it must be a string object. * * @param serverPort A string containing the port on the StarTeam server * to use. * @see #getServerPort() */ public void setServerPort(int serverPort) { this.serverPort = serverPort; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -