Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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?

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.

0 votes

Comments

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

Actually, what I really need is a way in Java code to do what the "scm show properties" command does.


Accepted answer

Permanent link
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

1 vote

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);
        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) {

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 log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Apr 07 '20, 9:37 a.m.

Question was seen: 1,778 times

Last updated: Mar 04 '21, 1:45 a.m.

Confirmation Cancel Confirm