-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaGitMiner.py
63 lines (49 loc) · 1.76 KB
/
JavaGitMiner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from concurrent.futures.thread import ThreadPoolExecutor
import jpype
import pandas
import FrechetDistance
import repoDB_Options
import getpass
executor = ThreadPoolExecutor(5)
class GitMiner():
def __init__(self, jar_path = 'GitMiner-1.0-SNAPSHOT.jar') -> None:
super().__init__()
# 指定jar包位置, 或者.class文件
self.jar_path = os.path.join(os.path.abspath('.'), jar_path)
# 开启JVM,且指定jar包, 或者.class文件位置
jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Djava.class.path=%s" % self.jar_path)
self.frechet = FrechetDistance.FrechetDistance()
def get_path_prefix_from_url(self,url):
repo_name = ""
stringlist = url.split("/")
tmp_name = stringlist[len(stringlist) - 1]
tmp_name = tmp_name.split('.')
repo_name = tmp_name[0]
print("this repo_name is" + repo_name)
db = repoDB_Options.repoDB_Options()
prefix = str(db.get_repo_path_prefix(repo_name))
return prefix
def git_clone(self, url):
# 引入java程序中的类.路径应该是项目中的package包路径.类名
MainDataGenerator = jpype.JClass('LaunchFunction.MainDataGenerator')
# 创建一个对象
mdg = MainDataGenerator()
# 执行类中的函数了
res = mdg.generateNew(url)
print("git clone res = ", res)
# res为1的话,则本地有项目了
if res == 0:
try:
path_prefix = self.get_path_prefix_from_url(url)
self.frechet.get_frechet_distance(path_prefix)
except pandas.errors.ParserError as e:
print(e)
except FileNotFoundError as e:
print(e)
return res
if __name__ == '__main__':
git_miner = GitMiner()
res = git_miner.git_clone(url="[email protected]:OpenSrcRepoDataMining/alluxio.git")
# res = git_miner.git_clone(url="[email protected]:njubigdata04/InvertedIndexWithHbase.git")
print(res)