lib/rake/funnel/support/specs_remover.rb in rake-funnel-0.7.0.pre vs lib/rake/funnel/support/specs_remover.rb in rake-funnel-0.8.0.pre
- old
+ new
@@ -18,42 +18,59 @@
end
private
def remove(projects, references, specs)
Dir[*projects].map do |project|
- xml = REXML::Document.new(File.read(project), attribute_quote: :quote)
- references = remove_references(references, xml)
- specs = remove_specs(specs, xml)
+ Trace.message("Processing #{project} with references #{references} and specs #{specs}")
- save(project, xml) if (references + specs).any?
+ removed_references, removed_specs = with_document(project) do |xml|
+ [remove_references(references, xml), remove_specs(specs, xml)]
+ end
{
project: project,
- packages: resolve_package_names(references),
- specs: resolve_paths(project, specs)
+ packages: resolve_package_names(removed_references),
+ specs: resolve_paths(project, removed_specs)
}
end
end
+ def with_document(project)
+ xml = REXML::Document.new(File.read(project), attribute_quote: :quote)
+
+ removed = yield(xml) if block_given?
+
+ save(project, xml) if [removed].flatten.compact.any?
+
+ removed
+ end
+
def remove_references(references, xml)
- deleted = references.map do |ref|
+ deleted = references.map { |ref|
query = "/Project//Reference[starts-with(lower-case(@Include), '#{ref.downcase}')]"
xml.elements.delete_all(query)
- end
+ }
+ .flatten
+ .tap { |d| Trace.message("Removed references: #{d.inspect}") }
- deleted.flatten.map { |d|
+ deleted.map { |d|
d.get_elements('/HintPath').map(&:text)
- }.flatten
+ }
+ .flatten
+ .tap { |d| Trace.message("HintPaths: #{d}") }
end
def remove_specs(specs, xml)
- deleted = specs.map do |glob|
+ deleted = specs.map { |glob|
query = "/Project//Compile[matches(lower-case(@Include), '#{glob}')]"
xml.elements.delete_all(query)
- end
+ }
- deleted.flatten.map { |d| d.attributes['Include'] }
+ deleted
+ .flatten
+ .map { |d| d.attributes['Include'] }
+ .tap { |d| Trace.message("Removed specs: #{d}") }
end
def save(project, xml)
File.open(project, 'w+') do |file|
xml.write(output: file, ie_hack: true)
@@ -85,10 +102,12 @@
class PaketReferences
class << self
def remove_packages(projects, packages)
projects.each do |project|
references = paket_references_for(project)
+ Trace.message("Found #{references || 'no paket.references'} for #{project}}")
+
next unless references
text = File.read(references)
removed = remove(text, packages)
@@ -103,10 +122,11 @@
[project_specific, global].select { |f| File.exist?(f) }.first
end
def remove(text, packages)
+ Trace.message("Removing packages: #{packages.inspect}")
packages.each do |package|
text = text.gsub(/^#{package}.*\n?/i, '')
end
text
end
@@ -117,12 +137,12 @@
def remove(args = {})
projects, packages, specs = ProjectFiles.remove_specs_and_references(list(args[:projects]),
list(args[:references]),
list(args[:specs]))
- delete(specs)
-
PaketReferences.remove_packages(projects, list(args[:packages]) + packages)
+
+ delete(specs)
end
private
def list(args)
([] << args).flatten.compact