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.crypto;
20  
21  import java.util.ArrayList;
22  import java.util.Arrays;
23  import java.util.List;
24  
25  import org.apache.maven.settings.Proxy;
26  import org.apache.maven.settings.Server;
27  import org.apache.maven.settings.Settings;
28  
29  /**
30   * Collects parameters that control the decryption of settings.
31   *
32   */
33  public class DefaultSettingsDecryptionRequest implements SettingsDecryptionRequest {
34  
35      private List<Server> servers;
36  
37      private List<Proxy> proxies;
38  
39      /**
40       * Creates an empty request.
41       */
42      public DefaultSettingsDecryptionRequest() {
43          // does nothing
44      }
45  
46      /**
47       * Creates a new request to decrypt the specified settings.
48       *
49       * @param settings The settings to decrypt, must not be {@code null}.
50       */
51      public DefaultSettingsDecryptionRequest(Settings settings) {
52          setServers(settings.getServers());
53          setProxies(settings.getProxies());
54      }
55  
56      /**
57       * Creates a new request to decrypt the specified server.
58       *
59       * @param server The server to decrypt, must not be {@code null}.
60       */
61      public DefaultSettingsDecryptionRequest(Server server) {
62          this.servers = new ArrayList<>(Arrays.asList(server));
63      }
64  
65      /**
66       * Creates a new request to decrypt the specified proxy.
67       *
68       * @param proxy The proxy to decrypt, must not be {@code null}.
69       */
70      public DefaultSettingsDecryptionRequest(Proxy proxy) {
71          this.proxies = new ArrayList<>(Arrays.asList(proxy));
72      }
73  
74      @Override
75      public List<Server> getServers() {
76          if (servers == null) {
77              servers = new ArrayList<>();
78          }
79  
80          return servers;
81      }
82  
83      @Override
84      public DefaultSettingsDecryptionRequest setServers(List<Server> servers) {
85          this.servers = servers;
86  
87          return this;
88      }
89  
90      @Override
91      public List<Proxy> getProxies() {
92          if (proxies == null) {
93              proxies = new ArrayList<>();
94          }
95  
96          return proxies;
97      }
98  
99      @Override
100     public DefaultSettingsDecryptionRequest setProxies(List<Proxy> proxies) {
101         this.proxies = proxies;
102 
103         return this;
104     }
105 }