Skip to content

Commit 2197ad2

Browse files
wolfboysbenjobs
and
benjobs
authored
[Improve] project src path improvements (#3649)
Co-authored-by: benjobs <[email protected]>
1 parent f456dfb commit 2197ad2

File tree

1 file changed

+23
-12
lines changed
  • streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity

1 file changed

+23
-12
lines changed

Diff for: streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/Project.java

+23-12
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,38 @@ public class Project implements Serializable {
106106

107107
private transient String dateTo;
108108

109-
/** project source */
110-
private transient String appSource;
111-
112109
/** get project source */
113110
@JsonIgnore
114111
public File getAppSource() {
115-
if (appSource == null) {
116-
appSource = Workspace.PROJECT_LOCAL_PATH();
117-
}
118-
File sourcePath = new File(appSource);
112+
File sourcePath = new File(Workspace.PROJECT_LOCAL_PATH());
119113
if (!sourcePath.exists()) {
120114
sourcePath.mkdirs();
115+
} else if (sourcePath.isFile()) {
116+
throw new IllegalArgumentException(
117+
"[StreamPark] project source base path: "
118+
+ sourcePath.getAbsolutePath()
119+
+ " must be directory");
121120
}
122-
if (sourcePath.isFile()) {
123-
throw new IllegalArgumentException("[StreamPark] sourcePath must be directory");
121+
122+
String sourceDir = getSourceDirName();
123+
File srcFile =
124+
new File(String.format("%s/%s/%s", sourcePath.getAbsolutePath(), name, sourceDir));
125+
String newPath = String.format("%s/%s", sourcePath.getAbsolutePath(), id);
126+
if (srcFile.exists()) {
127+
File newFile = new File(newPath);
128+
if (!newFile.exists()) {
129+
newFile.mkdirs();
130+
}
131+
// old project path move to new path
132+
srcFile.getParentFile().renameTo(newFile);
124133
}
134+
return new File(newPath, sourceDir);
135+
}
136+
137+
private String getSourceDirName() {
125138
String branches = this.getBranches() == null ? "main" : this.getBranches();
126139
String rootName = url.replaceAll(".*/|\\.git|\\.svn", "");
127-
String fullName = rootName.concat("-").concat(branches);
128-
String path = String.format("%s/%s/%s", sourcePath.getAbsolutePath(), getName(), fullName);
129-
return new File(path);
140+
return rootName.concat("-").concat(branches);
130141
}
131142

132143
@JsonIgnore

0 commit comments

Comments
 (0)