You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Mike Kelley <mi...@gmail.com> on 2008/04/09 13:06:04 UTC

Buildr::Java::CompileTask NOT needed if only package-info.class files are missing

I'm running buildr 1.2.10 against a project that contains
package-info.java files. The Java compiler happily ignores them
although comments in them are later incorporated into javadoc.

The problem is that the CompileTask is always considered necessary
(always rebuilds) because there aren't .class files to match the
package-info.java files. I'm new to buildr/ruby so I'm far from sure
this is the best solution to problem, but here is one:
----------------------------------------------------------------
class Buildr::Java::CompileTask
  def valid_class_file?(c) #:nodoc:
    not File.basename(c).include? '-'  # no package-info.class, for example
  end

  def needed?() #:nodoc:
    return false if source_files.empty?
    return true unless File.exist?(target.to_s)
    compiled_source_files = []
    source_files.each do |j, c|
      compiled_source_files << [j, c] if valid_class_file? c
    end
    return true if compiled_source_files.any? { |j, c| !File.exist?(c)
|| File.stat(j).mtime > File.stat(c).time }
    oldest = compiled_source_files.map { |j, c| File.stat(c).mtime }.min
    return classpath.any? { |path| application[path].timestamp > oldest }
  end
end

----------------------------------------------------------------

Does this or something it like seem like an appropriate change to make
down at the task level (rather than mucking with source file filtering
in all buildfiles)?  If so (Assaf and company), would this be more
welcome as a patch? :)

Mike

Re: Buildr::Java::CompileTask NOT needed if only package-info.class files are missing

Posted by Assaf Arkin <ar...@intalio.com>.
On Wed, Apr 9, 2008 at 4:06 AM, Mike Kelley <mi...@gmail.com>
wrote:

> I'm running buildr 1.2.10 against a project that contains
> package-info.java files. The Java compiler happily ignores them
> although comments in them are later incorporated into javadoc.


AFAIK if your package-info.java file had a class definition in it, javac
would compile it into a class file.  Javac only skips this source file
because it's empty, not the file name.

We do follow the convention of naming the class and source file the same, so
it's definitely worth considering skipping file names that are illegal class
names.

Only risk I can think of: if those files did contain class definitions,
Buildr would just silently ignore them.

Assaf


>
>
> The problem is that the CompileTask is always considered necessary
> (always rebuilds) because there aren't .class files to match the
> package-info.java files. I'm new to buildr/ruby so I'm far from sure
> this is the best solution to problem, but here is one:
> ----------------------------------------------------------------
> class Buildr::Java::CompileTask
>  def valid_class_file?(c) #:nodoc:
>    not File.basename(c).include? '-'  # no package-info.class, for example
>  end
>
>  def needed?() #:nodoc:
>    return false if source_files.empty?
>    return true unless File.exist?(target.to_s)
>    compiled_source_files = []
>    source_files.each do |j, c|
>      compiled_source_files << [j, c] if valid_class_file? c
>    end
>    return true if compiled_source_files.any? { |j, c| !File.exist?(c)
> || File.stat(j).mtime > File.stat(c).time }
>    oldest = compiled_source_files.map { |j, c| File.stat(c).mtime }.min
>    return classpath.any? { |path| application[path].timestamp > oldest }
>  end
> end
>
> ----------------------------------------------------------------
>
> Does this or something it like seem like an appropriate change to make
> down at the task level (rather than mucking with source file filtering
> in all buildfiles)?  If so (Assaf and company), would this be more
> welcome as a patch? :)
>
> Mike
>



-- 
CTO, Intalio
http://www.intalio.com