Commit e9adc38c authored by liaozan's avatar liaozan 🏀

Support dynamic group config

parent d3505be0
package com.schbrain.archetype.initializer.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author liaozan
* @since 2022/3/20
*/
@Configuration(proxyBeanMethods = false)
public class WebConfiguration implements WebMvcConfigurer {
@Bean
public CorsFilter corsFilter() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true);
corsConfiguration.addAllowedOriginPattern("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addExposedHeader("*");
corsConfiguration.addAllowedMethod("*");
UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
configurationSource.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(configurationSource);
}
}
\ No newline at end of file
...@@ -11,6 +11,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -11,6 +11,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "archetype") @ConfigurationProperties(prefix = "archetype")
public class ArchetypeProperties { public class ArchetypeProperties {
/**
* 骨架项目地址
*/
private String sourceUrl; private String sourceUrl;
} }
\ No newline at end of file
...@@ -11,8 +11,14 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -11,8 +11,14 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "gitlab") @ConfigurationProperties(prefix = "gitlab")
public class GitProperties { public class GitProperties {
/**
* gitlab server
*/
private String serverUrl; private String serverUrl;
/**
* 访问 token
*/
private String personalAccessToken; private String personalAccessToken;
} }
\ No newline at end of file
package com.schbrain.archetype.initializer.config.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;
/**
* @author liaozan
* @since 2023-05-29
*/
@Data
@ConfigurationProperties(prefix = "project.group")
public class ProjectGroupProperties {
/**
* 允许的项目命名空间
*/
private List<String> allowList;
}
package com.schbrain.archetype.initializer.controller; package com.schbrain.archetype.initializer.controller;
import com.schbrain.archetype.initializer.config.properties.ProjectGroupProperties;
import com.schbrain.archetype.initializer.param.ArchetypeGenerateParam; import com.schbrain.archetype.initializer.param.ArchetypeGenerateParam;
import com.schbrain.archetype.initializer.response.PreviewFileTree; import com.schbrain.archetype.initializer.response.PreviewFileTree;
import com.schbrain.archetype.initializer.service.ArchetypeService; import com.schbrain.archetype.initializer.service.ArchetypeService;
import com.schbrain.common.web.result.ResponseDTO; import com.schbrain.common.web.result.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -17,29 +19,44 @@ import java.util.List; ...@@ -17,29 +19,44 @@ import java.util.List;
* @since 2022/3/20 * @since 2022/3/20
*/ */
@RestController @RestController
@EnableConfigurationProperties(ProjectGroupProperties.class)
public class ArchetypeController { public class ArchetypeController {
@Autowired @Autowired
private ArchetypeService archetypeService; private ArchetypeService archetypeService;
@Autowired
@GetMapping("/archetype/update") private ProjectGroupProperties projectGroupProperties;
public ResponseDTO<Boolean> updateArchetype() {
return ResponseDTO.success(archetypeService.update()); /**
* 获取允许的 group 列表
*/
@GetMapping("/archetype/allowed_groups")
public ResponseDTO<List<String>> getAllowedGroupList() {
return ResponseDTO.success(projectGroupProperties.getAllowList());
} }
/**
* 生成项目
*/
@PostMapping("/archetype/generate") @PostMapping("/archetype/generate")
public ResponseDTO<String> generateArchetype(@RequestBody @Validated ArchetypeGenerateParam param) { public ResponseDTO<String> generateArchetype(@RequestBody @Validated ArchetypeGenerateParam param) {
return ResponseDTO.success(archetypeService.generate(param)); return ResponseDTO.success(archetypeService.generate(param));
} }
/**
* 预览项目
*/
@GetMapping("/archetype/preview/{id}") @GetMapping("/archetype/preview/{id}")
public ResponseDTO<List<PreviewFileTree>> previewArchetype(@PathVariable String id) throws FileNotFoundException { public ResponseDTO<List<PreviewFileTree>> previewArchetype(@PathVariable String id) throws FileNotFoundException {
return ResponseDTO.success(archetypeService.preview(id)); return ResponseDTO.success(archetypeService.preview(id));
} }
/**
* 下载项目
*/
@GetMapping("/archetype/download/{id}") @GetMapping("/archetype/download/{id}")
public void downloadArchetype(@PathVariable String id) throws IOException { public void downloadArchetype(@PathVariable String id) throws IOException {
archetypeService.download(id); archetypeService.download(id);
} }
} }
\ No newline at end of file
...@@ -18,9 +18,12 @@ public class GitlabController { ...@@ -18,9 +18,12 @@ public class GitlabController {
@Autowired @Autowired
private GitlabService gitlabService; private GitlabService gitlabService;
/**
* 获取 gitlab 群组
*/
@GetMapping("/gitlab/groups") @GetMapping("/gitlab/groups")
public List<Tree<Long>> groupList() { public List<Tree<Long>> groupList() {
return gitlabService.fetchGroups(); return gitlabService.fetchGroups();
} }
} }
\ No newline at end of file
...@@ -6,9 +6,7 @@ import cn.hutool.core.util.ZipUtil; ...@@ -6,9 +6,7 @@ import cn.hutool.core.util.ZipUtil;
import com.schbrain.archetype.initializer.maven.MavenUtils; import com.schbrain.archetype.initializer.maven.MavenUtils;
import com.schbrain.archetype.initializer.param.ArchetypeGenerateParam; import com.schbrain.archetype.initializer.param.ArchetypeGenerateParam;
import com.schbrain.archetype.initializer.response.PreviewFileTree; import com.schbrain.archetype.initializer.response.PreviewFileTree;
import com.schbrain.archetype.initializer.runner.ArchetypePreparer;
import com.schbrain.common.web.utils.ServletUtils; import com.schbrain.common.web.utils.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*; import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
...@@ -29,9 +27,6 @@ public class ArchetypeService { ...@@ -29,9 +27,6 @@ public class ArchetypeService {
private final TimedCache<String, String> archetypeNameCache = new TimedCache<>(Duration.ofHours(1).toMillis()); private final TimedCache<String, String> archetypeNameCache = new TimedCache<>(Duration.ofHours(1).toMillis());
@Autowired
private ArchetypePreparer archetypePreparer;
public String generate(ArchetypeGenerateParam param) { public String generate(ArchetypeGenerateParam param) {
String generateId = MavenUtils.generate(param); String generateId = MavenUtils.generate(param);
archetypeNameCache.put(generateId, param.getArtifactId()); archetypeNameCache.put(generateId, param.getArtifactId());
...@@ -52,11 +47,6 @@ public class ArchetypeService { ...@@ -52,11 +47,6 @@ public class ArchetypeService {
StreamUtils.copy(inputStream, response.getOutputStream()); StreamUtils.copy(inputStream, response.getOutputStream());
} }
public boolean update() {
archetypePreparer.installArchetype();
return true;
}
private PreviewFileTree buildFileTree(File root) { private PreviewFileTree buildFileTree(File root) {
File[] fileItems = root.listFiles(); File[] fileItems = root.listFiles();
if (ArrayUtil.isEmpty(fileItems)) { if (ArrayUtil.isEmpty(fileItems)) {
...@@ -97,4 +87,4 @@ public class ArchetypeService { ...@@ -97,4 +87,4 @@ public class ArchetypeService {
.toString(); .toString();
} }
} }
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"build": "vite build --mode production" "build": "vite build --mode production"
}, },
"dependencies": { "dependencies": {
"vue": "^3.3.2", "vue": "^3.3.4",
"axios": "^1.4.0", "axios": "^1.4.0",
"ant-design-vue": "^3.2.20", "ant-design-vue": "^3.2.20",
"highlight.js": "^11.8.0", "highlight.js": "^11.8.0",
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
"devDependencies": { "devDependencies": {
"@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue": "^4.2.3",
"typescript": "^5.0.4", "typescript": "^5.0.4",
"vite": "^4.3.5", "vite": "^4.3.9",
"vue-tsc": "^1.6.4" "vue-tsc": "^1.6.5"
} }
} }
\ No newline at end of file
...@@ -81,6 +81,7 @@ interface GroupNode { ...@@ -81,6 +81,7 @@ interface GroupNode {
const fileNodeList = ref<FileNode[]>([]) const fileNodeList = ref<FileNode[]>([])
const groupNodeList = ref<GroupNode[]>([]) const groupNodeList = ref<GroupNode[]>([])
const groupOptions = ref<SelectProps['options']>([])
const fileTreeData = ref<TreeProps['treeData']>([]) const fileTreeData = ref<TreeProps['treeData']>([])
const gitlabGroupTreeData = ref<TreeProps['treeData']>([]) const gitlabGroupTreeData = ref<TreeProps['treeData']>([])
const id = ref(-1) const id = ref(-1)
...@@ -92,25 +93,6 @@ const fileExtension = ref<string | null>() ...@@ -92,25 +93,6 @@ const fileExtension = ref<string | null>()
const loading = computed(() => isLoading.value) const loading = computed(() => isLoading.value)
const downloadForm = ref<FormInstance>(); const downloadForm = ref<FormInstance>();
const groupOptions = ref<SelectProps['options']>([
{
"value": "com.schbrain.dg",
"label": "com.schbrain.dg"
},
{
"value": "com.schbrain.kp",
"label": "com.schbrain.kp"
},
{
"value": "com.schbrain.rs",
"label": "com.schbrain.rs"
},
{
"value": "com.schbrain.xb",
"label": "com.schbrain.xb"
},
])
const formState = reactive<FormState>({ const formState = reactive<FormState>({
groupId: '', groupId: '',
artifactId: '', artifactId: '',
...@@ -137,6 +119,19 @@ const fetchGroupTreeList = async (initGitRepo: boolean) => { ...@@ -137,6 +119,19 @@ const fetchGroupTreeList = async (initGitRepo: boolean) => {
} }
} }
const fetchGroupOptions = async () => {
let data: BaseResponse = await request.get('/archetype/allowed_groups')
if (data.code === 0) {
groupOptions.value = data.data.map((group) => {
return {
value: group,
label: group
}
})
}
}
fetchGroupOptions()
const onGenerate = async () => { const onGenerate = async () => {
let result = await downloadForm.value?.validate() let result = await downloadForm.value?.validate()
if (result) { if (result) {
...@@ -278,4 +273,4 @@ const createGroupTreeData = (groupNodeList: GroupNode[]): any => { ...@@ -278,4 +273,4 @@ const createGroupTreeData = (groupNodeList: GroupNode[]): any => {
.ant-select { .ant-select {
text-align: left; text-align: left;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment