In the Java Server API, How to list the changed files
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!
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
you have the change set, so should be able to find the 'changes' from there..
Comments
Hello Sam.
At moment, I have the code below:
while (changeSetIterator.hasNext()) {The item is my change but How do I get the item name?
IChangeSet changeSet = (IChangeSet) changeSetIterator.next();
List<IChange> changes = changeSet.changes();
for (IChange iChange : changes) {
IVersionableHandle item = iChange.item();
...
}
}
The name of the file/folder is on the full IVersionable object. You can fetch this by calling: VersionableManager$fetchCompleteStates(...)
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.
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.