def main(args): log.debug('main got args: %s' % args) for arg in args: if arg.endswith('.jar'): zp = ZipFile(arg) for f in zp.filelist: if f.filename.endswith('.class'): print print print '%s' % f.filename, foo = ClassFile(zp.read(f.filename)) print ' => methods:%s, interfaces:%s' % (len( foo.methods()), len(foo.interfaces())) print foo zp.close()
def main(args): log.debug('main got args: %s' % args) for arg in args: if arg.endswith('.jar'): zp = ZipFile(arg) for f in zp.filelist: if f.filename.endswith('.class'): print print print '%s' % f.filename, foo = ClassFile(zp.read(f.filename)) print ' => methods:%s, interfaces:%s' % ( len(foo.methods()), len(foo.interfaces())) print foo zp.close()
def _compute_source_deps(self): """ Compute the set of dependencies actually used by the source files in the targets for the compilation task being analyzed. """ # Get the class products from the compiler. This provides us with all the info we # need about what source file/target produces what class. class_products = self.task.context.products.get('classes') for target in self.targets: # for each target, compute a mapping from classes that the target generates to the target # this mapping is self.targets_by_class if target not in class_products.by_target: # If the target isn't in the products map, that means that it had no products - which # only happens if the target has no source files. This occurs when a target is created # as a placeholder. continue for outdir in class_products.by_target[target]: for cl in class_products.by_target[target][outdir]: self.targets_by_class[cl].add(target) # For each source in the current target, compute a mapping from source files to the classes that they # really depend on. (Done by parsing class files.) for source in target.sources: # we can get the set of classes from a source file by going into the same class_products object source_file_deps = set() class_files = set() for dir in class_products.by_target[source]: class_files |= set([ ( clfile, dir) for clfile in class_products.by_target[source][dir] ]) # for each class file, get the set of referenced classes - these # are the classes that it depends on. for (cname, cdir) in class_files: cf = ClassFile.from_file(os.path.join(cdir, cname), False) dep_set = cf.get_external_class_references() dep_classfiles = [ "%s.class" % s for s in dep_set ] source_file_deps = source_file_deps.union(dep_classfiles) self.deps_by_source[source] = source_file_deps # add data from these classes to the target data in the map. self.class_deps_by_target[target].update(source_file_deps)
def setup_class(cls): cls._class_file = ClassFile( pkgutil.get_data(__name__, _EXAMPLE_RESOURCE))
# ================================================================================================== # Copyright 2011 Twitter, Inc. # -------------------------------------------------------------------------------------------------- # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this work except in compliance with the License. # You may obtain a copy of the License in the LICENSE file, or 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 from twitter.common import options from twitter.common.java.class_file import ClassFile if __name__ == '__main__': values, args = options.parse() for arg in args: cf = ClassFile.from_file(arg) print os.path.abspath(arg) print cf print
def main(args): for arg in args: cf = ClassFile.from_file(arg) print os.path.abspath(arg) print cf print
def setUpClass(cls): cls._class_data = pkgutil.get_data('twitter.common.java', _EXAMPLE_RESOURCE) assert cls._class_data is not None cls._class_file = ClassFile(cls._class_data)