def test_java_imports_releases_file_on_wrong_package(self): obj = JavaPackageImports('test', 'description', 'util', 'some.other.package', metrics_logger=Mock()).configure(Mock(), False) self.assertTrue(obj.wants_file(TestMetrics.hello_date_file)) lastline = self.read_file(TestMetrics.hello_date_file, obj) self.assertIn('package', lastline, msg='parser should release the file after mismatched package.') self.assertEqual(0, self.valueof(obj))
def test_java_imports_releases_file_on_wrong_package(self): obj = JavaPackageImports('test', 'description', 'util', 'some.other.package', metrics_logger=Mock()).configure( Mock(), False) self.assertTrue(obj.wants_file(TestMetrics.hello_date_file)) lastline = self.read_file(TestMetrics.hello_date_file, obj) self.assertIn( 'package', lastline, msg='parser should release the file after mismatched package.') self.assertEqual(0, self.valueof(obj))
def __init__(self, fast: bool, file_utils: FileUtils=FileUtils()): collectors = [JavaPackageImports('usageof.easymock', 'Get rid of easymock and use Mockito', 'org.easymock'), JavaPackageImports('usageof.mockobjects', 'Get rid of mockobjects and use Mockito', 'com.mockobjects'), JunitAssertWithoutMessage('usageof.assert.true.false', 'Do not use assertTrue or assertFalse without specifying a message') .unchecked(), ModulesDescription.commonJUnitFinder, WebTestFinder().unchecked().neutral(), InvalidTimedQueries()] super().__init__(collectors, 'Scan JIRA test files') self.file_utils = file_utils
def test_java_imports_gives_up_on_class_def(self): obj = JavaPackageImports('test', 'description', 'util', metrics_logger=Mock()).configure(Mock(), False) obj.pre_files_scan('test-module') self.assertTrue(obj.wants_file(TestMetrics.hello_date_file)) lastline = self.read_file(TestMetrics.hello_date_file, obj) obj.post_files_scan('test-module') self.assertIn('//marker', lastline) self.assertEqual(1, self.valueof(obj))
def test_java_imports_gives_up_on_class_def(self): obj = JavaPackageImports('test', 'description', 'util', metrics_logger=Mock()).configure( Mock(), False) obj.pre_files_scan('test-module') self.assertTrue(obj.wants_file(TestMetrics.hello_date_file)) lastline = self.read_file(TestMetrics.hello_date_file, obj) obj.post_files_scan('test-module') self.assertIn('//marker', lastline) self.assertEqual(1, self.valueof(obj))
def test_java_imports_respects_package_whitelist(self): obj = JavaPackageImports('test', 'description', 'Manager', 'mypackage', whitelist = ['WhitelistedManager'], metrics_logger=Mock()).configure(Mock(), False) obj.pre_files_scan('test-module') self.assertTrue(obj.wants_file(TestMetrics.hello_date_file)) obj.on_read_line('package mypackage;') obj.on_read_line('import WhitelistedManager;') obj.on_read_line('import IssueManager;') obj.post_files_scan('test-module') self.assertEqual(1, self.valueof(obj))
def __init__(self, fast: bool, file_utils: FileUtils=FileUtils()): collectors = [JavaPackageImports('usageof.CacheBuilder', 'Imports of CacheBuilder: prevent caches other than EhCache', 'com.google.common.cache.CacheBuilder').unchecked(), JavaPackageImports('usageof.java.util.Calendar', 'Stop using java.util.Calendar - use joda time instead', 'java.util.Calendar'), ManagersInJiraApi(), FileCountAndSize('velocity', lambda x: x.endswith('.vm'), 'Get rid of velocity files').unchecked(), FileCountAndSize('jsp', lambda x: x.endswith('.jsp'), 'Get rid of jsp files').unchecked(), GrepCount('usageof.css.important', lambda x: x.endswith(('.css', '.less')), 'Get rid of css !important usages', '!important'), GrepCount('usageof.system.getproperty', lambda x: x.endswith('.java') and not x.endswith('/SystemPropertiesAccessor.java'), 'Get rid of System.getProperty family usages ' '(use JiraSystemProperties class if you must)', ['System.getProperty', 'System.getProperties', 'Boolean.getBoolean', 'System.clearProperty', 'Integer.getInteger', 'Long.getLong', 'System.setProperty', 'System.setProperties']), GrepCount('usageof.actioncontext.getrequest', lambda x: x.endswith('.java'), 'Get rid of ActionContext.getRequest usages', 'ActionContext.getRequest'), GrepCount('usageof.webwork.action.jelly.tag', lambda x: x.endswith('.java'), 'Jelly dependencies on webwork actions blocks their removal', ('extends ActionTagSupport', 'extends UserAwareActionTagSupport', 'extends IssueSchemeAwareActionTagSupport', 'extends ProjectAwareActionTagSupport', 'extends PermissionSchemeAwareActionTagSupport')), GrepCount('usageof.not.component.accessor', lambda x: x.endswith('.java'), 'Should use component accessor to get components', ['import com.atlassian.jira.ComponentManager', 'import com.atlassian.jira.ManagerFactory', 'import com.atlassian.jira.util.ComponentLocator' 'import com.atlassian.jira.plugin.ComponentClassManager'], 'class'), GrepCount('tests.qunit.core.count', lambda x: x.endswith(('-test.js', '-tests.js')), 'Keep count of Qunit tests', ['test(', 'asyncTest(']).unchecked().rising(), GrepCount('frontend.number.of.soy.templates', lambda x: x.endswith('.soy'), 'Keep count of soy templates', '{/template}').unchecked().rising(), GrepCount('frontend.number.of.ww.tags', lambda x: x.endswith('.jsp'), 'Get rid of jsp webwork tags', '<ww:').unchecked(), GrepCount('frontend.number.of.velocity.macros', lambda x: x.endswith('.vm'), 'Rewrite velocity macros to soy', lambda x: x.strip().startswith('#macro')), GrepCount('frontend.number.of.css.rules', lambda x: x.endswith(('.css', '.less')), 'Keep track of styles complexity.', '{').unchecked(), GrepCount('frontend.number.of.lcss.mixins.invocations', lambda x: x.endswith('.less'), 'Keep track of mixin complexity.', lambda line: ');' in line and ':' not in line).unchecked(), FileCount('soy', lambda x: x.endswith('.soy'), 'Keep count of soy files.').unchecked().rising(), FileCount('frontend.helpers', lambda x: any(path in x for path in ['/webapp/template/aui/', 'webapp/template/standard', 'webapp/ui/aui-layout']), 'Number of files with JIRA exceptions in AUI').unchecked(), JavaPackageImports('usageof.generic.value.webwork.action', 'Should not be using GenericValue in webwork actions', 'org.ofbiz.core.entity.GenericValue', 'web.action'), JavaPackageImports('usageof.property.set.webwork.action', 'Should not be using Property Set in webwork actions', 'com.opensymphony.module.propertyset.PropertySet', 'web.action'), JavaPackageImports('usageof.crowd.user', 'use UserRename user', 'com.atlassian.crowd.embedded.api.User').unchecked(), JavaPackageImports('usageof.event.publisher.webwork.action', 'Should not be using Event Publisher in webwork actions', 'com.atlassian.event.api.EventPublisher', 'web.action'), JavaPackageImports('usageof.issue.event.dispatcher.webwork.action', 'Should not be using IssueEventDispatcher in webwork actions', 'com.atlassian.jira.event.issue.IssueEventDispatcher', 'web.action'), JavaPackageImports('usageof.issue.event.manager.webwork.action', 'Should not be using IssueEventManager in webwork actions', 'com.atlassian.jira.event.issue.IssueEventManager', 'web.action'), JavaPackageImports('usageof.ofbiz.delegator.interface.webwork.action', 'Should not be calling straight to Ofbiz in webwork actions ' '(DelegatorInterface)', 'org.ofbiz.core.entity.DelegatorInterface', 'web.action'), JavaPackageImports('usageof.ofbiz.delegator.webwork.action', 'Should not be calling straight to Ofbiz in webwork actions (OfBizDelegator)', 'com.atlassian.jira.ofbiz.OfBizDelegator', 'web.action'), JavaPackageImports('usageof.entity.engine.webwork.action', 'Should not be calling straight to Ofbiz in webwork actions (EntityEngine)', 'com.atlassian.jira.entity.EntityEngine', 'web.action'), JavaPackageImports('usageof.managers.webwork.action', 'Should not be using Managers in webwork actions', 'Manager', 'web.action', whitelist = ['.FeatureManager']), ModulesDescription.commonJUnitFinder, InvocationOfSoyTemplates().unchecked().rising(), InvocationOfVelocityMacros().unchecked()] + ([] if fast else [DeprecatedMethodUsage().unchecked()]) super().__init__(collectors, 'Scan JIRA source files') self.file_utils = file_utils
def test_java_imports_respects_package_whitelist(self): obj = JavaPackageImports('test', 'description', 'Manager', 'mypackage', whitelist=['WhitelistedManager'], metrics_logger=Mock()).configure( Mock(), False) obj.pre_files_scan('test-module') self.assertTrue(obj.wants_file(TestMetrics.hello_date_file)) obj.on_read_line('package mypackage;') obj.on_read_line('import WhitelistedManager;') obj.on_read_line('import IssueManager;') obj.post_files_scan('test-module') self.assertEqual(1, self.valueof(obj))