|
1 | 1 | package com.devonfw.tools.ide.url.tool.mvn; |
2 | 2 |
|
3 | | -import com.devonfw.tools.ide.url.updater.MavenBasedUrlUpdater; |
| 3 | +import java.util.Locale; |
| 4 | + |
| 5 | +import com.devonfw.tools.ide.url.model.folder.UrlVersion; |
| 6 | +import com.devonfw.tools.ide.url.updater.GithubUrlReleaseUpdater; |
4 | 7 | import com.devonfw.tools.ide.version.VersionIdentifier; |
5 | 8 |
|
6 | 9 | /** |
7 | | - * {@link MavenBasedUrlUpdater} for mvn (maven). |
| 10 | + * {@link GithubUrlReleaseUpdater} for mvn (maven). |
8 | 11 | */ |
9 | | -public class MvnUrlUpdater extends MavenBasedUrlUpdater { |
| 12 | +public class MvnUrlUpdater extends GithubUrlReleaseUpdater { |
10 | 13 |
|
11 | | - public static final VersionIdentifier MIN_VERSION = VersionIdentifier.of("3.0.4"); |
| 14 | + private static final VersionIdentifier MIN_VERSION = VersionIdentifier.of("3.0.4"); |
| 15 | + private static final VersionIdentifier MAVEN_4_IDENTIFIER = VersionIdentifier.of("4.0.0-alpha"); |
12 | 16 |
|
13 | 17 | @Override |
14 | | - protected String getMavenGroupIdPath() { |
| 18 | + public String getTool() { |
15 | 19 |
|
16 | | - return "org/apache/maven"; |
| 20 | + return "mvn"; |
17 | 21 | } |
18 | 22 |
|
19 | 23 | @Override |
20 | | - protected String getMavenArtifcatId() { |
| 24 | + public String getCpeVendor() { |
21 | 25 |
|
22 | | - return "maven-core"; |
| 26 | + return "apache"; |
23 | 27 | } |
24 | 28 |
|
25 | 29 | @Override |
26 | | - public String getTool() { |
| 30 | + public String getCpeProduct() { |
27 | 31 |
|
28 | | - return "mvn"; |
| 32 | + return "maven"; |
29 | 33 | } |
30 | 34 |
|
31 | 35 | @Override |
32 | | - protected boolean isValidVersion(String version) { |
| 36 | + protected String getGithubOrganization() { |
| 37 | + return "apache"; |
| 38 | + } |
33 | 39 |
|
34 | | - VersionIdentifier artifactVersion = VersionIdentifier.of(version); |
35 | | - if (artifactVersion != null) { |
36 | | - return artifactVersion.isGreaterOrEqual(MIN_VERSION); |
37 | | - } |
38 | | - return true; |
| 40 | + @Override |
| 41 | + protected String getGithubRepository() { |
| 42 | + |
| 43 | + return "maven"; |
39 | 44 | } |
40 | 45 |
|
41 | 46 | @Override |
42 | | - public String getCpeVendor() { |
| 47 | + protected String getDownloadBaseUrl() { |
43 | 48 |
|
44 | | - return "apache"; |
| 49 | + return "https://archive.apache.org"; |
45 | 50 | } |
46 | 51 |
|
47 | 52 | @Override |
48 | | - public String getCpeProduct() { |
| 53 | + public String mapVersion(String version) { |
49 | 54 |
|
50 | | - return "maven"; |
| 55 | + // Workaround to get Release Candidates. |
| 56 | + // A better solution would be a flag or a map to signal which version are wanted. |
| 57 | + String vLower = version.toLowerCase(Locale.ROOT); |
| 58 | + if (vLower.startsWith("maven ")) { |
| 59 | + version = version.substring(6); |
| 60 | + vLower = vLower.substring(6); |
| 61 | + } |
| 62 | + if (vLower.contains("-rc")) { |
| 63 | + return version; |
| 64 | + } else { |
| 65 | + return super.mapVersion(version); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + protected void addVersion(UrlVersion urlVersion) { |
| 71 | + |
| 72 | + VersionIdentifier versionIdentifier = urlVersion.getVersionIdentifier(); |
| 73 | + if (versionIdentifier.compareVersion(MIN_VERSION).isGreater()) { |
| 74 | + String version = mapVersion(urlVersion.getName()); |
| 75 | + |
| 76 | + // This is just a workaround because apache archive sorts its versions into maven-x folders. |
| 77 | + // A better solution would be to extract the major version of the VersionIdentifier |
| 78 | + // and put that into the String Formatter but no such method exists yet. |
| 79 | + String majorFolder = versionIdentifier.compareVersion(MAVEN_4_IDENTIFIER).isLess() ? "maven-3" : "maven-4"; |
| 80 | + doAddVersion(urlVersion, getDownloadBaseUrl() + "/dist/maven/" + majorFolder + "/${version}/binaries/apache-maven-${version}-bin.zip"); |
| 81 | + } |
51 | 82 | } |
52 | 83 | } |
0 commit comments