4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.gitea;
17 |
18 | /**
19 | * Gitea related exception
20 | *
21 | * @author zhanggx
22 | */
23 | public class GiteaException extends Exception {
24 |
25 | public GiteaException(String message) {
26 | super(message);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/GiteeException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.gitee;
17 |
18 | /**
19 | * Gitee related exception
20 | *
21 | * @author zhanggx
22 | */
23 | public class GiteeException extends Exception {
24 |
25 | public GiteeException(String message) {
26 | super(message);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/docs/API.md:
--------------------------------------------------------------------------------
1 | ### Kooder Search API
2 |
3 | **搜索接口**
4 |
5 | GET(POST): /search/repositories #仓库搜索
6 |
7 | |参数名 |参数含义 | 示例|
8 | --- | --- | ---
9 | |q|搜索关键字|q=password|
10 | |lang|指定编程语言(不支持多值)|lang=Java|
11 | |e.id|搜索指定企业的仓库(仅限 gitee)|e.id=1213|
12 | |sort|排序方法(stars,forks,update)|sort=update|
13 | |p|页码(每页20条)|p=3|
14 |
15 | GET(POST): /search/codes #代码搜索
16 |
17 | |参数名 |参数含义 | 示例|
18 | --- | --- | ---
19 | |q|搜索关键字|q=password|
20 | |lang|指定编程语言(不支持多值)|lang=Java|
21 | |e.id|搜索指定企业的仓库(仅限 gitee)|e.id=1213|
22 | |repo.id|搜索指定仓库的代码,支持多值,使用逗号隔开|repo.id=1213,32|
23 | |sort|排序方法(stars,forks,update)|sort=update|
24 | |p|页码(每页20条)|p=3|
25 |
26 | GET(POST): /search/issues #Issue 搜索
27 |
28 | |参数名 |参数含义 | 示例|
29 | --- | --- | ---
30 | |q|搜索关键字|q=password|
31 | |e.id|搜索指定企业的仓库(仅限 gitee)|e.id=1213|
32 | |sort|排序方法(create,update)|sort=update|
33 | |p|页码(每页20条)|p=3|
34 |
35 |
36 | **WebHook 回调接口**
37 |
38 | /gitlab/system # Gitlab 系统回调接口
39 | /gitlab/project # Gitlab 仓库回调接口
40 | /gitee # Gitee Premium 回调接口
41 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/index/IndexException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.index;
17 |
18 | /**
19 | * Lucene Index Exception
20 | * @author Winter Lau
21 | */
22 | public class IndexException extends RuntimeException {
23 |
24 | public IndexException(String message, Throwable cause) {
25 | super(message, cause);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/query/QueryException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.query;
17 |
18 | /**
19 | * Lucene Query Exception
20 | * @author Winter Lau
21 | */
22 | public class QueryException extends RuntimeException {
23 |
24 | public QueryException(String message, Throwable cause) {
25 | super(message, cause);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/EnterpriseHook.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.gitee;
17 |
18 | /**
19 | * @author zhanggx
20 | */
21 | public class EnterpriseHook {
22 |
23 | private String url;
24 |
25 | public String getUrl() {
26 | return url;
27 | }
28 |
29 | public void setUrl(String url) {
30 | this.url = url;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/PushWebHook.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.utils;
17 |
18 | /**
19 | * 对应 languages.json 文件中的 quote 字段
20 | */
21 | public class LanguageQuote {
22 |
23 | public String start;
24 | public String end;
25 | public boolean ignoreescape;
26 | public boolean docstring;
27 |
28 | public LanguageQuote(){}
29 |
30 | public LanguageQuote(String start, String end, boolean ignoreescape, boolean docstring) {
31 | this.start = start;
32 | this.end = end;
33 | this.ignoreescape = ignoreescape;
34 | this.docstring = docstring;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/queue/Queue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.queue;
17 |
18 | import java.util.Collection;
19 | import java.util.List;
20 |
21 | /**
22 | * 定义了获取索引任务的队列接口
23 | * @author Winter Lau
24 | */
25 | public interface Queue extends AutoCloseable{
26 |
27 | /**
28 | * 队列的唯一名称
29 | * @return
30 | */
31 | String type();
32 |
33 | /**
34 | * 添加任务到队列
35 | * @param tasks
36 | */
37 | void push(Collection tasks) ;
38 |
39 | /**
40 | * 从队列获取任务
41 | * @return
42 | */
43 | List pop(int count) ;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/code/RepositoryProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import com.gitee.kooder.models.CodeRepository;
19 |
20 | /**
21 | * 代码源接口定义
22 | * @author Winter Lau
23 | */
24 | public interface RepositoryProvider {
25 |
26 | String name();
27 |
28 | /**
29 | * 更新仓库
30 | * @param repo
31 | * @param traveler
32 | * @return 返回索引的文件数
33 | */
34 | int pull(CodeRepository repo, FileTraveler traveler);
35 |
36 | /**
37 | * 删除仓库
38 | * @param repo
39 | * @exception
40 | */
41 | void delete(CodeRepository repo) ;
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/IssueWebHook.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.gitee;
17 |
18 | /**
19 | * @author zhanggx
20 | */
21 | public class IssueWebHook {
22 |
23 | private Issue issue;
24 |
25 | private Repository repository;
26 |
27 | public Issue getIssue() {
28 | return issue;
29 | }
30 |
31 | public void setIssue(Issue issue) {
32 | this.issue = issue;
33 | }
34 |
35 | public Repository getRepository() {
36 | return repository;
37 | }
38 |
39 | public void setRepository(Repository repository) {
40 | this.repository = repository;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/examples/CollectorExample.java:
--------------------------------------------------------------------------------
1 | package com.gitee.kooder.examples;
2 |
3 | import com.gitee.kooder.storage.StorageFactory;
4 | import org.apache.lucene.index.IndexReader;
5 | import org.apache.lucene.search.*;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | import java.io.IOException;
10 |
11 | /**
12 | * Collector example
13 | * @author Winter Lau
14 | */
15 | public class CollectorExample {
16 |
17 | private final static Logger log = LoggerFactory.getLogger(CollectorExample.class);
18 |
19 | public static void main(String[] args) throws IOException {
20 | try (IndexReader reader = StorageFactory.getIndexReader("repo")) {
21 | IndexSearcher searcher = new IndexSearcher(reader);
22 | long ct = System.currentTimeMillis();
23 | searcher.search(new MatchAllDocsQuery(), new SimpleCollector() {
24 | @Override
25 | public ScoreMode scoreMode() {
26 | return ScoreMode.COMPLETE;
27 | }
28 |
29 | @Override
30 | public void collect(int doc) throws IOException {
31 | log.info("{}", doc);
32 | }
33 | });
34 | }
35 | SimpleCollector d;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/code/FileTraveler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import com.gitee.kooder.models.SourceFile;
19 |
20 | /**
21 | * 文件遍历回调接口
22 | * @author Winter Lau
23 | */
24 | public interface FileTraveler {
25 |
26 | /**
27 | * 更新源码文档(新文件、更改文件)
28 | * @param doc 文档信息
29 | * @return true: 继续下一个文档, false 不再处理下面文档
30 | */
31 | void updateDocument(SourceFile doc);
32 |
33 | /**
34 | * 删除文档
35 | * @param doc
36 | * @return
37 | */
38 | void deleteDocument(SourceFile doc);
39 |
40 | /**
41 | * 清空仓库所有文件,以待重建
42 | * @param repoId
43 | */
44 | void resetRepository(long repoId);
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/query/QueryFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.query;
17 |
18 | /**
19 | * 查询工具包
20 | * @author Winter Lau
21 | */
22 | public class QueryFactory {
23 |
24 | /**
25 | * 仓库查询器
26 | * @return
27 | */
28 | public final static RepoQuery REPO() {
29 | return new RepoQuery();
30 | }
31 |
32 | /**
33 | * Issue 任务查询器
34 | * @return
35 | */
36 | public final static IssueQuery ISSUE() {
37 | return new IssueQuery();
38 | }
39 |
40 | /**
41 | * 源码查询器
42 | * @return
43 | */
44 | public final static CodeQuery CODE() {
45 | return new CodeQuery();
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/GiteeWebHookEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.gitee;
17 |
18 | import java.util.Arrays;
19 |
20 | /**
21 | * @author zhanggx
22 | */
23 | public enum GiteeWebHookEvent {
24 |
25 | REPO_HOOK("Repo Hook"),
26 | PUSH_HOOK("Push Hook"),
27 | ISSUE_HOOK("Issue Hook");
28 |
29 | private String event;
30 |
31 | GiteeWebHookEvent(String event) {
32 | this.event = event;
33 | }
34 |
35 | public static GiteeWebHookEvent getEvent(String event) {
36 | return Arrays.stream(values())
37 | .filter(giteeWebHookEvent -> giteeWebHookEvent.event.equals(event))
38 | .findFirst()
39 | .orElse(null);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/Enterprise.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.gitee;
17 |
18 | /**
19 | * @author zhanggx
20 | */
21 | public class Enterprise {
22 |
23 | private Integer id;
24 | private String name;
25 | private String url;
26 |
27 | public Integer getId() {
28 | return id;
29 | }
30 |
31 | public void setId(Integer id) {
32 | this.id = id;
33 | }
34 |
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public void setName(String name) {
40 | this.name = name;
41 | }
42 |
43 | public String getUrl() {
44 | return url;
45 | }
46 |
47 | public void setUrl(String url) {
48 | this.url = url;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitea/RepositoryWebHook.java:
--------------------------------------------------------------------------------
1 | package com.gitee.kooder.gitea;
2 |
3 | /**
4 | * @author zhanggx
5 | */
6 | public class RepositoryWebHook {
7 |
8 | public static final String ACTION_CREATED = "created";
9 | public static final String ACTION_DELETED = "deleted";
10 |
11 | private String secret;
12 | private String action;
13 | private Repository repository;
14 | private User organization;
15 | private User sender;
16 |
17 | public String getSecret() {
18 | return secret;
19 | }
20 |
21 | public void setSecret(String secret) {
22 | this.secret = secret;
23 | }
24 |
25 | public String getAction() {
26 | return action;
27 | }
28 |
29 | public void setAction(String action) {
30 | this.action = action;
31 | }
32 |
33 | public Repository getRepository() {
34 | return repository;
35 | }
36 |
37 | public void setRepository(Repository repository) {
38 | this.repository = repository;
39 | }
40 |
41 | public User getOrganization() {
42 | return organization;
43 | }
44 |
45 | public void setOrganization(User organization) {
46 | this.organization = organization;
47 | }
48 |
49 | public User getSender() {
50 | return sender;
51 | }
52 |
53 | public void setSender(User sender) {
54 | this.sender = sender;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/User.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.gitee;
17 |
18 | /**
19 | * @author zhanggx
20 | */
21 | public class User {
22 |
23 | private Integer id;
24 |
25 | private String name;
26 |
27 | private String htmlUrl;
28 |
29 | public Integer getId() {
30 | return id;
31 | }
32 |
33 | public void setId(Integer id) {
34 | this.id = id;
35 | }
36 |
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 |
45 | public String getHtmlUrl() {
46 | return htmlUrl;
47 | }
48 |
49 | public void setHtmlUrl(String htmlUrl) {
50 | this.htmlUrl = htmlUrl;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitea/IssueWebHook.java:
--------------------------------------------------------------------------------
1 | package com.gitee.kooder.gitea;
2 |
3 | /**
4 | * @author zhanggx
5 | */
6 | public class IssueWebHook {
7 |
8 | private String secret;
9 | private String action;
10 | private Integer number;
11 | private Issue issue;
12 | private Repository repository;
13 | private User sender;
14 |
15 | public String getSecret() {
16 | return secret;
17 | }
18 |
19 | public void setSecret(String secret) {
20 | this.secret = secret;
21 | }
22 |
23 | public String getAction() {
24 | return action;
25 | }
26 |
27 | public void setAction(String action) {
28 | this.action = action;
29 | }
30 |
31 | public Integer getNumber() {
32 | return number;
33 | }
34 |
35 | public void setNumber(Integer number) {
36 | this.number = number;
37 | }
38 |
39 | public Issue getIssue() {
40 | return issue;
41 | }
42 |
43 | public void setIssue(Issue issue) {
44 | this.issue = issue;
45 | }
46 |
47 | public Repository getRepository() {
48 | return repository;
49 | }
50 |
51 | public void setRepository(Repository repository) {
52 | this.repository = repository;
53 | }
54 |
55 | public User getSender() {
56 | return sender;
57 | }
58 |
59 | public void setSender(User sender) {
60 | this.sender = sender;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/RepoWebHook.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.gitee;
17 |
18 | /**
19 | * @author zhanggx
20 | */
21 | public class RepoWebHook {
22 |
23 | public static final String ACTION_CREATE = "create";
24 | public static final String ACTION_DESTROY = "destroy";
25 |
26 | private String action;
27 |
28 | private Repository repository;
29 |
30 | public String getAction() {
31 | return action;
32 | }
33 |
34 | public void setAction(String action) {
35 | this.action = action;
36 | }
37 |
38 | public Repository getRepository() {
39 | return repository;
40 | }
41 |
42 | public void setRepository(Repository repository) {
43 | this.repository = repository;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/code/SvnRepositoryProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import com.gitee.kooder.models.CodeRepository;
19 |
20 | /**
21 | * TODO: SVN 仓库源
22 | * @author Winter Lau
23 | */
24 | public class SvnRepositoryProvider implements RepositoryProvider {
25 |
26 | @Override
27 | public String name() {
28 | return "svn";
29 | }
30 |
31 | /**
32 | * 更新仓库
33 | * @param repo
34 | * @param traveler
35 | * @return
36 | */
37 | @Override
38 | public int pull(CodeRepository repo, FileTraveler traveler) {
39 | return -1;
40 | }
41 |
42 | /**
43 | * 删除仓库
44 | * @param repo
45 | */
46 | @Override
47 | public void delete(CodeRepository repo) {
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/code/FileRepositoryProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import com.gitee.kooder.models.CodeRepository;
19 |
20 | /**
21 | * TODO: 基于本地文件的仓库源
22 | * @author Winter Lau
23 | */
24 | public class FileRepositoryProvider implements RepositoryProvider {
25 |
26 | @Override
27 | public String name() {
28 | return "file";
29 | }
30 |
31 | /**
32 | * 更新仓库
33 | * @param repo
34 | * @param traveler
35 | * @return
36 | */
37 | @Override
38 | public int pull(CodeRepository repo, FileTraveler traveler) {
39 | return -1;
40 | }
41 |
42 | /**
43 | * 删除仓库
44 | * @param repo
45 | */
46 | @Override
47 | public void delete(CodeRepository repo) {
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/models/CodeLine.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.models;
17 |
18 | /**
19 | * Code Line
20 | * used to show results of code search
21 | * @author Winter Lau
22 | */
23 | public class CodeLine {
24 |
25 | private int line; //Line num
26 | private String code; //Code
27 |
28 | public CodeLine(int line, String code) {
29 | this.code = code;
30 | this.line = line;
31 | }
32 |
33 | public int getLine() {
34 | return line;
35 | }
36 |
37 | public void setLine(int line) {
38 | this.line = line;
39 | }
40 |
41 | public StringBuffer getCode() {
42 | return new StringBuffer(code);
43 | }
44 |
45 | public void setCode(String code) {
46 | this.code = code;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/jcseg/JcsegAnalyzer.java:
--------------------------------------------------------------------------------
1 | package com.gitee.kooder.jcseg;
2 |
3 | import org.apache.lucene.analysis.Analyzer;
4 | import org.apache.lucene.analysis.Tokenizer;
5 | import org.lionsoul.jcseg.ISegment;
6 | import org.lionsoul.jcseg.dic.ADictionary;
7 | import org.lionsoul.jcseg.segmenter.SegmenterConfig;
8 |
9 | /**
10 | * Jcseg analyzer for lucene with version on or after 5.0
11 | *
12 | * @author chenxin
13 | */
14 | public final class JcsegAnalyzer extends Analyzer
15 | {
16 | public ISegment.Type type;
17 | public final SegmenterConfig config;
18 | public final ADictionary dic;
19 |
20 | /**
21 | * initialize the analyzer with the specified mode, configuration, dictionary
22 | *
23 | * @param type
24 | * @param config
25 | * @param dic
26 | */
27 | public JcsegAnalyzer(ISegment.Type type, SegmenterConfig config, ADictionary dic)
28 | {
29 | this.type = type;
30 | this.config = config;
31 | this.dic = dic;
32 | }
33 |
34 | public SegmenterConfig getConfig()
35 | {
36 | return config;
37 | }
38 |
39 | public ADictionary getDict()
40 | {
41 | return dic;
42 | }
43 |
44 | @Override
45 | protected TokenStreamComponents createComponents(String fieldName)
46 | {
47 | final Tokenizer tokenizer = new JcsegTokenizer(type, config, dic);
48 | return new TokenStreamComponents(tokenizer);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/action/IndexAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.action;
17 |
18 | import com.gitee.kooder.query.QueryFactory;
19 | import com.gitee.kooder.server.Action;
20 | import io.vertx.ext.web.RoutingContext;
21 |
22 | import java.io.IOException;
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | /**
27 | * Default action for web
28 | * @author Winter Lau
29 | */
30 | public class IndexAction implements Action {
31 |
32 | /**
33 | * web searcher
34 | * @param context
35 | * @return
36 | */
37 | public void index(RoutingContext context) throws IOException {
38 | Map params = new HashMap();
39 | params.put("total_repo_count", QueryFactory.REPO().totalCount());
40 | this.vm(context, "index.vm", params);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/queue/QueueProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.queue;
17 |
18 | import com.gitee.kooder.core.KooderConfig;
19 | import org.apache.commons.lang3.StringUtils;
20 |
21 | import java.util.Properties;
22 |
23 | /**
24 | * 队列工厂
25 | * @author Winter Lau
26 | */
27 | public class QueueFactory {
28 |
29 | static QueueProvider provider;
30 |
31 | static {
32 | Properties props = KooderConfig.getQueueProperties();
33 | String type = StringUtils.trim(props.getProperty("provider"));
34 | if("redis".equalsIgnoreCase(type))
35 | provider = new RedisQueueProvider(props);
36 | else if("embed".equalsIgnoreCase(type))
37 | provider = new EmbedQueueProvider(props);
38 | }
39 |
40 | public final static QueueProvider getProvider() {
41 | return provider;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/action/GiteaAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.action;
17 |
18 | import com.gitee.kooder.core.Constants;
19 | import com.gitee.kooder.core.KooderConfig;
20 | import com.gitee.kooder.gitea.GiteaException;
21 | import com.gitee.kooder.server.Action;
22 | import com.gitee.kooder.webhook.GiteaSystemHookManager;
23 | import io.vertx.ext.web.RoutingContext;
24 |
25 | /**
26 | * Handle Gitea webhook
27 | * http://localhost:8080/gitea web hook (new project/project updated etc)
28 | * @author Winter Lau
29 | */
30 | public class GiteaAction implements Action {
31 |
32 | String SECRET_TOKEN = KooderConfig.getProperty("gitea.secret_token", Constants.DEFAULT_SECRET_TOKEN);
33 |
34 | /**
35 | * Gitea webhook handler
36 | * @param context
37 | */
38 | public void index(RoutingContext context) throws GiteaException {
39 | GiteaSystemHookManager.handleEvent(SECRET_TOKEN, context);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/action/GiteeAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.action;
17 |
18 | import com.gitee.kooder.core.Constants;
19 | import com.gitee.kooder.core.KooderConfig;
20 | import com.gitee.kooder.gitee.GiteeException;
21 | import com.gitee.kooder.server.Action;
22 | import com.gitee.kooder.webhook.GiteeWebHookManager;
23 | import io.vertx.ext.web.RoutingContext;
24 |
25 | /**
26 | * Handle Gitee webhook
27 | * http://localhost:8080/gitee web hook (new project/project updated etc)
28 | *
29 | * @author Winter Lau
30 | */
31 | public class GiteeAction implements Action {
32 |
33 | String SECRET_TOKEN = KooderConfig.getProperty("gitee.secret_token", Constants.DEFAULT_SECRET_TOKEN);
34 |
35 | /**
36 | * Gitee webhook handler
37 | *
38 | * @param context
39 | */
40 | public void index(RoutingContext context) throws GiteeException {
41 | GiteeWebHookManager.handleEvent(SECRET_TOKEN, context);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/code/RepositoryFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import com.gitee.kooder.models.CodeRepository;
19 | import org.slf4j.Logger;
20 | import org.slf4j.LoggerFactory;
21 |
22 | import java.util.*;
23 |
24 | /**
25 | * 各种仓库源的管理
26 | * @author Winter Lau
27 | */
28 | public class RepositoryFactory {
29 |
30 | private final static Logger log = LoggerFactory.getLogger(RepositoryFactory.class);
31 |
32 | private final static Map providers = new HashMap(){{
33 | put(CodeRepository.SCM_GIT, new GitRepositoryProvider());
34 | put(CodeRepository.SCM_SVN, new SvnRepositoryProvider());
35 | put(CodeRepository.SCM_FILE, new FileRepositoryProvider());
36 | }};
37 |
38 | /**
39 | * 根据 scm 获取仓库操作类实例
40 | * @param scm
41 | * @return
42 | */
43 | public final static RepositoryProvider getProvider(String scm) {
44 | return providers.get(scm);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/utils/FileClassifierResult.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.utils;
17 |
18 | /**
19 | * This class used to mapping language.json segment defined
20 | * @author Winter Lau
21 | */
22 | public class FileClassifierResult {
23 |
24 | public String[] extensions;
25 | public String[] extensionfile;
26 | public String[] line_comment;
27 | public String[] complexitychecks;
28 | public String[][] multi_line;
29 | public LanguageQuote[] quotes;
30 | public boolean nestedmultiline;
31 | public String[] keywords; // Used to identify languages that share extensions
32 | public String[] filenames;
33 | public String comment;
34 |
35 | public FileClassifierResult(){}
36 |
37 | public FileClassifierResult(String extensions) {
38 | this.extensions = extensions.toLowerCase().split(",");
39 | }
40 |
41 | public FileClassifierResult(String extensions, String keywords) {
42 | this.extensions = extensions.toLowerCase().split(",");
43 | this.keywords = keywords.toLowerCase().split(",");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/core/src/main/resources/simplelogger.properties:
--------------------------------------------------------------------------------
1 | # SLF4J's SimpleLogger configuration file
2 | # Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
3 | # org.slf4j.simpleLogger.logFile=System.out
4 |
5 | # Default logging detail level for all instances of SimpleLogger.
6 | # Must be one of ("trace", "debug", "info", "warn", or "error").
7 | # If not specified, defaults to "info".
8 | org.slf4j.simpleLogger.defaultLogLevel=info
9 |
10 | # Logging detail level for a SimpleLogger instance named "xxxxx".
11 | # Must be one of ("trace", "debug", "info", "warn", or "error").
12 | # If not specified, the default logging detail level is used.
13 | #org.slf4j.simpleLogger.log.xxxxx=
14 |
15 | # Set to true if you want the current date and time to be included in output messages.
16 | # Default is false, and will output the number of milliseconds elapsed since startup.
17 | org.slf4j.simpleLogger.showDateTime=true
18 |
19 | # The date and time format to be used in the output messages.
20 | # The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
21 | # If the format is not specified or is invalid, the default format is used.
22 | # The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
23 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss
24 |
25 | # Set to true if you want to output the current thread name.
26 | # Defaults to true.
27 | org.slf4j.simpleLogger.showThreadName=false
28 |
29 | # Set to true if you want the Logger instance name to be included in output messages.
30 | # Defaults to true.
31 | org.slf4j.simpleLogger.showLogName=true
32 |
33 | # Set to true if you want the last component of the name to be included in output messages.
34 | # Defaults to false.
35 | org.slf4j.simpleLogger.showShortLogName=true
--------------------------------------------------------------------------------
/gateway/src/main/resources/simplelogger.properties:
--------------------------------------------------------------------------------
1 | # SLF4J's SimpleLogger configuration file
2 | # Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
3 | #org.slf4j.simpleLogger.logFile=System.out
4 |
5 | # Default logging detail level for all instances of SimpleLogger.
6 | # Must be one of ("trace", "debug", "info", "warn", or "error").
7 | # If not specified, defaults to "info".
8 | org.slf4j.simpleLogger.defaultLogLevel=info
9 |
10 | # Logging detail level for a SimpleLogger instance named "xxxxx".
11 | # Must be one of ("trace", "debug", "info", "warn", or "error").
12 | # If not specified, the default logging detail level is used.
13 | #org.slf4j.simpleLogger.log.xxxxx=
14 |
15 | # Set to true if you want the current date and time to be included in output messages.
16 | # Default is false, and will output the number of milliseconds elapsed since startup.
17 | org.slf4j.simpleLogger.showDateTime=true
18 |
19 | # The date and time format to be used in the output messages.
20 | # The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
21 | # If the format is not specified or is invalid, the default format is used.
22 | # The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
23 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss
24 |
25 | # Set to true if you want to output the current thread name.
26 | # Defaults to true.
27 | org.slf4j.simpleLogger.showThreadName=false
28 |
29 | # Set to true if you want the Logger instance name to be included in output messages.
30 | # Defaults to true.
31 | org.slf4j.simpleLogger.showLogName=true
32 |
33 | # Set to true if you want the last component of the name to be included in output messages.
34 | # Defaults to false.
35 | org.slf4j.simpleLogger.showShortLogName=true
--------------------------------------------------------------------------------
/indexer/src/main/resources/simplelogger.properties:
--------------------------------------------------------------------------------
1 | # SLF4J's SimpleLogger configuration file
2 | # Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
3 | # org.slf4j.simpleLogger.logFile=System.out
4 |
5 | # Default logging detail level for all instances of SimpleLogger.
6 | # Must be one of ("trace", "debug", "info", "warn", or "error").
7 | # If not specified, defaults to "info".
8 | org.slf4j.simpleLogger.defaultLogLevel=info
9 |
10 | # Logging detail level for a SimpleLogger instance named "xxxxx".
11 | # Must be one of ("trace", "debug", "info", "warn", or "error").
12 | # If not specified, the default logging detail level is used.
13 | #org.slf4j.simpleLogger.log.xxxxx=
14 |
15 | # Set to true if you want the current date and time to be included in output messages.
16 | # Default is false, and will output the number of milliseconds elapsed since startup.
17 | org.slf4j.simpleLogger.showDateTime=true
18 |
19 | # The date and time format to be used in the output messages.
20 | # The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
21 | # If the format is not specified or is invalid, the default format is used.
22 | # The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
23 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss
24 |
25 | # Set to true if you want to output the current thread name.
26 | # Defaults to true.
27 | org.slf4j.simpleLogger.showThreadName=false
28 |
29 | # Set to true if you want the Logger instance name to be included in output messages.
30 | # Defaults to true.
31 | org.slf4j.simpleLogger.showLogName=true
32 |
33 | # Set to true if you want the last component of the name to be included in output messages.
34 | # Defaults to false.
35 | org.slf4j.simpleLogger.showShortLogName=true
--------------------------------------------------------------------------------
/gateway/src/main/webapp/css/main.css:
--------------------------------------------------------------------------------
1 |
2 | body {padding:8px;font-size:10pt;}
3 |
4 | em.highlight {color:red;font-style:normal;}
5 | em.md {font-style:normal;}
6 | em.codeline {width:24px;text-align:right;font-style:normal;margin-right:10px;}
7 |
8 | #INPUT_SEARCH {width:610px;}
9 |
10 | #SearchResults {float:left;width:740px;margin-left:10px;}
11 | #SearchResults ul { list-style-type:none; margin:20px 0 0 0; padding:0;}
12 | #SearchFacets {float:left; width:200px; }
13 | #SearchResults .facets {margin-top:20px;}
14 | #SearchResults blockquote {padding-top:0;padding-bottom:0;margin:10px 0 5px 0;}
15 | #SearchResults #SortMenu {float:right;margin-right:10px;}
16 | #SortMenu .active { font-weight: bold; }
17 | #SearchResults #SearchTabs {margin:0 20px 20px 0;}
18 | #SearchResults #SearchTabs li {margin-right:20px;}
19 | #SearchResults .breadcrumb {margin:0;}
20 | #SearchResults li.repo {margin-bottom:20px;}
21 | #SearchResults li .meta {color:#999;}
22 | #SearchResults li .meta a {color:#999;}
23 | #SearchResults li .meta .label {margin-right:10px;}
24 |
25 | blockquote.CodeResults ol {list-style-type:none;margin:0;padding:0}
26 | blockquote.CodeResults ol li {margin:0;padding:0}
27 | blockquote.CodeResults ol li:after {content: ""; display: table; clear: both;}
28 | blockquote.CodeResults ol li em.line {font-style:normal;float:left; width: 26px; padding-right:3px; text-align:right;background:#f2f2f2;}
29 | blockquote.CodeResults ol li em.line a {color: black;}
30 | blockquote.CodeResults ol li em.line a:hover {color: #5755d9;}
31 | blockquote.CodeResults ol li em.code {float:left;width:590px; margin-left:6px;font-style:normal;word-wrap:break-word;}
32 |
33 | #SearchFacets .menu {margin-bottom:20px;}
34 | #SearchFacets .menu .active {font-weight:bold;}
35 | #SearchFacets li a {overflow: hidden;text-overflow:ellipsis;white-space: nowrap;}
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitee/Label.java:
--------------------------------------------------------------------------------
1 | package com.gitee.kooder.gitee;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 |
5 | import java.util.Date;
6 |
7 | /**
8 | * @author zhanggx
9 | */
10 | public class Label {
11 |
12 | private Integer id;
13 | private String name;
14 | private String color;
15 | private Integer repositoryId;
16 | private String url;
17 | @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssX")
18 | private Date createdAt;
19 | @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssX")
20 | private Date updatedAt;
21 |
22 | public Integer getId() {
23 | return id;
24 | }
25 |
26 | public void setId(Integer id) {
27 | this.id = id;
28 | }
29 |
30 | public String getName() {
31 | return name;
32 | }
33 |
34 | public void setName(String name) {
35 | this.name = name;
36 | }
37 |
38 | public String getColor() {
39 | return color;
40 | }
41 |
42 | public void setColor(String color) {
43 | this.color = color;
44 | }
45 |
46 | public Integer getRepositoryId() {
47 | return repositoryId;
48 | }
49 |
50 | public void setRepositoryId(Integer repositoryId) {
51 | this.repositoryId = repositoryId;
52 | }
53 |
54 | public String getUrl() {
55 | return url;
56 | }
57 |
58 | public void setUrl(String url) {
59 | this.url = url;
60 | }
61 |
62 | public Date getCreatedAt() {
63 | return createdAt;
64 | }
65 |
66 | public void setCreatedAt(Date createdAt) {
67 | this.createdAt = createdAt;
68 | }
69 |
70 | public Date getUpdatedAt() {
71 | return updatedAt;
72 | }
73 |
74 | public void setUpdatedAt(Date updatedAt) {
75 | this.updatedAt = updatedAt;
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/gitea/PushWebHook.java:
--------------------------------------------------------------------------------
1 | package com.gitee.kooder.gitea;
2 |
3 | /**
4 | * @author zhanggx
5 | */
6 | public class PushWebHook {
7 |
8 | private String secret;
9 | private String ref;
10 | private String before;
11 | private String after;
12 | private String compareUrl;
13 | private Repository repository;
14 | private User pusher;
15 | private User sender;
16 |
17 | public String getSecret() {
18 | return secret;
19 | }
20 |
21 | public void setSecret(String secret) {
22 | this.secret = secret;
23 | }
24 |
25 | public String getRef() {
26 | return ref;
27 | }
28 |
29 | public void setRef(String ref) {
30 | this.ref = ref;
31 | }
32 |
33 | public String getBefore() {
34 | return before;
35 | }
36 |
37 | public void setBefore(String before) {
38 | this.before = before;
39 | }
40 |
41 | public String getAfter() {
42 | return after;
43 | }
44 |
45 | public void setAfter(String after) {
46 | this.after = after;
47 | }
48 |
49 | public String getCompareUrl() {
50 | return compareUrl;
51 | }
52 |
53 | public void setCompareUrl(String compareUrl) {
54 | this.compareUrl = compareUrl;
55 | }
56 |
57 | public Repository getRepository() {
58 | return repository;
59 | }
60 |
61 | public void setRepository(Repository repository) {
62 | this.repository = repository;
63 | }
64 |
65 | public User getPusher() {
66 | return pusher;
67 | }
68 |
69 | public void setPusher(User pusher) {
70 | this.pusher = pusher;
71 | }
72 |
73 | public User getSender() {
74 | return sender;
75 | }
76 |
77 | public void setSender(User sender) {
78 | this.sender = sender;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/bin/service.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # description: jsw-test
3 | # processname: jsw-test
4 | # chkconfig: 234 20 80
5 |
6 | # 程序名称
7 | SERVICE_NAME=jsw-test
8 | #程序路径获取相对路径,可填写绝对路径,如APP_HOME=/usr/local/bingo_cdp/deploy/bingo-cdp-timerjob-linux
9 | APP_HOME=$(dirname $(pwd))
10 | EXEC=/opt/jsvc/commons-daemon-1.0.15-src/src/native/unix/jsvc
11 | JAVA_HOME=/usr/java/jdk1.8.0_51
12 |
13 | #依赖路径
14 | cd ${APP_HOME}
15 | CLASS_PATH="$PWD/classes":"$PWD/lib/*"
16 |
17 | #程序入口类
18 | CLASS=main.DaemonMainClassForLinux
19 |
20 | #程序ID文件
21 | PID=${APP_HOME}/${SERVICE_NAME}.pid
22 | #日志输出路径
23 | LOG_OUT=${APP_HOME}/logs/${SERVICE_NAME}.out
24 | LOG_ERR=${APP_HOME}/logs/${SERVICE_NAME}.err
25 |
26 | #输出
27 | echo "service name: $SERVICE_NAME"
28 | echo "app home: $APP_HOME"
29 | echo "jsvc: $EXEC"
30 | echo "java home: $JAVA_HOME"
31 | echo "class path: $CLASS_PATH"
32 | echo "main class: $CLASS"
33 |
34 | #执行
35 | do_exec()
36 | {
37 | $EXEC -home "$JAVA_HOME" -Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8 -Djcifs.smb.client.dfs.disabled=false -Djcifs.resolveOrder=DNS -Xms512M -Xmx1024M -cp $CLASS_PATH -outfile $LOG_OUT -errfile $LOG_ERR -pidfile $PID $1 $CLASS
38 | }
39 |
40 | #根据参数执行
41 | case "$1" in
42 | start)
43 | do_exec
44 | echo "${SERVICE_NAME} started"
45 | ;;
46 | stop)
47 | do_exec "-stop"
48 | echo "${SERVICE_NAME} stopped"
49 | ;;
50 | restart)
51 | if [ -f "$PID" ]; then
52 | do_exec "-stop"
53 | do_exec
54 | echo "${SERVICE_NAME} restarted"
55 | else
56 | echo "service not running, will do nothing"
57 | exit 1
58 | fi
59 | ;;
60 | status)
61 | ps -ef | grep jsvc
62 | ;;
63 | *)
64 | echo "usage: service ${SERVICE_NAME} {start|stop|restart|status}" >&2
65 | exit 3
66 | ;;
67 | esac
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/models/Relation.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.models;
17 |
18 | /**
19 | * Relation info
20 | * @author Winter Lau
21 | */
22 | public final class Relation {
23 |
24 | protected long id;
25 | protected String name;
26 | protected String url;
27 |
28 | public Relation() {}
29 |
30 | public Relation(long id, String name, String url) {
31 | this.id = id;
32 | this.name = name;
33 | this.url = url;
34 | }
35 |
36 | public final static Relation EMPTY() {
37 | return new Relation(0, "NONE", null);
38 | }
39 |
40 | public long getId() {
41 | return id;
42 | }
43 |
44 | public void setId(long id) {
45 | this.id = id;
46 | }
47 |
48 | public String getName() {
49 | return name;
50 | }
51 |
52 | public void setName(String name) {
53 | this.name = name;
54 | }
55 |
56 | public String getUrl() {
57 | return url;
58 | }
59 |
60 | public void setUrl(String url) {
61 | this.url = url;
62 | }
63 |
64 | @Override
65 | public boolean equals(Object obj) {
66 | if(obj == null)
67 | return false;
68 | if(!(obj instanceof Relation))
69 | return false;
70 | return id == ((Relation)obj).id;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/server/Tester.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.indexer;
17 |
18 | import org.apache.commons.daemon.Daemon;
19 | import org.apache.commons.daemon.DaemonContext;
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | /**
24 | * Make gateway as a daemon
25 | * @author Winter Lau
26 | */
27 | public class ServerDaemon implements Daemon {
28 |
29 | private final static Logger log = LoggerFactory.getLogger(ServerDaemon.class);
30 |
31 | private FetchTaskThread fetchTaskThread;
32 |
33 | public ServerDaemon() {}
34 |
35 | /**
36 | * 命令行启动服务
37 | * @param args
38 | */
39 | public static void main(String[] args) {
40 | ServerDaemon daemon = new ServerDaemon();
41 | daemon.init(null);
42 | daemon.start();
43 | log.info("Gitee Search Indexer started !");
44 | }
45 |
46 | @Override
47 | public void init(DaemonContext dc) {
48 | this.fetchTaskThread = new FetchTaskThread();
49 | }
50 |
51 | @Override
52 | public void start() {
53 | this.fetchTaskThread.start();
54 | }
55 |
56 | @Override
57 | public void stop() {
58 | this.fetchTaskThread.interrupt();
59 | try {
60 | this.fetchTaskThread.join(2000, 20);
61 | } catch (InterruptedException e) {}
62 | }
63 |
64 | @Override
65 | public void destroy() {
66 | log.info("Gitee Search Indexer exit.");
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/models/CodeOwner.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.models;
17 |
18 | /**
19 | * The main developer of one source file
20 | * @author Winter Lau
21 | */
22 | public class CodeOwner {
23 |
24 | private int noLines;
25 | private String name;
26 | private int mostRecentUnixCommitTimestamp;
27 |
28 | public CodeOwner(String name, int noLines, int mostRecentUnixCommitTimestamp) {
29 | this.setName(name);
30 | this.setNoLines(noLines);
31 | this.setMostRecentUnixCommitTimestamp(mostRecentUnixCommitTimestamp);
32 | }
33 |
34 | public void incrementLines() {
35 | this.noLines++;
36 | }
37 |
38 | public int getNoLines() {
39 | return noLines;
40 | }
41 |
42 | public void setNoLines(int noLines) {
43 | this.noLines = noLines;
44 | }
45 |
46 | public String getName() {
47 | return name;
48 | }
49 |
50 | public void setName(String name) {
51 | this.name = name;
52 | }
53 |
54 | public int getMostRecentUnixCommitTimestamp() {
55 | return mostRecentUnixCommitTimestamp;
56 | }
57 |
58 | public void setMostRecentUnixCommitTimestamp(int mostRecentUnixCommitTimestamp) {
59 | this.mostRecentUnixCommitTimestamp = mostRecentUnixCommitTimestamp;
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return String.format("Name: %s, Time: %d, LINES: %d", name, mostRecentUnixCommitTimestamp, noLines);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/jcseg/JcsegTokenizerFactory.java:
--------------------------------------------------------------------------------
1 | package com.gitee.kooder.jcseg;
2 |
3 | import java.io.IOException;
4 | import java.util.Map;
5 | import java.util.Map.Entry;
6 |
7 | import org.apache.lucene.analysis.Tokenizer;
8 | import org.apache.lucene.analysis.util.TokenizerFactory;
9 | import org.apache.lucene.util.AttributeFactory;
10 | import org.lionsoul.jcseg.ISegment;
11 | import org.lionsoul.jcseg.dic.ADictionary;
12 | import org.lionsoul.jcseg.dic.DictionaryFactory;
13 | import org.lionsoul.jcseg.segmenter.SegmenterConfig;
14 |
15 | /**
16 | * Jcseg tokenizer factory class for lucene/solr
17 | *
18 | * @author chenxin
19 | */
20 | public class JcsegTokenizerFactory extends TokenizerFactory
21 | {
22 |
23 | public final ISegment.Type type;
24 | public final SegmenterConfig config;
25 | public final ADictionary dic;
26 |
27 | /**
28 | * set the mode arguments in the schema.xml
29 | * configuration file to change the segment mode for Jcseg
30 | * @throws IOException
31 | *
32 | * @see TokenizerFactory#TokenizerFactory(Map)
33 | */
34 | public JcsegTokenizerFactory(Map args) throws IOException
35 | {
36 | super(args);
37 |
38 | type = ISegment.Type.fromString(args.get("mode"));
39 |
40 | // initialize the task configuration and the dictionary
41 | config = new SegmenterConfig(true);
42 | // check and apply this-level Jcseg settings
43 | for ( Entry entry : args.entrySet() ) {
44 | if ( entry.getKey().startsWith("jcseg_") ) {
45 | config.set(entry.getKey().replace("jcseg_", "jcseg."), entry.getValue());
46 | }
47 | }
48 |
49 | dic = DictionaryFactory.createSingletonDictionary(config);
50 | }
51 |
52 | public SegmenterConfig getTaskConfig()
53 | {
54 | return config;
55 | }
56 |
57 | public ADictionary getDict()
58 | {
59 | return dic;
60 | }
61 |
62 | @Override
63 | public Tokenizer create(AttributeFactory factory)
64 | {
65 | return new JcsegTokenizer(type, config, dic);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/SearchCmd.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import org.apache.lucene.analysis.*;
19 | import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
20 |
21 | import java.io.StringReader;
22 |
23 | /**
24 | * 源码分词器
25 | * @author Winter Lau
26 | */
27 | public class TechCodeAnalyzer extends Analyzer {
28 |
29 | @Override
30 | protected TokenStreamComponents createComponents(String fieldName) {
31 | return new TokenStreamComponents(new TechCodeTokenizer());
32 | }
33 |
34 | public static void main(String[] args) throws Exception {
35 | String text = "源码: Hello.java: This is a J2Cache demo of the #CodeAnalyzer .NET API. public void main(String[] args){return 0;} C# C++//我是中国人";
36 | //String text = FileUtils.readFileToString(new File("D:\\test.txt"));
37 | //String text = "9615 #";
38 | //String text = "源码: Hello.java China";
39 | //System.out.println(text);
40 |
41 | Analyzer analyzer = new TechCodeAnalyzer();
42 | try (TokenStream stream = analyzer.tokenStream(null, new StringReader(text))){
43 | CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class);
44 | stream.reset();
45 | while (stream.incrementToken()) {
46 | //System.out.print(termAtt.toString() + "\\");
47 | }
48 | System.out.println();
49 | stream.end();
50 | }
51 | //测试高亮
52 | //System.out.println("HLCODE:" + SearchHelper.hlcode(text, "dotnet"));
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/examples/GroupingSearchExample.java:
--------------------------------------------------------------------------------
1 | package com.gitee.kooder.examples;
2 |
3 | import com.gitee.kooder.storage.StorageFactory;
4 | import org.apache.lucene.document.Document;
5 | import org.apache.lucene.index.IndexReader;
6 | import org.apache.lucene.search.*;
7 | import org.apache.lucene.search.grouping.*;
8 | import org.apache.lucene.util.BytesRef;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | import java.io.IOException;
13 |
14 | /**
15 | * GroupingSearch example
16 | * @author Winter Lau
17 | */
18 | public class GroupingSearchExample {
19 |
20 | private final static Logger log = LoggerFactory.getLogger(GroupingSearchExample.class);
21 |
22 | public static void main(String[] args) throws IOException {
23 | Sort sort = new Sort(new SortField("count.star", SortField.Type.INT, true));
24 | GroupingSearch groupingSearch = new GroupingSearch("lang");
25 | groupingSearch.setGroupSort(sort);
26 | groupingSearch.setSortWithinGroup(sort);
27 | groupingSearch.setGroupDocsLimit(10);
28 | //进行分组的域上建立的必须是SortedDocValuesField类型
29 | try (IndexReader reader = StorageFactory.getIndexReader("repo")) {
30 | IndexSearcher searcher = new IndexSearcher(reader);
31 | long ct = System.currentTimeMillis();
32 | TopGroups result = groupingSearch.search(searcher, new MatchAllDocsQuery(), 0,10);
33 |
34 | log.info("totalHitCount: {}, groupCount:{}, time:{}ms", result.totalHitCount, result.groups.length, System.currentTimeMillis()-ct);
35 |
36 | // 按照分组打印查询结果
37 | for (GroupDocs groupDocs : result.groups){
38 | if (groupDocs != null) {
39 | log.info("[{},{}]", groupDocs.groupValue.utf8ToString(), groupDocs.totalHits);
40 |
41 | for(ScoreDoc scoreDoc : groupDocs.scoreDocs){
42 | Document doc = searcher.doc(scoreDoc.doc);
43 | log.info("\tdoc:{},id:{},name:{},stars:{},score:{}",
44 | scoreDoc.doc, doc.get("id"), doc.get("name"), doc.get("count.star"), scoreDoc.score);
45 | }
46 | }
47 | }
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/indexer/src/main/java/com/gitee/kooder/indexer/Gitlab.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.indexer;
17 |
18 | import com.gitee.kooder.core.KooderConfig;
19 | import org.apache.commons.lang3.math.NumberUtils;
20 | import org.gitlab4j.api.GitLabApi;
21 |
22 | /**
23 | * Gitlab access instance
24 | * @author Winter Lau
25 | */
26 | public class Gitlab {
27 |
28 | private static String gitlab_url;
29 | private static String access_token;
30 | private static int version;
31 | private static String gsearch_url;
32 | private static String system_hook_url;
33 | private static String project_hook_url;
34 | private static String secret_token;
35 |
36 | public final static GitLabApi INSTANCE;
37 |
38 | static {
39 | gitlab_url = KooderConfig.getProperty("gitlab.url");
40 | access_token = KooderConfig.getProperty("gitlab.personal_access_token");
41 | version = NumberUtils.toInt(KooderConfig.getProperty("gitlab.version"), 4);
42 | gsearch_url = KooderConfig.getProperty("http.url");
43 | system_hook_url = gsearch_url + "/gitlab/system";
44 | project_hook_url = gsearch_url + "/gitlab/project";
45 | secret_token = KooderConfig.getProperty("gitlab.secret_token", "gsearch");
46 |
47 | INSTANCE = new GitLabApi((version != 3) ? GitLabApi.ApiVersion.V4 : GitLabApi.ApiVersion.V3, gitlab_url, access_token);
48 | // Set the connect timeout to 1 second and the read timeout to 5 seconds
49 | int connectTimeout = NumberUtils.toInt(KooderConfig.getProperty("gitlab.connect_timeout"), 2000);
50 | int readTimeout = NumberUtils.toInt(KooderConfig.getProperty("gitlab.read_timeout"), 10000);
51 | INSTANCE.setRequestTimeout(connectTimeout, readTimeout);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/server/AutoContentTypeStaticHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.server;
17 |
18 | import com.gitee.kooder.core.KooderConfig;
19 | import io.vertx.ext.web.RoutingContext;
20 | import io.vertx.ext.web.handler.impl.StaticHandlerImpl;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.nio.file.Path;
27 | import java.util.Properties;
28 |
29 | /**
30 | * 自动生成静态文件对应的 Content-Type 信息,弥补 vertx 的不足
31 | * @author Winter Lau
32 | */
33 | public class AutoContentTypeStaticHandler extends StaticHandlerImpl {
34 |
35 | private final static Logger log = LoggerFactory.getLogger(AutoContentTypeStaticHandler.class);
36 | private final static Properties CONTENT_TYPES = new Properties();
37 | private final static Path webRoot;
38 |
39 | static {
40 | String sWebroot = KooderConfig.getProperty("http.webroot");
41 | webRoot = KooderConfig.getPath(sWebroot);
42 | try (InputStream stream = AutoContentTypeStaticHandler.class.getResourceAsStream("/mime-types.properties")) {
43 | CONTENT_TYPES.load(stream);
44 | } catch(IOException e) {
45 | log.error("Failed to loading mime-types.properties", e);
46 | }
47 | }
48 |
49 | public AutoContentTypeStaticHandler(){
50 | super();
51 | this.setAllowRootFileSystemAccess(true);
52 | this.setWebRoot(webRoot.toString());
53 | }
54 |
55 | @Override
56 | public void handle(RoutingContext context) {
57 | String path = context.request().path();
58 | int idx = path.lastIndexOf(".");
59 | String ctype = (idx > 0) ? CONTENT_TYPES.getProperty(path.substring(idx + 1).toLowerCase()) : null;
60 | if(ctype != null)
61 | context.response().putHeader("content-type", ctype);
62 | super.handle(context);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/storage/IndexStorage.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.core;
17 |
18 | import java.io.BufferedReader;
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.io.InputStreamReader;
22 | import java.util.*;
23 |
24 | /**
25 | * 搜索关键字封装对象,从关键字中提取一些固定维度信息,例如编程语言等
26 | * @author Winter Lau (javayou@gmail.com)
27 | */
28 | public class SearchKey {
29 |
30 | private final static List languages = new ArrayList();
31 | private String key;
32 | private Map facets;
33 |
34 | static {
35 | try (
36 | InputStream stream = SearchKey.class.getResourceAsStream("/languages");
37 | BufferedReader reader = new BufferedReader(new InputStreamReader(stream))
38 | ) {
39 | do {
40 | String line = reader.readLine();
41 | if(line == null)
42 | break;
43 | line = line.trim();
44 | if(line.length() == 0 || line.charAt(0) == '#')
45 | continue;
46 | languages.add(line.split("/"));
47 | } while(true);
48 | } catch (IOException e) {
49 | e.printStackTrace();
50 | }
51 | }
52 |
53 | private SearchKey(){
54 | this.facets = new HashMap<>();
55 | }
56 |
57 | public final static SearchKey parse(String key) {
58 | SearchKey skey = new SearchKey();
59 | List keys = SearchHelper.splitKeywords(key);
60 | keys.removeIf( k -> {
61 | for(String[] langs : languages) {
62 | if(Arrays.binarySearch(langs, k) >= 0) {
63 | skey.facets.put("lang", k);
64 | return true;
65 | }
66 | }
67 | return false;
68 | });
69 | skey.key = String.join(" ", keys);
70 | return skey;
71 | }
72 |
73 | public String getKey() {
74 | return key;
75 | }
76 |
77 | public Map getFacets() {
78 | return facets;
79 | }
80 |
81 | public static void main(String[] args) {
82 | SearchKey sk = SearchKey.parse("j2cache java");
83 | System.out.println(sk.key);
84 | sk.facets.forEach((k,v)->System.out.printf("%s -> %s\n",k,v));
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/action/TaskAction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
31 | * lucene invoke Tokenizer#setReader(Reader input) to set the inputPending
32 | * after invoke the reset, global object input will be available
33 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.action;
17 |
18 | import com.gitee.kooder.core.Constants;
19 | import com.gitee.kooder.models.QueryResult;
20 | import com.gitee.kooder.query.QueryFactory;
21 | import com.gitee.kooder.server.Action;
22 | import io.vertx.ext.web.RoutingContext;
23 | import org.apache.commons.lang3.StringUtils;
24 |
25 | import java.io.IOException;
26 | import java.util.Arrays;
27 |
28 | /**
29 | * Action for search, both for web and api
30 | * @author Winter Lau
31 | */
32 | interface SearchActionBase extends Action {
33 |
34 | /**
35 | * execute search
36 | * @param context
37 | * @param type
38 | * @return
39 | * @throws IOException
40 | */
41 | default QueryResult _search(RoutingContext context, String type) throws IOException {
42 | String q = param(context.request(), "q");
43 | if(StringUtils.isBlank(q))
44 | return null;
45 |
46 | QueryResult result = null;
47 | int page = Math.max(1, param(context.request(),"p", 1));
48 |
49 | String sort = param(context.request(), "sort");
50 | String lang = param(context.request(), Constants.FIELD_LANGUAGE);
51 |
52 | switch (type) {
53 | case Constants.TYPE_REPOSITORY:
54 | result = QueryFactory.REPO()
55 | .setEnterpriseId(param(context.request(), Constants.FIELD_ENTERPRISE_ID, 0))
56 | .setSearchKey(q)
57 | .addFacets(Constants.FIELD_LANGUAGE, lang)
58 | .setSort(sort)
59 | .setPage(page)
60 | .setPageSize(PAGE_SIZE)
61 | .execute();
62 | break;
63 |
64 | case Constants.TYPE_ISSUE:
65 | result = QueryFactory.ISSUE()
66 | .setEnterpriseId(param(context.request(), Constants.FIELD_ENTERPRISE_ID, 0))
67 | .setSearchKey(q)
68 | .setSort(sort)
69 | .setPage(page)
70 | .setPageSize(PAGE_SIZE)
71 | .execute();
72 | break;
73 |
74 | case Constants.TYPE_CODE:
75 | result = QueryFactory.CODE()
76 | .setSearchKey(q)
77 | .addFacets(Constants.FIELD_LANGUAGE, lang)
78 | .addFacets(Constants.FIELD_REPO_NAME, param(context.request(), Constants.FIELD_REPO_NAME))
79 | .addFacets(Constants.FIELD_CODE_OWNER, param(context.request(), Constants.FIELD_CODE_OWNER))
80 | .setSort(sort)
81 | .setPage(page)
82 | .setPageSize(PAGE_SIZE)
83 | .execute();
84 | }
85 | return result;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/models/Searchable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import com.gitee.kooder.query.QueryException;
19 | import org.apache.commons.lang3.StringUtils;
20 | import org.apache.lucene.analysis.Analyzer;
21 | import org.apache.lucene.analysis.TokenStream;
22 | import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
23 | import org.apache.lucene.queryparser.classic.ParseException;
24 | import org.apache.lucene.queryparser.classic.QueryParser;
25 | import org.apache.lucene.search.Query;
26 | import org.apache.lucene.search.highlight.*;
27 |
28 | import java.io.IOException;
29 | import java.io.StringReader;
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | /**
34 | * Source code analyzer
35 | * @author Winter Lau
36 | */
37 | public class SourceCodeAnalyzer extends Analyzer {
38 |
39 | private final static String separatorChars = "~!@#$%^&*()-_+[]{}?/\\<>.;,'\"\r\n\t";
40 | private final static String replaceChars = StringUtils.repeat(' ', separatorChars.length());
41 | private final static Formatter hl_fmt = new SimpleHTMLFormatter("", "");
42 |
43 | @Override
44 | protected TokenStreamComponents createComponents(String s) {
45 | return new TokenStreamComponents(new SourceCodeTokenizer());
46 | }
47 |
48 | /**
49 | * extract text content to tokens
50 | * @param code
51 | * @return
52 | */
53 | public List tokens(String code) {
54 | List tokens = new ArrayList<>();
55 | try (TokenStream stream = tokenStream(null, new StringReader(code))){
56 | CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class);
57 | stream.reset();
58 | while (stream.incrementToken()) {
59 | tokens.add(termAtt.toString());
60 | }
61 | stream.end();
62 | } catch (IOException e) {
63 | throw new QueryException("Failed to tokens: " + code, e);
64 | }
65 | return tokens;
66 | }
67 |
68 | /**
69 | * Highlight code
70 | * @param code
71 | * @param key
72 | * @return
73 | * @throws Exception
74 | */
75 | public String highlight(String code, String key) {
76 | try {
77 | key = StringUtils.replaceChars(key, separatorChars, replaceChars);
78 | QueryParser parser = new QueryParser(null, this);
79 | Query query = parser.parse(key);
80 | QueryScorer scorer = new QueryScorer(query);
81 | Highlighter hig = new Highlighter(hl_fmt, scorer);
82 | TokenStream tokens = this.tokenStream(null, new StringReader(code));
83 | String[] fragments = hig.getBestFragments(tokens, code, hig.getMaxDocCharsToAnalyze());
84 | return String.join( "", fragments);
85 | } catch (ParseException e) {
86 | String escape_key = QueryParser.escape(key);
87 | if(StringUtils.equals(key, escape_key))
88 | return code;
89 | return highlight(code, escape_key);
90 | } catch (IOException | InvalidTokenOffsetsException e) {
91 | return code;
92 | }
93 | }
94 |
95 | }
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/utils/JsonUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import com.gitee.kooder.core.Constants;
19 | import com.gitee.kooder.index.IndexManager;
20 | import com.gitee.kooder.models.SourceFile;
21 | import org.apache.lucene.document.Document;
22 | import org.apache.lucene.document.NumericDocValuesField;
23 | import org.apache.lucene.facet.FacetsConfig;
24 | import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
25 | import org.apache.lucene.index.IndexWriter;
26 | import org.apache.lucene.index.Term;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 |
30 | import java.io.IOException;
31 |
32 | /**
33 | * Travel all file in repository and build index for it
34 | * @author Winter Lau
35 | */
36 | public class CodeFileTraveler implements FileTraveler {
37 |
38 | private final static Logger log = LoggerFactory.getLogger(CodeFileTraveler.class);
39 |
40 | private IndexWriter writer;
41 | private TaxonomyWriter taxonomyWriter;
42 |
43 | public CodeFileTraveler(IndexWriter writer, TaxonomyWriter taxonomyWriter) {
44 | this.writer = writer;
45 | this.taxonomyWriter = taxonomyWriter;
46 | }
47 |
48 | /**
49 | * update source file index
50 | *
51 | * @param codeid document object
52 | */
53 | @Override
54 | public void updateDocument(SourceFile codeid) {
55 | try {
56 | Document doc = buildFacetDocument(codeid.getDocument());
57 | writer.updateDocument(new Term(Constants.FIELD_UUID, codeid.getUuid()), doc);
58 | } catch (IllegalArgumentException | IOException e) {
59 | log.error("Failed to update ducment: file:" + codeid.getName() + " in repo:" + codeid.getRepository().getName(), e);
60 | }
61 | }
62 |
63 | /**
64 | * Delete single file document
65 | *
66 | * @param codeid
67 | * @return
68 | */
69 | @Override
70 | public void deleteDocument(SourceFile codeid) {
71 | //log.info("deleteDocument:" + codeid);
72 | try {
73 | writer.deleteDocuments(new Term(Constants.FIELD_UUID, codeid.getUuid()));
74 | } catch (IOException e) {
75 | log.error("Failed to delete ducment with uuid = " + codeid.getUuid(), e);
76 | }
77 | }
78 |
79 | /**
80 | * Clear all file document belong to one repository
81 | *
82 | * @param repoId
83 | */
84 | @Override
85 | public void resetRepository(long repoId) {
86 | //log.info("resetRepository:" + repoId);
87 | try {
88 | writer.deleteDocuments(NumericDocValuesField.newSlowExactQuery(Constants.FIELD_REPO_ID, repoId));
89 | } catch (IOException e) {
90 | log.error("Failed to reset repository with id = " + repoId, e);
91 | }
92 | }
93 |
94 | /**
95 | * Building facet document
96 | * @param doc
97 | * @return
98 | * @throws IOException
99 | */
100 | private Document buildFacetDocument(Document doc) throws IOException {
101 | FacetsConfig facetsConfig = IndexManager.facetsConfig;
102 | return facetsConfig.build(taxonomyWriter, doc);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/query/IssueQuery.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.query;
17 |
18 | import com.gitee.kooder.core.AnalyzerFactory;
19 | import com.gitee.kooder.core.Constants;
20 | import org.apache.lucene.index.Term;
21 | import org.apache.lucene.queryparser.classic.ParseException;
22 | import org.apache.lucene.queryparser.classic.QueryParser;
23 | import org.apache.lucene.search.*;
24 |
25 | /**
26 | * Issue 搜索
27 | * @author Winter Lau
28 | */
29 | public class IssueQuery extends QueryBase {
30 | /**
31 | * 索引类型
32 | *
33 | * @return
34 | */
35 | @Override
36 | public String type() {
37 | return Constants.TYPE_ISSUE;
38 | }
39 |
40 | /**
41 | * Last issue based on created_at field
42 | * Because gitlab issue api doesn't support filter by id
43 | * @return
44 | */
45 | @Override
46 | protected Sort getLastestObjectSort() {
47 | return new Sort(new SortField(Constants.FIELD_CREATED_AT, SortField.Type.LONG, true));
48 | }
49 |
50 | /**
51 | * 构建查询对象
52 | *
53 | * @return
54 | */
55 | @Override
56 | protected Query buildUserQuery() {
57 | if(parseSearchKey) {
58 | QueryParser parser = new QueryParser("issue", AnalyzerFactory.getInstance(false));
59 | try {
60 | return parser.parse(searchKey);
61 | } catch (ParseException e) {
62 | throw new QueryException("Failed to parse \""+searchKey+"\"", e);
63 | }
64 | }
65 | String q = QueryParser.escape(searchKey);
66 | BooleanQuery.Builder builder = new BooleanQuery.Builder();
67 | //filter
68 | //search
69 | BooleanQuery.Builder qbuilder = new BooleanQuery.Builder();
70 | qbuilder.add(makeBoostQuery(Constants.FIELD_IDENT, q, 100.0f), BooleanClause.Occur.SHOULD);
71 | qbuilder.add(makeBoostQuery(Constants.FIELD_TITLE, q, 10.0f), BooleanClause.Occur.SHOULD);
72 | qbuilder.add(makeBoostQuery(Constants.FIELD_TAGS, q, 1.0f), BooleanClause.Occur.SHOULD);
73 | qbuilder.add(makeBoostQuery(Constants.FIELD_DESC, q, 1.0f), BooleanClause.Occur.SHOULD);
74 | qbuilder.setMinimumNumberShouldMatch(1);
75 |
76 | builder.add(qbuilder.build(), BooleanClause.Occur.MUST);
77 |
78 | return builder.build();
79 | }
80 |
81 | /**
82 | * 对搜索加权
83 | * @param field
84 | * @param q
85 | * @param boost
86 | * @return
87 | */
88 | @Override
89 | protected BoostQuery makeBoostQuery(String field, String q, float boost) {
90 | if("ident".equals(field))
91 | return new BoostQuery(new TermQuery(new Term(Constants.FIELD_IDENT, q)), boost);
92 | return super.makeBoostQuery(field, q, boost);
93 | }
94 |
95 | /**
96 | * 构建排序对象
97 | *
98 | * @return
99 | */
100 | @Override
101 | protected Sort buildSort() {
102 | if("create".equals(sort))
103 | return new Sort(new SortedNumericSortField(Constants.FIELD_CREATED_AT, SortField.Type.LONG, true));
104 | if("update".equals(sort))
105 | return new Sort(new SortedNumericSortField(Constants.FIELD_UPDATED_AT, SortField.Type.LONG, true));
106 | return Sort.RELEVANCE;
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/core/src/main/java/com/gitee/kooder/queue/EmbedQueueProvider.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.gitee.kooder.code;
17 |
18 | import com.gitee.kooder.core.Constants;
19 | import com.gitee.kooder.index.IndexException;
20 | import com.gitee.kooder.models.CodeRepository;
21 | import com.gitee.kooder.storage.StorageFactory;
22 | import org.apache.lucene.document.*;
23 | import org.apache.lucene.index.IndexNotFoundException;
24 | import org.apache.lucene.index.IndexReader;
25 | import org.apache.lucene.index.IndexWriter;
26 | import org.apache.lucene.index.Term;
27 | import org.apache.lucene.search.IndexSearcher;
28 | import org.apache.lucene.search.TermQuery;
29 | import org.apache.lucene.search.TopDocs;
30 |
31 | import java.io.IOException;
32 |
33 | /**
34 | * 用于管理源代码仓库元信息
35 | * @author Winter Lau
36 | */
37 | public interface RepositoryManager {
38 |
39 | RepositoryManager INSTANCE = new LuceneRepositoryManager();
40 |
41 | /**
42 | * 根据仓库的编号获取仓库元信息
43 | * @param id
44 | * @return
45 | */
46 | CodeRepository get(long id);
47 |
48 | /**
49 | * 保存仓库元信息,如果存在 id 相同的则覆盖更新
50 | * @param repo
51 | */
52 | void save(CodeRepository repo);
53 |
54 | /**
55 | * 删除元信息
56 | * @param id
57 | * @return
58 | */
59 | boolean delete(long id);
60 |
61 | }
62 |
63 | /**
64 | * 使用 Lucene 索引库来保存代码仓库元信息
65 | * @author Winter Lau
66 | */
67 | class LuceneRepositoryManager implements RepositoryManager {
68 |
69 | @Override
70 | public CodeRepository get(long id) {
71 | try (IndexReader reader = StorageFactory.getIndexReader(Constants.TYPE_METADATA)) {
72 | IndexSearcher searcher = new IndexSearcher(reader);
73 | TopDocs docs = searcher.search(new TermQuery(new Term(Constants.FIELD_REPO_ID, String.valueOf(id))), 1);
74 | if (docs.totalHits.value == 0)
75 | return null;
76 | Document doc = reader.document(docs.scoreDocs[0].doc);
77 | return new CodeRepository().setDocument(doc);
78 | } catch (IndexNotFoundException e) {
79 | return null;
80 | } catch (IOException e) {
81 | throw new IndexException("Failed to get repo in metedata db : id = " + id, e);
82 | }
83 | }
84 |
85 | @Override
86 | public void save(CodeRepository repo) {
87 | synchronized (this){ //不支持并发写入
88 | try (IndexWriter writer = StorageFactory.getIndexWriter(Constants.TYPE_METADATA)) {
89 | Document doc = repo.getDocument();
90 | writer.updateDocument(new Term(Constants.FIELD_REPO_ID, repo.getIdAsString()), doc);
91 | } catch (IOException e) {
92 | throw new IndexException("Failed to save repo in metedata db : " + repo, e);
93 | }
94 | }
95 | }
96 |
97 | @Override
98 | public boolean delete(long id) {
99 | synchronized (this) {
100 | try (IndexWriter writer = StorageFactory.getIndexWriter(Constants.TYPE_METADATA)) {
101 | writer.deleteDocuments(new Term(Constants.FIELD_REPO_ID, String.valueOf(id)));
102 | } catch (IOException e) {
103 | throw new IndexException("Failed to delete repo from metedata db, id = " + id, e);
104 | }
105 | return false;
106 | }
107 | }
108 |
109 | }
--------------------------------------------------------------------------------
/gateway/src/main/java/com/gitee/kooder/server/Action.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2021, OSChina (oschina.net@gmail.com).
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *