Skip to content

Commit a75c274

Browse files
CodeCasterXclaude
andcommitted
[fit-launcher] 重构 init 命令支持 Service/Plugin 分离架构和交互式引导
- 支持创建独立的 Service (SPI) 和 Plugin 项目,符合 FIT 框架的插件架构规范 - 将模板代码从 fit.js 中分离到独立的 .tpl 文件,提高可维护性 - 新增交互式引导模式,所有参数均有合理默认值,用户可直接回车使用 - 保持向后兼容,支持命令行参数方式用于自动化场景 - Service 项目使用 build-service goal,Plugin 项目使用 build-plugin 和 package-plugin goals - Plugin 项目自动依赖对应的 Service 项目 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 2176490 commit a75c274

File tree

9 files changed

+684
-340
lines changed

9 files changed

+684
-340
lines changed

framework/fit/java/fit-launcher/src/main/resources/bin/fit.js

Lines changed: 323 additions & 340 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Maven
2+
target/
3+
pom.xml.tag
4+
pom.xml.releaseBackup
5+
pom.xml.versionsBackup
6+
pom.xml.next
7+
release.properties
8+
dependency-reduced-pom.xml
9+
buildNumber.properties
10+
.mvn/timing.properties
11+
12+
# IDE
13+
.idea/
14+
*.iml
15+
.vscode/
16+
.eclipse/
17+
.settings/
18+
.classpath
19+
.project
20+
21+
# OS
22+
.DS_Store
23+
Thumbs.db
24+
25+
# Logs
26+
*.log
27+
28+
# Build
29+
build/
30+
dist/
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# {{PROJECT_NAME}}
2+
3+
A FIT Framework Plugin (Service Implementation).
4+
5+
## Project Information
6+
7+
- **Group ID**: {{GROUP_ID}}
8+
- **Artifact ID**: {{ARTIFACT_ID}}
9+
- **Package**: {{PACKAGE}}
10+
- **Service Dependency**: {{SERVICE_GROUP_ID}}:{{SERVICE_ARTIFACT_ID}}
11+
- **FIT Version**: {{FIT_VERSION}}
12+
13+
## Build
14+
15+
```bash
16+
mvn clean install
17+
```
18+
19+
This will:
20+
1. Build the plugin JAR file
21+
2. Package the plugin with all dependencies
22+
23+
## Plugin Structure
24+
25+
```
26+
{{PROJECT_NAME}}/
27+
├── src/main/java/
28+
│ └── {{PACKAGE_PATH}}/
29+
│ └── Default{{SERVICE_NAME}}.java # 服务实现(使用 @Component 和 @Fitable)
30+
└── src/main/resources/
31+
└── application.yml # FIT 配置文件
32+
```
33+
34+
## Key Annotations
35+
36+
- `@Component` - 标记为 FIT 组件,自动注册到 IoC 容器
37+
- `@Fitable(id = "default-{{SERVICE_ID}}")` - 标记为可远程调用的实现
38+
39+
## Usage
40+
41+
### 1. 部署插件
42+
43+
将构建好的插件 JAR 包部署到 FIT 应用的插件目录:
44+
45+
```bash
46+
cp target/{{ARTIFACT_ID}}-1.0-SNAPSHOT.jar /path/to/fit-app/plugins/
47+
```
48+
49+
### 2. 在应用中使用
50+
51+
首先确保 service 项目已安装到本地仓库或远程仓库。
52+
53+
然后在应用中注入并使用服务:
54+
55+
```java
56+
@Component
57+
public class MyController {
58+
59+
@FitBean
60+
private {{SERVICE_NAME}} {{SERVICE_ID}};
61+
62+
public void usePlugin() {
63+
String result = {{SERVICE_ID}}.execute();
64+
System.out.println(result);
65+
}
66+
}
67+
```
68+
69+
## Documentation
70+
71+
For more information about FIT Framework plugins, visit:
72+
- [FIT Plugin Development Guide](https://github.com/ModelEngine-Group/fit-framework/tree/main/docs)
73+
- [FIT Quick Start Guide](https://github.com/ModelEngine-Group/fit-framework/tree/main/docs)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) {{YEAR}} FIT Framework Project.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
package {{PACKAGE}};
7+
8+
import {{SERVICE_PACKAGE}}.{{SERVICE_NAME}};
9+
import modelengine.fitframework.annotation.Component;
10+
import modelengine.fitframework.annotation.Fitable;
11+
12+
/**
13+
* {{SERVICE_NAME}} 的默认实现
14+
*/
15+
@Component
16+
public class Default{{SERVICE_NAME}} implements {{SERVICE_NAME}} {
17+
@Override
18+
@Fitable(id = "default-{{SERVICE_ID}}")
19+
public String execute() {
20+
return "{{SERVICE_NAME}} plugin is working successfully!";
21+
}
22+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fit:
2+
beans:
3+
packages:
4+
- '{{PACKAGE}}'
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>{{GROUP_ID}}</groupId>
7+
<artifactId>{{ARTIFACT_ID}}</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<java.version>17</java.version>
13+
14+
<!-- FIT version -->
15+
<fit.version>{{FIT_VERSION}}</fit.version>
16+
17+
<!-- Maven plugin versions -->
18+
<maven.compiler.version>3.14.0</maven.compiler.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.fitframework</groupId>
24+
<artifactId>fit-api</artifactId>
25+
<version>${fit.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.fitframework</groupId>
29+
<artifactId>fit-util</artifactId>
30+
<version>${fit.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>{{SERVICE_GROUP_ID}}</groupId>
34+
<artifactId>{{SERVICE_ARTIFACT_ID}}</artifactId>
35+
<version>{{SERVICE_VERSION}}</version>
36+
</dependency>
37+
</dependencies>
38+
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-compiler-plugin</artifactId>
44+
<version>${maven.compiler.version}</version>
45+
<configuration>
46+
<source>${java.version}</source>
47+
<target>${java.version}</target>
48+
<encoding>${project.build.sourceEncoding}</encoding>
49+
<compilerArgs>
50+
<arg>-parameters</arg>
51+
</compilerArgs>
52+
</configuration>
53+
</plugin>
54+
<plugin>
55+
<groupId>org.fitframework</groupId>
56+
<artifactId>fit-build-maven-plugin</artifactId>
57+
<version>${fit.version}</version>
58+
<executions>
59+
<execution>
60+
<id>build-plugin</id>
61+
<goals>
62+
<goal>build-plugin</goal>
63+
</goals>
64+
</execution>
65+
<execution>
66+
<id>package-plugin</id>
67+
<goals>
68+
<goal>package-plugin</goal>
69+
</goals>
70+
</execution>
71+
</executions>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# {{PROJECT_NAME}}
2+
3+
A FIT Framework Service (SPI).
4+
5+
## Project Information
6+
7+
- **Group ID**: {{GROUP_ID}}
8+
- **Artifact ID**: {{ARTIFACT_ID}}
9+
- **Package**: {{PACKAGE}}
10+
- **FIT Version**: {{FIT_VERSION}}
11+
12+
## Build
13+
14+
```bash
15+
mvn clean install
16+
```
17+
18+
This will:
19+
1. Build the service JAR file
20+
2. Make it available for plugin implementations
21+
22+
## Service Structure
23+
24+
```
25+
{{PROJECT_NAME}}/
26+
└── src/main/java/
27+
└── {{PACKAGE_PATH}}/
28+
└── {{SERVICE_NAME}}.java # 服务接口(使用 @Genericable)
29+
```
30+
31+
## Key Annotations
32+
33+
- `@Genericable(id = "{{SERVICE_NAME}}")` - 标记服务接口,支持远程和本地调用
34+
35+
## Usage
36+
37+
### 1. 安装到本地仓库
38+
39+
```bash
40+
mvn clean install
41+
```
42+
43+
### 2. 创建插件实现
44+
45+
其他项目可以依赖此服务并创建插件实现:
46+
47+
```xml
48+
<dependency>
49+
<groupId>{{GROUP_ID}}</groupId>
50+
<artifactId>{{ARTIFACT_ID}}</artifactId>
51+
<version>1.0-SNAPSHOT</version>
52+
</dependency>
53+
```
54+
55+
然后实现 {{SERVICE_NAME}} 接口:
56+
57+
```java
58+
@Component
59+
public class Default{{SERVICE_NAME}} implements {{SERVICE_NAME}} {
60+
@Override
61+
@Fitable(id = "default-{{SERVICE_ID}}")
62+
public String execute() {
63+
return "Implementation result";
64+
}
65+
}
66+
```
67+
68+
## Documentation
69+
70+
For more information about FIT Framework services, visit:
71+
- [FIT Service Development Guide](https://github.com/ModelEngine-Group/fit-framework/tree/main/docs)
72+
- [FIT Quick Start Guide](https://github.com/ModelEngine-Group/fit-framework/tree/main/docs)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) {{YEAR}} FIT Framework Project.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
package {{PACKAGE}};
7+
8+
import modelengine.fitframework.annotation.Genericable;
9+
10+
/**
11+
* {{SERVICE_NAME}} 服务接口(SPI)
12+
*/
13+
public interface {{SERVICE_NAME}} {
14+
/**
15+
* 执行服务操作
16+
*
17+
* @return 服务执行结果
18+
*/
19+
@Genericable(id = "{{SERVICE_NAME}}")
20+
String execute();
21+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>{{GROUP_ID}}</groupId>
7+
<artifactId>{{ARTIFACT_ID}}</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<java.version>17</java.version>
13+
14+
<!-- FIT version -->
15+
<fit.version>{{FIT_VERSION}}</fit.version>
16+
17+
<!-- Maven plugin versions -->
18+
<maven.compiler.version>3.14.0</maven.compiler.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.fitframework</groupId>
24+
<artifactId>fit-api</artifactId>
25+
<version>${fit.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.fitframework</groupId>
29+
<artifactId>fit-util</artifactId>
30+
<version>${fit.version}</version>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-compiler-plugin</artifactId>
39+
<version>${maven.compiler.version}</version>
40+
<configuration>
41+
<source>${java.version}</source>
42+
<target>${java.version}</target>
43+
<encoding>${project.build.sourceEncoding}</encoding>
44+
<compilerArgs>
45+
<arg>-parameters</arg>
46+
</compilerArgs>
47+
</configuration>
48+
</plugin>
49+
<plugin>
50+
<groupId>org.fitframework</groupId>
51+
<artifactId>fit-build-maven-plugin</artifactId>
52+
<version>${fit.version}</version>
53+
<executions>
54+
<execution>
55+
<id>build-service</id>
56+
<goals>
57+
<goal>build-service</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
</project>

0 commit comments

Comments
 (0)