A script that looks for obsolete URIs still in the code base.
This commit is contained in:
parent
1e2a9c575a
commit
1bf36caef7
6 changed files with 379 additions and 0 deletions
77
utilities/ISF-transition/obsoleteUris/known_exceptions.rb
Normal file
77
utilities/ISF-transition/obsoleteUris/known_exceptions.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
class KnownExceptionsError < StandardError; end
|
||||
|
||||
class ExtensionSkipper
|
||||
def initialize(extension)
|
||||
@extension = extension
|
||||
end
|
||||
|
||||
def skip?(path, line, uri)
|
||||
return File.extname(path) == @extension
|
||||
end
|
||||
end
|
||||
|
||||
class PathSkipper
|
||||
def initialize(root_path, relative_path)
|
||||
@root_path = root_path
|
||||
@absolute_path = File.expand_path(relative_path, @root_path)
|
||||
end
|
||||
|
||||
def skip?(path, line, uri)
|
||||
return @absolute_path == File.expand_path(path, @root_path)
|
||||
end
|
||||
end
|
||||
|
||||
class LineSkipper
|
||||
def initialize(root_path, relative_path, line_number)
|
||||
@inner = PathSkipper.new(root_path, relative_path)
|
||||
@line_number = line_number
|
||||
end
|
||||
|
||||
def skip?(path, line, uri)
|
||||
return @inner.skip?(path, line, uri) && line == @line_number
|
||||
end
|
||||
end
|
||||
|
||||
class KnownExceptions
|
||||
# ------------------------------------------------------------------------------------
|
||||
private
|
||||
# ------------------------------------------------------------------------------------
|
||||
|
||||
def parse_file(file)
|
||||
skippers = []
|
||||
File.readlines(file).each do |line|
|
||||
# ignore blank lines, and lines starting with '#' or '!'.
|
||||
line.strip!
|
||||
next if line.length == 0 || line[0..0] == '#' || line[0] == ?!
|
||||
|
||||
if line =~ /^\.[^\/]*$/
|
||||
skippers << ExtensionSkipper.new(line)
|
||||
elsif line =~ /^(\S+)\s*$/
|
||||
skippers << PathSkipper.new(@root_path, $1)
|
||||
elsif line =~ /^(\S+)\s*(\d+)\s*$/
|
||||
skippers << LineSkipper.new(@root_path, $1, $2.to_i)
|
||||
else
|
||||
raise "BOGUS line in known_exceptions file: '#{line}'"
|
||||
end
|
||||
end
|
||||
skippers
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------------------------
|
||||
public
|
||||
# ------------------------------------------------------------------------------------
|
||||
|
||||
def initialize(root_path, file)
|
||||
@root_path = File.expand_path(root_path)
|
||||
@skippers = parse_file(file)
|
||||
end
|
||||
|
||||
def skip?(file, line_number = -1, string = "@!#IMPOSSIBLE#!@")
|
||||
@skippers.each() do |skipper|
|
||||
if skipper.skip?(file, line_number, string)
|
||||
return true
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue