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