1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.property.processor;
17
18 import java.io.File;
19 import java.util.Properties;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.kuali.common.util.OrgUtils;
23 import org.kuali.common.util.Str;
24 import org.kuali.common.util.maven.MavenConstants;
25 import org.kuali.common.util.project.KualiProjectConstants;
26 import org.kuali.common.util.project.ProjectUtils;
27 import org.kuali.common.util.project.model.Project;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.util.Assert;
31
32
33
34
35 public class ProjectProcessor implements PropertyProcessor {
36
37 private static final Logger logger = LoggerFactory.getLogger(ProjectProcessor.class);
38
39 private static final String KS_GROUP_ID = KualiProjectConstants.STUDENT_GROUP_ID;
40 private static final String FS = File.separator;
41 private static final String DOT = ".";
42 private static final String PROJECT_GROUP_ID_PATH = "project.groupId.path";
43
44 @Override
45 public void process(Properties properties) {
46
47
48 Assert.notNull(properties, "properties are null");
49
50
51 validate(properties);
52
53
54 fixKSGroupIds(properties);
55
56
57 Project p = ProjectUtils.getProject(properties);
58
59
60 String orgId = properties.getProperty(MavenConstants.ORG_ID_KEY);
61 String orgCode = properties.getProperty(MavenConstants.ORG_ID_CODE_KEY);
62
63
64 String groupCode = OrgUtils.getGroupCode(orgId, p.getGroupId());
65
66
67 String userHome = System.getProperty("user.home");
68 String orgHome = userHome + FS + DOT + orgCode;
69 String groupHome = orgHome + FS + groupCode;
70
71
72 properties.setProperty(PROJECT_GROUP_ID_PATH, Str.getPath(p.getGroupId()));
73 properties.setProperty("project.orgId.home", orgHome);
74 properties.setProperty("project.groupId.home", groupHome);
75 properties.setProperty("project.home", groupHome);
76
77
78 properties.setProperty("project.groupId.code", groupCode);
79
80
81 properties.setProperty("project.build.timestamp.millis", Long.toString(System.currentTimeMillis()));
82
83 }
84
85
86 protected void validate(Properties properties) {
87 Assert.notNull(properties.getProperty(MavenConstants.GROUP_ID_KEY), MavenConstants.GROUP_ID_KEY + " is null");
88 Assert.notNull(properties.getProperty(MavenConstants.ARTIFACT_ID_KEY), MavenConstants.ARTIFACT_ID_KEY + " is null");
89 Assert.notNull(properties.getProperty(MavenConstants.ORG_ID_KEY), MavenConstants.ORG_ID_KEY + " is null");
90 Assert.notNull(properties.getProperty(MavenConstants.ORG_ID_CODE_KEY), MavenConstants.ORG_ID_CODE_KEY + " is null");
91 }
92
93 protected void fixKSGroupIds(Properties properties) {
94
95 String groupId = properties.getProperty(MavenConstants.GROUP_ID_KEY);
96
97
98 if (!StringUtils.startsWith(groupId, KS_GROUP_ID)) {
99 return;
100 }
101
102
103 properties.setProperty(MavenConstants.GROUP_ID_KEY, KualiProjectConstants.STUDENT_GROUP_ID);
104
105
106
107 if (!StringUtils.equals(groupId, KualiProjectConstants.STUDENT_GROUP_ID)) {
108 logger.debug("original={}", groupId);
109 properties.setProperty(MavenConstants.GROUP_ID_ORIGINAL_KEY, groupId);
110 }
111 }
112
113 }