1
|
|
|
from coalib.bears.Bear import Bear |
2
|
|
|
from coalib.bears.BEAR_KIND import BEAR_KIND |
3
|
|
|
from coalib.settings.FunctionMetadata import FunctionMetadata |
4
|
|
|
|
5
|
|
|
|
6
|
|
View Code Duplication |
class ProjectWideBear(Bear): |
|
|
|
|
7
|
|
|
""" |
8
|
|
|
A ProjectWideBear is a Bear that analyzes all files at once. This has the |
9
|
|
|
advantage of drawing advanced semantic analysis that give results that are |
10
|
|
|
applicable to the whole codebase. |
11
|
|
|
""" |
12
|
|
|
|
13
|
|
|
def __init__(self, |
14
|
|
|
file_set, # A set of file_proxies |
15
|
|
|
section, |
16
|
|
|
message_queue, |
17
|
|
|
timeout=0): |
18
|
|
|
Bear.__init__(self, section, message_queue, timeout) |
19
|
|
|
self.file_set = file_set |
20
|
|
|
|
21
|
|
|
self.kwargs = self.get_metadata().create_params_from_section(section) |
22
|
|
|
|
23
|
|
|
@staticmethod |
24
|
|
|
def kind(): |
25
|
|
|
return BEAR_KIND.PROJECTWIDE |
26
|
|
|
|
27
|
|
|
def execute_task(self, task, kwargs): |
28
|
|
|
""" |
29
|
|
|
This method is responsible for getting results from the |
30
|
|
|
analysis routines. |
31
|
|
|
""" |
32
|
|
|
return list(self.analyze(task, **kwargs)) |
33
|
|
|
|
34
|
|
|
def analyze(self, |
35
|
|
|
file_set, |
36
|
|
|
*args, |
37
|
|
|
dependency_results=None, |
38
|
|
|
**kwargs): |
39
|
|
|
""" |
40
|
|
|
Handles the given file. |
41
|
|
|
|
42
|
|
|
:param file_set: A set of FileProxy objects. |
43
|
|
|
:return: A list of Result |
44
|
|
|
""" |
45
|
|
|
raise NotImplementedError("This function has to be implemented for a " |
46
|
|
|
"runnable bear.") |
47
|
|
|
|
48
|
|
|
def generate_tasks(self): |
49
|
|
|
""" |
50
|
|
|
This method is responsible for providing the files and arguments for |
51
|
|
|
the tasks the bear needs to perform. |
52
|
|
|
""" |
53
|
|
|
return [self.file_set, self.kwargs] |
54
|
|
|
|
55
|
|
|
@classmethod |
56
|
|
|
def get_metadata(cls): |
57
|
|
|
return FunctionMetadata.from_function( |
58
|
|
|
cls.run, |
59
|
|
|
omit={"self", "file_proxy", "dependency_results"}) |
|
|
|
|