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.maven.nexus;
17  
18  import de.smartics.util.lang.Arguments;
19  import de.smartics.util.lang.BlankArgumentException;
20  
21  /**
22   * The data to send to the Nexus server to access artifact resolution
23   * information.
24   */
25  public final class NexusRequest
26  {
27    // ********************************* Fields *********************************
28  
29    // --- constants ------------------------------------------------------------
30  
31    // --- members --------------------------------------------------------------
32  
33    /**
34     * The path to the Nexus server.
35     */
36    private final String nexusServer;
37  
38    /**
39     * The identifier of the repository to query on the given nexus server.
40     */
41    private final String repositoryId;
42  
43    /**
44     * The group identifier of the requested artifact.
45     */
46    private final String groupId;
47  
48    /**
49     * The identifier of the requested artifact.
50     */
51    private final String artifactId;
52  
53    /**
54     * The extension of the file of the requested artifact.
55     */
56    private final String extension;
57  
58    // ****************************** Initializer *******************************
59  
60    // ****************************** Constructors ******************************
61  
62    /**
63     * Default constructor.
64     *
65     * @param nexusServer the path to the Nexus server.
66     * @param repositoryId the identifier of the repository to query on the given
67     *          nexus server.
68     * @param groupId the group identifier of the requested artifact.
69     * @param artifactId the identifier of the requested artifact.
70     * @param extension the extension of the file of the requested artifact.
71     * @throws BlankArgumentException if any parameter value is blank.
72     */
73    public NexusRequest(final String nexusServer, final String repositoryId,
74        final String groupId, final String artifactId, final String extension)
75      throws BlankArgumentException
76    {
77      Arguments.checkNotBlank("nexusServer", nexusServer);
78      Arguments.checkNotBlank("repositoryId", repositoryId);
79      Arguments.checkNotBlank("groupId", groupId);
80      Arguments.checkNotBlank("artifactId", artifactId);
81      Arguments.checkNotBlank("extension", extension);
82  
83      this.nexusServer = nexusServer;
84      this.repositoryId = repositoryId;
85      this.groupId = groupId;
86      this.artifactId = artifactId;
87      this.extension = extension;
88    }
89  
90    // ****************************** Inner Classes *****************************
91  
92    // ********************************* Methods ********************************
93  
94    // --- init -----------------------------------------------------------------
95  
96    // --- get&set --------------------------------------------------------------
97  
98    /**
99     * Returns the path to the Nexus server.
100    *
101    * @return the path to the Nexus server.
102    */
103   public String getNexusServer()
104   {
105     return nexusServer;
106   }
107 
108   /**
109    * Returns the identifier of the repository to query on the given nexus
110    * server.
111    *
112    * @return the identifier of the repository to query on the given nexus
113    *         server.
114    */
115   public String getRepositoryId()
116   {
117     return repositoryId;
118   }
119 
120   /**
121    * Returns the group identifier of the requested artifact.
122    *
123    * @return the group identifier of the requested artifact.
124    */
125   public String getGroupId()
126   {
127     return groupId;
128   }
129 
130   /**
131    * Returns the identifier of the requested artifact.
132    *
133    * @return the identifier of the requested artifact.
134    */
135   public String getArtifactId()
136   {
137     return artifactId;
138   }
139 
140   /**
141    * Returns the string representation of the artifact.
142    *
143    * @return the string representation of the artifact.
144    */
145   public String getArtifactString()
146   {
147     return groupId + ':' + artifactId;
148   }
149 
150   /**
151    * Returns the extension of the file of the requested artifact.
152    *
153    * @return the extension of the file of the requested artifact.
154    */
155   public String getExtension()
156   {
157     return extension;
158   }
159 
160   // --- business -------------------------------------------------------------
161 
162   // --- object basics --------------------------------------------------------
163 
164   /**
165    * Returns the string representation of the object.
166    *
167    * @return the string representation of the object.
168    */
169   @Override
170   public String toString()
171   {
172     final StringBuilder buffer = new StringBuilder();
173 
174     buffer.append(nexusServer).append(':').append(repositoryId).append(':')
175         .append(groupId).append(':').append(artifactId).append(':')
176         .append(extension);
177 
178     return buffer.toString();
179   }
180 }