It's all about the answers!

Ask a question

What is the quickest way to determine if files have changed during build?

Todd Strangio (52610) | asked Jun 07 '13, 1:37 p.m.
Currently we're using an scm 'status' command, which we've found isn't great, performance-wise.  Is there a recommended approach for determining if a file has changed during the build?

How would this be done using the plain Java API?

Jeff Care commented Jun 07 '13, 1:40 p.m.

Do you mean actually changed during the build or changed from one build to the next?

Todd Strangio commented Jun 07 '13, 1:56 p.m.

Hi Jeff, thanks for the quick reply.  I actually meant 'changed during the build'....some of our builds change source files during build and I'd like to know what the experts think is the best approach to getting this data.

Accepted answer

permanent link
Jeff Care (1.0k3833) | answered Jun 11 '13, 1:07 p.m.
One approach would be to compute checksums for each file in your extracted build tree prior to building anything, storing the information into a file. You can then to the same process after the build is over and compare the checksums.

Of course I don't know your requirements, but generally speaking it's a bad idea to be modifying source files during a build.
Todd Strangio selected this answer as the correct answer

Todd Strangio commented Jun 11 '13, 1:18 p.m.

Thanks Jeff.  How would this be done using the Java API?

Tim Mok commented Jun 11 '13, 2:38 p.m.

You wouldn't need the plain Java API to perform any of this. Your build will load the content and you just need something to compute the checksums for before and after.

Jeff Care commented Jun 11 '13, 3:24 p.m.

You shouldn't need to use the RTC API: all the classes you would need for this exist as part of the JDK. You could also probably implement this solution using a shell script, though the comparison part might be tricky that way.

Can you elaborate on why you modify source files during your build? Maybe there's a different way to approach your problem that wouldn't involve such a terrible anti-pattern.

Todd Strangio commented Jun 11 '13, 3:38 p.m.

Some of our builds update a file during build with version info, which is then used during the deployment process.  Looks like the SCM command is our best option for now, thanks for the answers.

Jeff Care commented Jun 11 '13, 6:54 p.m.

I see.

Again, I don't know the specifics, but in (superficially) similar cases in the past I have treated the source file as a template, generating the actual shipped file during the build process using the template, using token replacement, sed, or whatever other automated editing facility was available in the given context.

One other answer

permanent link
Tim Mok (6.6k38) | answered Jun 10 '13, 9:58 a.m.
The command line is your best option. You might be able to get something more lightweight with the plain Java API but it would be quite a bit reimplementing of the command-line and I don't know how much time you're willing to spend on that.

Your answer

Register or 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.