1

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.

ach
  • 2,314
  • 1
  • 13
  • 23
  • My P4 skills are nonexistent, could you clarify what you mean by "alter and fully synchronise a specific workspace" this feels like something that should be easy to do using the tf command line but I'm not quite sure what you mean – James Reed Aug 12 '13 at 22:14
  • @JamesReed, what I mean by altering a workspace is what is done either by a sequence of `tf workfold /{map|unmap|cloak|decloak}` or a single call to `Workspace.update`; that I have achieved. And synchronizing a workspace is getting the freshest (or a specified) revision of all files which are mapped by that workspace - and that's where I'm stuck. Sorry if I'm using inconsistent terminology. – ach Aug 12 '13 at 22:26

1 Answers1

1

Thanks everyone, the error in Workspace.get turned out to be the result of my own inattention. The versions of the com.microsoft.tfs.sdk-11.0.0.jar and the libnative_*.so files did not match. Now that I've made sure that all files match each other, the problem is solved.

ach
  • 2,314
  • 1
  • 13
  • 23