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