1 package org.apache.maven.shared.runtime;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.Serializable;
23
24 /**
25 * Encapsulates the unique identifier for a Maven project.
26 * <p>
27 * More specifically, this object holds a project's group id, artifact id and version. This information is typically
28 * generated by Maven and stored within the file
29 * {@code META-INF/maven/<groupId>/<artifactId>/pom.properties} in the packaged project.
30 * </p>
31 *
32 * @author <a href="mailto:markh@apache.org">Mark Hobson</a>
33 * @version $Id: MavenProjectProperties.java 831910 2009-11-02 15:05:33Z markh $
34 */
35 public class MavenProjectProperties implements Serializable
36 {
37 // constants --------------------------------------------------------------
38
39 /**
40 * The serial version ID.
41 */
42 private static final long serialVersionUID = 5233832086526764232L;
43
44 // fields -----------------------------------------------------------------
45
46 /**
47 * The Maven project group id.
48 */
49 private final String groupId;
50
51 /**
52 * The Maven project artifact id.
53 */
54 private final String artifactId;
55
56 /**
57 * The Maven project version.
58 */
59 private final String version;
60
61 // constructors -----------------------------------------------------------
62
63 /**
64 * Creates a new {@code MavenProjectProperties} with the specified Maven project group id, artifact id and version
65 * properties.
66 *
67 * @param groupId
68 * the group id, not null
69 * @param artifactId
70 * the artifact id, not null
71 * @param version
72 * the version, not null
73 */
74 public MavenProjectProperties( String groupId, String artifactId, String version )
75 {
76 if ( groupId == null )
77 {
78 throw new IllegalArgumentException( "groupId cannot be null" );
79 }
80
81 if ( artifactId == null )
82 {
83 throw new IllegalArgumentException( "artifactId cannot be null" );
84 }
85
86 if ( version == null )
87 {
88 throw new IllegalArgumentException( "version cannot be null" );
89 }
90
91 this.groupId = groupId;
92 this.artifactId = artifactId;
93 this.version = version;
94 }
95
96 // public methods ---------------------------------------------------------
97
98 /**
99 * Gets the group id for these Maven project properties.
100 *
101 * @return the group id
102 */
103 public String getGroupId()
104 {
105 return groupId;
106 }
107
108 /**
109 * Gets the artifact id for these Maven project properties.
110 *
111 * @return the artifact id
112 */
113 public String getArtifactId()
114 {
115 return artifactId;
116 }
117
118 /**
119 * Gets the version for these Maven project properties.
120 *
121 * @return the version
122 */
123 public String getVersion()
124 {
125 return version;
126 }
127
128 // Object methods ---------------------------------------------------------
129
130 /**
131 * {@inheritDoc}
132 */
133 @Override
134 public int hashCode()
135 {
136 int hashCode = 17;
137
138 hashCode = ( hashCode * 37 ) + groupId.hashCode();
139
140 hashCode = ( hashCode * 37 ) + artifactId.hashCode();
141
142 hashCode = ( hashCode * 37 ) + version.hashCode();
143
144 return hashCode;
145 }
146
147 /**
148 * {@inheritDoc}
149 */
150 @Override
151 public boolean equals( Object object )
152 {
153 if ( object == this )
154 {
155 return true;
156 }
157
158 if ( !( object instanceof MavenProjectProperties ) )
159 {
160 return false;
161 }
162
163 MavenProjectProperties info = (MavenProjectProperties) object;
164
165 return groupId.equals( info.getGroupId() )
166 && artifactId.equals( info.getArtifactId() )
167 && version.equals( info.getVersion() );
168 }
169
170 /**
171 * {@inheritDoc}
172 */
173 @Override
174 public String toString()
175 {
176 StringBuffer buffer = new StringBuffer();
177
178 buffer.append( getClass().getName() );
179 buffer.append( "[" );
180 buffer.append( "groupId=" ).append( groupId ).append( "," );
181 buffer.append( "artifactId=" ).append( artifactId ).append( "," );
182 buffer.append( "version=" ).append( version );
183 buffer.append( "]" );
184
185 return buffer.toString();
186 }
187 }