I am writing a plugin for SBT that requires a list of the class files generated by the last run of the Scala compiler.
This list of class files is then passed into a program that performs some bytecode transformations. Since this transformation process can be slow, I only want the class files written by the last run of the Scala compiler (i.e. those that there modified), not all class files in the output directory.
How can I obtain a list of the files last generated by the compile
task?
I think you cannot get this information directly from the
Analysis
object returned by thecompile
task.However, what you could do is to check
analysis.relations.allProducts
for changes. If any of the files is modified you can execute yours task, which performs bytecode transformations.You could use a modified version of a FileFunction.cached, to check for changes.
The function takes following parameters:
cacheBaseDirectory
- location of the cacheinStyle
- description of how the changes should be discovered (see sbt.FilesInfo for possible options)action
- a function run, when the files has been modified. The function takes a list of modified files as an argument.The function returns another function which is run only if the set of files passed to it as an argument is modified.
Example