001package org.apache.maven.settings.building;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023import java.util.Properties;
024
025/**
026 * Collects settings that control building of effective settings.
027 * 
028 * @author Benjamin Bentmann
029 */
030public class DefaultSettingsBuildingRequest
031    implements SettingsBuildingRequest
032{
033
034    private File globalSettingsFile;
035
036    private File userSettingsFile;
037
038    private SettingsSource globalSettingsSource;
039
040    private SettingsSource userSettingsSource;
041
042    private Properties systemProperties;
043
044    private Properties userProperties;
045
046    public File getGlobalSettingsFile()
047    {
048        return globalSettingsFile;
049    }
050
051    public DefaultSettingsBuildingRequest setGlobalSettingsFile( File globalSettingsFile )
052    {
053        this.globalSettingsFile = globalSettingsFile;
054
055        return this;
056    }
057
058    public SettingsSource getGlobalSettingsSource()
059    {
060        return globalSettingsSource;
061    }
062
063    public DefaultSettingsBuildingRequest setGlobalSettingsSource( SettingsSource globalSettingsSource )
064    {
065        this.globalSettingsSource = globalSettingsSource;
066
067        return this;
068    }
069
070    public File getUserSettingsFile()
071    {
072        return userSettingsFile;
073    }
074
075    public DefaultSettingsBuildingRequest setUserSettingsFile( File userSettingsFile )
076    {
077        this.userSettingsFile = userSettingsFile;
078
079        return this;
080    }
081
082    public SettingsSource getUserSettingsSource()
083    {
084        return userSettingsSource;
085    }
086
087    public DefaultSettingsBuildingRequest setUserSettingsSource( SettingsSource userSettingsSource )
088    {
089        this.userSettingsSource = userSettingsSource;
090
091        return this;
092    }
093
094    public Properties getSystemProperties()
095    {
096        if ( systemProperties == null )
097        {
098            systemProperties = new Properties();
099        }
100
101        return systemProperties;
102    }
103
104    public DefaultSettingsBuildingRequest setSystemProperties( Properties systemProperties )
105    {
106        if ( systemProperties != null )
107        {
108            this.systemProperties = new Properties();
109            // MNG-5670 guard against ConcurrentModificationException
110            for ( String key : System.getProperties().stringPropertyNames() )
111            {
112                this.systemProperties.put( key, System.getProperty( key ) );
113            }
114        }
115        else
116        {
117            this.systemProperties = null;
118        }
119
120        return this;
121    }
122
123    public Properties getUserProperties()
124    {
125        if ( userProperties == null )
126        {
127            userProperties = new Properties();
128        }
129
130        return userProperties;
131    }
132
133    public DefaultSettingsBuildingRequest setUserProperties( Properties userProperties )
134    {
135        if ( userProperties != null )
136        {
137            this.userProperties = new Properties();
138            this.userProperties.putAll( userProperties );
139        }
140        else
141        {
142            this.userProperties = null;
143        }
144
145        return this;
146    }
147
148}