It's all about the answers!

Ask a question

How to get file properties via Java API


Geoff Alexander (19623948) | asked Apr 07 '20, 9:37 a.m.
edited Apr 07 '20, 10:09 a.m.

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?

Update: What I actually need is a way in Java code is to do what the "scm show properties" command does, that is, get the list of file / folder properties.


Comments
David Lafreniere commented Apr 07 '20, 9:40 a.m.
FORUM MODERATOR / JAZZ DEVELOPER

What properties specifically are you looking for? (there might be different API for the different properties).


Geoff Alexander commented Apr 07 '20, 10:01 a.m. | edited Apr 07 '20, 10:09 a.m.
Actually, what I really need is a way in Java code to do what the "scm show properties" command does.

Accepted answer


permanent link
David Lafreniere (4.8k7) | answered Apr 08 '20, 7:57 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
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
Geoff Alexander commented Apr 08 '20, 8:47 a.m. | edited Apr 08 '20, 9:15 a.m.
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
David Lafreniere commented Apr 09 '20, 7:04 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
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()?


David Lafreniere commented Feb 08 '21, 12:28 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
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


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.