1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.scm;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.kuali.common.util.execute.Executable;
23 import org.kuali.common.util.file.DirRequest;
24 import org.kuali.common.util.nullify.NullUtils;
25 import org.kuali.common.util.project.ProjectUtils;
26 import org.kuali.common.util.project.model.ProjectIdentifier;
27 import org.kuali.common.util.spring.SpringUtils;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.context.annotation.Bean;
30 import org.springframework.context.annotation.Configuration;
31 import org.springframework.context.annotation.Import;
32 import org.springframework.core.env.Environment;
33
34 @Configuration
35 @Import(ScmConfig.class)
36 public class ScmProjectConfig {
37
38 private static final String PROJECTS_KEY = "scm.build.projects";
39 private static final String RELATIVE_DIR_KEY = "scm.dir.relative";
40 private static final String SOURCE_DIR_KEY = "scm.dir.src";
41 private static final String INCLUDES_KEY = "scm.includes";
42 private static final String EXCLUDES_KEY = "scm.excludes";
43 private static final String SKIP_KEY = "scm.skip";
44 private static final String COMMIT_SKIP_KEY = "scm.commit.skip";
45 private static final String COMMIT_PATHS_KEY = "scm.commit.paths";
46 private static final String COMMIT_MESSAGE_KEY = "scm.commit.message";
47
48 @Autowired
49 Environment env;
50
51 @Autowired
52 ScmConfig scmConfig;
53
54 @Bean
55 public Executable projectScmConfigUpdateScmExecutable() {
56
57 boolean skip = SpringUtils.getBoolean(env, SKIP_KEY, UpdateScmExecutable.DEFAULT_SKIP_VALUE);
58 boolean skipCommit = SpringUtils.getBoolean(env, COMMIT_SKIP_KEY, UpdateScmExecutable.DEFAULT_SKIP_COMMIT_VALUE);
59 List<File> commitPaths = SpringUtils.getFilesFromCSV(env, COMMIT_PATHS_KEY, NullUtils.NONE);
60 String commitMessage = SpringUtils.getProperty(env, COMMIT_MESSAGE_KEY);
61
62 UpdateScmExecutable exec = new UpdateScmExecutable();
63 exec.setRequests(projectScmConfigDirRequests());
64 exec.setScmService(scmConfig.scmService());
65 exec.setSkip(skip);
66 exec.setSkipCommit(skipCommit);
67 exec.setCommitPaths(commitPaths);
68 exec.setMessage(commitMessage);
69 return exec;
70 }
71
72 @Bean
73 public List<DirRequest> projectScmConfigDirRequests() {
74 List<String> projectIds = SpringUtils.getNoneSensitiveListFromCSV(env, PROJECTS_KEY);
75 List<String> includes = SpringUtils.getNoneSensitiveListFromCSV(env, INCLUDES_KEY);
76 List<String> excludes = SpringUtils.getNoneSensitiveListFromCSV(env, EXCLUDES_KEY);
77 List<ProjectIdentifier> identifiers = ProjectUtils.getIdentifiers(projectIds);
78 File stagingDir = SpringUtils.getFile(env, SOURCE_DIR_KEY);
79 File relativeDir = SpringUtils.getFile(env, RELATIVE_DIR_KEY);
80 List<DirRequest> requests = new ArrayList<DirRequest>();
81 for (ProjectIdentifier identifier : identifiers) {
82 DirRequest request = getDirRequest(identifier, stagingDir, relativeDir, includes, excludes);
83 requests.add(request);
84 }
85 return requests;
86 }
87
88 protected DirRequest getDirRequest(ProjectIdentifier identifier, File stagingDir, File relativeDir, List<String> includes, List<String> excludes) {
89 String key = "scm.build." + identifier.getArtifactId() + ".dir";
90
91 File projectResourceDir = SpringUtils.getFile(env, key);
92 File targetDir = ProjectUtils.getResourceDirectory(projectResourceDir, identifier.getGroupId(), identifier.getArtifactId());
93 File sourceDir = ProjectUtils.getResourceDirectory(stagingDir, identifier.getGroupId(), identifier.getArtifactId());
94 DirRequest request = new DirRequest();
95 request.setRelativeDir(relativeDir);
96 request.setTargetDir(targetDir);
97 request.setSourceDir(sourceDir);
98 request.setIncludes(includes);
99 request.setExcludes(excludes);
100 return request;
101 }
102
103 }