SIFT是一种命令行工具,可从JVM字节码分析和反向模型软件系统设计。它通过使用称为系统模型模板的预定义模板来处理.class或.jar文件来运行。这些模板提供了有关技术堆栈或特定项目构造的知识,该模板使工具能够生成系统的全面模型。
最终的系统模型由描述系统的结构和行为的实体组成。
--diff选项分析新功能或更改的影响。
带有轴突框架模板的弹簧靴;在https://github.com/eugenp/tutorials/tree/master/axon中过滤和确认的订单。




Usage: sift [OPTIONS]
Sift is a command-line tool that analyzes and reverse models software system designs
from JVM bytecode.
Template options:
-t, --template TEMPLATE The template producing the system model.
-l, --list-templates Print all installed templates.
-T, --list-entity-types Lists entity types defined by template.
-f, --class-dir, --classes PATH|URI|MAVEN_COORD
Provide class input as a directory, JAR file, URI
(pointing to a JAR), or Maven coordinate.
-d, --diff FILE_JSON|URI|MAVEN_COORD Compare the system model from '-f' with another,
specified as a JSON file (previously saved System
Model), class input as a directory, JAR file, URI
(pointing to a JAR), or Maven coordinate.
--profile Print execution times and input/output for the
executed template.
-D, --dump-system-model Print all entities along with their properties and
metadata.
Entity tree/graph options:
-L, --max-depth INT Max display depth of the tree.
-F, --filter REGEX Filter nodes by label. (repeatable)
-S, --filter-context REGEX Filter nodes by label, while also including
sibling nodes. (repeatable)
-e, --exclude REGEX Exclude nodes when label matches REGEX.
(repeatable)
-c, --column [all|element-id|element-type|entity-type]
Columns to display. (repeatable)
-E, --exclude-type ENTITY_TYPE Exclude entity types from tree. (repeatable)
-r, --tree-root ENTITY_TYPE Tree built around requested entity type.
(repeatable)
--no-emoji Disables printing emoji in entity labels.
Visualization options:
-R, --render Render entities with graphviz's DOT language.
--edge-layout [spline|polyline|ortho]
Sets the layout for the lines between nodes.
(default: spline)
Serialization options:
-s, --save FILE_JSON Save the resulting system model as json.
--load FILE_JSON Load a previously saved system model.
Debug options:
--debug Print log/logCount statements from the executed
template.
-X, --debug-inverse-trace Print the inverse element trace for the elements
specified with --debug-element-traces
-x, --debug-element-trace ELEMENT_ID Print all element traces leading to the specified
elements
Miscellaneous options:
-a, --ansi [none|ansi16|ansi256|truecolor]
Override automatically detected ANSI support.
--stacktrace Print stacktrace to stderr if an error occurs
--version Print version and release date.
-m, --maven-repository VALUE Additional maven repositories to use for
downloading artifacts. Maven central
(https://repo1.maven.org/maven2/) and local user
repositories are always included.
--statistics Print internal statistics about the system model
template context.
--generate-completion [bash|zsh|fish]
-h, --help Show this message and exit
Examples:
sift --template spring-axon -f my-spring-project
Model the system using the "spring-axon" template on the classes in the
"my-spring-project" directory.
sift -t spring-axon -f . -F "Order(Created|Shipped)"
Model the system using the "spring-axon" template on the current directory's
classes, filter nodes containing the regular expression "Order(Created|Shipped)".
sift -t spring-axon -f . --diff feature-01.json
Compare the current design of the system using the "spring-axon" template on
the classes in the current directory against a previously saved system model
from "feature-01.json" and show the differences.
sift -t sift -f "net.onedaybeard.sift:core:0.13.0" --diff "net.onedaybeard.sift:core:0.9.0"
Compare two different versions of the DSL API using the 'sift' template, specified
by their maven coordinates.
系统模型描述了系统内实体的结构和关系。实体是系统中的对象或组件,由类,方法,字段,参数或通用签名独特地识别。
实体由其Entity.Type分类。实体类型代表系统中任何值得注意的部分。例如,类型可以包括REST控制器,HTTP端点,入站/出站消息,RDS,存储库等。
$ sift --template spring-axon -f target/classes --list-entity-types
entity types of spring-axon
1 aggregate
2 aggregate-ctor
1 aggregate-member
6 command
6 command-handler
1 controller
13 endpoint
7 event
7 event-handler
7 event-sourcing-handler
1 projection
3 query
4 query-handler系统模型模板描述了如何在给定技术堆栈和/或特定于项目的构造中识别实体。这些模板以声明性的DSL编写,用于从输入类中产生系统模型。 DSL提供了高级抽象,用于识别和相互关联的实体与阶级结构或使用。
下面的代码显示了一个简单的系统模型模板,该模板可以标识系统内的REST控制器和HTTP端点,并将两个实体关联。
val controller = Entity . Type ( " controller " )
val endpoint = Entity . Type ( " endpoint " )
template {
// iterate over all input classes
classes {
annotatedBy< RestController >() // filter classes
entity(controller) // mark remaining as 'controller'
methods { // iterate all controller methods
annotatedBy< Endpoint >() // filter @Endpoint methods
entity(endpoint)
// associate controllers with their endpoints
controller[ " endpoints " ] = endpoint
}
}
}输入元素(类,方法,参数,字段,通用签名)分批按线处理。系统模型模板的执行可以与--profile选项相比。

典型的模板可以用约100-200行的代码表示。一些模板,例如JPA和JDBI的模板,显着较短。用户定义的模板可以包含多个现有模板,以更好地描述基础系统,同时还可以保持最终的DSL简洁。
SIFT需要Java 17或更高版本的运行时间。
对于Window用户,建议在WSL下进行筛选,直到适当的Windows路径到位为止。
安装SIFT的最简单方法是克隆存储库并运行mvn install ,然后将SIFT.ZSH | SH复制到$PATH上的位置,例如:
mvn install 。这将SIFT安装到~/.local/share/sift/binsift.zsh或sift.sh复制到~/.local/bin/sift main分支总是指向最新的发布提交。
如果安装了GRAALVM和本机图像,则可以使用native-image Maven配置文件: mvn install -P native-image构建本机二进制。所得的二进制将位于~/.local/share/sift/bin/sift中。 sift.zsh和sift.sh首先检查本机二进制是否可用,否则尝试运行jar。
本机二进制文件比JAR快得多,但是如果需要对系统模型(VIA --load或--diff )或包含未知类型的系统模型(例如,来自withValue() )的系统模型模板,则可能会引起问题。