View Javadoc
1   /**
2    * Copyright 2004-2014 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.maven.spring;
17  
18  import static org.kuali.common.maven.spring.MavenAwareUtils.getInternalProperties;
19  import static org.kuali.common.util.FormatUtils.getCount;
20  import static org.kuali.common.util.base.Precondition.checkNotNull;
21  import static org.kuali.common.util.log.Loggers.newLogger;
22  import static org.kuali.common.util.maven.MavenUtils.augmentProjectProperties;
23  
24  import java.util.Properties;
25  
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.settings.Settings;
28  import org.kuali.common.util.execute.Executable;
29  import org.slf4j.Logger;
30  
31  public class AugmentMavenPropertiesExecutable implements Executable {
32  
33  	private static final Logger logger = newLogger();
34  
35  	public AugmentMavenPropertiesExecutable(MavenProject mavenProject, Settings settings, boolean skip) {
36  		this.mavenProject = checkNotNull(mavenProject, "mavenProject");
37  		this.settings = settings;
38  		this.skip = skip;
39  	}
40  
41  	private final MavenProject mavenProject;
42  	private final Settings settings;
43  	private final boolean skip;
44  
45  	@Override
46  	public void execute() {
47  
48  		if (skip) {
49  			return;
50  		}
51  
52  		// Extract the Properties object Maven is using
53  		Properties mavenProperties = mavenProject.getProperties();
54  
55  		// Retain the original size of the native Maven properties
56  		int originalSize = mavenProperties.size();
57  
58  		// Create a new properties object that aggregates important information from the Maven model
59  		// eg project.getGroupId() gets inserted into the properties object as project.groupId
60  		Properties internal = getInternalProperties(mavenProject, settings);
61  
62  		// Add the internal properties to the properties object Maven is using
63  		mavenProperties.putAll(internal);
64  
65  		// Add organization, group, and path properties and tokenize the version number adding properties for each token along with
66  		// a boolean property indicating if this is a SNAPSHOT build
67  		augmentProjectProperties(mavenProperties);
68  
69  		// Print something useful if we are in debug mode
70  		logger.debug("Added {} properties", getCount(mavenProperties.size() - originalSize));
71  
72  	}
73  
74  	public MavenProject getMavenProject() {
75  		return mavenProject;
76  	}
77  
78  	public Settings getSettings() {
79  		return settings;
80  	}
81  
82  	public boolean isSkip() {
83  		return skip;
84  	}
85  
86  }