Accessing artifacts of finished build

What is the proper way to access the artifacts of a SFinishedBuild from a plugin?

I see getArtifactsDirectory() and ArtifactsGuard. I assume I can enumerate the files in the specified directory using java.io.File.list(), but if I wanted to read or write a specific file, I must use an ArtifactsGuard. Is this correct?

Do I inject ArtifactsGuard into my extension or do I need to create one?

3 comments
Comment actions Permalink

It would be better to use ArtifactsGuard. You can obtain it from the Spring.
If you want to enumerate and then modify some files in a directory, lock this directory for writing.

ArtifactsGuard is required because there can be operations, like build configuration or project rename. In this case project and build configuration names in artifacts folder should be renamed too, but this can be done only if there are no processes currently working with artifacts. Thus the locking is required.

0
Comment actions Permalink

OK. I was wondering if I should lock directories or just files. That answers the question.

If I lock a directory, does the lock cascade or do I need to lock subdirectories/files? Can I lock a file/directory for read and then later lock it for write?

0
Comment actions Permalink

It is enough to lock directory. The lock is hierarchical, i.e. if you lock a directory or a file, all parent directories will be locked too.

Internally guard uses ReentrantReadWriteLocks, so upgrading of the lock is not possible, you should unlock read lock before taking the write lock.

0

Please sign in to leave a comment.