How to get file properties via Java API
The RTC CLI has to the "scm get property" command to get a file's property. How can I do the same using the RTC Java API?
|
Accepted answer
1) Get the IShareable for the file.
Ex: ResourceType resourceType = CommonUtil.getResourceType(path, monitor); if (resourceType == null) { // pick file as the default - doesn't exist resourceType = ResourceType.FILE; } IShareable shareable = SharingManager.getInstance().findShareable(path, resourceType));
2) Get the FileItemInfo.
Ex:
FileItemInfo info = ((Shareable) shareable).getFileItemInfo(monitor);
FileItemInfo has the following properties:
-line delimiter
-encoding
-executable
-content type
Geoff Alexander selected this answer as the correct answer
Comments
David, thanks for the answer.
Is it possible to get the properties from IVersionable (actually IFileItem and IFolder), as I'm processing file / folder changes from an IChangeSet via IChangeSet.changes()?
1
The Class FileState also has the properties you care about.
FileState.getContentType()
FileState.getLineDelimiter(), ec.
So:
IVersionableHandle handle = getVersionableHandle();
IVersionableManager versionableManager = SCMPlatform.getWorkspaceManager(getRepository()).versionableManager(); versionableState = versionableManager.fetchCompleteState(handle, monitor);
FileState fileState = ClientFileStateFactory.create(repo, versionableState .getItemType(), state);
Geoff Alexander
commented Feb 08 '21, 11:00 a.m.
After upgrading from Plain Java Library 6.0 to Plain Java Library 6.0.5, ClientFileStateFactory.create() is marked deprecated. Is there a suggested replacement for ClientFileStateFactory.create()?
The Javadoc indicates which method to use instead.See below:
* @deprecated
Use {@link #create(ITeamRepository, IItemType, ItemWithLinks)} instead so that the file state includes changes to external links */ @Deprecated public static FileState create(ITeamRepository repo, IItemType type, IVersionable item) {
Geoff Alexander
commented Feb 08 '21, 12:54 p.m.
Thanks David. I did look in the 6.0.5 Plain Java Library Javadoc, but found that there is no Javadoc for ClientFileStateFactory. This is probably due to ClientFileStateFactory being in the internal com.ibm.team.filesystem.client.internal package. Is there some other place I should be looking for Javadocs?
|
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.
Comments
What properties specifically are you looking for? (there might be different API for the different properties).