Remove the caching of source_files #64

merged 1 commit into from Aug 1, 2012


None yet
2 participants

sgonyea commented Aug 1, 2012

This allows me to run a task which generates java source files, prior to having rake-compiler compile them.

This is especially useful when you need to generate Thrift java sources or, should your life be one of pain and misery, wsimport (WSDL SOAP to java).

Scott Gonyea Do not cache the list of source_files
This allows me to run a task which generates java source files, prior to having rake-compiler compile them.

luislavena commented Aug 1, 2012

@sgonyea thanks for the pull request.

I have a question thought. As you know, source_files is used to make the task depend on the existing files. if new files are added, how the task (that was already defined) will know about the newer files?

Saying this because once one of those files gets updated it will force a recompilation which might get the files be generated again

(I'm just guessing since I haven't seen an example of this)

This cached source file issue is only present in the Java task, which uses source_files to actually build the jar.

Going to merge this, but if you can include an example here (or answer my previous question) will make myself very happy 😃

Thank you! ❤️

@luislavena luislavena added a commit that referenced this pull request Aug 1, 2012

@luislavena luislavena Merge pull request #64 from sgonyea/master
Remove the caching of source_files

@luislavena luislavena merged commit cc7c795 into rake-compiler:master Aug 1, 2012

sgonyea commented Aug 2, 2012

Sure thing! That's perfectly fair. So, my rake task looks like the following (below). What I do, effectively, is turn a WSDL into a bunch of .java source files.

Prior to my patch, what would happen is the JavaExtensionTask would quickly assemble its task, the moment it's defined, and immediately list any files in the "ext_dir" folder and cache them.

So the tasks that I want to run before (ie, delete old .java files + generate new ones) would not have their effects realized until the next run. So if files were no longer present (wouldn't happen in my case) it would try to compile them. If new files appeared (would / could happen), then they just wouldn't get compiled into the JAR. If no files exist, then the task will blow up, complaining that javac tried to compile no files.

After the patch, it will gather a list of source files each time it references source_files. That said, if you envision any side effects, then we can always try to delay the evaluation of much of the task's logic, until after it is invoked.

require 'fileutils'
desc 'Clean up any generated files from the WSDL / JAR'
task :clean_wsdl do
  FileUtils.rm_rf "#{Bundler.root}/ext/com"
  FileUtils.rm_rf "#{Bundler.root}/lib/jars/et_api.jar"
  FileUtils.rm_rf "#{Bundler.root}/tmp/java/et_api"

task :generate_sources do
  wsdl_url = ""
  wsdl_out_file = "lib/fml.wsdl"

  # Save the wsdl somewhere.
  `curl -s "#{wsdl_url}" -o #{wsdl_out_file}`
  `wsimport "#{wsdl_url}" -s ext -Xnocompile`

require 'rake/javaextensiontask'

task :compile => [:clean_wsdl, :generate_sources] do |ext| = "et_api"
  ext.ext_dir = "ext/com"
  ext.lib_dir = "lib/jars"

luislavena commented Aug 2, 2012

Thank you for the comment describing the usage @sgonyea, is very helpful to know how my project is being used.

Something to mention is that when you create a file-less task (like clean_wsdl and generate_sources), those will be run every time, even when no file has been changed (or need to).

A small thing to keep in mind if you want to avoid wasting extra-cycles.

I'll work on a release soon, but no ETA yet.

Once again, thank you for your contribution and the comment describing the need for it.

sgonyea commented Aug 3, 2012

Yeah, it can definitely be more intelligent :). This was my quick puzzle-it-through hack. Thank you for creating rake-compiler, btw. It's very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment