Author: sebb
Date: Thu Apr 26 16:47:59 2018
New Revision: 1830243
URL: http://svn.apache.org/viewvc?rev=1830243&view=rev
Log:
Add code to optionally check URLs
Modified:
attic/site-jekyll/src/_plugins/generate_projects.rb
Modified: attic/site-jekyll/src/_plugins/generate_projects.rb
URL:
http://svn.apache.org/viewvc/attic/site-jekyll/src/_plugins/generate_projects.rb?rev=1830243&r1=1830242&r2=1830243&view=diff
==============================================================================
--- attic/site-jekyll/src/_plugins/generate_projects.rb (original)
+++ attic/site-jekyll/src/_plugins/generate_projects.rb Thu Apr 26 16:47:59 2018
@@ -5,6 +5,10 @@
require 'json'
+# define the environment variable to run checks
+# Use the value 'Subversion' to also check viewvc URLs (more expensive)
+CHECK_URLS=ENV['CHECK_URLS']
+
module Jekyll
class ProjectPage < Page
def initialize(site, prj)
@@ -75,6 +79,11 @@ module Jekyll
# N.B. the variable name must agree with that used by the template
# Also it should not be one of the Jekyll page variable names.
self.data['json'] = prj # pass the massaged data from projects.json
+
+ # Optionally check all the URLs
+ if CHECK_URLS
+ checkUrls prj
+ end
end
end
@@ -90,3 +99,40 @@ module Jekyll
end
end
end
+
+if CHECK_URLS
+
+ private
+
+ require "net/http"
+ def url_exist?(url_string)
+ url = URI.parse(url_string)
+ req = Net::HTTP.new(url.host, url.port)
+ req.use_ssl = (url.scheme == 'https')
+ path = url.path if url.path
+ res = req.request_head(path || '/')
+ if res.kind_of?(Net::HTTPRedirection)
+ location = res['Location']
+ new_uri = URI.parse(location)
+ uri_str = if new_uri.relative? then url + location else new_uri.to_s end
+ url_exist?(uri_str.to_s) # Go after any redirect and make sure you can
access the redirected URL
+ else
+ unless res.code == "200"
+ puts "** Cannot find #{url_string} : #{res.code}"
+ end
+ end
+ rescue => e
+ puts "** Cannot find #{url_string} : #{e.inspect}"
+ end
+ def checkUrls(prj)
+ puts prj['name']
+ list = %W{wiki issueURL website} # scmURL may trigger blocky
+ list << 'scmURL' unless prj['scmType'] == 'Subversion' and CHECK_URLS !=
'Subversion'
+ list.each do |item|
+ if prj[item] and prj[item] != ''
+ url_exist? prj[item]
+ end
+ end
+ url_exist? "http://archive.apache.org/dist/#{prj['dist']}" if prj['dist']
+ end
+end