Example usage for org.apache.commons.configuration PropertiesConfiguration getHeader

List of usage examples for org.apache.commons.configuration PropertiesConfiguration getHeader

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration getHeader.

Prototype

public String getHeader() 

Source Link

Document

Return the comment header.

Usage

From source file:com.liferay.ide.sdk.core.SDK.java

protected void persistAppServerProperties(Map<String, String> properties)
        throws FileNotFoundException, IOException, ConfigurationException {
    IPath loc = getLocation();//from ww w  . ja  v  a  2  s .co  m

    // check for build.<username>.properties

    String userName = System.getProperty("user.name"); //$NON-NLS-1$

    File userBuildFile = loc.append("build." + userName + ".properties").toFile(); //$NON-NLS-1$ //$NON-NLS-2$

    if (userBuildFile.exists()) {
        /*
         * the build file exists so we need to check the following conditions 1. if the header in the comment
         * contains the text written by a previous SDK operation then we can write it again 2. if the file was not
         * previously written by us we will need to prompt the user with permission yes/no to update the
         * build.<username>.properties file
         */

        PropertiesConfiguration propsConfig = new PropertiesConfiguration(userBuildFile);

        String header = propsConfig.getHeader();

        boolean shouldUpdateBuildFile = false;

        if (header != null && header.contains(MSG_MANAGED_BY_LIFERAY_IDE)) {
            shouldUpdateBuildFile = true;
        } else {
            String overwrite = getPrefStore().get(SDKCorePlugin.PREF_KEY_OVERWRITE_USER_BUILD_FILE, ALWAYS);

            if (ALWAYS.equals(overwrite)) {
                shouldUpdateBuildFile = true;
            } else {
                shouldUpdateBuildFile = false;
            }
        }

        if (shouldUpdateBuildFile) {
            for (String key : properties.keySet()) {
                propsConfig.setProperty(key, properties.get(key));
            }

            propsConfig.setHeader(MSG_MANAGED_BY_LIFERAY_IDE);
            propsConfig.save(userBuildFile);
        }

    } else {
        Properties props = new Properties();

        props.putAll(properties);

        props.store(new FileOutputStream(userBuildFile), MSG_MANAGED_BY_LIFERAY_IDE);
    }

}