How to get file properties via 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));
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
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()?
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);
IVersionableManager versionableManager = SCMPlatform.getWorkspaceManager(getRepository()).versionableManager();
versionableState = versionableManager.fetchCompleteState(handle, monitor);
FileState fileState = ClientFileStateFactory.create(repo, versionableState .getItemType(), state);
1 vote
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) {
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) {
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?
Comments
David Lafreniere
FORUM MODERATOR / JAZZ DEVELOPER Apr 07 '20, 9:40 a.m.What properties specifically are you looking for? (there might be different API for the different properties).
Geoff Alexander
Apr 07 '20, 10:09 a.m.