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  /**
22   * Provides access information for the continuous integration server.
23   */
24  public final class CiServer extends Server
25  {
26    /**
27     * The class version identifier.
28     * <p>
29     * The value of this constant is {@value}.
30     * </p>
31     */
32    private static final long serialVersionUID = 1L;
33  
34    /**
35     * The URL to the server.
36     */
37    private final String url;
38  
39    /**
40     * Default constructor.
41     *
42     * @param logger the logger to use for this class.
43     * @param url the URL to the server.
44     * @param server the server information from the <code>settings.xml</code>.
45     */
46    public CiServer(final Logger logger, final Server server, final String url)
47    {
48      checkParameter(logger, server, url);
49  
50      this.url = url;
51  
52      if (server != null)
53      {
54        this.setId(server.getId());
55        this.setUsername(server.getUsername());
56  
57        this.setPassword(server.getPassword());
58        this.setPassphrase(server.getPassphrase());
59        this.setPrivateKey(server.getPrivateKey());
60  
61        this.setDirectoryPermissions(server.getDirectoryPermissions());
62        this.setFilePermissions(server.getFilePermissions());
63        this.setConfiguration(server.getConfiguration());
64  
65        this.setSourceLevel(server.getSourceLevel());
66      }
67    }
68  
69    private void checkParameter(final Logger logger, final Server server,
70        final String url)
71    {
72      if (logger != null)
73      {
74        if (StringUtils.isBlank(url))
75        {
76          logger.warn("Ci-Server URL is null");
77        }
78        if (server == null || StringUtils.isBlank(server.getId())
79            || StringUtils.isBlank(server.getUsername())
80            || StringUtils.isBlank(server.getPassword()))
81        {
82          logger.warn("Server in settings is not correct id, username and "
83                      + "password are needed (passphrase and private key are"
84                      + " not supported right now).");
85        }
86      }
87    }
88  
89    /**
90     * Returns the URL to the server.
91     *
92     * @return the URL to the server.
93     */
94    public String getUrl()
95    {
96      return url;
97    }
98  }