View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.property.processor;
17  
18  import java.io.File;
19  import java.util.Properties;
20  
21  import org.kuali.common.util.OrgUtils;
22  import org.kuali.common.util.Project;
23  import org.kuali.common.util.Str;
24  import org.springframework.util.Assert;
25  
26  public class ProjectProcessor implements PropertyProcessor {
27  
28  	private static final String FS = File.separator;
29  	private static final String DOT = ".";
30  
31  	@Override
32  	public void process(Properties properties) {
33  		Project p = getProject(properties);
34  		validate(p);
35  		String groupCode = OrgUtils.getGroupCode(p.getOrgId(), p.getGroupId());
36  		String groupBase = OrgUtils.getGroupBase(p.getOrgId(), p.getGroupId());
37  		String userHome = System.getProperty("user.home");
38  		String orgHome = userHome + FS + DOT + p.getOrgCode();
39  		String groupHome = orgHome + FS + groupCode;
40  		properties.setProperty("project.groupId.code", groupCode);
41  		properties.setProperty("project.groupId.path", Str.getPath(p.getGroupId()));
42  		properties.setProperty("project.groupId.base", groupBase);
43  		properties.setProperty("project.groupId.base.path", Str.getPath(groupBase));
44  		properties.setProperty("project.orgId.home", orgHome);
45  		properties.setProperty("project.groupId.home", groupHome);
46  		// Add the current milliseconds value as a project property
47  		properties.setProperty("project.build.timestamp.millis", Long.toString(System.currentTimeMillis()));
48  
49  	}
50  
51  	protected void validate(Project project) {
52  		Assert.notNull(project.getOrgId(), "orgId is null");
53  		Assert.notNull(project.getOrgCode(), "orgCode is null");
54  		Assert.notNull(project.getOrgPath(), "orgPath is null");
55  		Assert.notNull(project.getGroupId(), "groupId is null");
56  		Assert.notNull(project.getArtifactId(), "artifactId is null");
57  		Assert.notNull(project.getVersion(), "version is null");
58  	}
59  
60  	protected Project getProject(Properties properties) {
61  		Project project = new Project();
62  		project.setOrgId(properties.getProperty("project.orgId"));
63  		project.setOrgCode(properties.getProperty("project.orgId.code"));
64  		project.setOrgPath(properties.getProperty("project.orgId.path"));
65  		project.setGroupId(properties.getProperty("project.groupId"));
66  		project.setArtifactId(properties.getProperty("project.artifactId"));
67  		project.setVersion(properties.getProperty("project.version"));
68  		return project;
69  	}
70  
71  }