commit d44fed37441367005985bb791ee2fa400fede0d9
Author: zhangqian <2323020057@qq.com>
Date: Thu Jun 4 11:04:59 2026 +0800
1
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..89c3cbb
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..b2a0c5f
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,67 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.2.0
+
+
+ com.oneflow.studio.modules.file.start
+ BitFun-Open
+ 1.0-SNAPSHOT
+
+
+ 21
+ 21
+ UTF-8
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/oneflow/studio/modules/file/start/BitFunApplication.java b/src/main/java/com/oneflow/studio/modules/file/start/BitFunApplication.java
new file mode 100644
index 0000000..1554298
--- /dev/null
+++ b/src/main/java/com/oneflow/studio/modules/file/start/BitFunApplication.java
@@ -0,0 +1,11 @@
+package com.oneflow.studio.modules.file.start;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class BitFunApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(BitFunApplication.class, args);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/oneflow/studio/modules/file/start/config/BitFunProperties.java b/src/main/java/com/oneflow/studio/modules/file/start/config/BitFunProperties.java
new file mode 100644
index 0000000..43321d7
--- /dev/null
+++ b/src/main/java/com/oneflow/studio/modules/file/start/config/BitFunProperties.java
@@ -0,0 +1,17 @@
+package com.oneflow.studio.modules.file.start.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+
+@Component
+@Data
+@ConfigurationProperties(prefix = "bitfun")
+public class BitFunProperties {
+
+ private String workspaceRoot;
+ private String installDir;
+ private String exePath;
+
+}
diff --git a/src/main/java/com/oneflow/studio/modules/file/start/controller/BitFunController.java b/src/main/java/com/oneflow/studio/modules/file/start/controller/BitFunController.java
new file mode 100644
index 0000000..6474f0d
--- /dev/null
+++ b/src/main/java/com/oneflow/studio/modules/file/start/controller/BitFunController.java
@@ -0,0 +1,93 @@
+package com.oneflow.studio.modules.file.start.controller;
+
+import com.oneflow.studio.modules.file.start.config.BitFunProperties;
+import com.oneflow.studio.modules.file.start.req.BitFunReq;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/bitfun")
+public class BitFunController {
+
+ private final BitFunProperties bitFunProperties;
+
+ public BitFunController(BitFunProperties bitFunProperties) {
+ this.bitFunProperties = bitFunProperties;
+ }
+
+ @PostMapping("/open")
+ public Map open(@RequestBody BitFunReq request) throws Exception {
+ System.out.println("开始测试--------------------------");
+ String projectName = safeName(request.getProjectName());
+ String branch = safeName(request.getBranch());
+ String codeName = safeName(request.getCodeName());
+
+ String workspaceName = codeName + projectName + "-" + branch;
+ Path workspacePath = Paths.get(bitFunProperties.getWorkspaceRoot(), workspaceName);
+
+ Files.createDirectories(workspacePath);
+
+ boolean alreadyCloned = isGitProject(workspacePath);
+
+ if (!alreadyCloned) {
+ if (Files.list(workspacePath).findAny().isPresent()) {
+ throw new RuntimeException("工作区已存在但不是 Git 项目:" + workspacePath);
+ }
+
+ ProcessBuilder gitClone = new ProcessBuilder(
+ "git",
+ "clone",
+ "-b",
+ request.getBranch(),
+ request.getGitUrl(),
+ "."
+ );
+
+ gitClone.directory(workspacePath.toFile());
+ gitClone.inheritIO();
+
+ int cloneExitCode = gitClone.start().waitFor();
+
+ if (cloneExitCode != 0) {
+ throw new RuntimeException("git clone 失败");
+ }
+ }
+
+ ProcessBuilder openBitFun = new ProcessBuilder(
+ bitFunProperties.getExePath(),
+ "--open-workspace",
+ workspacePath.toString()
+ );
+
+ openBitFun.directory(new File(bitFunProperties.getInstallDir()));
+ openBitFun.start();
+
+ Map result = new HashMap<>();
+ result.put("success", true);
+ result.put("alreadyCloned", alreadyCloned);
+ result.put("message", alreadyCloned ? "项目已存在,已直接打开 BitFun 工作区" : "项目克隆完成,已打开 BitFun 工作区");
+ result.put("workspacePath", workspacePath.toString());
+
+ return result;
+ }
+
+ private boolean isGitProject(Path path) {
+ return Files.exists(path.resolve(".git"));
+ }
+
+ private String safeName(String value) {
+ if (value == null) {
+ return "";
+ }
+ return value.replaceAll("[\\\\/:*?\"<>|]", "-").trim();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/oneflow/studio/modules/file/start/req/BitFunReq.java b/src/main/java/com/oneflow/studio/modules/file/start/req/BitFunReq.java
new file mode 100644
index 0000000..dd903b0
--- /dev/null
+++ b/src/main/java/com/oneflow/studio/modules/file/start/req/BitFunReq.java
@@ -0,0 +1,11 @@
+package com.oneflow.studio.modules.file.start.req;
+
+import lombok.Data;
+
+@Data
+public class BitFunReq {
+ private String gitUrl;
+ private String branch;
+ private String projectName;
+ private String codeName;
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
new file mode 100644
index 0000000..b7f8d19
--- /dev/null
+++ b/src/main/resources/application.yml
@@ -0,0 +1,7 @@
+server:
+ port: 8089
+
+bitfun:
+ workspace-root: D:\workpsace-temp
+ install-dir: D:\bitfun
+ exe-path: D:\bitfun\bitfun-desktop.exe
\ No newline at end of file