[FIXED JENKINS-7260] Add an option to copy empty directories #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The plugin mainly relies on jenkins-core API which implementation has changed a few times between 1.463 and 1.642, so it's actually quite difficult to add new features or to change its behavior.
The DirScanner.Glob doesn't archive empty directories because it actually generates a list of files to save and then create the correct directory tree to match the location of those files.
One workaround I found is to write a custom DirScanner (based on DirScanner.Filter) which actually scans the whole workspace, excludes files which are not part of the Ant pattern and automatically accepts directories whatever the Ant pattern is (see hudson.util.FileVisitor.FilterFileVisitor.visit method).
The pitfall is that you can't exclude directories anymore. At least I filter them at the top-level, meaning if your workspace contains dir1, dir2, dir3 and your include pattern is dir1/**, it won't copy dir2 and dir3.
That way I think I was able to minimize copy/paste and still relies on the jenkins-core API to actually do
anything.