Usages of

com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Item.getItemType()
private ItemAndVersionResult(final Item item, final VersionSpec targetVersion) { // code omitted ... /** * @return the {@link ItemType} of the server or local item (never * <code>null</code>) */ public ItemType getItemType() { if (item != null) { return item.getItemType(); } else { return file.isDirectory() ? ItemType.FOLDER : ItemType.FILE; } }
public DiffItem( final Item item, final String localPath, final String tempFile, final DiffItem rootItem, final VersionSpec version) { this( item.getServerItem(), localPath, tempFile, item.getEncoding().getCodePage(), rootItem, item.getItemType(), item.getCheckinDate().getTimeInMillis(), true, version); Check.notNull(item, "item"); //$NON-NLS-1$ this.item = item; changesetVersion = item.getChangeSetID(); }
public TFSItemNode(final Item item, final VersionControlClient vcClient) { // code omitted ... @Override public String getType() { if (item.getItemType() == ItemType.FOLDER) { return ITypedElement.FOLDER_TYPE; } return CompareUtils.computeTypeFromFilename(getName()); }
/** * Compare two tfs item based on MD5 hash * * @param node1 * @param node2 * @param monitor * @return */ private ContentComparisonResult tfsItemNodesCompare( final TFSItemNode node1, final TFSItemNode node2, final IProgressMonitor monitor) { final Item item1 = node1.getItem(); final Item item2 = node2.getItem(); if (item1.getItemType() == ItemType.FOLDER || item2.getItemType() == ItemType.FOLDER) { return ContentComparisonResult.EQUAL; } final byte[] hash1 = item1.getContentHashValue(); final byte[] hash2 = item2.getContentHashValue(); return compareByHash(hash1, hash2); }
/** * Creates a {@link VersionedFileDiffLaunchItem} with the default label text * (generated from the given arguments). * * @param client * a {@link VersionControlClient} (not null) * @param fileItem * the file item (folders are not supported). Not null. * @param version * the version of the item (may be null) * @throws CLCException * if a folder was given instead of a file for the fileItem * parameter */ public VersionedFileDiffLaunchItem(final VersionControlClient client, final Item item, final VersionSpec version) throws CLCException { Check.notNull(client, "client"); //$NON-NLS-1$ Check.notNull(item, "item"); //$NON-NLS-1$ if (item.getItemType() == ItemType.FOLDER) { throw new CLCException(Messages.getString("VersionedFileDiffLaunchItem.CannotCompareFileWithFolder")); //$NON-NLS-1$ } this.client = client; this.item = item; this.version = version; }
private String formatDirectoryItem(final Item item) { final StringBuffer sb = new StringBuffer(); /* * This looks dumb to me, but Microsoft's client puts a $ (not "$/") * before each folder item, instead of something like "/" after it. */ if (item.getItemType() == ItemType.FOLDER) { sb.append(ServerPath.ROOT_NAME_ONLY); } final String itemName = VersionedFileSpec.formatPathWithDeletionIfNecessary( ServerPath.getFileName(item.getServerItem()), item.getDeletionID()); sb.append(itemName); return sb.toString(); }
/** * {@inheritDoc} */ @Override public void export(Map<File, Revision> revisionMap, Map<File, File> destinationMap) throws ConfigurationManagementException { for (Map.Entry<File, Revision> entry : revisionMap.entrySet()) { File file = entry.getKey(); Revision revision = entry.getValue(); File destinationFile = destinationMap.get(file); String itemPath = getPathFromRevision(revision); VersionSpec versionSpec = VersionSpec.parseSingleVersionFromSpec(revision.getStringRepresentation(), null); Item item = getWorkspace().getClient().getItem(itemPath, versionSpec, DeletedState.NON_DELETED, GetItemsOptions.INCLUDE_SOURCE_RENAMES); // Can't download a directory if (item.getItemType() == ItemType.FILE) { item.downloadFile(getWorkspace().getClient(), destinationFile.getAbsolutePath()); } } }
public int getChangeSetID(String path, Pattern[] excludedPatterns, Pattern[] includedPatterns) { Item item = versionClient.getItem(path); int changeSetID = item.getChangeSetID(); if (item.getItemType() == ItemType.FOLDER) { for (Item i : versionClient.getItems(path, RecursionType.FULL).getItems()) { String childPath = i.getServerItem().charAt(0) == '$' ? i.getServerItem().substring(1) : i.getServerItem(); if (excludedPatterns != null && excludedPatterns.length > 0 && isPatterns(childPath, excludedPatterns)) continue; if (includedPatterns != null && includedPatterns.length > 0 && !isPatterns(childPath, includedPatterns)) continue; if (changeSetID < i.getChangeSetID()) changeSetID = i.getChangeSetID(); } } return changeSetID; }
@Override public TaskStatus run(final TaskProgressMonitor progressMonitor) throws Exception { final String taskName = Messages.formatString("CloneTask.CloningFormat", //$NON-NLS-1$ tfsPath, bare ? repository.getDirectory().getAbsolutePath() : repository.getWorkTree().getAbsolutePath()); progressMonitor.beginTask( taskName, 1, TaskProgressDisplay.DISPLAY_PROGRESS.combine(TaskProgressDisplay.DISPLAY_SUBTASK_DETAIL)); /* * Query the changesets. */ /* See if this is an actual server path. */ final Item item = vcClient.getItem(tfsPath, versionSpec, DeletedState.NON_DELETED, GetItemsOptions.NONE); Check.notNull(item, "item"); //$NON-NLS-1$ if (item.getItemType() != ItemType.FOLDER) { return new TaskStatus(TaskStatus.ERROR, Messages.formatString("CloneTask.CannotCloneFileFormat", tfsPath)); //$NON-NLS-1$ } /* Determine the latest changeset on the server. */ final Changeset[] changesets = vcClient.queryHistory( tfsPath, versionSpec, 0, RecursionType.FULL, null, new ChangesetVersionSpec(0), versionSpec, depth, false, false, false, false); /* * Create and configure the repository. */ repository.create(bare); final ConfigureRepositoryTask configureTask = new ConfigureRepositoryTask(repository, serverURI, tfsPath); configureTask.setTag(tag); final TaskStatus configureStatus = new TaskExecutor(new NullTaskProgressMonitor()).execute(configureTask); if (!configureStatus.isOK()) { return configureStatus; } if (changesets.length > 0) { ObjectId lastCommitID = null; ObjectId lastTreeID = null; Item[] previousChangesetItems = null; /* * Download changesets. */ final int numberOfChangesetToDownload = changesets.length; progressMonitor.setWork(numberOfChangesetToDownload); for (int i = numberOfChangesetToDownload; i > 0; i--) { CreateCommitForChangesetVersionSpecTask commitTask = new CreateCommitForChangesetVersionSpecTask( repository, vcClient, changesets[i - 1], previousChangesetItems, lastCommitID, witClient); TaskStatus commitStatus = new TaskExecutor(progressMonitor.newSubTask(1)).execute(commitTask); if (!commitStatus.isOK()) { return commitStatus; } lastCommitID = commitTask.getCommitID(); lastTreeID = commitTask.getCommitTreeID(); previousChangesetItems = commitTask.getCommittedItems(); Check.notNull(lastCommitID, "lastCommitID"); //$NON-NLS-1$ Check.notNull(lastTreeID, "lastTreeID"); //$NON-NLS-1$ new ChangesetCommitMap(repository).setChangesetCommit( changesets[i - 1].getChangesetID(), commitTask.getCommitID()); progressMonitor.displayVerbose(Messages.formatString("CloneTask.ClonedFormat", //$NON-NLS-1$ Integer.toString(changesets[i - 1].getChangesetID()), ObjectIdUtil.abbreviate(repository, lastCommitID))); } progressMonitor.setDetail(Messages.getString("CloneTask.Finalizing")); //$NON-NLS-1$ /* Update master head reference */ RefUpdate ref = repository.updateRef(Constants.R_HEADS + Constants.MASTER); ref.setNewObjectId(lastCommitID); ref.update(); /* Create tfs branch */ TfsBranchUtil.create(repository, Constants.R_HEADS + Constants.MASTER); /* * Check out the cloned commit. */ if (!bare) { DirCache dirCache = repository.lockDirCache(); DirCacheCheckout checkout = new DirCacheCheckout(repository, dirCache, lastTreeID); checkout.checkout(); dirCache.unlock(); RepositoryUtil.fixFileAttributes(repository); } progressMonitor.endTask(); final int finalChangesetID = changesets[0].getChangesetID(); if (numberOfChangesetToDownload == 1) { progressMonitor.displayMessage(Messages.formatString("CloneTask.ClonedFormat", //$NON-NLS-1$ Integer.toString(finalChangesetID), ObjectIdUtil.abbreviate(repository, lastCommitID))); } else { progressMonitor.displayMessage(Messages.formatString("CloneTask.ClonedMultipleFormat", //$NON-NLS-1$ changesets.length, Integer.toString(finalChangesetID), ObjectIdUtil.abbreviate(repository, lastCommitID))); } } else { // the folder exists on the server but is empty progressMonitor.displayMessage(Messages.getString("CloneTask.NothingToDownload")); //$NON-NLS-1$ progressMonitor.displayMessage(Messages.formatString("CloneTask.ClonedFolderEmptyFormat", //$NON-NLS-1$ tfsPath)); } log.info("Clone task completed."); //$NON-NLS-1$ return TaskStatus.OK_STATUS; }
/** * Takes a {@link DiffItem} and returns a list of qualifying child diff * items (which includes the original diff item), optionally recursing * fully. The server is queried for some paths, and the local disk is * examined for items not in the repository. * * @param rootItem * the item to examine for child changes (not null). * @param workspace * a workspace that can be used for server queries and working folder * mapping queries (not null). * @param recursive * if true, both server and filesystem directories are fully * recursed. * @param version * the version of the root item to generate items for. May be null. * @param tempDirectory * a temporary directory to be used for new {@link DiffItem}s (not * null). * @return a list of {@link DiffFolderItem}s. */ private List<DiffItem> generateChildDiffItems( final DiffItem rootItem, final Workspace workspace, final boolean recursive, final VersionSpec version, final File tempDirectory) { Check.notNull(rootItem, "rootItem"); //$NON-NLS-1$ Check.notNull(workspace, "workspace"); //$NON-NLS-1$ Check.notNull(tempDirectory, "tempDirectory"); //$NON-NLS-1$ final List<DiffItem> directoryList = new ArrayList<DiffItem>(); final boolean isWorkspaceVersionSpec = (version instanceof WorkspaceVersionSpec); /* * Query all the items from the server that match the given root item * (at the given version spec). These items come back sorted so related * items are contiguous for faster searching. */ Item[] itemArray = null; if (version != null) { itemArray = getFilteredServerItemList(rootItem.getServerPath(), version, false, recursive, false, true); } else if (rootItem.isInRepository()) { itemArray = getFilteredServerItemList( rootItem.getServerPath(), new WorkspaceVersionSpec(workspace), false, recursive, false, true); } /* * Start with the root item. */ directoryList.add(rootItem); /* * If there are server items, iterate through them, and for each item * keep walking in an inner loop to find items in the same directory. * Then continue iterating after passing the related items. */ if (itemArray != null && itemArray.length > 0) { /* * Query the pending changes for edit changes and keep a map so we * can look them up during iteration. */ final Map<String, PendingChange> serverPathToExistingAPendingChanges = new HashMap<String, PendingChange>(); if (isWorkspaceVersionSpec) { final PendingSet pendingChangeSet = workspace.getPendingChanges(new String[] { rootItem.getServerPath() }, recursive ? RecursionType.FULL : RecursionType.NONE, false); if (pendingChangeSet != null && pendingChangeSet.getPendingChanges() != null && pendingChangeSet.getPendingChanges().length > 0) { for (int i = 0; i < pendingChangeSet.getPendingChanges().length; i++) { final PendingChange change = pendingChangeSet.getPendingChanges()[i]; if (change != null && change.getChangeType().contains(ChangeType.EDIT)) { serverPathToExistingAPendingChanges.put(change.getServerItem(), change); } } } } /* * Build the list of directory items (each item can have children). * * Iterate over the items from the starting index, and iterate over * the remainder in a second loop inside to collapse contiguous * items into one diff item (the items list is sorted). * * The variables in the outer loop start with "first" and the * variables in the inner start with "second". */ String localPath = null; String serverPath = null; String path = null; int index = 1; while (index < itemArray.length) { final Item firstItem = itemArray[index]; final String firstFolderName = ServerPath.getParent(firstItem.getServerItem()); final DiffFolderItem firstDiffFolderItem = new DiffFolderItem(firstFolderName, null, null, rootItem, false, version); /* * If no version was given, see if the directory really exists * on disk. */ boolean firstLocalFolderExists = true; if (version == null) { final PathTranslation firstTranslation = workspace.translateServerPathToLocalPath(firstFolderName); if (firstTranslation != null && firstTranslation.isCloaked() == false) { firstLocalFolderExists = new File(firstTranslation.getTranslatedPath()).exists(); } else { firstLocalFolderExists = false; } } /* * If the server path is the root folder "$/", chop the length * to just "$". */ int firstPathOffset = firstFolderName.length(); if (firstPathOffset == 2) { firstPathOffset = 1; } /* * Save the starting index and loop over the remaining items * until we match one in a different directory. */ final int startingIndex = index; while (index < itemArray.length) { final Item secondItem = itemArray[index]; /* * Assign the second item's server path to the outer loop's * serverPath variable. */ serverPath = secondItem.getServerItem(); /* * If the second item is not a child of the first item, or * if it has a path separator after our first path's offset * (which mean it's a whole directory underneath the first * item), then we stop iterating because it can't be a * direct child and needs its own diff item later. */ if (ServerPath.isChild(firstFolderName, serverPath) == false || serverPath.indexOf(ServerPath.PREFERRED_SEPARATOR_CHARACTER, firstPathOffset + 1) >= 0) { break; } /* * If the item is a folder and we were given a version to * fetch, or it exists locally, process its children. */ if ((version != null || firstLocalFolderExists) && secondItem.getItemType() == ItemType.FOLDER) { /* * See if it's mapped. It may not be mapped */ final PathTranslation secondTranslation = workspace.translateServerPathToLocalPath(serverPath); if (secondTranslation != null && secondTranslation.isCloaked() == false) { /* * Assign to the outer loop's local path. */ localPath = secondTranslation.getTranslatedPath(); } /* * If there was a version given, use a temp file for it, * otherwise use the actual local file. */ if (version != null) { path = constructTempFile(tempDirectory, serverPath); } else { path = localPath; } Check.notNull(path, "path"); //$NON-NLS-1$ try { if (version != null || new File(path).exists()) { final DiffFolderItem secondDiffFolderItem = new DiffFolderItem(serverPath, localPath, path, rootItem, true, version); /* * If the first item has already been added to * the list, add the second item to its * children. */ final int indexOfFirstItem = directoryList.indexOf(firstDiffFolderItem); if (indexOfFirstItem >= 0) { final DiffFolderItem parent = (DiffFolderItem) directoryList.get(indexOfFirstItem); parent.addDirectory(secondDiffFolderItem); } /* * Add it to the end of the list so it will be * processed on further iteration in the outer * loop. */ if (recursive) { directoryList.add(secondDiffFolderItem); } } } catch (final Throwable t) { log.error("Inner exception evaluating diff items", t); //$NON-NLS-1$ } } /* * Move on to the next list item in the inner loop. */ index++; } /* * The inner loop has stopped moving because it found a * different directory, so process all the files between the * startingIndex to the current index. */ if (version != null || firstLocalFolderExists) { for (int i = startingIndex; i < index; i++) { if (itemArray[i].getItemType() != ItemType.FOLDER) { serverPath = itemArray[i].getServerItem(); final PathTranslation thirdTranslation = workspace.translateServerPathToLocalPath(serverPath); if (thirdTranslation != null && thirdTranslation.isCloaked() == false) { localPath = thirdTranslation.getTranslatedPath(); } if (version != null) { path = constructTempFile(tempDirectory, serverPath); } else { path = localPath; } final DiffItem fileDiffItem = new DiffItem(itemArray[i], localPath, path, rootItem, version); if (serverPathToExistingAPendingChanges.containsKey((itemArray[i].getServerItem()))) { fileDiffItem.setIsPendingChange(true); } if (isWorkspaceVersionSpec && localPath != null) { final FileSystemAttributes localFileAttributes = FileSystemUtils.getInstance().getAttributes(localPath); if (localFileAttributes.exists() && localFileAttributes.isReadOnly() == false) { fileDiffItem.setWritable(true); } } if (version != null || new File(path).exists()) { /* * Find the parent to put this file into. */ final int indexOfFirstItem = directoryList.indexOf(firstDiffFolderItem); if (indexOfFirstItem >= 0) { ((DiffFolderItem) directoryList.get(indexOfFirstItem)).addFile(fileDiffItem); } } } } } } } /* * Walk down from the root item to find any filesystem items that don't * have a corresponding server item. */ if (version == null) { String[] onDiskSubdirectories = null; /* * If the root item is on disk, and exists, list the subdirectories * in it. */ if (rootItem.getLocalPath() != null) { final File rootFile = new File(rootItem.getLocalPath()); if (rootFile.isDirectory() && rootFile.exists()) { /* * List all the subdirectories. */ onDiskSubdirectories = rootFile.list(new DirectoriesOnlyFilter()); makePathsAbsolute(onDiskSubdirectories, rootFile); /* * Sort them. */ Arrays.sort(onDiskSubdirectories, LocalPath.TOP_DOWN_COMPARATOR); } } if (onDiskSubdirectories != null) { for (int i = 0; i < onDiskSubdirectories.length; i++) { final String subDirectoryName = onDiskSubdirectories[i]; final DiffFolderItem subDirectoryDiffFolderItem = new DiffFolderItem(null, subDirectoryName, subDirectoryName, rootItem, false, version); ((DiffFolderItem) rootItem).addDirectory(subDirectoryDiffFolderItem); } } if (recursive) { final List<DiffFolderItem> subdirectoryList = new ArrayList<DiffFolderItem>(); /* * Iterate over all the directories we've added so far and * expand them. */ for (int i = 0; i < directoryList.size(); i++) { getSubDirectoryDiffItems((DiffFolderItem) directoryList.get(i), directoryList, subdirectoryList); } directoryList.addAll(subdirectoryList); } } return directoryList; }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes