1 /*
2 * Themis: Java Project Framework
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.themis.lethe.analysis;
18
19 import org.w3c.dom.Element;
20
21 /**
22 * Maven Module Id.
23 */
24 public class ThemisAnalysisMavenId {
25 /**
26 * GroupId element.
27 */
28 private static final String EL_GROUPID = "groupId";
29
30 /**
31 * ArtifactId element.
32 */
33 private static final String EL_ARTIFACTID = "artifactId";
34
35 /**
36 * Version element.
37 */
38 private static final String EL_VERSION = "version";
39
40 /**
41 * Parent groupId indication.
42 */
43 private static final String PARENT_GROUP = "${project.groupId}";
44
45 /**
46 * Parent version indication.
47 */
48 private static final String PARENT_VERSION = "${project.version}";
49
50 /**
51 * The groupId.
52 */
53 private String theGroupId;
54
55 /**
56 * The artifactId.
57 */
58 private String theArtifactId;
59
60 /**
61 * The version.
62 */
63 private String theVersion;
64
65 /**
66 * Constructor.
67 *
68 * @param pElement the element containing the values
69 */
70 ThemisAnalysisMavenId(final Element pElement) {
71 /* Access the values */
72 theGroupId = ThemisAnalysisMaven.getElementValue(pElement, EL_GROUPID);
73 theArtifactId = ThemisAnalysisMaven.getElementValue(pElement, EL_ARTIFACTID);
74 theVersion = ThemisAnalysisMaven.getElementValue(pElement, EL_VERSION);
75 }
76
77 /**
78 * Constructor.
79 *
80 * @param pElement the element containing the values
81 * @param pParent the parent Id
82 */
83 ThemisAnalysisMavenId(final Element pElement,
84 final ThemisAnalysisMavenId pParent) {
85 /* Process as much as we can */
86 this(pElement);
87
88 /* Handle missing groupId/version */
89 if (theGroupId == null || PARENT_GROUP.equals(theGroupId)) {
90 theGroupId = pParent.getGroupId();
91 }
92 if (theVersion == null || PARENT_VERSION.equals(theVersion)) {
93 theVersion = pParent.getVersion();
94 }
95 }
96
97 /**
98 * Obtain the groupId.
99 *
100 * @return the groupId
101 */
102 public String getGroupId() {
103 return theGroupId;
104 }
105
106 /**
107 * Obtain the artifactId.
108 *
109 * @return the artifactId
110 */
111 public String getArtifactId() {
112 return theArtifactId;
113 }
114
115 /**
116 * Obtain the version.
117 *
118 * @return the version
119 */
120 public String getVersion() {
121 return theVersion;
122 }
123
124 @Override
125 public String toString() {
126 return theGroupId + ":" + theArtifactId + ":" + theVersion;
127 }
128 }