It's all about the answers!

Ask a question

In the Java Server API, How to list the changed files


Pietro Bottino (35715) | asked Jul 26 '16, 1:41 p.m.
Good afternoon,

I'm developing a new "scm" advisor (Server-side) for to check a specific duplicated file extension on Deliver operation.

With API, I've already retrieved change sets, components, streams, baselines etc. But I've not found a way to list the change files (of Change set). Also, I need to list the components' files.

I've found several articles to retrieve files, but only Client-Side advisors.

Does anyone know how to do this?

Thank you!

2 answers



permanent link
sam detweiler (12.5k6195201) | answered Jul 26 '16, 2:57 p.m.
you have the change set,  so should be able to find the 'changes' from there..

Comments
Pietro Bottino commented Jul 26 '16, 4:42 p.m. | edited Jul 26 '16, 4:44 p.m.

Hello Sam.

At moment, I have the code below:

while (changeSetIterator.hasNext()) {           
    IChangeSet changeSet = (IChangeSet) changeSetIterator.next();           
    List<IChange> changes = changeSet.changes();           
    for (IChange iChange : changes) {              
        IVersionableHandle item = iChange.item();
        ...
    } 
}
The item is my change but How do I get the item name?







David Lafreniere commented Jul 31 '16, 12:08 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

The name of the file/folder is on the full IVersionable object. You can fetch this by calling: VersionableManager$fetchCompleteStates(...)


permanent link
Luca Martinucci (1.0k397112) | answered Jul 28 '16, 4:17 a.m.
edited Jul 28 '16, 4:17 a.m.
Pietro,
this code I wrote retrieves the paths of files contained in a change set:

.........
IChange change = (IChange)changesIterator.next();
IVersionableHandle changeObj = null;
Integer changeKind = change.kind();
switch (changeKind) {
case 1: {
    // added
    addedElement = true;
    changeObj = change.afterState();
    };
break;
case 2: {
    // modified
    modifiedElement = true;
    changeObj = change.afterState();
};
break;
case 16: {
    // removed
    deletedElement = true;
    changeObj = change.beforeState();
};
default: {
};
break;
}
// element path, starting from the component root
String elementPath = "";
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(findStreamFromEnvironment(deliveryTargetName, repositoryProgressMonitorHandle), changeSet.getComponent());
List<?> nameItemPairs = null;                                           
if (modifiedElement) {
    IAncestorReport reports[] = scmService.configurationLocateAncestors(configProvider, new IVersionableHandle[] {changeObj}, null, repositoryProgressMonitorHandle);
    nameItemPairs = reports[0].getNameItemPairs();
}   
if (addedElement) {
    IAncestorReport reports[] = scmService.configurationLocateAncestors(configProvider, new IVersionableHandle[] {changeObj}, null, repositoryProgressMonitorHandle);
    nameItemPairs = reports[0].getNameItemPairs();                       
}           
if (deletedElement) {
    IAncestorReport reports[] = scmService.configurationDetermineAncestorsInHistory(configProvider, new IVersionableHandle[] {changeObj}, null, repositoryProgressMonitorHandle);
    nameItemPairs = reports[0].getNameItemPairs();
}           
if (nameItemPairs.isEmpty()) {
    IAncestorReport reports[] = scmService.configurationDetermineAncestorsInHistory(configProvider, new IVersionableHandle[] {changeObj}, null, repositoryProgressMonitorHandle);
    nameItemPairs = reports[0].getNameItemPairs();
}                   
for (Iterator<?> iterator = nameItemPairs.iterator(); iterator.hasNext();) {
    INameItemPair nameItemPair = (INameItemPair)iterator.next();
    String pathPiece = nameItemPair.getName();
    if (pathPiece != null) {
        elementPath = elementPath.concat("/" + pathPiece);
    }
}
if (elementPath.isEmpty()) {
    elementPath = "<element removed by another change set>";
}


I hope it helps you.

Your answer


Register or to post 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.