VIVO-4 remove the license substitution code from the license scanner
Now, it only scans.
This commit is contained in:
parent
07cf4ad00d
commit
e2b5c71874
4 changed files with 52 additions and 166 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -4,7 +4,6 @@
|
||||||
# Explicitly declare text files we want to always be normalized and converted
|
# Explicitly declare text files we want to always be normalized and converted
|
||||||
# to native line endings on checkout.
|
# to native line endings on checkout.
|
||||||
|
|
||||||
*.properties
|
|
||||||
*.conf text
|
*.conf text
|
||||||
*.config text
|
*.config text
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ class Licenser
|
||||||
#
|
#
|
||||||
def sanity_checks_on_parameters()
|
def sanity_checks_on_parameters()
|
||||||
# Check that all necessary properties are here.
|
# Check that all necessary properties are here.
|
||||||
raise("Properties file must contain a value for 'scan_only'") if @scan_only_string == nil
|
|
||||||
raise("Properties file must contain a value for 'source_dir'") if @source_dir == nil
|
raise("Properties file must contain a value for 'source_dir'") if @source_dir == nil
|
||||||
raise("Properties file must contain a value for 'known_exceptions'") if @known_exceptions_file == nil
|
raise("Properties file must contain a value for 'known_exceptions'") if @known_exceptions_file == nil
|
||||||
raise("Properties file must contain a value for 'skip_directories'") if @skip_directories_list == nil
|
raise("Properties file must contain a value for 'skip_directories'") if @skip_directories_list == nil
|
||||||
|
@ -63,43 +62,6 @@ class Licenser
|
||||||
if !File.exist?(@known_exceptions_file)
|
if !File.exist?(@known_exceptions_file)
|
||||||
raise "Known exceptions file does not exist: #{@known_exceptions_file}"
|
raise "Known exceptions file does not exist: #{@known_exceptions_file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@scan_only
|
|
||||||
raise("Properties file must contain a value for 'target_dir'") if @target_dir == nil
|
|
||||||
raise("Properties file must contain a value for 'license_file'") if @license_file == nil
|
|
||||||
|
|
||||||
if File.exist?(@target_dir)
|
|
||||||
raise "Target directory already exists: #{@target_dir}"
|
|
||||||
end
|
|
||||||
|
|
||||||
target_parent = File.dirname(@target_dir)
|
|
||||||
if !File.exist?(target_parent)
|
|
||||||
raise "Path to target directory doesn't exist: #{target_parent}"
|
|
||||||
end
|
|
||||||
|
|
||||||
if !File.exist?(@license_file)
|
|
||||||
raise "License file does not exist: #{@license_file}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Prepare the license as an array of lines of text,
|
|
||||||
# with the current year substituted in for ${year}
|
|
||||||
#
|
|
||||||
def prepare_license_text(license_file)
|
|
||||||
if (license_file == nil)
|
|
||||||
return []
|
|
||||||
end
|
|
||||||
|
|
||||||
year_string = DateTime.now.year.to_s
|
|
||||||
|
|
||||||
text = []
|
|
||||||
File.open(license_file) do |file|
|
|
||||||
file.each do |line|
|
|
||||||
text << line.gsub('${year}', year_string)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return text
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# The globs in the exceptions file are assumed to be
|
# The globs in the exceptions file are assumed to be
|
||||||
|
@ -126,8 +88,6 @@ class Licenser
|
||||||
def scan_dir(source_dir, target_dir)
|
def scan_dir(source_dir, target_dir)
|
||||||
@stats.enter_directory(source_dir)
|
@stats.enter_directory(source_dir)
|
||||||
|
|
||||||
Dir.mkdir(File.expand_path(target_dir, @target_dir)) if !@scan_only
|
|
||||||
|
|
||||||
Dir.foreach(File.join(@source_dir, source_dir)) do |filename|
|
Dir.foreach(File.join(@source_dir, source_dir)) do |filename|
|
||||||
source_path_relative = File.join(source_dir, filename)
|
source_path_relative = File.join(source_dir, filename)
|
||||||
source_path = File.join(@source_dir, source_path_relative)
|
source_path = File.join(@source_dir, source_path_relative)
|
||||||
|
@ -162,27 +122,12 @@ class Licenser
|
||||||
elsif is_directory
|
elsif is_directory
|
||||||
scan_dir(source_path_relative, target_path_relative)
|
scan_dir(source_path_relative, target_path_relative)
|
||||||
elsif is_match
|
elsif is_match
|
||||||
if @scan_only
|
@stats.record_scan_matching(filename)
|
||||||
@stats.record_scan_matching(filename)
|
scan_file(source_path, filename)
|
||||||
scan_file(source_path, filename)
|
|
||||||
else
|
|
||||||
@stats.record_copy_matching(filename)
|
|
||||||
copy_file_with_license(source_path, target_path, filename)
|
|
||||||
end
|
|
||||||
elsif is_exception
|
elsif is_exception
|
||||||
@stats.record_known_exception(filename)
|
@stats.record_known_exception(filename)
|
||||||
if @scan_only
|
|
||||||
# do nothing
|
|
||||||
else
|
|
||||||
copy_file_without_license(source_path, target_path)
|
|
||||||
end
|
|
||||||
else # not a match
|
else # not a match
|
||||||
if @scan_only
|
@stats.record_scan_non_matching(filename)
|
||||||
@stats.record_scan_non_matching(filename)
|
|
||||||
else
|
|
||||||
@stats.record_copy_non_matching(filename)
|
|
||||||
copy_file_without_license(source_path, target_path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -215,7 +160,7 @@ class Licenser
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# This file would be eligible for licensing if we weren't in scan-only mode.
|
# This file should contain a license tag.
|
||||||
#
|
#
|
||||||
def scan_file(source_path, filename)
|
def scan_file(source_path, filename)
|
||||||
found = 0
|
found = 0
|
||||||
|
@ -236,57 +181,6 @@ class Licenser
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This file matches at least one of the file-matching strings, and does not
|
|
||||||
# match any exceptions. Replace the magic string with the license text.
|
|
||||||
#
|
|
||||||
def copy_file_with_license(source_path, target_path, filename)
|
|
||||||
found = 0
|
|
||||||
File.open(source_path) do |source_file|
|
|
||||||
File.open(target_path, "w") do |target_file|
|
|
||||||
source_file.each do |line|
|
|
||||||
if line.include?(MAGIC_STRING)
|
|
||||||
found += 1
|
|
||||||
insert_license_text(target_file, line)
|
|
||||||
else
|
|
||||||
target_file.print line
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if found == 0
|
|
||||||
@stats.record_no_tag(filename, source_path)
|
|
||||||
elsif found == 1
|
|
||||||
@stats.record_tag(filename)
|
|
||||||
else
|
|
||||||
raise("File contains #{found} license lines: #{source_path}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Figure out the comment characters and write the license text to the file.
|
|
||||||
#
|
|
||||||
def insert_license_text(target_file, line)
|
|
||||||
ends = line.split(MAGIC_STRING)
|
|
||||||
if ends.size != 2
|
|
||||||
raise ("Can't parse this license line: #{line}")
|
|
||||||
end
|
|
||||||
|
|
||||||
target_file.print "#{ends[0].strip}\n"
|
|
||||||
|
|
||||||
@license_text.each do |text|
|
|
||||||
target_file.print "#{text.rstrip}\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
target_file.print "#{ends[1].strip}\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
# This file either doesn't match any of the file-matching strings, or
|
|
||||||
# matches an exception
|
|
||||||
#
|
|
||||||
def copy_file_without_license(source_path, target_path)
|
|
||||||
FileUtils.cp(source_path, target_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------------
|
||||||
public
|
public
|
||||||
# ------------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------------
|
||||||
|
@ -296,9 +190,6 @@ class Licenser
|
||||||
# * properties is a map of keys to values, probably parsed from a properties file.
|
# * properties is a map of keys to values, probably parsed from a properties file.
|
||||||
#
|
#
|
||||||
def initialize(properties)
|
def initialize(properties)
|
||||||
@scan_only_string = properties['scan_only']
|
|
||||||
@scan_only = 'false' != @scan_only_string
|
|
||||||
|
|
||||||
@file_match_list = properties['file_matchers']
|
@file_match_list = properties['file_matchers']
|
||||||
@skip_directories_list = properties['skip_directories']
|
@skip_directories_list = properties['skip_directories']
|
||||||
@report_level_string = properties['report_level']
|
@report_level_string = properties['report_level']
|
||||||
|
@ -319,7 +210,6 @@ class Licenser
|
||||||
@short_report = @report_level_string === 'short'
|
@short_report = @report_level_string === 'short'
|
||||||
@file_matchers = @file_match_list.strip.split(/,\s*/)
|
@file_matchers = @file_match_list.strip.split(/,\s*/)
|
||||||
@skip_directories = @skip_directories_list.strip.split(/,\s*/)
|
@skip_directories = @skip_directories_list.strip.split(/,\s*/)
|
||||||
@license_text = prepare_license_text(@license_file)
|
|
||||||
@known_exceptions = prepare_exception_globs(@known_exceptions_file, @source_dir)
|
@known_exceptions = prepare_exception_globs(@known_exceptions_file, @source_dir)
|
||||||
|
|
||||||
@stats = LicenserStats.new(@source_dir, @file_matchers, @full_report)
|
@stats = LicenserStats.new(@source_dir, @file_matchers, @full_report)
|
||||||
|
@ -332,25 +222,24 @@ class Licenser
|
||||||
|
|
||||||
# Report the summary statistics
|
# Report the summary statistics
|
||||||
def report(properties)
|
def report(properties)
|
||||||
verb = @scan_only ? "scanned" : "copied"
|
|
||||||
if (@short_report)
|
if (@short_report)
|
||||||
subs = 0
|
tags = 0
|
||||||
@stats.substitutions.each {|line| subs += line[1] }
|
@stats.tagged_files.each {|line| tags += line[1] }
|
||||||
known = 0
|
known = 0
|
||||||
@stats.known_exceptions.each {|line| known += line[1] }
|
@stats.known_exceptions.each {|line| known += line[1] }
|
||||||
missing = 0
|
missing = 0
|
||||||
@stats.missing_tags.each {|line| missing += line[1] }
|
@stats.missing_tags.each {|line| missing += line[1] }
|
||||||
|
|
||||||
puts "Licenser: #{verb} #{@stats.file_count} files in #{@stats.dir_count} directories."
|
puts "Licenser: scanned #{@stats.file_count} files in #{@stats.dir_count} directories."
|
||||||
printf(" Substitutions: %5d\n", subs)
|
printf(" Licensed files: %5d\n", tags)
|
||||||
printf(" Known exceptions: %5d\n", known)
|
printf(" Known exceptions: %5d\n", known)
|
||||||
printf(" Missing tags: %5d\n", missing)
|
printf(" Missing tags: %5d\n", missing)
|
||||||
else
|
else
|
||||||
puts "Licenser: run completed at #{DateTime.now.strftime("%H:%M:%S on %b %d, %Y")}"
|
puts "Licenser: run completed at #{DateTime.now.strftime("%H:%M:%S on %b %d, %Y")}"
|
||||||
puts " #{verb} #{@stats.file_count} files in #{@stats.dir_count} directories."
|
puts " scanned #{@stats.file_count} files in #{@stats.dir_count} directories."
|
||||||
puts
|
puts
|
||||||
puts 'Substitutions'
|
puts 'Licensed files'
|
||||||
@stats.substitutions.sort.each do |line|
|
@stats.tagged_files.sort.each do |line|
|
||||||
printf("%5d %s\n", line[1], line[0])
|
printf("%5d %s\n", line[1], line[0])
|
||||||
end
|
end
|
||||||
puts
|
puts
|
||||||
|
|
|
@ -7,7 +7,7 @@ Collect the statistics of a licenser run.
|
||||||
=end
|
=end
|
||||||
|
|
||||||
class LicenserStats
|
class LicenserStats
|
||||||
attr_reader :substitutions
|
attr_reader :tagged_files
|
||||||
attr_reader :missing_tags
|
attr_reader :missing_tags
|
||||||
attr_reader :known_exceptions
|
attr_reader :known_exceptions
|
||||||
attr_reader :file_count
|
attr_reader :file_count
|
||||||
|
@ -33,10 +33,10 @@ class LicenserStats
|
||||||
@file_matchers = file_matchers
|
@file_matchers = file_matchers
|
||||||
@full = full
|
@full = full
|
||||||
|
|
||||||
# keep track of how many substitutions for all file types
|
# keep track of how many tags are found in all file types
|
||||||
@substitutions = Hash.new()
|
@tagged_files = Hash.new()
|
||||||
file_matchers.each do |matcher|
|
file_matchers.each do |matcher|
|
||||||
@substitutions[matcher] = 0
|
@tagged_files[matcher] = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# keep track of missing tags, only in file types that have missing tags
|
# keep track of missing tags, only in file types that have missing tags
|
||||||
|
@ -84,8 +84,8 @@ class LicenserStats
|
||||||
end
|
end
|
||||||
|
|
||||||
def record_tag(filename)
|
def record_tag(filename)
|
||||||
puts " Substituted license text into #{filename}" if @full
|
puts " Found license tag into #{filename}" if @full
|
||||||
@substitutions[which_match(filename)] += 1
|
@tagged_files[which_match(filename)] += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def record_no_tag(filename, source_path)
|
def record_no_tag(filename, source_path)
|
||||||
|
|
|
@ -1,37 +1,35 @@
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# Properties for running the licenser utility in Vitro core.
|
# Properties for running the licenser utility in Vitro core.
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
# The path to the top level directory to be scanned or copied
|
# The path to the top level directory to be scanned or copied
|
||||||
# (if relative, then relative to this file)
|
# (if relative, then relative to this file)
|
||||||
source_dir = ../../../
|
source_dir = ../../../
|
||||||
|
|
||||||
# The path to the top level directory to copy into (ignored if only scanning)
|
# The path to the top level directory to copy into (ignored if only scanning)
|
||||||
# (if relative, then relative to this file)
|
# (if relative, then relative to this file)
|
||||||
target_dir =
|
target_dir =
|
||||||
|
|
||||||
# A list of filename globs that match the files we want to license,
|
# A list of filename globs that match the files we want to license,
|
||||||
# delimited by commas with optional white-space.
|
# delimited by commas with optional white-space.
|
||||||
file_matchers = *.java, *.jsp, *.tld, *.xsl, *.xslt, *.css, *.js, *.ftl, *.xml
|
file_matchers = *.java, *.jsp, *.tld, *.xsl, *.xslt, *.css, *.js, *.ftl, *.xml
|
||||||
|
|
||||||
# "globs" that describe paths that we won't follow for scanning OR FOR COPYING.
|
# "globs" that describe paths that we won't follow for scanning OR FOR COPYING.
|
||||||
# (relative to the source_dir)
|
# (relative to the source_dir)
|
||||||
skip_directories = ./bin, ./.svn, ./**/.svn, ./webapp/.build
|
skip_directories = ./bin, ./.svn, ./**/.svn, ./webapp/.build
|
||||||
|
|
||||||
# The path to a file containing filename/path globs that match the files that
|
# The path to a file containing filename/path globs that match the files that
|
||||||
# we know should have no license tags in them.
|
# we know should have no license tags in them.
|
||||||
# The file contains one glob per line; blank lines and comments ("#") are ignored.
|
# The file contains one glob per line; blank lines and comments ("#") are ignored.
|
||||||
# (if relative, then relative to the source directory)
|
# (if relative, then relative to the source directory)
|
||||||
known_exceptions = webapp/config/licenser/known_exceptions.txt
|
known_exceptions = webapp/config/licenser/known_exceptions.txt
|
||||||
|
|
||||||
# The path to the text of the license agreement (ignored if only scanning)
|
# The path to the text of the license agreement (ignored if only scanning)
|
||||||
# If the agreement contains a ${year} token, the current year will be substituted.
|
# If the agreement contains a ${year} token, the current year will be substituted.
|
||||||
# (if relative, then relative to the source directory)
|
# (if relative, then relative to the source directory)
|
||||||
license_file = doc/license.txt
|
license_file = doc/license.txt
|
||||||
|
|
||||||
# Set to 'full' for a full report, 'short' for a brief statment, or to anything
|
# Set to 'full' for a full report, 'short' for a brief statment, or to anything
|
||||||
# else for a medium-length summary.
|
# else for a medium-length summary.
|
||||||
report_level = short
|
#report_level = short
|
||||||
|
report_level = medium
|
||||||
# if true, we are just scanning, not copying.
|
|
||||||
scan_only = true
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue