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