Beispiel #1
0
 def handle_noargs(self, **options):
     pname = smart_decode(options.get('pname'))
     bname = smart_decode(options.get('bname'))
     release = smart_decode(options.get('release'))
     create_code_db(pname, bname, release)
     if options.get('local', False):
         create_code_local(pname, bname, release)
         if options.get('link', False):
             link_eclipse(pname, bname, release)
Beispiel #2
0
 def handle_noargs(self, **options):
     pname = smart_decode(options.get('pname'))
     bname = smart_decode(options.get('bname'))
     release = smart_decode(options.get('release'))
     create_code_db(pname, bname, release)
     if options.get('local', False):
         create_code_local(pname, bname, release)
         if options.get('link', False):
             link_eclipse(pname, bname, release)
Beispiel #3
0
    def testCodeWords(self):
        create_code_db('project1', 'core', '3.0')

        parse_code('project1', 'core', '3.0', 'java')

        code_words =\
            get_project_code_words(Project.objects.get(dir_name='project1'))

        self.assertTrue('rootapplication' in code_words)
        self.assertTrue('tag2' in code_words)
        self.assertTrue('dog' not in code_words)
        self.assertEqual(10, len(code_words))
Beispiel #4
0
    def testCodeWords(self):
        create_code_db('project1', 'core', '3.0')

        parse_code('project1', 'core', '3.0', 'java')

        code_words =\
            get_project_code_words(Project.objects.get(dir_name='project1'))

        self.assertTrue('rootapplication' in code_words)
        self.assertTrue('tag2' in code_words)
        self.assertTrue('dog' not in code_words)
        self.assertEqual(10, len(code_words))
Beispiel #5
0
 def testListCodeDB(self):
     self.assertEqual(0, len(list_code_db('project1')))
     create_code_db('project1', 'core', '3.0')
     self.assertEqual(1, len(list_code_db('project1')))
     create_code_db('project1', 'lib', '3.0')
     create_code_db('project1', 'core', '3.1')
     self.assertEqual(3, len(list_code_db('project1')))
Beispiel #6
0
 def testListCodeDB(self):
     self.assertEqual(0, len(list_code_db('project1')))
     create_code_db('project1', 'core', '3.0')
     self.assertEqual(1, len(list_code_db('project1')))
     create_code_db('project1', 'lib', '3.0')
     create_code_db('project1', 'core', '3.1')
     self.assertEqual(3, len(list_code_db('project1')))
Beispiel #7
0
    def testJavaDiff(self):
        create_code_db('project1', 'core', '3.0')
        create_code_db('project1', 'core', '3.1')
        parse_code('project1', 'core', '3.0', 'java')
        parse_code('project1', 'core', '3.1', 'java')
        cdiff = diff_codebases('project1', 'core', '3.0', '3.1')

        self.assertEqual(4, cdiff.packages_size_from)
        self.assertEqual(5, cdiff.packages_size_to)
        self.assertEqual(1, cdiff.added_packages.count())
        self.assertEqual(0, cdiff.removed_packages.count())

        self.assertEqual(18, cdiff.types_size_from)
        self.assertEqual(19, cdiff.types_size_to)
        self.assertEqual(1, cdiff.added_types.count())
        self.assertEqual(1, cdiff.removed_types.count())

        self.assertEqual(44, cdiff.methods_size_from)
        self.assertEqual(44, cdiff.methods_size_to)
        self.assertEqual(1, cdiff.added_methods.count())
        self.assertEqual(1, cdiff.removed_methods.count())

        self.assertEqual(3, cdiff.fields_size_from)
        self.assertEqual(4, cdiff.fields_size_to)
        self.assertEqual(0, cdiff.added_fields.count())
        self.assertEqual(0, cdiff.removed_fields.count())

        self.assertEqual(6, cdiff.ann_fields_size_from)
        self.assertEqual(5, cdiff.ann_fields_size_to)
        self.assertEqual(0, cdiff.added_ann_fields.count())
        self.assertEqual(1, cdiff.removed_ann_fields.count())

        self.assertEqual(5, cdiff.enum_values_size_from)
        self.assertEqual(7, cdiff.enum_values_size_to)
        self.assertEqual(0, cdiff.added_enum_values.count())
        self.assertEqual(0, cdiff.removed_enum_values.count())
Beispiel #8
0
    def testJavaDiff(self):
        create_code_db('project1', 'core', '3.0')
        create_code_db('project1', 'core', '3.1')
        parse_code('project1', 'core', '3.0', 'java')
        parse_code('project1', 'core', '3.1', 'java')
        cdiff = diff_codebases('project1', 'core', '3.0', '3.1')

        self.assertEqual(4, cdiff.packages_size_from)
        self.assertEqual(5, cdiff.packages_size_to)
        self.assertEqual(1, cdiff.added_packages.count())
        self.assertEqual(0, cdiff.removed_packages.count())

        self.assertEqual(18, cdiff.types_size_from)
        self.assertEqual(19, cdiff.types_size_to)
        self.assertEqual(1, cdiff.added_types.count())
        self.assertEqual(1, cdiff.removed_types.count())

        self.assertEqual(44, cdiff.methods_size_from)
        self.assertEqual(44, cdiff.methods_size_to)
        self.assertEqual(1, cdiff.added_methods.count())
        self.assertEqual(1, cdiff.removed_methods.count())

        self.assertEqual(3, cdiff.fields_size_from)
        self.assertEqual(4, cdiff.fields_size_to)
        self.assertEqual(0, cdiff.added_fields.count())
        self.assertEqual(0, cdiff.removed_fields.count())

        self.assertEqual(6, cdiff.ann_fields_size_from)
        self.assertEqual(5, cdiff.ann_fields_size_to)
        self.assertEqual(0, cdiff.added_ann_fields.count())
        self.assertEqual(1, cdiff.removed_ann_fields.count())

        self.assertEqual(5, cdiff.enum_values_size_from)
        self.assertEqual(7, cdiff.enum_values_size_to)
        self.assertEqual(0, cdiff.added_enum_values.count())
        self.assertEqual(0, cdiff.removed_enum_values.count())
Beispiel #9
0
 def create_codebase(self):
     self.codebase = create_code_db(self.pname, 'core', self.release)
     parse_code(self.pname, 'core', self.release, 'java')
Beispiel #10
0
 def testCreateCodeDB(self):
     create_code_db('project1', 'core', '3.0')
     self.assertEqual(1, CodeBase.objects.all().count())
Beispiel #11
0
    def testJavaCodeParser(self):
        create_code_db('project1', 'core', '3.0')

        codebase = parse_code('project1', 'core', '3.0', 'java')

        ### Test some Classes ###
        ce = CodeElement.objects.get(fqn='RootApplication')
        self.assertEqual('RootApplication', ce.simple_name)
        self.assertEqual('class', ce.kind.kind)
        # Test containees & containers
        self.assertEqual(1, ce.containees.count())
        self.assertEqual('package', ce.containers.all()[0].kind.kind)
        self.assertEqual('', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Application')
        self.assertEqual('Application', ce.simple_name)
        self.assertEqual('class', ce.kind.kind)
        # Test containees & containers
        self.assertEqual(1, ce.containees.count())
        self.assertEqual('package', ce.containers.all()[0].kind.kind)
        self.assertEqual('p1', ce.containers.all()[0].fqn)

        self.assertEqual(2,
                CodeElement.objects.filter(simple_name='Application').count())

        # Test hierarchy
        ce = CodeElement.objects.get(fqn='p1.AnimalException')
        # Nothing because the parent is not in the codebase
        # (java.lang.Exception)
        self.assertEqual(0, ce.parents.count())

        ce = CodeElement.objects.get(fqn='p1.p2.Dog')
        fqns = [parent.fqn for parent in ce.parents.all()]
        self.assertTrue('p1.p2.Canidae' in fqns)
        self.assertTrue('p1.p2.Tag' in fqns)
        self.assertTrue('p1.p2.Tag2' in fqns)

        # Test internal classes
        ce = CodeElement.objects.get(fqn='p3.Special.InnerSpecial')
        self.assertEqual('InnerSpecial', ce.simple_name)
        self.assertEqual('p3.Special', ce.containers.all()[0].fqn)
        self.assertEqual('method1', ce.containees.all()[0].simple_name)
        self.assertEqual('p3.Special.InnerSpecial.method1',
                ce.containees.all()[0].fqn)

        ### Test some Methods and Parameters ###
        ce = CodeElement.objects.get(fqn='p1.BigCat.doSomething')
        method = ce.methodelement
        self.assertEqual(4, method.parameters_length)
        self.assertTrue(MethodElement.objects.filter(simple_name='doSomething')
                .filter(parameters_length=4).exists())
        self.assertEqual(4, ce.parameters().count())
        self.assertEqual('method', ce.kind.kind)
        # Test container
        self.assertEqual('p1.BigCat', ce.containers.all()[0].fqn)

        self.assertEqual('specials', ce.parameters().all()[3].simple_name)
        # Array info is stripped from type.
        self.assertEqual('byte', ce.parameters().all()[2].type_fqn)
        # Generic info is stripped from type
        self.assertEqual('java.util.List', ce.parameters().all()[3].type_fqn)
        self.assertEqual('method parameter',
                ce.parameters().all()[3].kind.kind)

        ce = CodeElement.objects.get(fqn='p1.Animal.getParents')
        self.assertEqual('java.util.Collection', ce.methodelement.return_fqn)
        self.assertEqual('method', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Animal', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Animal.run')
        self.assertEqual('void', ce.methodelement.return_fqn)
        self.assertEqual('method', ce.kind.kind)

        ### Test some Fields ###
        ce = CodeElement.objects.get(fqn='p1.Animal.MAX_AGE')
        self.assertEqual('MAX_AGE', ce.simple_name)
        self.assertEqual('int', ce.fieldelement.type_simple_name)
        self.assertEqual('int', ce.fieldelement.type_fqn)
        self.assertEqual('field', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Animal', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Cat.name')
        self.assertEqual('java.lang.String', ce.fieldelement.type_fqn)
        self.assertEqual('field', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Cat', ce.containers.all()[0].fqn)

        ### Test some Enumerations ###
        ce = CodeElement.objects.get(fqn='p1.AnimalType')
        self.assertEqual('enumeration', ce.kind.kind)
        self.assertTrue(ce.kind.is_type)
        self.assertEqual('enumeration value',
                ce.containees.all()[0].kind.kind)
        self.assertEqual('p1.AnimalType',
                ce.containees.all()[0].fieldelement.type_fqn)
        simple_names = [v.simple_name for v in ce.containees.all()]
        self.assertTrue('NOT_SURE' in simple_names)
        self.assertEqual(3, len(simple_names))

        ce = CodeElement.objects.get(fqn='p1.SubAnimalType')
        self.assertEqual('enumeration', ce.kind.kind)
        self.assertTrue(ce.kind.is_type)
        simple_names = [v.simple_name for v in ce.containees.all()]
        self.assertTrue('SOFT' in simple_names)
        # Because it is private!
        self.assertTrue('SubAnimalType' not in simple_names)
        self.assertTrue('getOther' in simple_names)
        self.assertTrue('other' not in simple_names)
        self.assertEqual(3, len(simple_names))

        ### Test some Annotations ###
        ce = CodeElement.objects.get(fqn='p1.AnimalTag')
        self.assertEqual('annotation', ce.kind.kind)
        self.assertEqual('annotation field', ce.containees.all()[0].kind.kind)
        fooBar = ce.containees.filter(simple_name='fooBar').all()[0]
        self.assertEqual('java.lang.String', fooBar.fieldelement.type_fqn)
        self.assertEqual(6, ce.containees.count())

        self.assertEqual(106, codebase.code_elements.count())

        clear_code_elements('project1', 'core', '3.0', 'xml')
        self.assertEqual(106, codebase.code_elements.count())
        clear_code_elements('project1', 'core', '3.0')
        self.assertEqual(0, codebase.code_elements.count())
Beispiel #12
0
 def testCreateCodeDB(self):
     create_code_db('project1', 'core', '3.0')
     self.assertEqual(1, CodeBase.objects.all().count())
Beispiel #13
0
    def testJavaCodeParser(self):
        create_code_db('project1', 'core', '3.0')

        codebase = parse_code('project1', 'core', '3.0', 'java')

        ### Test some Classes ###
        ce = CodeElement.objects.get(fqn='RootApplication')
        self.assertEqual('RootApplication', ce.simple_name)
        self.assertEqual('class', ce.kind.kind)
        # Test containees & containers
        self.assertEqual(1, ce.containees.count())
        self.assertEqual('package', ce.containers.all()[0].kind.kind)
        self.assertEqual('', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Application')
        self.assertEqual('Application', ce.simple_name)
        self.assertEqual('class', ce.kind.kind)
        # Test containees & containers
        self.assertEqual(1, ce.containees.count())
        self.assertEqual('package', ce.containers.all()[0].kind.kind)
        self.assertEqual('p1', ce.containers.all()[0].fqn)

        self.assertEqual(
            2,
            CodeElement.objects.filter(simple_name='Application').count())

        # Test hierarchy
        ce = CodeElement.objects.get(fqn='p1.AnimalException')
        # Nothing because the parent is not in the codebase
        # (java.lang.Exception)
        self.assertEqual(0, ce.parents.count())

        ce = CodeElement.objects.get(fqn='p1.p2.Dog')
        fqns = [parent.fqn for parent in ce.parents.all()]
        self.assertTrue('p1.p2.Canidae' in fqns)
        self.assertTrue('p1.p2.Tag' in fqns)
        self.assertTrue('p1.p2.Tag2' in fqns)

        # Test internal classes
        ce = CodeElement.objects.get(fqn='p3.Special.InnerSpecial')
        self.assertEqual('InnerSpecial', ce.simple_name)
        self.assertEqual('p3.Special', ce.containers.all()[0].fqn)
        self.assertEqual('method1', ce.containees.all()[0].simple_name)
        self.assertEqual('p3.Special.InnerSpecial.method1',
                         ce.containees.all()[0].fqn)

        ### Test some Methods and Parameters ###
        ce = CodeElement.objects.get(fqn='p1.BigCat.doSomething')
        method = ce.methodelement
        self.assertEqual(4, method.parameters_length)
        self.assertTrue(
            MethodElement.objects.filter(simple_name='doSomething').filter(
                parameters_length=4).exists())
        self.assertEqual(4, ce.parameters().count())
        self.assertEqual('method', ce.kind.kind)
        # Test container
        self.assertEqual('p1.BigCat', ce.containers.all()[0].fqn)

        self.assertEqual('specials', ce.parameters().all()[3].simple_name)
        # Array info is stripped from type.
        self.assertEqual('byte', ce.parameters().all()[2].type_fqn)
        # Generic info is stripped from type
        self.assertEqual('java.util.List', ce.parameters().all()[3].type_fqn)
        self.assertEqual('method parameter',
                         ce.parameters().all()[3].kind.kind)

        ce = CodeElement.objects.get(fqn='p1.Animal.getParents')
        self.assertEqual('java.util.Collection', ce.methodelement.return_fqn)
        self.assertEqual('method', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Animal', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Animal.run')
        self.assertEqual('void', ce.methodelement.return_fqn)
        self.assertEqual('method', ce.kind.kind)

        ### Test some Fields ###
        ce = CodeElement.objects.get(fqn='p1.Animal.MAX_AGE')
        self.assertEqual('MAX_AGE', ce.simple_name)
        self.assertEqual('int', ce.fieldelement.type_simple_name)
        self.assertEqual('int', ce.fieldelement.type_fqn)
        self.assertEqual('field', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Animal', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Cat.name')
        self.assertEqual('java.lang.String', ce.fieldelement.type_fqn)
        self.assertEqual('field', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Cat', ce.containers.all()[0].fqn)

        ### Test some Enumerations ###
        ce = CodeElement.objects.get(fqn='p1.AnimalType')
        self.assertEqual('enumeration', ce.kind.kind)
        self.assertTrue(ce.kind.is_type)
        self.assertEqual('enumeration value', ce.containees.all()[0].kind.kind)
        self.assertEqual('p1.AnimalType',
                         ce.containees.all()[0].fieldelement.type_fqn)
        simple_names = [v.simple_name for v in ce.containees.all()]
        self.assertTrue('NOT_SURE' in simple_names)
        self.assertEqual(3, len(simple_names))

        ce = CodeElement.objects.get(fqn='p1.SubAnimalType')
        self.assertEqual('enumeration', ce.kind.kind)
        self.assertTrue(ce.kind.is_type)
        simple_names = [v.simple_name for v in ce.containees.all()]
        self.assertTrue('SOFT' in simple_names)
        # Because it is private!
        self.assertTrue('SubAnimalType' not in simple_names)
        self.assertTrue('getOther' in simple_names)
        self.assertTrue('other' not in simple_names)
        self.assertEqual(3, len(simple_names))

        ### Test some Annotations ###
        ce = CodeElement.objects.get(fqn='p1.AnimalTag')
        self.assertEqual('annotation', ce.kind.kind)
        self.assertEqual('annotation field', ce.containees.all()[0].kind.kind)
        fooBar = ce.containees.filter(simple_name='fooBar').all()[0]
        self.assertEqual('java.lang.String', fooBar.fieldelement.type_fqn)
        self.assertEqual(6, ce.containees.count())

        self.assertEqual(106, codebase.code_elements.count())

        clear_code_elements('project1', 'core', '3.0', 'xml')
        self.assertEqual(106, codebase.code_elements.count())
        clear_code_elements('project1', 'core', '3.0')
        self.assertEqual(0, codebase.code_elements.count())