Usages of

com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Item.getDownloadURL()
public TFSItemNode(final Item item, final VersionControlClient vcClient) { // code omitted ... /* * The AItem that we were instantiated with may not contain a download URL. * If that's the case, we need to requery the server. */ @Override protected Item getDownloadItem() { if (downloadItem == null) { if (item.getDownloadURL() != null) { downloadItem = item; } else { downloadItem = vcClient.getItem( item.getServerItem(), new ChangesetVersionSpec(item.getChangeSetID()), item.getDeletionID(), true); // downloadItem = vcClient.getItem(item.getItemID(), // item.getChangeSetID(), true); } } return downloadItem; }
/** * Downloads a collection of {@link Item}s to a temporary location * preserving the server path structure. The local download location is * specified by the localRoot parameter, which can be null (a temporary * location is chosen by the method in this case). * <p> * {@link Item}s that are files must have a non-null download URL. Folder * {@link Item}s will be created on disk even if empty. * <p> * <!-- Event Origination Info --> * <p> * This method is an <b>core event origination point</b>. The * {@link EventSource} object that accompanies each event fired by this * method describes the execution context (current thread, etc.) when and * where this method was invoked. * * @param items * the set of items to download (must not be <code>null</code>) * @param serverRoot * the server path shared by all items (must not be <code>null</code> * or empty). * @param localRoot * the local path where the downloaded items will be placed. If null, * a temporary path is chosen by the method. * @return the full local path to the directory where the items were * downloaded. * @throws CanceledException * if this operation is canceled by the default {@link TaskMonitor} */ public String downloadItems(final Item[] items, final String serverRoot, String localRoot) throws CanceledException { Check.notNull(items, "items"); //$NON-NLS-1$ Check.notNull(serverRoot, "serverRoot"); //$NON-NLS-1$ final TaskMonitor taskMonitor = TaskMonitorService.getTaskMonitor(); taskMonitor.begin(Messages.getString("VersionControlClient.DownloadingItems"), items.length + 2); //$NON-NLS-1$ try { if (localRoot == null) { try { localRoot = TempStorageService.getInstance().createTempDirectory().getAbsolutePath(); } catch (final IOException ex) { throw new VersionControlException(ex); } TempStorageService.getInstance().forgetItem(new File(localRoot)); } taskMonitor.worked(1); Arrays.sort(items, new Comparator<Item>() { @Override public int compare(final Item item1, final Item item2) { return ServerPath.compareTopDown(item1.getServerItem(), item2.getServerItem()); } }); taskMonitor.worked(1); final EventSource eventSource = EventSource.newFromHere(); /* * Since we will dispatch some get operations to be completed in a * different thread (managed by an Executor), we have to keep track * of them here. The completion service wraps the bounded executor * shared by all GetEngines that use the same VersionControlClients. * The completion service only tracks the jobs we have submitted for * execution, so we can simply count the completed jobs to know when * they have all been processed. */ final AccountingCompletionService<WorkerStatus> completionService = new AccountingCompletionService<WorkerStatus>(getUploadDownloadWorkerExecutor()); try { for (int i = 0; i < items.length; i++) { if (taskMonitor.isCanceled()) { throw new CanceledException(); } final Item item = items[i]; if (item.getItemType() == ItemType.FILE) { Check.notNull(item.getDownloadURL(), "item.getDownloadUrl()"); //$NON-NLS-1$ } if (ServerPath.isChild(serverRoot, item.getServerItem()) == false) { throw new IllegalArgumentException( MessageFormat.format( "Item''s server path {0} must start with server root {1}", //$NON-NLS-1$ item.getServerItem(), serverRoot)); } final String localPath = ServerPath.makeLocal(item.getServerItem(), serverRoot, localRoot); taskMonitor.setCurrentWorkDescription(localPath); completionService.submit( new TempDownloadWorker( eventSource, taskMonitor, this, item.getDownloadURL(), new File(localPath), item.getItemType())); taskMonitor.worked(1); } } finally { GetEngine.waitForCompletions(completionService); } if (taskMonitor.isCanceled()) { throw new CanceledException(); } return localRoot; } finally { taskMonitor.done(); } }
final Item remoteItem, // code omitted ... @Override public IStorage getStorage(final IProgressMonitor monitor) throws TeamException { String tempFilename; /* Ensure we're still online */ if (TFSEclipseClientPlugin.getDefault().getProjectManager().getProjectStatus( resource.getProject()) != ProjectRepositoryStatus.ONLINE) { throw new TeamException( new Status( IStatus.ERROR, TFSEclipseClientPlugin.PLUGIN_ID, 0, Messages.getString("LatestResourceVariant.NotCurrentlyConnectedReturnOnlineToViewSyncInfo"), //$NON-NLS-1$ null)); } /* * The remote is a deletion, do not display the latest contents (empty.) */ if (isEffectiveDelete()) { return null; } AbstractGetToTempLocationCommand getCommand; /* * If there's a conflict-free get operation, then the DURL in the get * operation is the latest version. (In a conflict, the DURL in a get * operation is the common ancestor's.) */ if (operation != null && !operation.hasConflict()) { getCommand = new GetDownloadURLToTempLocationCommand(repository, operation.getDownloadURL(), resource.getName()); } /* * Otherwise, if there's a get operation, get the latest version of this * file with this name. (Synchronize is inherently slot-mode.) */ else if (operation != null) { final String serverPath = repository.getWorkspace().getMappedServerPath(resource.getLocation().toOSString()); getCommand = new GetVersionedItemToTempLocationCommand(repository, serverPath, LatestVersionSpec.INSTANCE); } /* * We may have an Item identifying the latest resource. (On 2010 * servers, pending deletes will suppress get operations even when the * latest version is newer. */ else if (remoteItem != null && remoteItem.getDownloadURL() != null) { getCommand = new GetDownloadURLToTempLocationCommand(repository, remoteItem.getDownloadURL()); } /* * Otherwise, there's no get operation, which means we were latest at * synchronize time. */ else { final String serverPath = repository.getWorkspace().getMappedServerPath(resource.getLocation().toOSString()); /* * If this is an outgoing file creation (add, branch, etc. - the * remote latest version is 0) then there is no remote copy. */ if (pendingChange != null && pendingChange.getVersion() == 0) { return null; } /* * If this is the target of an outgoing rename, treat this as if * there is no remote copy. */ if (pendingChange != null && pendingChange.isRename() && ServerPath.equals(serverPath, pendingChange.getServerItem())) { return null; } /* * Otherwise, simply get the latest version of the file at this * name. */ getCommand = new GetVersionedItemToTempLocationCommand(repository, serverPath, LatestVersionSpec.INSTANCE); } IStatus status; try { status = getCommand.run(monitor); } catch (final Exception e) { throw new TeamException( MessageFormat.format( Messages.getString("LatestResourceVariant.CouldNotGetStorageForLatestVersionOfResourceFormat"), //$NON-NLS-1$ resource.getName().toString()), e); } /* * The synchronization framework may cancel the monitor while the * command is running, which causes a cancel status, or maybe the cancel * happened after the command was finished. Either way, the correct way * to signal that the storage could not be fetched for cancel is to * throw. */ if (monitor.isCanceled() || (status != null && status.getSeverity() == IStatus.CANCEL)) { throw new OperationCanceledException(); } if (status == null || !status.isOK()) { throw new TeamException( MessageFormat.format( Messages.getString("LatestResourceVariant.CouldNotGetStorageForLatestVersionOfResourceFormat"), //$NON-NLS-1$ resource.getName().toString()), (status != null) ? status.getException() : null); } tempFilename = getCommand.getTempLocation(); return new SynchronizeTempFileStorage(tempFilename); }
private void ensureUpdatesFullyPopulated(final ILocalVersionUpdate[] updates) { final boolean setFileTimeToCheckin = workspace.getOptions().contains(WorkspaceOptions.SET_FILE_TO_CHECKIN); // For the logic for fetching from QueryPendingChanges final List<ItemSpec> toFetchFromPendingChanges = new ArrayList<ItemSpec>(); final Map<String, IPopulatableLocalVersionUpdate> targetServerItemMap = new TreeMap<String, IPopulatableLocalVersionUpdate>(String.CASE_INSENSITIVE_ORDER); // For the logic for fetching from QueryItems final List<IPopulatableLocalVersionUpdate> toFetchFromQueryItems = new ArrayList<IPopulatableLocalVersionUpdate>(); final LocalWorkspaceTransaction transaction = new LocalWorkspaceTransaction(workspace, wLock); try { transaction.execute(new WorkspacePropertiesLocalVersionTransaction() { @Override public void invoke(final LocalWorkspaceProperties wp, final WorkspaceVersionTable lv) { for (final ILocalVersionUpdate update : updates) { // We only care about unpopulated // IPopulatableLocalVersionUpdate objects. if (!(update instanceof IPopulatableLocalVersionUpdate)) { continue; } final IPopulatableLocalVersionUpdate cUpdate = (IPopulatableLocalVersionUpdate) update; final WorkspaceLocalItem lvExisting = lv.getByServerItem(cUpdate.getSourceServerItem(), cUpdate.isCommitted()); if (null != lvExisting && lvExisting.getVersion() == cUpdate.getVersionLocal()) { cUpdate.updateFrom(lvExisting); } if (cUpdate.isFullyPopulated(setFileTimeToCheckin)) { continue; } if (null != cUpdate.getPendingChangeTargetServerItem()) { toFetchFromPendingChanges.add( new ItemSpec(cUpdate.getPendingChangeTargetServerItem(), RecursionType.NONE)); targetServerItemMap.put(cUpdate.getPendingChangeTargetServerItem(), cUpdate); } else { toFetchFromQueryItems.add(cUpdate); } } } }); } finally { try { transaction.close(); } catch (final IOException e) { throw new VersionControlException(e); } } if (toFetchFromPendingChanges.size() > 0) { Check.isTrue( options.contains(UpdateLocalVersionQueueOptions.UPDATE_SERVER), "Making a server call to fetch missing local version data during an offline operation"); //$NON-NLS-1$ // We can't call Workspace.GetPendingChanges here, since that's an // offline operation. We want *real* PendingChange objects here, // from the server. final WebServiceLayer webServiceLayer = workspace.getClient().getWebServiceLayer(); final PendingChange[] pendingChanges = webServiceLayer.queryServerPendingChanges( workspace, toFetchFromPendingChanges.toArray(new ItemSpec[toFetchFromPendingChanges.size()]), true, workspace.getClient().mergeWithDefaultItemPropertyFilters(null)); for (final PendingChange pendingChange : pendingChanges) { final IPopulatableLocalVersionUpdate cUpdate = targetServerItemMap.get(pendingChange.getServerItem()); if (cUpdate == null) { log.warn("EnsureUpdatesFullyPopulated: Query did not return a PendingChange"); //$NON-NLS-1$ continue; } cUpdate.updateFrom(pendingChange); Check.isTrue( cUpdate.isFullyPopulated(setFileTimeToCheckin), "cUpdate.isFullyPopulated(setFileTimeToCheckin)"); //$NON-NLS-1$ // Save off the download URL in case we need it after calling // UpdateLocalVersion. cUpdate.setDownloadURL(pendingChange.getDownloadURL()); } } for (final IPopulatableLocalVersionUpdate update : toFetchFromQueryItems) { final GetItemsOptions options = GetItemsOptions.INCLUDE_SOURCE_RENAMES.combine(GetItemsOptions.UNSORTED).combine( GetItemsOptions.DOWNLOAD); final ItemSet[] items = workspace.getClient().getItems(new ItemSpec[] { new ItemSpec(update.getSourceServerItem(), RecursionType.NONE) }, new ChangesetVersionSpec(update.getVersionLocal()), DeletedState.ANY, ItemType.ANY, options); if (items[0].getItems().length != 1) { log.warn("EnsureUpdatesFullyPopulated: Result missing"); //$NON-NLS-1$ } for (final Item item : items[0].getItems()) { update.updateFrom(item); Check.isTrue( update.isFullyPopulated(setFileTimeToCheckin), "update.isFullyPopulated(setFileTimeToCheckin)"); //$NON-NLS-1$ // Save off the download URL in case we need it after calling // UpdateLocalVersion. update.setDownloadURL(item.getDownloadURL()); break; } } }
@Override protected void populate(final PropertyHolder propertyHolder) { final Item item = change.getItem(); propertyHolder.addProperty( Messages.getString("ChangePropertySource.ChangeTypesPropertyName"), //$NON-NLS-1$ Messages.getString("ChangePropertySource.ChangeTypesPropertyDescription"), //$NON-NLS-1$ change.getChangeType().toUIString(true, item)); propertyHolder.addProperty( Messages.getString("ChangePropertySource.ChangesetIdPropertyName"), //$NON-NLS-1$ String.valueOf(item.getChangeSetID())); final Calendar c = item.getCheckinDate(); Object value = (c != null ? dateFormat.format(c.getTime()) : null); propertyHolder.addProperty( Messages.getString("ChangePropertySource.CheckinDatePropertyName"), //$NON-NLS-1$ Messages.getString("ChangePropertySource.CheckinDatePropertyDescription"), //$NON-NLS-1$ value); propertyHolder.addProperty( Messages.getString("ChangePropertySource.DeletionIdPropertyName"), //$NON-NLS-1$ String.valueOf(item.getDeletionID())); propertyHolder.addProperty( Messages.getString("ChangePropertySource.EncodingPropertyName"), //$NON-NLS-1$ String.valueOf(item.getEncoding())); final ItemType itemType = item.getItemType(); value = (itemType != null ? itemType.toString() : null); propertyHolder.addProperty( Messages.getString("ChangePropertySource.ItemTypePropertyName"), //$NON-NLS-1$ Messages.getString("ChangePropertySource.ItemTypePropertyDescription"), //$NON-NLS-1$ value); propertyHolder.addProperty( Messages.getString("ChangePropertySource.ItemIdPropertyName"), //$NON-NLS-1$ String.valueOf(item.getItemID())); propertyHolder.addProperty( Messages.getString("ChangePropertySource.ServerItemPropertyName"), //$NON-NLS-1$ Messages.getString("ChangePropertySource.ServerItemPropertyDescription"), //$NON-NLS-1$ item.getServerItem()); propertyHolder.addProperty(Messages.getString("ChangePropertySource.TimeZonePropertyName"), item.getTimeZone()); //$NON-NLS-1$ propertyHolder.addProperty( Messages.getString("ChangePropertySource.TimeZoneOffsetPropertyName"), //$NON-NLS-1$ item.getTimeZoneO()); final byte[] hash = item.getContentHashValue(); value = (hash != null ? ArrayUtils.byteArrayToHexString(hash) : null); propertyHolder.addProperty(Messages.getString("ChangePropertySource.HashValuePropertyName"), value); //$NON-NLS-1$ propertyHolder.addProperty( Messages.getString("ChangePropertySource.ContentLengthPropertyName"), //$NON-NLS-1$ String.valueOf(item.getContentLength())); propertyHolder.addProperty( Messages.getString("ChangePropertySource.DownloadUrlPropertyName"), //$NON-NLS-1$ item.getDownloadURL()); }
private static void viewVersionedItemArtifact(final Shell shell, final ArtifactID artifactID) { Check.notNull(artifactID, "artifactID"); //$NON-NLS-1$ final TFSRepository repository = TFSCommonUIClientPlugin.getDefault().getProductPlugin().getRepositoryManager().getDefaultRepository(); final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); Item item = null; if (VersionedItemLinkTypeNames.VERSIONED_ITEM.equals(artifactID.getArtifactType())) { final VersionedItemLinkData linkData = VersionedItemLinkParser.parse(artifactID); final VersionSpec version = new ChangesetVersionSpec(linkData.getChangesetVersion()); final DeletedState deletedState = (linkData.getDeletionID() != 0) ? DeletedState.DELETED : DeletedState.NON_DELETED; final QueryItemsCommand queryCommand = new QueryItemsCommand(repository, new ItemSpec[] { new ItemSpec(linkData.getItemPath(), RecursionType.NONE) }, version, deletedState, ItemType.ANY, GetItemsOptions.DOWNLOAD); final IStatus status = UICommandExecutorFactory.newUICommandExecutor(shell).execute(queryCommand); if (!status.isOK()) { return; } final Item[] items = queryCommand.getItemSets()[0].getItems(); if (items.length != 1 || items[0] == null) { MessageDialog.openError( shell, Messages.getString("WorkItemLinksControl.InvalidVersionedItemLinkTitle"), //$NON-NLS-1$ MessageFormat.format( Messages.getString("WorkItemLinksControl.VersionedItemNotFoundFormat"), //$NON-NLS-1$ linkData.getItemPath(), linkData.getChangesetVersion())); return; } item = items[0]; } else if (VersionedItemLinkTypeNames.LATEST_VERSION.equals(artifactID.getArtifactType())) { int itemId; try { itemId = Integer.parseInt(artifactID.getToolSpecificID()); } catch (final NumberFormatException e) { MessageDialog.openError( shell, Messages.getString("WorkItemLinksControl.InvalidVersionedItemLinkTitle"), //$NON-NLS-1$ MessageFormat.format( Messages.getString("WorkItemLinksControl.ItemIdInvalidFormat"), //$NON-NLS-1$ artifactID.getToolSpecificID())); return; } final QueryItemsByIDCommand queryCommand = new QueryItemsByIDCommand(repository, new int[] { itemId }, Changeset.MAX, GetItemsOptions.DOWNLOAD); final IStatus status = UICommandExecutorFactory.newUICommandExecutor(shell).execute(queryCommand); if (!status.isOK()) { return; } final Item[] items = queryCommand.getItems(); if (items.length != 1 || items[0] == null) { MessageDialog.openError( shell, Messages.getString("WorkItemLinksControl.InvalidVersionedItemLinkTitle"), //$NON-NLS-1$ MessageFormat.format( Messages.getString("WorkItemLinksControl.LatestVersionNotFoundFormat"), //$NON-NLS-1$ artifactID.getToolSpecificID())); return; } item = items[0]; } else { log.error( MessageFormat.format("Could not parse versioned artifact type: {0}", artifactID.getArtifactType())); //$NON-NLS-1$ MessageDialog.openError( shell, Messages.getString("WorkItemLinksControl.InvalidVersionedItemLinkTitle"), //$NON-NLS-1$ MessageFormat.format( Messages.getString("WorkItemLinksControl.UnknownVersionedArtifactTypeFormat"), //$NON-NLS-1$ artifactID.getArtifactType())); return; } if (item.getItemType() == ItemType.FOLDER) { ViewFileHelper.viewServerFolder(item.getServerItem()); } else { ViewFileHelper.viewFromDownloadURL(repository, item.getDownloadURL(), page, false); } }
/* * (non-Javadoc) * * @see com.microsoft.tfs.client.clc.Command#run() */ @Override public void run() throws ArgumentException, MalformedURLException, CLCException, LicenseException { Option o = null; VersionSpec optionVersion = null; if ((o = findOptionType(OptionVersion.class)) != null) { final VersionSpec[] versions = ((OptionVersion) o).getParsedVersionSpecs(); if (versions == null || versions.length == 0) { throw new InvalidOptionValueException(Messages.getString("CommandPrint.ExactlyOneVersionRequired")); //$NON-NLS-1$ } if (versions.length > 1) { throw new InvalidOptionValueException(Messages.getString("CommandPrint.VersionRangeNotPermitted")); //$NON-NLS-1$ } optionVersion = versions[0]; } /* * If no version option was supplied, default to latest. */ if (optionVersion == null) { optionVersion = LatestVersionSpec.INSTANCE; } // Use the default version they specified in the option. final QualifiedItem[] qualifiedItems = parseQualifiedItems(optionVersion, false, 0); if (qualifiedItems.length != 1) { throw new InvalidFreeArgumentException(Messages.getString("CommandPrint.ExactlyOneFileItemRequired")); //$NON-NLS-1$ } final QualifiedItem qi = qualifiedItems[0]; if (Wildcard.isWildcard(qi.getPath())) { throw new InvalidFreeArgumentException(Messages.getString("CommandPrint.WildcardsNotAllowed")); //$NON-NLS-1$ } final TFSTeamProjectCollection connection = createConnection(true); final VersionControlClient client = connection.getVersionControlClient(); initializeClient(client); /* * Query the server to get a download URL for the spec. */ final ItemSet itemSet = client.getItems( qi.getPath(), qi.getVersions()[0], RecursionType.NONE, DeletedState.NON_DELETED, ItemType.FILE, true); final Item[] items = itemSet.getItems(); if (items == null) { throw new InvalidFreeArgumentException(Messages.getString("CommandPrint.ExactlyOneFileItemRequired")); //$NON-NLS-1$ } if (items.length != 1) { throw new InvalidFreeArgumentException( Messages.getString("CommandPrint.SpecifiedFileDoesNotExistAtVersion")); //$NON-NLS-1$ } final Item item = items[0]; Check.isTrue( item.getDownloadURL() != null && item.getDownloadURL().length() > 0, "item.getDownloadURL() != null && item.getDownloadURL().length() > 0"); //$NON-NLS-1$ /* * Download the item to a stream. */ client.downloadFileToStream( new DownloadSpec(item.getDownloadURL()), getDisplay().getPrintStream(), true, null, null); }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes