You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project in team foundation server named master-builds . the master-build folder has a xml file named build-main.xml
i want to fetch this files from server and make some changes in it (change the version number ) and check in again , how can i achieve it using TFS JAVA SDK 14.0.3 .
I tried the samples provided in the folder but not able to achieve
This is the code snippet to create workspace
public static Workspace createAndMapWorkspace(final TFSTeamProjectCollection tpc) {
final String workspaceName = "SampleVCWorkspace" + System.currentTimeMillis(); //$NON-NLS-1$
Workspace workspace = null;
// Get the workspace
workspace = tpc.getVersionControlClient().tryGetWorkspace(ConsoleSettings.MAPPING_LOCAL_PATH);
// Create and map the workspace if it does not exist
if (workspace == null) {
workspace = tpc.getVersionControlClient().createWorkspace(
null,
workspaceName,
"Sample workspace comment", //$NON-NLS-1$
WorkspaceLocation.SERVER,
null,
WorkspacePermissionProfile.getPrivateProfile());
// Map the workspace
final WorkingFolder workingFolder = new WorkingFolder(
ConsoleSettings.MAPPING_SERVER_PATH,
LocalPath.canonicalize(ConsoleSettings.MAPPING_LOCAL_PATH));
workspace.createWorkingFolder(workingFolder);
}
System.out.println("Workspace '" + workspaceName + "' now exists and is mapped"); //$NON-NLS-1$ //$NON-NLS-2$
return workspace;
}
public static void getLatest(final Workspace workspace) {
final ItemSpec spec = new ItemSpec(ConsoleSettings.MAPPING_LOCAL_PATH, RecursionType.FULL);
final GetRequest request = new GetRequest(spec, LatestVersionSpec.INSTANCE);
workspace.get(request, GetOptions.NONE);
}
public static File addFile(final Workspace workspace) {
// Create the file locally
final File newFile = new File(ConsoleSettings.MAPPING_LOCAL_PATH, "SampleAppFile"); //$NON-NLS-1$
writeFileContents(newFile, "", "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
// Pend an add
// The encoding is passed as null and the add will detect the encoding
// of the file
workspace.pendAdd(new String[] {
newFile.getAbsolutePath()
}, false, ENCODING, LockLevel.UNCHANGED, GetOptions.NONE, PendChangesOptions.NONE);
// Checkin the pending change
final int cs = checkinPendingChanges(workspace, "Adding a sample file"); //$NON-NLS-1$
System.out.println("Added file " + newFile.getAbsolutePath() + " in CS# " + cs); //$NON-NLS-1$ //$NON-NLS-2$
return newFile;
}
public static void editFile(final Workspace workspace, final File file) {
// Pend edit
final ItemSpec fileSpec = new ItemSpec(file.getAbsolutePath(), RecursionType.NONE);
workspace.pendEdit(
new ItemSpec[] {
fileSpec
},
LockLevel.UNCHANGED,
ENCODING,
GetOptions.NONE,
PendChangesOptions.NONE);
// Edit the file
writeFileContents(file, "Edited this file at " + new Date().toString(), "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
// Checkin the pending change
final int cs = checkinPendingChanges(workspace, "Editing the sample file"); //$NON-NLS-1$
System.out.println("Edited file " + file.getAbsolutePath() + " in CS# " + cs); //$NON-NLS-1$ //$NON-NLS-2$
}
`
These are my questions
I was able to successfully add a new file to the remote server , but am not able to edit an existing remote file .
If i call editFile followed by addFile method it will get updated , but i dont want to add enw file every time ,what i want is to fetch the latest version of the buils-main.xml file from server and make changes and do the check in.
Also after creating the workspace in local path i couldnt see it in that path , is that the correct behavior ?
Could anyone Please help me on this?
The text was updated successfully, but these errors were encountered:
I have a project in team foundation server named master-builds . the master-build folder has a xml file named build-main.xml
i want to fetch this files from server and make some changes in it (change the version number ) and check in again , how can i achieve it using TFS JAVA SDK 14.0.3 .
I tried the samples provided in the folder but not able to achieve
This is the code snippet to create workspace
`
These are my questions
I was able to successfully add a new file to the remote server , but am not able to edit an existing remote file .
If i call editFile followed by addFile method it will get updated , but i dont want to add enw file every time ,what i want is to fetch the latest version of the buils-main.xml file from server and make changes and do the check in.
Also after creating the workspace in local path i couldnt see it in that path , is that the correct behavior ?
Could anyone Please help me on this?
The text was updated successfully, but these errors were encountered: