Repository navigation
Conversation
JRuby's rakelib/graph.rake (graph:viz, added in 2011 as an "ant target visualizer") drew the targets of JRuby's Ant build.xml with Graphviz. JRuby no longer has an Ant build and removes it in jruby/jruby#9761, so move the idea here as a reusable feature: - Rake::Ant.dot(project) returns Graphviz DOT text with an edge from each dependency to the target that depends on it, sanitizing - and . in target names as graph.rake did - ant_graph_task(name, buildfile, output) defines a task that ant_imports the build file and pipes the DOT text to `dot -Tpng -x` - CI installs Graphviz so the PNG test runs; it skips without `dot` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rake no longer exposes its DSL at the top level outside a Rakefile, so the global include was both unnecessary and the thing modern Rake removed on purpose. ant_import and ant_task now define tasks via Rake::Task.define_task. Fixes jruby#1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…m its test Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2982fd8 to
51727e6
Compare
Upgrade notes for existing usersWho is affected: only code that is not a Rakefile but relied on Not affected: Rakefiles. Rake already provides its DSL to a Rakefile's # Rakefile: no changes needed
require 'ant'
ant_import
ant_task :compile => :prep do
javac :srcdir => 'src', :destdir => 'build'
endSymptom if you are affected: How to fix it (any one of these): # 1. Opt in to the DSL where you use it (what this gem used to do globally)
require 'ant'
include Rake::DSL # at top level of a script
# or inside a class/module:
class MyBuild
include Rake::DSL
end
# 2. Extend a single object instead of polluting everything
builder = Object.new.extend(Rake::DSL)
# 3. Skip the DSL and call Rake's API directly
Rake::Task.define_task(:compile => :prep) { ... }
Rake::FileTask.define_task('out.jar' => 'src') { ... }Option 1 is the minimal change for an existing script. Options 2 and 3 are preferred for new code because they do not leak methods into every object, which is what current Rake itself avoids. Because this is a behaviour change for non-Rakefile users, I'd suggest a minor version bump and a changelog line when releasing. |
|
@headius let me know if there is anything more here. |
Fixes #1.
Rake no longer defines its DSL at the top level outside a Rakefile. This gem worked around that with a global
include Rake::DSL, which leakstask,file,sh, etc. into every object, the thing modern Rake removed on purpose.ant_importandant_tasknow callRake::Task.define_taskinstead of the baretask.require 'rake/dsl_definition'and the globalinclude Rake::DSL.test_rake.rbno longer includesRake::DSL.ant,ant_importandant_taskremain top-level methods, so Rakefiles are unaffected. Scripts that relied on this gem leakingtask/shinto the top level will needinclude Rake::DSLthemselves, so this probably deserves a minor version bump.Tested on JRuby with Ant 1.10.18: 30 runs, 0 failures (1 skip:
ANT_HOMEunset). Also ran a real Rakefile usingant_importandant_task, and confirmedObject.new.respond_to?(:task, true)is false afterrequire 'ant'.Stacked on #7: this branch includes #7's commit (its head is in a fork, so it can't be the PR base). Once #7 merges, that commit drops out of this diff.
ant_graph_tasknow also usesRake::Task.define_taskandtest_graph.rbno longer includesRake::DSL, so no follow-up is needed. Full suite with both: 33 runs, 0 failures (1 skip:ANT_HOMEunset).🤖 Generated with Claude Code