
org.kuali.maven.plugins.spring.LoadMojo Maven / Gradle / Ivy
/**
* Copyright 2011-2013 The Kuali Foundation
*
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/ecl2.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kuali.maven.plugins.spring;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.kuali.common.util.CollectionUtils;
import org.kuali.common.util.MavenUtils;
import org.kuali.common.util.PropertyUtils;
import org.kuali.common.util.service.SpringService;
/**
*
* This mojo provides the ability to load a Spring context XML file. It uses a lightweight integration technique between Spring and Maven
* centered around java.util.Properties
. Prior to the Spring context being loaded, it is injected with a
* java.util.Properties
object containing the full set of Maven properties. The java.util.Properties
object is
* registered in the context as a bean under the name mavenProperties
.
*
*
* One common use of the injected Maven properties in a Spring context is for replacing property placeholders.
*
*
* For example, to inject the Maven version number into a Spring context:
*
*
*
* <beans>
* <context:property-placeholder properties-ref="mavenProperties" />
* <bean id="version" class="java.lang.String">
* <constructor-arg value="${project.version}" />
* </bean>
* </beans>
*
*
* @goal load
*/
public class LoadMojo extends AbstractMojo {
/**
* Maven project
*
* @parameter default-value="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* Location of a Spring context XML file. This can be a file on the local file system, or any URL Spring's Resource loading framework
* understands eg {@code classpath:my-context.xml}
*
* @parameter expression="${spring.location}" default-value="classpath:${project.artifactId}-context.xml"
* @required
*/
private String location;
/**
* List of additional Spring context XML files to load (if any).
*
* @parameter
*/
private List locations;
/**
* Additional properties to supply to the Spring context.
*
* @parameter
*/
private Properties properties;
/**
* If true, Maven properties are injected into the Spring context as a java.util.Properties
object
*
* @parameter expression="${spring.injectProperties}" default-value="true"
*/
private boolean injectProperties;
/**
* If true, the MavenProject
object is injected into the Spring context
*
* @parameter expression="${spring.injectProject}" default-value="false"
*/
private boolean injectProject;
/**
* If true, this mojo
object is injected into the Spring context
*
* @parameter expression="${spring.injectMojo}" default-value="false"
*/
private boolean injectMojo;
/**
* The name to use when registering the java.util.Properties
object containing Maven properties as a bean in the Spring
* context.
*
* @parameter expression="${spring.propertiesBeanName}" default-value="mavenProperties"
*/
private String propertiesBeanName;
/**
* The name to use when registering the MavenProject
object as a bean in the Spring context.
*
* @parameter expression="${spring.projectBeanName}" default-value="project"
*/
private String projectBeanName;
/**
* The name to use when registering this mojo
object as a bean in the Spring context.
*
* @parameter expression="${spring.mojoBeanName}" default-value="mojo"
*/
private String mojoBeanName;
/**
* The implementation of {@code org.kuali.common.util.service.SpringService} to use
*
* @parameter expression="${spring.serviceClassname}" default-value="org.kuali.common.util.service.DefaultSpringService"
* @required
*/
private String serviceClassname;
/**
* By default, execution of this mojo is automatically skipped for Maven projects with a packaging of type pom
. If
* forceMojoExecution
is true
this mojo will always execute. forceMojoExecution
overrides
* skip
.
*
* @parameter expression="${spring.forceMojoExecution}" default-value="false"
*/
private boolean forceMojoExecution;
/**
* By default, execution of this mojo is automatically skipped for Maven projects with a packaging of type pom
. Set this
* parameter to true
to explicitly skip executing this mojo for other scenarios. NOTE: forceMojoExecution
* overrides skip
.
*
* @parameter expression="${spring.skip}" default-value="false"
*/
private boolean skip;
@Override
public void execute() throws MojoExecutionException {
// Might be skipping execution altogether
if (MavenUtils.skip(forceMojoExecution, skip, project.getPackaging())) {
return;
}
// Combine mojo properties, project properties and internal maven properties into a Properties object
Properties mavenProperties = MojoUtils.getMavenProperties(project, properties);
// Combine the main context location with any optional locations
List contextLocations = CollectionUtils.combine(location, locations);
// Assemble any beans we may be injecting
List includes = Arrays.asList(injectProperties, injectProject, injectMojo);
List beanNames = CollectionUtils.getList(includes, Arrays.asList(propertiesBeanName, projectBeanName, mojoBeanName));
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy