How to write/upload any file(zip) inside any specific folder of RTC source control (component) in java?
![]()
I have found following code from 1 of the articles but I am not sure how to pass parameters to that method. Basically it requies 'IFileItem' object. I dont know how to create or get that object containing details of the folder of RTC source control where I want to upload my file.
//method to uploadContentToFile
public static IFileItem uploadContentToFile(IFileItem fileItem,
ITeamRepository repo, String newContent) throws TeamRepositoryException {
IProgressMonitor monitor = new NullProgressMonitor();
IFileItem fileWorkingCopy = (IFileItem) fileItem.getWorkingCopy();
IFileContentManager contentManager = FileSystemCore
.getContentManager(repo);
VersionedContentManagerByteArrayInputStreamPovider inputStream = new VersionedContentManagerByteArrayInputStreamPovider(
newContent.getBytes());
IFileContent uploadedcontent = null;
uploadedcontent = contentManager.storeContent(
IFileContent.ENCODING_UTF_8,
FileLineDelimiter.LINE_DELIMITER_PLATFORM, inputStream, null,
monitor);
fileWorkingCopy.setContent(uploadedcontent);
System.out.println("Loaded new content into file.");
return fileWorkingCopy;
}
//method to applyLock
public static void applyLock(ITeamRepository repo,
IWorkspaceConnection streamConnection,
IComponentHandle componentHandle, IFileItem fileItem,
IProgressMonitor monitor) throws TeamRepositoryException {
IWorkspaceManager wsManager = (IWorkspaceManager) repo
.getClientLibrary(IWorkspaceManager.class);
IVersionableLockOperationFactory lockFactory = wsManager
.lockOperationFactory();
ArrayList<IVersionableLockOperation> lockOperations = new ArrayList<IVersionableLockOperation>();
lockOperations.add(lockFactory.acquire(fileItem, streamConnection,
componentHandle));
wsManager.applyLockOperations(lockOperations, monitor);
}
//method to removeLock
public static void removeLock(ITeamRepository repo,
IWorkspaceConnection streamConnection,
IComponentHandle componentHandle, IFileItem fileItem,
IProgressMonitor monitor) throws TeamRepositoryException {
IWorkspaceManager wsManager = (IWorkspaceManager) repo
.getClientLibrary(IWorkspaceManager.class);
IVersionableLockOperationFactory lockFactory = wsManager
.lockOperationFactory();
ArrayList<IVersionableLockOperation> lockOperations = new ArrayList<IVersionableLockOperation>();
lockOperations.add(lockFactory.release(fileItem, streamConnection,
componentHandle, true));
wsManager.applyLockOperations(lockOperations, monitor);
}
|
Accepted answer
![]() Take a look at the following link: http://thescmlounge.blogspot.in/ and search for Uploading new content. Follow through with committing the change to a change set. Vivek Mishra selected this answer as the correct answer
Comments Also see https://rsjazz.wordpress.com/2013/09/30/delivering-change-sets-and-baselines-to-a-stream-using-the-plain-java-client-libraries/ and make sure to understand which file types, line ending etc. to use for zip - e.g. look at the values it has in RTC Eclipse. ZIP is not mergeable binary (which is why it normally should not be in SCM). |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.