| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | module Cask | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |   class Auditor | 
					
						
							| 
									
										
										
										
											2019-05-07 17:06:54 +02:00
										 |  |  |     extend Predicable | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def self.audit(cask, audit_download: false, audit_appcast: false, | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |                    audit_online: false, audit_strict: false, | 
					
						
							|  |  |  |                    audit_token_conflicts: false, audit_new_cask: false, | 
					
						
							|  |  |  |                    quarantine: true, commit_range: nil) | 
					
						
							| 
									
										
										
										
											2019-05-07 17:06:54 +02:00
										 |  |  |       new(cask, audit_download: audit_download, | 
					
						
							|  |  |  |                 audit_appcast: audit_appcast, | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |                 audit_online: audit_online, | 
					
						
							|  |  |  |                 audit_new_cask: audit_new_cask, | 
					
						
							|  |  |  |                 audit_strict: audit_strict, | 
					
						
							|  |  |  |                 audit_token_conflicts: audit_token_conflicts, | 
					
						
							| 
									
										
										
										
											2019-05-07 17:06:54 +02:00
										 |  |  |                 quarantine: quarantine, commit_range: commit_range).audit | 
					
						
							| 
									
										
										
										
											2016-10-24 04:08:56 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-07 06:41:40 +02:00
										 |  |  |     attr_reader :cask, :commit_range | 
					
						
							| 
									
										
										
										
											2016-10-24 04:08:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 17:06:54 +02:00
										 |  |  |     def initialize(cask, audit_download: false, audit_appcast: false, | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |                    audit_online: false, audit_strict: false, | 
					
						
							|  |  |  |                    audit_token_conflicts: false, audit_new_cask: false, | 
					
						
							|  |  |  |                    quarantine: true, commit_range: nil) | 
					
						
							| 
									
										
										
										
											2016-10-24 04:08:56 -04:00
										 |  |  |       @cask = cask | 
					
						
							|  |  |  |       @audit_download = audit_download | 
					
						
							| 
									
										
										
										
											2019-05-07 17:06:54 +02:00
										 |  |  |       @audit_appcast = audit_appcast | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |       @audit_online = audit_online | 
					
						
							|  |  |  |       @audit_strict = audit_strict | 
					
						
							|  |  |  |       @audit_new_cask = audit_new_cask | 
					
						
							| 
									
										
										
										
											2018-08-31 13:16:11 +00:00
										 |  |  |       @quarantine = quarantine | 
					
						
							| 
									
										
										
										
											2017-05-07 06:41:40 +02:00
										 |  |  |       @commit_range = commit_range | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |       @audit_token_conflicts = audit_token_conflicts | 
					
						
							| 
									
										
										
										
											2016-10-24 04:08:56 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |     attr_predicate :audit_appcast?, :audit_download?, :audit_online?, | 
					
						
							|  |  |  |                    :audit_strict?, :audit_new_cask?, :audit_token_conflicts?, :quarantine? | 
					
						
							| 
									
										
										
										
											2016-10-24 04:08:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def audit | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |       warnings = Set.new | 
					
						
							|  |  |  |       errors = Set.new | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 19:39:11 +01:00
										 |  |  |       if !Homebrew.args.value("language") && language_blocks | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         language_blocks.each_key do |l| | 
					
						
							|  |  |  |           audit = audit_languages(l) | 
					
						
							|  |  |  |           puts audit.summary | 
					
						
							|  |  |  |           warnings += audit.warnings | 
					
						
							|  |  |  |           errors += audit.errors | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-25 22:47:31 +02:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         audit = audit_cask_instance(cask) | 
					
						
							|  |  |  |         puts audit.summary | 
					
						
							|  |  |  |         warnings += audit.warnings | 
					
						
							|  |  |  |         errors += audit.errors | 
					
						
							| 
									
										
										
										
											2016-09-25 22:47:31 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       { warnings: warnings, errors: errors } | 
					
						
							| 
									
										
										
										
											2016-09-25 22:47:31 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 04:08:56 -04:00
										 |  |  |     private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def audit_languages(languages) | 
					
						
							| 
									
										
										
										
											2018-09-17 20:11:11 +02:00
										 |  |  |       ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.to_sentence}" | 
					
						
							| 
									
										
										
										
											2020-07-21 21:28:58 +02:00
										 |  |  |       localized_cask = CaskLoader.load(cask.sourcefile_path) | 
					
						
							|  |  |  |       config = localized_cask.config | 
					
						
							|  |  |  |       config.languages = languages | 
					
						
							|  |  |  |       localized_cask.config = config | 
					
						
							|  |  |  |       audit_cask_instance(localized_cask) | 
					
						
							| 
									
										
										
										
											2016-10-24 04:08:56 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def audit_cask_instance(cask) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |       audit = Audit.new(cask, appcast:         audit_appcast?, | 
					
						
							|  |  |  |                               online:          audit_online?, | 
					
						
							|  |  |  |                               strict:          audit_strict?, | 
					
						
							|  |  |  |                               new_cask:        audit_new_cask?, | 
					
						
							|  |  |  |                               token_conflicts: audit_token_conflicts?, | 
					
						
							| 
									
										
										
										
											2020-07-21 19:05:55 +02:00
										 |  |  |                               download:        audit_download?, | 
					
						
							|  |  |  |                               quarantine:      quarantine?, | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |                               commit_range:    commit_range) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       audit.run! | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |       audit | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-10-24 04:08:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def language_blocks | 
					
						
							|  |  |  |       cask.instance_variable_get(:@dsl).instance_variable_get(:@language_blocks) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |