View Javadoc
1   /*
2    *    Copyright 2011-2023 the original author or authors.
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    *       https://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 org.commonjava.maven.plugins.execroot;
17  
18  import org.apache.maven.plugin.MojoExecutionException;
19  import org.apache.maven.project.MavenProject;
20  
21  /**
22   * The Class ProjectRef.
23   */
24  public class ProjectRef {
25  
26      /** The group id. */
27      private String groupId;
28  
29      /** The artifact id. */
30      private String artifactId;
31  
32      /**
33       * Gets the group id.
34       *
35       * @return the group id
36       */
37      public String getGroupId() {
38          return groupId;
39      }
40  
41      /**
42       * Sets the group id.
43       *
44       * @param groupId
45       *            the new group id
46       */
47      public void setGroupId(final String groupId) {
48          this.groupId = groupId;
49      }
50  
51      /**
52       * Gets the artifact id.
53       *
54       * @return the artifact id
55       */
56      public String getArtifactId() {
57          return artifactId;
58      }
59  
60      /**
61       * Sets the artifact id.
62       *
63       * @param artifactId
64       *            the new artifact id
65       */
66      public void setArtifactId(final String artifactId) {
67          this.artifactId = artifactId;
68      }
69  
70      /**
71       * Validate.
72       *
73       * @throws MojoExecutionException
74       *             the mojo execution exception
75       */
76      public void validate() throws MojoExecutionException {
77          if (empty(groupId) || empty(artifactId)) {
78              throw new MojoExecutionException("Project references must contain groupId AND artifactId.");
79          }
80      }
81  
82      /**
83       * Empty.
84       *
85       * @param str
86       *            the str
87       *
88       * @return true, if successful
89       */
90      private boolean empty(final String str) {
91          return str == null || str.trim().length() == 0;
92      }
93  
94      /**
95       * Matches.
96       *
97       * @param project
98       *            the project
99       *
100      * @return true, if successful
101      */
102     public boolean matches(final MavenProject project) {
103         return project.getGroupId().equals(groupId) && project.getArtifactId().equals(artifactId);
104     }
105 
106     @Override
107     public String toString() {
108         return groupId + ":" + artifactId;
109     }
110 
111 }