    # File lib/chef/knife/cookbook_metadata.rb, line 73
          def generate_metadata_from_file(cookbook, file)
            ui.info("Generating metadata for #{cookbook} from #{file}")
            md = Chef::Cookbook::Metadata.new
            md.name(cookbook)
            md.from_file(file)
            json_file = File.join(File.dirname(file), 'metadata.json')
            File.open(json_file, "w") do |f|
              f.write(Chef::JSONCompat.to_json_pretty(md))
            end
            generated = true
            Chef::Log.debug("Generated #{json_file}")
          rescue Exceptions::ObsoleteDependencySyntax, Exceptions::InvalidVersionConstraint => e
            ui.stderr.puts "ERROR: The cookbook '#{cookbook}' contains invalid or obsolete metadata syntax."
            ui.stderr.puts "in #{file}:"
            ui.stderr.puts
            ui.stderr.puts e.message
            exit 1
          end