
org.kuali.maven.plugins.spring.MojoUtils 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.Properties;
import org.apache.maven.project.MavenProject;
import org.kuali.common.util.LocationUtils;
import org.kuali.common.util.PropertyUtils;
import org.kuali.common.util.property.GlobalPropertiesMode;
import org.kuali.common.util.service.SpringService;
public class MojoUtils {
public static SpringService getService(String serviceClassname) {
try {
Class> serviceClass = Class.forName(serviceClassname);
return (SpringService) serviceClass.newInstance();
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Unexpected error", e);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Unexpected error", e);
} catch (InstantiationException e) {
throw new IllegalStateException("Unexpected error", e);
}
}
public static Properties getMavenProperties(MavenProject project, Properties mojoProperties) {
// Get internal Maven config as a properties object
Properties internal = MojoUtils.getInternalProperties(project);
// The ordering here is significant.
// Properties supplied directly to the mojo override properties from project.getProperties()
// But, internal Maven properties need to always win.
// ${project.artifactId} needs to always faithfully represent the correct artifactId
Properties properties = PropertyUtils.combine(project.getProperties(), mojoProperties, internal);
// Explicitly override internal Maven props with system/env props (simulates the default maven behavior)
PropertyUtils.overrideWithGlobalValues(properties, GlobalPropertiesMode.BOTH);
// Return the overridden properties
return properties;
}
public static Properties getInternalProperties(MavenProject project) {
Properties properties = new Properties();
properties.setProperty("project.id", project.getId());
properties.setProperty("project.groupId", project.getGroupId());
properties.setProperty("project.artifactId", project.getArtifactId());
properties.setProperty("project.version", project.getVersion());
properties.setProperty("project.packaging", project.getPackaging());
properties.setProperty("project.name", project.getName());
properties.setProperty("project.description", project.getDescription());
properties.setProperty("project.inceptionYear", project.getInceptionYear());
properties.setProperty("project.ciManagement.system", project.getCiManagement().getSystem());
properties.setProperty("project.ciManagement.url", project.getCiManagement().getUrl());
properties.setProperty("project.issueManagement.system", project.getIssueManagement().getSystem());
properties.setProperty("project.issueManagement.url", project.getIssueManagement().getUrl());
properties.setProperty("project.basedir", LocationUtils.getCanonicalPath(project.getBasedir()));
properties.setProperty("project.build.directory", project.getBuild().getDirectory());
properties.setProperty("project.build.outputDirectory", project.getBuild().getOutputDirectory());
properties.setProperty("project.build.testOutputDirectory", project.getBuild().getTestOutputDirectory());
properties.setProperty("project.build.sourceDirectory", project.getBuild().getSourceDirectory());
properties.setProperty("project.build.scriptSourceDirectory", project.getBuild().getScriptSourceDirectory());
properties.setProperty("project.build.testSourceDirectory", project.getBuild().getTestSourceDirectory());
return properties;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy