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

com.github.htfv.maven.plugins.testing.ProjectProperties Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2012 htfv (Aliaksei Lahachou)
 *
 * 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 com.github.htfv.maven.plugins.testing;

import java.io.File;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

public class ProjectProperties
{
    private static class Singleton
    {
        public static final ProjectProperties INSTANCE = new ProjectProperties();
    }

    public static ProjectProperties getInstance()
    {
        return Singleton.INSTANCE;
    }

    private File basedir;
    private File outputDirectory;
    private PropertiesConfiguration projectProperties;

    public ProjectProperties()
    {
        try
        {
            projectProperties = new PropertiesConfiguration(
                    ProjectProperties.class.getResource("/project.properties"));
        }
        catch (ConfigurationException e)
        {
            throw new RuntimeException("Failed to load 'project.properties'", e);
        }
    }

    public String getArtifactId()
    {
        return projectProperties.getString("project.artifactId");
    }

    public File getBasedir()
    {
        if (basedir == null)
        {
            basedir = new File(projectProperties.getString("project.basedir"));
        }

        return basedir;
    }

    public String getGroupId()
    {
        return projectProperties.getString("project.groupId");
    }

    public File getOutputDirectory()
    {
        if (outputDirectory == null)
        {
            outputDirectory = new File(
                    projectProperties.getString("project.build.outputDirectory"));
        }

        return outputDirectory;
    }

    public String getVersion()
    {
        return projectProperties.getString("project.version");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy