javaapirational-team-concertibm-jazz

IBM RTC API - Adding files to change sets


Basically I'm experimenting with the IBM Rational Team Concert Plain Java Client API, and I'm stuck at adding operations to change sets.

I create a new change set, retrieve the Operation factory and then I'd like to add a new file from the local machine file system (might be a new file of a project).

val changeSetHandle = workspaceConnection.createChangeSet(component, null)
val operationFactory = workspaceConnection.configurationOpFactory()
val saveOperation = operationFactory.save(...)

I do not understand how to to obtain an IVersionable handle to submit to the save() method.


Solution

  • You can refer to this thread which shows an example of IVersionable:

    // Create a new file and give it some content
    IFileItem file = (IFileItem) IFileItem.ITEM_TYPE.createItem();
    file.setName("file.txt");
    file.setParent(projectFolder);
    
    // Create file content.
    IFileContentManager contentManager = FileSystemCore.getContentManager(repository);
    IFileContent fileContent = contentManager.storeContent(
                  "UTF-8",
                  FileLineDelimiter.LINE_DELIMITER_LF,
                  new VersionedContentManagerByteArrayInputStreamPovider(BYTE_ARRAY),
                  null,
                  null);
    
    file.setContent(fileContent);
    file.setContentType(IFileItem.CONTENT_TYPE_TEXT);
    file.setFileTimestamp(new Date());
    
    workspaceConnection.configurationOpFactory().save(file);
    

    However, this is not enough:

    IConfigurationOpFactory is used to update a repository workspace by adding changes to a change set.
    The usage pattern is to get a workspace connection, create a bunch of save operations, then run IWorkspaceConnection#commit() on those ops.
    Calling save() without committing the change drops the op onto the stack for the garbage collector to gobble up. ;)