As a part of the process of transiting from P4 to TFS, I need to translate some automated scripts calling the p4
command into their TFS equivalents.
One of my scripts executes a couple of commands:
p4 <server-and-login-options> -c <wksp_name> client -i < <definition>
p4 <server-and-login-options> -c <wksp_name> sync [-f]
In Perforce, that is enough to (optionally) alter and fully synchronize a specific workspace. This works seamlessly on both Windows and Linux.
After wandering around MSDN documentation for a few weeks, it seems I've failed to discover an equivalent in TFS.
I tried to use the TFS Java SDK for the job:
...
WorkingFolder[] workingFolders = ...;
Workspace wksp = null;
try
{
wksp = vcs.getWorkspace(workspaceName, VersionControlConstants.AUTHENTICATED_USER);
wksp.update(null, WORKSPACE_COMMENT, workingFolders, true);
}
catch (WorkspaceNotFoundException ex)
{
wksp = vcs.createWorkspace(
workingFolders,
workspaceName,
WORKSPACE_COMMENT,
WorkspaceLocation.SERVER,
WorkspaceOptions.NONE);
}
final VersionSpec versionSpec = LatestVersionSpec.INSTANCE;
GetOptions getOptions = GetOptions.NONE;
if (force)
getOptions = getOptions.combine(GetOptions.GET_ALL);
final GetStatus getStatus = wksp.get(versionSpec, getOptions);
...
This works for me on Windows.
But not on Linux. The getWorkspace
/createWorkspace
part works all right, the effect can be verified by tf workfold
. However, inside Workspace.get
the program crashes with the following message:
Exception in thread "main" java.lang.NoSuchMethodError: <init>
at com.microsoft.tfs.jni.internal.filesystem.NativeFileSystem.nativeGetAttributes(Native Method)
at com.microsoft.tfs.jni.internal.filesystem.NativeFileSystem.getAttributes(NativeFileSystem.java:74)
at com.microsoft.tfs.jni.FileSystemUtils.getAttributes(FileSystemUtils.java:39)
at com.microsoft.tfs.core.clients.versioncontrol.engines.internal.GetEngine.processOperation(GetEngine.java:1800)
at com.microsoft.tfs.core.clients.versioncontrol.engines.internal.GetEngine.processOperationsInternal(GetEngine.java:1163)
at com.microsoft.tfs.core.clients.versioncontrol.engines.internal.GetEngine.processOperations(GetEngine.java:957)
at com.microsoft.tfs.core.clients.versioncontrol.engines.internal.GetEngine.processGetOperations(GetEngine.java:782)
at com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.get(Workspace.java:2429)
at com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.get(Workspace.java:2307)
at com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.get(Workspace.java:2295)
at com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace.get(Workspace.java:2271)
at TfsGet.main(TfsGet.java:181)
Well, I am not a Unix boy and don't know how to diagnose and fix it. So I tried to leave the getWorkspace
/createWorkspace
part in Java and call tf get
. However it seems that I need to specify particular directories and files which I want to update.
I feel that the job must be quite common and cannot believe nobody ever got it done.