All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kuali.maven.plugins.properties.TranslatePropertiesMojo Maven / Gradle / Ivy

Go to download

The Properties Maven Plugin is here to make life a little easier when dealing with properties. It provides goals to read and write properties from files. The Kuali version of this plugin adds support for loading properties from XML files and reading properties files from any location Spring resource loading can understand (eg classpath:myprops.properties)

The newest version!
/**
 * Copyright 2009-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.properties;

import java.util.Properties;

import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

/**
 * Translate the indicated properties into classpath friendly form.
 *
 * eg Transform org.kuali.rice into org/kuali/rice
 *
 * A new project property with ".path" added as a suffix gets set with the transformed value
 *
 * @goal translate-properties
 */
public class TranslatePropertiesMojo extends AbstractMojo {

    /**
     * @parameter default-value="${project}"
     * @required
     * @readonly
     */
    private MavenProject project;

    /**
     * The list of properties to translate
     *
     * @parameter
     * @required
     */
    private String[] properties;

    /**
     * The suffix appended to the existing property name where the translated property is stored
     *
     * @parameter expression="${properties.suffix}" default-value=".path"
     * @required
     */
    private String suffix;

    protected String getProperty(String key) {
        String sys = System.getProperty(key);
        String proj = project.getProperties().getProperty(key);
        if (!StringUtils.isBlank(sys)) {
            return sys;
        } else {
            return proj;
        }

    }

    @Override
    public void execute() throws MojoExecutionException {
        Properties props = project.getProperties();
        for (String key : properties) {
            String value = getProperty(key);
            if (StringUtils.isBlank(value)) {
                continue;
            } else {
                String newValue = value.replace(".", "/");
                String newKey = key + suffix;
                getLog().info("Setting " + newKey + "=" + newValue);
                props.setProperty(newKey, newValue);
            }
        }
    }

    public String[] getProperties() {
        return properties;
    }

    public void setProperties(String[] properties) {
        this.properties = properties;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy