From 7d39a5cf6669e5be7f1c0954864b0919823de9ab Mon Sep 17 00:00:00 2001 From: Alan Gates Date: Fri, 18 Mar 2016 13:51:49 -0700 Subject: Initial python to find public APIs in Hadoop and compare them to output of the jar analyzer. This needs integrated with James' scripts to replace the GPL jar analyzer. --- .../runtime/src/test/python/find-public-apis.py | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 bigtop-tests/spec-tests/runtime/src/test/python/find-public-apis.py (limited to 'bigtop-tests') diff --git a/bigtop-tests/spec-tests/runtime/src/test/python/find-public-apis.py b/bigtop-tests/spec-tests/runtime/src/test/python/find-public-apis.py new file mode 100755 index 00000000..091c496e --- /dev/null +++ b/bigtop-tests/spec-tests/runtime/src/test/python/find-public-apis.py @@ -0,0 +1,80 @@ +#!/usr/bin/python + +''' +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +''' + +import os +import re +import warnings +from optparse import OptionParser + +def main(): + parser = OptionParser() + parser.add_option("-d", "--directory", help="Top level directory of source tree") + parser.add_option("-r", "--report", help="API compatibility report file, in HTML format") + + (options, args) = parser.parse_args() + + # Get the ATS endpoint if it's not given. + if options.directory == None: + print "You must specify a top level directory of the source tree" + return 1 + + if options.report == None: + print "You must specify the report to check against" + return 1 + + publicClasses = set() + for directory in os.walk(options.directory): + for afile in directory[2]: + if re.search("\.java$", afile) != None: + handle = open(os.path.join(directory[0], afile)) + # Figure out the package we're in + pre = re.search("org/apache/hadoop[\w/]*", directory[0]) + if pre == None: + warnings.warn("No package for " + directory[0]) + continue + package = pre.group(0) + expecting = 0 + for line in handle: + if re.search("@InterfaceAudience.Public", line) != None: + expecting = 1 + classname = re.search("class (\w*)", line) + if classname != None and expecting == 1: + publicClasses.add(package + "/" + classname.group(1)) + expecting = 0 + handle.close() + + handle = open(options.report) + haveChecked = set() + for line in handle: + classre = re.search("mangled: (org/apache/hadoop[\w/]+)", line) + if classre != None: + classname = classre.group(1) + if classname not in haveChecked: + if classname in publicClasses: + print "Warning, found change in public class " + classname + haveChecked.add(classname) + handle.close() + + + + +main() + + -- cgit v1.2.3