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    @Override
047    public File getGlobalSettingsFile()
048    {
049        return globalSettingsFile;
050    }
051
052    @Override
053    public DefaultSettingsBuildingRequest setGlobalSettingsFile( File globalSettingsFile )
054    {
055        this.globalSettingsFile = globalSettingsFile;
056
057        return this;
058    }
059
060    @Override
061    public SettingsSource getGlobalSettingsSource()
062    {
063        return globalSettingsSource;
064    }
065
066    @Override
067    public DefaultSettingsBuildingRequest setGlobalSettingsSource( SettingsSource globalSettingsSource )
068    {
069        this.globalSettingsSource = globalSettingsSource;
070
071        return this;
072    }
073
074    @Override
075    public File getUserSettingsFile()
076    {
077        return userSettingsFile;
078    }
079
080    @Override
081    public DefaultSettingsBuildingRequest setUserSettingsFile( File userSettingsFile )
082    {
083        this.userSettingsFile = userSettingsFile;
084
085        return this;
086    }
087
088    @Override
089    public SettingsSource getUserSettingsSource()
090    {
091        return userSettingsSource;
092    }
093
094    @Override
095    public DefaultSettingsBuildingRequest setUserSettingsSource( SettingsSource userSettingsSource )
096    {
097        this.userSettingsSource = userSettingsSource;
098
099        return this;
100    }
101
102    @Override
103    public Properties getSystemProperties()
104    {
105        if ( systemProperties == null )
106        {
107            systemProperties = new Properties();
108        }
109
110        return systemProperties;
111    }
112
113    @Override
114    public DefaultSettingsBuildingRequest setSystemProperties( Properties systemProperties )
115    {
116        if ( systemProperties != null )
117        {
118            this.systemProperties = new Properties();
119            // MNG-5670 guard against ConcurrentModificationException
120            for ( String key : System.getProperties().stringPropertyNames() )
121            {
122                this.systemProperties.put( key, System.getProperty( key ) );
123            }
124        }
125        else
126        {
127            this.systemProperties = null;
128        }
129
130        return this;
131    }
132
133    @Override
134    public Properties getUserProperties()
135    {
136        if ( userProperties == null )
137        {
138            userProperties = new Properties();
139        }
140
141        return userProperties;
142    }
143
144    @Override
145    public DefaultSettingsBuildingRequest setUserProperties( Properties userProperties )
146    {
147        if ( userProperties != null )
148        {
149            this.userProperties = new Properties();
150            this.userProperties.putAll( userProperties );
151        }
152        else
153        {
154            this.userProperties = null;
155        }
156
157        return this;
158    }
159
160}