View Javadoc
1   package org.apache.maven.settings.building;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.Properties;
24  
25  /**
26   * Collects settings that control building of effective settings.
27   *
28   * @author Benjamin Bentmann
29   */
30  public class DefaultSettingsBuildingRequest
31      implements SettingsBuildingRequest
32  {
33  
34      private File globalSettingsFile;
35  
36      private File userSettingsFile;
37  
38      private SettingsSource globalSettingsSource;
39  
40      private SettingsSource userSettingsSource;
41  
42      private Properties systemProperties;
43  
44      private Properties userProperties;
45  
46      @Override
47      public File getGlobalSettingsFile()
48      {
49          return globalSettingsFile;
50      }
51  
52      @Override
53      public DefaultSettingsBuildingRequest setGlobalSettingsFile( File globalSettingsFile )
54      {
55          this.globalSettingsFile = globalSettingsFile;
56  
57          return this;
58      }
59  
60      @Override
61      public SettingsSource getGlobalSettingsSource()
62      {
63          return globalSettingsSource;
64      }
65  
66      @Override
67      public DefaultSettingsBuildingRequest setGlobalSettingsSource( SettingsSource globalSettingsSource )
68      {
69          this.globalSettingsSource = globalSettingsSource;
70  
71          return this;
72      }
73  
74      @Override
75      public File getUserSettingsFile()
76      {
77          return userSettingsFile;
78      }
79  
80      @Override
81      public DefaultSettingsBuildingRequest setUserSettingsFile( File userSettingsFile )
82      {
83          this.userSettingsFile = userSettingsFile;
84  
85          return this;
86      }
87  
88      @Override
89      public SettingsSource getUserSettingsSource()
90      {
91          return userSettingsSource;
92      }
93  
94      @Override
95      public DefaultSettingsBuildingRequest setUserSettingsSource( SettingsSource userSettingsSource )
96      {
97          this.userSettingsSource = userSettingsSource;
98  
99          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 }