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 projectSettingsFile;
34  
35      private File userSettingsFile;
36  
37      private SettingsSource globalSettingsSource;
38  
39      private SettingsSource projectSettingsSource;
40  
41      private SettingsSource userSettingsSource;
42  
43      private Properties systemProperties;
44  
45      private Properties userProperties;
46  
47      @Override
48      public File getGlobalSettingsFile() {
49          return globalSettingsFile;
50      }
51  
52      @Override
53      public DefaultSettingsBuildingRequest setGlobalSettingsFile(File globalSettingsFile) {
54          this.globalSettingsFile = globalSettingsFile;
55  
56          return this;
57      }
58  
59      @Override
60      public SettingsSource getGlobalSettingsSource() {
61          return globalSettingsSource;
62      }
63  
64      @Override
65      public DefaultSettingsBuildingRequest setGlobalSettingsSource(SettingsSource globalSettingsSource) {
66          this.globalSettingsSource = globalSettingsSource;
67  
68          return this;
69      }
70  
71      @Override
72      public File getProjectSettingsFile() {
73          return projectSettingsFile;
74      }
75  
76      @Override
77      public DefaultSettingsBuildingRequest setProjectSettingsFile(File projectSettingsFile) {
78          this.projectSettingsFile = projectSettingsFile;
79  
80          return this;
81      }
82  
83      @Override
84      public SettingsSource getProjectSettingsSource() {
85          return projectSettingsSource;
86      }
87  
88      @Override
89      public DefaultSettingsBuildingRequest setProjectSettingsSource(SettingsSource projectSettingsSource) {
90          this.projectSettingsSource = projectSettingsSource;
91  
92          return this;
93      }
94  
95      @Override
96      public File getUserSettingsFile() {
97          return userSettingsFile;
98      }
99  
100     @Override
101     public DefaultSettingsBuildingRequest setUserSettingsFile(File userSettingsFile) {
102         this.userSettingsFile = userSettingsFile;
103 
104         return this;
105     }
106 
107     @Override
108     public SettingsSource getUserSettingsSource() {
109         return userSettingsSource;
110     }
111 
112     @Override
113     public DefaultSettingsBuildingRequest setUserSettingsSource(SettingsSource userSettingsSource) {
114         this.userSettingsSource = userSettingsSource;
115 
116         return this;
117     }
118 
119     @Override
120     public Properties getSystemProperties() {
121         if (systemProperties == null) {
122             systemProperties = new Properties();
123         }
124 
125         return systemProperties;
126     }
127 
128     @Override
129     public DefaultSettingsBuildingRequest setSystemProperties(Properties systemProperties) {
130         if (systemProperties != null) {
131             this.systemProperties = new Properties();
132             synchronized (systemProperties) { // avoid concurrent modification if someone else sets/removes an unrelated
133                 // system property
134                 this.systemProperties.putAll(systemProperties);
135             }
136         } else {
137             this.systemProperties = null;
138         }
139 
140         return this;
141     }
142 
143     @Override
144     public Properties getUserProperties() {
145         if (userProperties == null) {
146             userProperties = new Properties();
147         }
148 
149         return userProperties;
150     }
151 
152     @Override
153     public DefaultSettingsBuildingRequest setUserProperties(Properties userProperties) {
154         if (userProperties != null) {
155             this.userProperties = new Properties();
156             this.userProperties.putAll(userProperties);
157         } else {
158             this.userProperties = null;
159         }
160 
161         return this;
162     }
163 }