View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.settings.building;
20  
21  import java.io.File;
22  import java.util.Properties;
23  
24  /**
25   * Collects settings that control building of effective settings.
26   *
27   * @author Benjamin Bentmann
28   */
29  public class DefaultSettingsBuildingRequest implements SettingsBuildingRequest {
30  
31      private File globalSettingsFile;
32  
33      private File userSettingsFile;
34  
35      private SettingsSource globalSettingsSource;
36  
37      private SettingsSource userSettingsSource;
38  
39      private Properties systemProperties;
40  
41      private Properties userProperties;
42  
43      @Override
44      public File getGlobalSettingsFile() {
45          return globalSettingsFile;
46      }
47  
48      @Override
49      public DefaultSettingsBuildingRequest setGlobalSettingsFile(File globalSettingsFile) {
50          this.globalSettingsFile = globalSettingsFile;
51  
52          return this;
53      }
54  
55      @Override
56      public SettingsSource getGlobalSettingsSource() {
57          return globalSettingsSource;
58      }
59  
60      @Override
61      public DefaultSettingsBuildingRequest setGlobalSettingsSource(SettingsSource globalSettingsSource) {
62          this.globalSettingsSource = globalSettingsSource;
63  
64          return this;
65      }
66  
67      @Override
68      public File getUserSettingsFile() {
69          return userSettingsFile;
70      }
71  
72      @Override
73      public DefaultSettingsBuildingRequest setUserSettingsFile(File userSettingsFile) {
74          this.userSettingsFile = userSettingsFile;
75  
76          return this;
77      }
78  
79      @Override
80      public SettingsSource getUserSettingsSource() {
81          return userSettingsSource;
82      }
83  
84      @Override
85      public DefaultSettingsBuildingRequest setUserSettingsSource(SettingsSource userSettingsSource) {
86          this.userSettingsSource = userSettingsSource;
87  
88          return this;
89      }
90  
91      @Override
92      public Properties getSystemProperties() {
93          if (systemProperties == null) {
94              systemProperties = new Properties();
95          }
96  
97          return systemProperties;
98      }
99  
100     @Override
101     public DefaultSettingsBuildingRequest setSystemProperties(Properties systemProperties) {
102         if (systemProperties != null) {
103             this.systemProperties = new Properties();
104             synchronized (
105                     systemProperties) { // avoid concurrentmodification if someone else sets/removes an unrelated system
106                 // property
107                 this.systemProperties.putAll(systemProperties);
108             }
109         } else {
110             this.systemProperties = null;
111         }
112 
113         return this;
114     }
115 
116     @Override
117     public Properties getUserProperties() {
118         if (userProperties == null) {
119             userProperties = new Properties();
120         }
121 
122         return userProperties;
123     }
124 
125     @Override
126     public DefaultSettingsBuildingRequest setUserProperties(Properties userProperties) {
127         if (userProperties != null) {
128             this.userProperties = new Properties();
129             this.userProperties.putAll(userProperties);
130         } else {
131             this.userProperties = null;
132         }
133 
134         return this;
135     }
136 }