Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (C) 2011 JFrog Ltd.
  *
  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
  *
 * 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.jfrog.hudson.util;
Utility class to help rewrite a properties file while keeping the contents of the properties file intact (e.g comments)

Author(s):
Tomer Cohen
public class PropertyUtils {
    private static final Logger debuggingLogger = Logger.getLogger(PropertyUtils.class.getName());
    private PropertyUtils() {
        // utility class
        throw new IllegalAccessError();
    }

    
Read the gradle.properties and parse it into org.jfrog.hudson.release.gradle.GradleModules. Only those keys which are given will be included in the parsing.

Parameters:
gradlePropPath The path of the gradle.properties file
propKeys The property keys that should be taken into account when reading the properties file.
Returns:
A map of org.jfrog.hudson.release.gradle.GradleModules that were assembled from the properties file, with the version as its value.
Throws:
java.io.IOException In case an error occurs while reading the properties file, this exception is thrown.
    public static Map<StringStringgetModulesPropertiesFromPropFile(FilePath gradlePropPathString[] propKeys)
            throws IOExceptionInterruptedException {
        Properties gradleProps = loadGradleProperties(gradlePropPath);
        Map<StringStringversionsByPropKey = Maps.newLinkedHashMap();
        for (String propKey : propKeys) {
            if (gradleProps.containsKey(propKey)) {
                versionsByPropKey.put(propKeygradleProps.getProperty(propKey));
            }
        }
        return versionsByPropKey;
    }

    
Load a properties file from a file path

Parameters:
gradlePropertiesFilePath The file path where the gradle.properties is located.
Returns:
The loaded properties.
Throws:
java.io.IOException In case an error occurs while reading the properties file, this exception is thrown.
    private static Properties loadGradleProperties(FilePath gradlePropertiesFilePath)
            throws IOExceptionInterruptedException {
        return gradlePropertiesFilePath.act(new FilePath.FileCallable<Properties>() {
            public Properties invoke(File gradlePropertiesFileVirtualChannel channelthrows IOExceptionInterruptedException {
                Properties gradleProps = new Properties();
                if (gradlePropertiesFile.exists()) {
                    .fine("Gradle properties file exists at: " + gradlePropertiesFile.getAbsolutePath());
                    FileInputStream stream = null;
                    try {
                        stream = new FileInputStream(gradlePropertiesFile);
                        gradleProps.load(stream);
                    } catch (IOException e) {
                        .fine("IO exception occurred while trying to read properties file from: " +
                                gradlePropertiesFile.getAbsolutePath());
                        throw new RuntimeException(e);
                    } finally {
                        Closeables.closeQuietly(stream);
                    }
                }
                return gradleProps;
            }
        });
    }
New to GrepCode? Check out our FAQ X