Skip to content

Commit bdf981e

Browse files
ZhiFengJiajiazhifeng
authored andcommitted
feat:初始化文件树
1 parent 910824e commit bdf981e

File tree

22 files changed

+714
-79
lines changed

22 files changed

+714
-79
lines changed

remote-core/src/main/java/com/jzf/remote/core/JavaFileObjectByteCode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class JavaFileObjectByteCode extends SimpleJavaFileObject {
2020
private final ByteArrayOutputStream byteArrayOutputStream;
2121

2222
protected JavaFileObjectByteCode(String className) {
23-
super(URI.create("string:///" + className.replaceAll("\\.", "/") + Kind.CLASS.extension), Kind.CLASS);
23+
super(URI.create("string:///" + className + Kind.CLASS.extension), Kind.CLASS);
2424
this.byteArrayOutputStream = new ByteArrayOutputStream();
2525
}
2626

remote-core/src/main/java/com/jzf/remote/core/JavaFileObjectSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class JavaFileObjectSource extends SimpleJavaFileObject {
1616
private final CharSequence content;
1717

1818
protected JavaFileObjectSource(String className, CharSequence content) {
19-
super(URI.create("string:///" + className.replaceAll("\\.", "/") + Kind.SOURCE.extension), Kind.SOURCE);
19+
super(URI.create("string:///" + className + Kind.SOURCE.extension), Kind.SOURCE);
2020
this.content = content;
2121
}
2222

remote-web/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
<artifactId>commons-io</artifactId>
5555
<version>2.11.0</version>
5656
</dependency>
57+
<dependency>
58+
<groupId>org.projectlombok</groupId>
59+
<artifactId>lombok</artifactId>
60+
</dependency>
5761

5862
<dependency>
5963
<groupId>org.springframework.boot</groupId>

remote-web/src/assembly/assembly.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
1+
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
24
<!-- id 标识符,添加到生成文件名称的后缀符。如果指定id的话,目标文件则是 ${artifactId}-${id}.jar -->
35
<id>distribution</id>
46
<formats>

remote-web/src/main/java/com/jzf/remote/web/controller/RemoteDebugController.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.springframework.web.bind.annotation.PostMapping;
55
import org.springframework.web.bind.annotation.RequestMapping;
66
import org.springframework.web.bind.annotation.RestController;
7-
import org.springframework.web.multipart.MultipartFile;
87

98
/**
109
* @author jiazhifeng
@@ -27,18 +26,13 @@ public class RemoteDebugController {
2726
* 2.监控服务的内存占用,线程堆栈信息等等.
2827
* 3.可以把这段调式代码想象成打包部署时就已经存在项目中一样.
2928
*
30-
* @param file 待执行的java文件
29+
* @param className 待编译的Java文件名称
30+
* @param sourceCode 待编译的Java源码
3131
* @return java文件执行结果
3232
*/
33-
@PostMapping("/executeJavaSourceFile")
34-
public String executeJavaSourceFile(MultipartFile file) throws Exception {
35-
String className = file.getOriginalFilename().replace(".java", "");
36-
String sourceCode = new String(file.getBytes());
37-
return JavaFileExecuter.execute(className, sourceCode);
38-
}
39-
4033
@PostMapping("/executeJavaSourceCode")
4134
public String executeJavaSourceCode(String className, String sourceCode) throws Exception {
35+
className = className.substring(className.lastIndexOf("\\") + 1, className.lastIndexOf("."));
4236
return JavaFileExecuter.execute(className, sourceCode);
4337
}
4438
}

remote-web/src/main/java/com/jzf/remote/web/controller/SourceCodeController.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.jzf.remote.web.controller;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.nio.charset.Charset;
6+
import java.util.ArrayList;
7+
import java.util.Collection;
8+
import java.util.List;
9+
import java.util.stream.Collectors;
10+
11+
import com.jzf.remote.web.model.dto.TreeDTO;
12+
import com.jzf.remote.web.util.TreeUtils;
13+
import org.apache.commons.io.FileUtils;
14+
import org.springframework.web.bind.annotation.GetMapping;
15+
import org.springframework.web.bind.annotation.PathVariable;
16+
import org.springframework.web.bind.annotation.PostMapping;
17+
import org.springframework.web.bind.annotation.RequestMapping;
18+
import org.springframework.web.bind.annotation.RestController;
19+
20+
@RestController
21+
@RequestMapping("/project")
22+
public class projectController {
23+
24+
@PostMapping("/getFile")
25+
public String getFile(String filePath) throws IOException {
26+
return FileUtils.readFileToString(new File(TreeUtils.fileDirectory + filePath), Charset.forName("UTF-8"));
27+
}
28+
29+
@GetMapping("/tree")
30+
public List<TreeDTO> tree() {
31+
TreeDTO root = new TreeDTO(null);
32+
TreeUtils.generateTree(new File(TreeUtils.fileDirectory),root);
33+
return root.getChildren();
34+
}
35+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.jzf.remote.web.model.dto;
2+
3+
import lombok.Data;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* @author jiazhifeng
10+
* @date 2021/12/8 9:25
11+
*/
12+
@Data
13+
public class TreeDTO {
14+
public static final String FOLDER_ICON = "jstree-folder";
15+
public static final String FILE_ICON = "jstree-file";
16+
17+
private String id;
18+
private String text;
19+
private String icon;
20+
private State state = new State();
21+
private List<TreeDTO> children = new ArrayList<>();
22+
private String li_attr;
23+
private String a_attr;
24+
25+
public TreeDTO(String name){
26+
this.id = name;
27+
this.text = name;
28+
}
29+
30+
public TreeDTO(String id,String text){
31+
this.id = id;
32+
this.text = text;
33+
}
34+
35+
public TreeDTO(String id,String text,String icon){
36+
this.id = id;
37+
this.text = text;
38+
this.icon = icon;
39+
}
40+
41+
@Data
42+
public static class State{
43+
private boolean opened;
44+
private boolean disabled;
45+
private boolean selected;
46+
}
47+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.jzf.remote.web.util;
2+
3+
import com.jzf.remote.web.model.dto.TreeDTO;
4+
5+
import java.io.File;
6+
7+
/**
8+
* @author jiazhifeng
9+
* @date 2021/12/8 10:59
10+
*/
11+
public class TreeUtils {
12+
public static final String fileDirectory = System.getProperty("user.dir") + "/../source_code_files/";
13+
14+
public static void generateTree(File fileDir, TreeDTO tree) {
15+
if (fileDir.exists()) {
16+
File[] files = fileDir.listFiles();
17+
if (files != null) {
18+
for (File file : files) {
19+
String filePath = file.getPath().substring(fileDirectory.length() - 1);
20+
if (file.isDirectory()) {
21+
TreeDTO treeDTO = new TreeDTO(filePath, file.getName(), TreeDTO.FOLDER_ICON);
22+
tree.getChildren().add(treeDTO);
23+
generateTree(file, treeDTO);
24+
} else {
25+
tree.getChildren().add(new TreeDTO(filePath, file.getName(), TreeDTO.FILE_ICON));
26+
}
27+
}
28+
}
29+
}
30+
}
31+
32+
}

0 commit comments

Comments
 (0)