It's all about the answers!

Ask a question

How to retrieve a list of files that have been modified using an Ant Task


Clinton Morrison (1111) | asked May 03 '15, 8:16 p.m.

I have a daily scheduled build that runs. I would like to know the following using Ant with Build Forge

Retrieve a list of the files that have changed

Download these files to a text file

Read the txt file

If the txt file contains certain directories then run particular tasks

2 answers



permanent link
Spencer Murata (2.3k115971) | answered May 04 '15, 8:17 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
 I would look into using the adaptor for that use case.  There is an article here on it:
http://www-01.ibm.com/support/docview.wss?uid=swg27011163&aid=1

I don't know exactly how Ant factors in, but you don't need it to execute this task.  I would run the command line argument that would get the list of changed files.  You didn't specify which SCM you are using, but that command wouldn't be anything special in most SCMs.  Put that command into the execute block of the adaptor and then create a results block that filters for the particular directories you are interested in.  Then do whatever tasks you need for the particular directories.

~Spencer

permanent link
Vijay Reddy Gaddam (563041) | answered May 04 '15, 9:33 a.m.
 Hi Clinton Morrison,

There is no direct way go get the list of files using ant task, but you can do the same by using the combination of ant task and Java API. For this use a buildfile which has pointer to both the ant task and Java API.

Steps that you can follow: 
1. Get the changeSets list that are delivered from previous build to current build. For this their is an Ant Task. Refer: https://jazz.net/wiki/bin/view/Main/BuildFAQ#How_can_I_generate_a_change_log

2. Secondly you can write some java API which reads list of changeSets from which you can find the list of changed files list and write the list into a text file where you can futhur proceed. For processing the changeSets the following is a code snippet which might help you.

List<IChangeSetHandle> changeSetHandles = wm.findChangeSets(changeSetSearchCriteria,
IWorkspaceManager.MAX_QUERY_SIZE, null);

for (IChangeSetHandle iChangeSetHandle : changeSetHandles) {

IChangeSet changeSet = (IChangeSet) teamRepository.itemManager().fetchCompleteItem(
iChangeSetHandle, IItemManager.DEFAULT, null);

System.out.println("======Changeset: " + changeSet.getItemId() + " comment: "
+ changeSet.getComment());

// Search criteria for workspaces in change sets belong to
IWorkspaceSearchCriteria iWorkspaceSearchCriteria = IWorkspaceSearchCriteria.FACTORY
.newInstance();
// setting kind i.e. it indicates search in stream's or
// workspaces
iWorkspaceSearchCriteria.setKind(IWorkspaceSearchCriteria.WORKSPACES);
List<IWorkspaceHandle> workspacesList = wm.findWorkspacesContainingChangeset(
iChangeSetHandle, iWorkspaceSearchCriteria, Integer.MAX_VALUE, null);

for (IWorkspaceHandle iWorkspaceHandle : workspacesList) {
// used for finding stream/workspace name when UUID is
// passed
IWorkspaceConnection workspaceConnection = wm.getWorkspaceConnection(
iWorkspaceHandle, null);
// System.out.println(" ======> RWS Name : " + workspaceConnection.getName());

// }

// Finding changes(file names) in change sets and path of
// files
List changes = changeSet.changes();
IVersionableManager versionableManager = SCMPlatform.getWorkspaceManager(
teamRepository).versionableManager();
for (Object change : changes) {
Change aChange = (Change) change;

String relativePath = null;
String fileName = null;
if (aChange.item() instanceof IFileItemHandle) {
IFileItemHandle fileItemHandle = (IFileItemHandle) aChange.afterState();
IFileItem fileItem = (IFileItem) versionableManager.fetchCompleteState(
fileItemHandle, null);
// System.out.print(" ======> fileItemHandle : ");
// System.out.println(fileItemHandle);
if (fileItem instanceof IFolder) {
IFolder folder = (IFolder) fileItem;
relativePath = getFilePath(
fileItem,
workspaceConnection.configuration(changeSet.getComponent()),
null, true);
fileName = folder.getName();
System.out.println("Folder Name :" + fileName + "\t relativePath:"
+ relativePath);
} else {
relativePath = getFilePath(
fileItem,
workspaceConnection.configuration(changeSet.getComponent()),
null, true);
fileName = ((FileItem) fileItem).getName();
// System.out.println("File Name :" + fileName + "\t relativePath:"
// + relativePath);
}
}
}
}

}

}
}

// To get the file path
private static String getFilePath(IVersionableHandle folder, IConfiguration config,
IProgressMonitor monitor, Boolean searchInHistory) throws TeamRepositoryException {

List lst = new ArrayList<IVersionableHandle>(), ancestors;
lst.add(folder);
if (searchInHistory) {
ancestors = config.determineAncestorsInHistory(lst, monitor);

} else {
ancestors = config.locateAncestors(lst, monitor);
}

return getFullPath(ancestors);
}

// To get the complete relative file path
private static String getFullPath(List ancestor) throws TeamRepositoryException {
String directoryPath = "";
for (Object ancestorObj : ancestor) {
IAncestorReport ancestorImpl = (IAncestorReport) ancestorObj;
for (Object nameItemPairObj : ancestorImpl.getNameItemPairs()) {
INameItemPair nameItemPair = (INameItemPair) nameItemPairObj;
String pathName = nameItemPair.getName();
if (pathName != null && !pathName.equals("")) {
directoryPath = directoryPath + "\\" + pathName;
}
}
}
return directoryPath;
}

Thanks and Regards,
Vijay Reddy.

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.