Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid removing files not ended in .rb #452

Open
wants to merge 1 commit into
base: 1.x-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/warbler/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def define_compiled_task
task "compiled" do
jar.compile(config)
task @name do
rm_f config.compiled_ruby_files.map {|f| f.sub(/\.rb$/, '.class') }
extensions = config.compiled_ruby_files&.map { |f| File.extname(f) }&.uniq || ['.rb']
regex_extensions = extensions.map { |extension| extension.sub('.', '\.') }.join('|')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RegExp.union is pretty great:

extensions = Pathname.glob("config/**/*").map(&:extname).uniq
# [".pem", ".rb", ".yml", ".ignore", "", ".md", ".markdown", ".json"]
Regexp.union(extensions)
# /\.pem|\.rb|\.yml|\.ignore||\.md|\.markdown|\.json/

rm_f config.compiled_ruby_files.map {|f| f.sub(/#{regex_extensions}$/, '.class') }
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/warbler/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
config.gems = ["rake"]
config.webserver = "test"
config.webxml.jruby.max.runtimes = 5

config.compiled_ruby_files = FileList['**/*.rb', '**/.rake']
end
end

Expand Down Expand Up @@ -150,6 +152,12 @@ def run_task(t)
File.exist?('app/helpers/application_helper.class').should be false
end

it "should not delete another extensions but .class files after finishing the jar" do
config.features << "compiled"
silence { run_task "warble" }
File.exist?('lib/tasks/utils.rake').should be true
end

context "where symlinks are available" do
begin
FileUtils.ln_s "README.txt", "r.txt.symlink", :verbose => false
Expand Down