• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 18880966434

28 Oct 2025 03:55PM UTC coverage: 68.862% (+0.3%) from 68.544%
18880966434

Pull #1496

github

web-flow
Merge 5e72e0006 into 8749d60f0
Pull Request #1496: #1492: Add Spring-Boot-CLI Commandlet

3484 of 5543 branches covered (62.85%)

Branch coverage included in aggregate %.

9115 of 12753 relevant lines covered (71.47%)

3.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.2
cli/src/main/java/com/devonfw/tools/ide/tool/mvn/MvnArtifact.java
1
package com.devonfw.tools.ide.tool.mvn;
2

3
import java.util.Objects;
4
import java.util.regex.Matcher;
5
import java.util.regex.Pattern;
6

7
import com.devonfw.tools.ide.tool.repository.MvnRepository;
8
import com.devonfw.tools.ide.tool.repository.SoftwareArtifact;
9

10
/**
11
 * Simple type representing a maven artifact.
12
 */
13
public class MvnArtifact extends SoftwareArtifact {
14

15
  /** {@link #getGroupId() Group ID} of IDEasy. */
16
  public static final String GROUP_ID_IDEASY = "com.devonfw.tools.IDEasy";
17

18
  /** {@link #getArtifactId() Artifact ID} of IDEasy command line interface. */
19
  public static final String ARTIFACT_ID_IDEASY_CLI = "ide-cli";
20

21
  /** {@link #getClassifier() Classifier} of source code. */
22
  public static final String CLASSIFER_SOURCES = "sources";
23

24
  /** {@link #getType() Type} of JAR file. */
25
  public static final String TYPE_JAR = "jar";
26

27
  /** {@link #getType() Type} of POM XML file. */
28
  public static final String TYPE_POM = "pom";
29

30
  /** {@link #getFilename() Filename} for artifact metadata with version information. */
31
  public static final String MAVEN_METADATA_XML = "maven-metadata.xml";
32

33
  private static final Pattern SNAPSHOT_VERSION_PATTERN = Pattern.compile("-\\d{8}\\.\\d{6}-\\d+");
4✔
34

35
  private final String groupId;
36

37
  private final String artifactId;
38

39
  private final String classifier;
40

41
  private final String type;
42

43
  private final String filename;
44

45
  private String path;
46

47
  private String downloadUrl;
48

49
  /**
50
   * The constructor.
51
   *
52
   * @param groupId the {@link #getGroupId() group ID}.
53
   * @param artifactId the {@link #getArtifactId() artifact ID}.
54
   * @param version the {@link #getVersion() version}.
55
   */
56
  public MvnArtifact(String groupId, String artifactId, String version) {
57
    this(groupId, artifactId, version, TYPE_JAR);
6✔
58
  }
1✔
59

60
  /**
61
   * The constructor.
62
   *
63
   * @param groupId the {@link #getGroupId() group ID}.
64
   * @param artifactId the {@link #getArtifactId() artifact ID}.
65
   * @param version the {@link #getVersion() version}.
66
   * @param type the {@link #getType() type}.
67
   */
68
  public MvnArtifact(String groupId, String artifactId, String version, String type) {
69
    this(groupId, artifactId, version, type, "");
7✔
70
  }
1✔
71

72
  /**
73
   * The constructor.
74
   *
75
   * @param groupId the {@link #getGroupId() group ID}.
76
   * @param artifactId the {@link #getArtifactId() artifact ID}.
77
   * @param version the {@link #getVersion() version}.
78
   * @param type the {@link #getType() type}.
79
   * @param classifier the {@link #getClassifier() classifier}.
80
   */
81
  public MvnArtifact(String groupId, String artifactId, String version, String type, String classifier) {
82
    this(groupId, artifactId, version, type, classifier, null);
8✔
83
  }
1✔
84

85
  MvnArtifact(String groupId, String artifactId, String version, String type, String classifier, String filename) {
86
    super(version);
3✔
87
    this.groupId = requireNotEmpty(groupId, "groupId");
5✔
88
    this.artifactId = requireNotEmpty(artifactId, "artifactId");
5✔
89
    this.classifier = notNull(classifier);
4✔
90
    this.type = requireNotEmpty(type, "type");
5✔
91
    this.filename = filename;
3✔
92
  }
1✔
93

94
  /**
95
   * @return the group ID (e.g. {@link #GROUP_ID_IDEASY}).
96
   */
97
  public String getGroupId() {
98
    return this.groupId;
3✔
99
  }
100

101
  /**
102
   * @return the artifact ID (e.g. {@link #ARTIFACT_ID_IDEASY_CLI}).
103
   */
104
  public String getArtifactId() {
105
    return this.artifactId;
3✔
106
  }
107

108
  /**
109
   * @param newVersion the new value of {@link #getVersion()}.
110
   * @return a new {@link MvnArtifact} with the given version.
111
   */
112
  public MvnArtifact withVersion(String newVersion) {
113

114
    if (this.version.equals(newVersion)) {
5!
115
      return this;
×
116
    }
117
    return new MvnArtifact(this.groupId, this.artifactId, newVersion, this.type, this.classifier, this.filename);
15✔
118
  }
119

120
  /**
121
   * @return the classifier. Will be the empty {@link String} for no classifier.
122
   */
123
  public String getClassifier() {
124
    return this.classifier;
3✔
125
  }
126

127
  /**
128
   * @param newClassifier the new value of {@link #getClassifier()}.
129
   * @return a new {@link MvnArtifact} with the given classifier.
130
   */
131
  public MvnArtifact withClassifier(String newClassifier) {
132

133
    if (this.classifier.equals(newClassifier)) {
5✔
134
      return this;
2✔
135
    }
136
    return new MvnArtifact(this.groupId, this.artifactId, this.version, this.type, newClassifier, this.filename);
15✔
137
  }
138

139
  /**
140
   * @return the type (e.g. #TYPE_JAR}
141
   */
142
  public String getType() {
143
    return type;
3✔
144
  }
145

146
  /**
147
   * @param newType the new value of {@link #getType()}.
148
   * @return a new {@link MvnArtifact} with the given type.
149
   */
150
  public MvnArtifact withType(String newType) {
151

152
    if (this.type.equals(newType)) {
5✔
153
      return this;
2✔
154
    }
155
    return new MvnArtifact(this.groupId, this.artifactId, this.version, newType, this.classifier, this.filename);
15✔
156
  }
157

158
  /**
159
   * @return the filename of the artifact.
160
   */
161
  public String getFilename() {
162

163
    if (this.filename == null) {
3✔
164
      String infix = "";
2✔
165
      if (!this.classifier.isEmpty()) {
4!
166
        infix = "-" + this.classifier;
4✔
167
      }
168
      return this.artifactId + "-" + this.version + infix + "." + this.type;
9✔
169
    }
170
    return this.filename;
3✔
171
  }
172

173
  /**
174
   * @param newFilename the new value of {@link #getFilename()}.
175
   * @return a new {@link MvnArtifact} with the given filename.
176
   */
177
  public MvnArtifact withFilename(String newFilename) {
178

179
    if (Objects.equals(this.filename, newFilename)) {
5✔
180
      return this;
2✔
181
    }
182
    return new MvnArtifact(this.groupId, this.artifactId, this.version, this.type, this.classifier, newFilename);
15✔
183
  }
184

185
  /**
186
   * @return a new {@link MvnArtifact} for {@link #MAVEN_METADATA_XML}.
187
   */
188
  public MvnArtifact withMavenMetadata() {
189

190
    return withType("xml").withFilename(MAVEN_METADATA_XML);
6✔
191
  }
192

193
  /**
194
   * @return {@code true} if this artifact represents {@link #MAVEN_METADATA_XML}.
195
   * @see #withMavenMetadata()
196
   */
197
  public boolean isMavenMetadata() {
198
    return MAVEN_METADATA_XML.equals(this.filename);
5✔
199
  }
200

201
  /**
202
   * @return the {@link String} with the path to the specified artifact relative to the maven repository base path or URL. For snapshots, includes the
203
   *     timestamped version in the artifact filename.
204
   */
205
  public String getPath() {
206
    if (this.path == null) {
3✔
207
      StringBuilder sb = new StringBuilder();
4✔
208
      // Common path start: groupId/artifactId/version
209
      sb.append(this.groupId.replace('.', '/')).append('/')
11✔
210
          .append(this.artifactId).append('/');
4✔
211

212
      if (!this.version.startsWith("*")) {
5✔
213
        sb.append(getBaseVersion()).append('/');
7✔
214
      }
215
      sb.append(getFilename());
5✔
216
      this.path = sb.toString();
4✔
217
    }
218
    return this.path;
3✔
219
  }
220

221
  @Override
222
  protected String computeKey() {
223

224
    int capacity = this.groupId.length() + this.artifactId.length() + this.version.length() + type.length() + classifier.length() + 4;
22✔
225
    StringBuilder sb = new StringBuilder(capacity);
5✔
226
    sb.append(this.groupId).append(':').append(this.artifactId).append(':').append(this.version).append(':').append(this.type);
20✔
227
    if (!this.classifier.isEmpty()) {
4✔
228
      sb.append(':').append(this.classifier);
7✔
229
    }
230
    String key = sb.toString();
3✔
231
    assert (key.length() <= capacity);
5!
232
    return key;
2✔
233
  }
234

235
  /**
236
   * Checks if the current artifact version is a snapshot version.
237
   *
238
   * @return true if this is a snapshot version, false otherwise
239
   */
240
  public boolean isSnapshot() {
241
    return this.version.endsWith("-SNAPSHOT") || SNAPSHOT_VERSION_PATTERN.matcher(this.version).find();
15✔
242
  }
243

244
  /**
245
   * Gets the base version without snapshot timestamp. For snapshot versions like "2024.04.001-beta-20240419.123456-1", returns "2024.04.001-beta-SNAPSHOT". For
246
   * release versions, returns the version as is.
247
   *
248
   * @return the base version
249
   */
250
  public String getBaseVersion() {
251
    Matcher matcher = SNAPSHOT_VERSION_PATTERN.matcher(this.version);
5✔
252
    if (matcher.find()) {
3✔
253
      return matcher.replaceAll("-SNAPSHOT");
4✔
254
    }
255
    return this.version;
3✔
256
  }
257

258
  /**
259
   * @return the download URL to download the artifact from the maven repository.
260
   */
261
  public String getDownloadUrl() {
262
    if (this.downloadUrl == null) {
3✔
263
      String baseUrl = getMvnBaseUrl();
3✔
264
      this.downloadUrl = baseUrl + "/" + getPath();
6✔
265
    }
266
    return this.downloadUrl;
3✔
267
  }
268

269
  public String getMvnBaseUrl() {
270
    return isSnapshot() ? MvnRepository.MAVEN_SNAPSHOTS : MvnRepository.MAVEN_CENTRAL;
7✔
271
  }
272

273
  @Override
274
  public int hashCode() {
275
    return Objects.hash(this.groupId, this.artifactId, this.version);
19✔
276
  }
277

278
  @Override
279
  public boolean equals(Object obj) {
280
    if (obj == this) {
3!
281
      return true;
×
282
    } else if (obj instanceof MvnArtifact other) {
6!
283
      return this.groupId.equals(other.groupId) && this.artifactId.equals(other.artifactId) && this.version.equals(other.version)
23!
284
          && this.classifier.equals(other.classifier) && this.type.equals(other.type) && Objects.equals(this.filename, other.filename);
16!
285
    }
286
    return false;
×
287
  }
288

289
  private static String notNull(String value) {
290

291
    if (value == null) {
2!
292
      return "";
×
293
    }
294
    return value;
2✔
295
  }
296

297
  /**
298
   * @param artifactId the {@link #getArtifactId() artifact ID}.
299
   * @param version the {@link #getVersion() version}.
300
   * @param type the {@link #getType() type}.
301
   * @param classifier the {@link #getClassifier() classifier}.
302
   * @return the IDEasy {@link MvnArtifact}.
303
   */
304
  public static MvnArtifact ofIdeasy(String artifactId, String version, String type, String classifier) {
305

306
    return new MvnArtifact(GROUP_ID_IDEASY, artifactId, version, type, classifier);
9✔
307
  }
308

309
  /**
310
   * @param version the {@link #getVersion() version}.
311
   * @param type the {@link #getType() type}.
312
   * @param classifier the {@link #getClassifier() classifier}.
313
   * @return the IDEasy {@link MvnArtifact}.
314
   */
315
  public static MvnArtifact ofIdeasyCli(String version, String type, String classifier) {
316

317
    return ofIdeasy(ARTIFACT_ID_IDEASY_CLI, version, type, classifier);
6✔
318
  }
319
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc