View Javadoc

1   /*
2    * Copyright 2012 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.ci.maven;
17  
18  import org.apache.maven.settings.Server;
19  import org.codehaus.plexus.util.StringUtils;
20  
21  import de.smartics.ci.maven.util.SettingsDecrypter;
22  
23  /**
24   * Provides access information for the continuous integration server.
25   */
26  public final class CiServer extends Server
27  {
28    /**
29     * The class version identifier.
30     * <p>
31     * The value of this constant is {@value}.
32     * </p>
33     */
34    private static final long serialVersionUID = 1L;
35  
36    /**
37     * The URL to the server.
38     */
39    private final String url;
40  
41    /**
42     * Default constructor.
43     *
44     * @param logger the logger to use for this class.
45     * @param url the URL to the server.
46     * @param server the server information from the <code>settings.xml</code>.
47     * @param settingsDecrypter the decryptor when passwords are encrypted in the
48     *          settings.xml.
49     */
50    public CiServer(final Logger logger, final Server server, final String url,
51        final SettingsDecrypter settingsDecrypter)
52    {
53      checkParameter(logger, server, url);
54  
55      this.url = url;
56  
57      if (server != null)
58      {
59        this.setId(server.getId());
60        this.setUsername(server.getUsername());
61        final String decryptedPassword =
62            settingsDecrypter.decrypt(server.getPassword());
63        this.setPassword(decryptedPassword);
64        this.setPassphrase(server.getPassphrase());
65        this.setPrivateKey(server.getPrivateKey());
66  
67        this.setDirectoryPermissions(server.getDirectoryPermissions());
68        this.setFilePermissions(server.getFilePermissions());
69        this.setConfiguration(server.getConfiguration());
70  
71        this.setSourceLevel(server.getSourceLevel());
72      }
73    }
74  
75    private void checkParameter(final Logger logger, final Server server,
76        final String url)
77    {
78      if (logger != null)
79      {
80        if (StringUtils.isBlank(url))
81        {
82          logger.warn("Ci-Server URL is null");
83        }
84        if (server == null || StringUtils.isBlank(server.getId())
85            || StringUtils.isBlank(server.getUsername())
86            || StringUtils.isBlank(server.getPassword()))
87        {
88          logger.warn("Server in settings is not correct id, username and "
89                      + "password are needed (passphrase and private key are"
90                      + " not supported right now).");
91        }
92      }
93    }
94  
95    /**
96     * Returns the URL to the server.
97     *
98     * @return the URL to the server.
99     */
100   public String getUrl()
101   {
102     return url;
103   }
104 }