跳到主要内容

关于 OpenSibyl

提示

对于他在工业领域中的应用,可以查看 QCON2023 的演讲:代码快照 x 覆盖率:洞察研发体系的最后 100 米

提示

在不进行编译的情况下难以拿到准确的引用链(issue5),所以sibyl2原生提供的引用链是偏大的。如果你希望使用准确的引用链功能,请转向 srctx 项目。 sibyl2将专注于从文本中提取语言特性的部分。

OpenSibyl 是一个开箱即用的高性能代码分析服务。仅需要一次花费数秒的分析上传,即可将您的仓库源码转换为逻辑结构存储,供您在任意时刻进行读取与使用。

upload

sandbox-agent/src/main/java/com/alibaba/jvm/sandbox/agent/SandboxClassLoader.java
package com.alibaba.jvm.sandbox.agent;

import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
import java.util.Enumeration;
import java.util.jar.JarFile;

class SandboxClassLoader extends URLClassLoader {
// ...
@SuppressWarnings("unused")
public void closeIfPossible() {
if (this instanceof Closeable) {
try {
((Closeable) this).close();
} catch (Throwable cause) {
// ignore...
}
return;
}

try {
final Object sun_misc_URLClassPath = forceGetDeclaredFieldValue(URLClassLoader.class, "ucp", this);
final Object java_util_Collection = forceGetDeclaredFieldValue(sun_misc_URLClassPath.getClass(), "loaders", sun_misc_URLClassPath);

for (final Object sun_misc_URLClassPath_JarLoader :
((Collection) java_util_Collection).toArray()) {
try {
final JarFile java_util_jar_JarFile = forceGetDeclaredFieldValue(sun_misc_URLClassPath_JarLoader.getClass(), "jar", sun_misc_URLClassPath_JarLoader);
java_util_jar_JarFile.close();
} catch (Throwable t) {
// if we got this far, this is probably not a JAR loader so skip it
}
}

} catch (Throwable cause) {
// ignore...
}

}
// ...
}

当然他是跨语言的,且无需编译。

./extract.go
package sibyl2

import (
"context"
"errors"
"fmt"

"github.com/opensibyl/sibyl2/pkg/core"
"github.com/opensibyl/sibyl2/pkg/extractor"
)

// ExtractConfig todo: should not use config ptr for parallel running
type ExtractConfig struct {
LangType core.LangType
ExtractType extractor.ExtractType
FileFilter func(path string) bool
}

func DefaultConfig() *ExtractConfig {
return &ExtractConfig{}
}

func ExtractFromString(content string, config *ExtractConfig) (*extractor.FileResult, error) {
return ExtractFromBytes([]byte(content), config)
}

// ...
提示

目前我们支持的语言可见 多语言

  • 作为一个底层组件,我们提供了多种部署模式来适应不同严格程度的业务场景。
  • 除此之外,我们也允许开发者单独将其当做命令行工具、golang库使用。
  • 你可以用它构建各种各样神奇的功能,例如为你的git仓库历史构建动画:

您可以通过 常见场景 一节了解它的一些实际场景。 快来 体验 吧~