payload = super.getPayload();
117 | payload.put("platform", "UNIVERSAL");
118 | payload.put("url", url);
119 | return payload;
120 | }
121 |
122 | protected HttpEntityEnclosingRequestBase createAnnounceHttpRequest() {
123 | try {
124 | return new HttpPost(createURI(ANNOUNCE_ENDPOINT));
125 | } catch (URISyntaxException e) {
126 | throw new IllegalArgumentException(e);
127 | }
128 | }
129 |
130 | protected HttpEntityEnclosingRequestBase createDefaultHttpRequest() {
131 | try {
132 | return new HttpPut(createURI(DEFAULT_ENDPOINT));
133 | } catch (URISyntaxException e) {
134 | throw new IllegalArgumentException(e);
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/io/sdkman/maven/MinorMojo.java:
--------------------------------------------------------------------------------
1 | package io.sdkman.maven;
2 |
3 | import org.apache.http.HttpResponse;
4 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
5 | import org.apache.http.client.methods.HttpPost;
6 | import org.apache.maven.plugin.MojoExecutionException;
7 | import org.apache.maven.plugins.annotations.Mojo;
8 | import org.apache.maven.plugins.annotations.Parameter;
9 |
10 | import java.io.IOException;
11 | import java.net.URISyntaxException;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | import static io.sdkman.maven.infra.ApiEndpoints.ANNOUNCE_ENDPOINT;
17 | import static io.sdkman.maven.infra.ApiEndpoints.RELEASE_ENDPOINT;
18 |
19 | /**
20 | * Release and announce.
21 | *
22 | * @author Andres Almiray
23 | */
24 | @Mojo(name = "minor-release")
25 | public class MinorMojo extends BaseMojo {
26 |
27 | /** The hashtag to use (legacy) */
28 | @Parameter(property = "sdkman.hashtag")
29 | protected String hashtag;
30 |
31 | /** The URL from where the candidate version can be downloaded */
32 | @Parameter(property = "sdkman.url")
33 | protected String url;
34 |
35 | /**
36 | * Platform to downloable URL mappings.
37 | * Supported platforms are:
38 | *
39 | * - MAC_OSX
40 | * - WINDOWS_64
41 | * - LINUX_64
42 | * - LINUX_32
43 | *
44 | * Example:
45 | *
46 | * "MAC_OSX" :"https://host/micronaut-x.y.z-macosx.zip"
47 | * "LINUX_64" :"https://host/micronaut-x.y.z-linux64.zip"
48 | * "WINDOWS_64":"https://host/micronaut-x.y.z-win.zip"
49 | *
50 | */
51 | @Parameter(property = "sdkman.platforms")
52 | protected Map platforms;
53 |
54 | /** The URL where the release notes can be found */
55 | @Parameter(property = "sdkman.release.notes.url")
56 | protected String releaseNotesUrl;
57 |
58 | @Override
59 | protected HttpEntityEnclosingRequestBase createHttpRequest() {
60 | try {
61 | return new HttpPost(createURI(RELEASE_ENDPOINT));
62 | } catch (URISyntaxException e) {
63 | throw new IllegalArgumentException(e);
64 | }
65 | }
66 |
67 | @Override
68 | protected void doExecute() throws MojoExecutionException {
69 | try {
70 | HttpResponse resp = executeMinorRelease();
71 | int statusCode = resp.getStatusLine().getStatusCode();
72 | if (statusCode < 200 || statusCode >= 300) {
73 | throw new IllegalStateException("Server returned error " + resp.getStatusLine());
74 | }
75 | } catch (Exception e) {
76 | throw new MojoExecutionException("Sdk minor release failed", e);
77 | }
78 | }
79 |
80 | protected HttpResponse executeMinorRelease() throws IOException {
81 | List responses = new ArrayList<>();
82 |
83 | if (platforms == null || platforms.isEmpty()) {
84 | responses.add(execCall(getReleasePayload(), createHttpRequest()));
85 | } else {
86 | for (Map.Entry platform : platforms.entrySet()) {
87 | Map payload = super.getPayload();
88 | payload.put("platform", platform.getKey());
89 | payload.put("url", platform.getValue());
90 | responses.add(execCall(payload, createHttpRequest()));
91 | }
92 | }
93 |
94 | responses.add(execCall(getAnnouncePayload(), createAnnounceHttpRequest()));
95 |
96 | return responses.stream()
97 | .filter(resp -> {
98 | int statusCode = resp.getStatusLine().getStatusCode();
99 | return statusCode < 200 || statusCode >= 300;
100 | })
101 | .findFirst()
102 | .orElse(responses.get(responses.size() - 1));
103 | }
104 |
105 | protected Map getAnnouncePayload() {
106 | Map payload = super.getPayload();
107 | if (hashtag != null && !hashtag.isEmpty()) payload.put("hashtag", hashtag);
108 | if (releaseNotesUrl != null && !releaseNotesUrl.isEmpty()) payload.put("url", releaseNotesUrl);
109 | return payload;
110 | }
111 |
112 | protected Map getReleasePayload() {
113 | Map payload = super.getPayload();
114 | payload.put("platform", "UNIVERSAL");
115 | payload.put("url", url);
116 | return payload;
117 | }
118 |
119 | protected HttpEntityEnclosingRequestBase createAnnounceHttpRequest() {
120 | try {
121 | return new HttpPost(createURI(ANNOUNCE_ENDPOINT));
122 | } catch (URISyntaxException e) {
123 | throw new IllegalArgumentException(e);
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/main/java/io/sdkman/maven/ReleaseMojo.java:
--------------------------------------------------------------------------------
1 | package io.sdkman.maven;
2 |
3 | import org.apache.http.HttpResponse;
4 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
5 | import org.apache.http.client.methods.HttpPost;
6 | import org.apache.maven.plugin.MojoExecutionException;
7 | import org.apache.maven.plugins.annotations.Mojo;
8 | import org.apache.maven.plugins.annotations.Parameter;
9 |
10 | import java.io.IOException;
11 | import java.net.URISyntaxException;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | import static io.sdkman.maven.infra.ApiEndpoints.RELEASE_ENDPOINT;
17 |
18 | /**
19 | * Release a candidate.
20 | *
21 | * @author Julien Viet
22 | */
23 | @Mojo(name = "release")
24 | public class ReleaseMojo extends BaseMojo {
25 |
26 | /** The URL from where the candidate version can be downloaded */
27 | @Parameter(property = "sdkman.url")
28 | protected String url;
29 |
30 | /**
31 | * Platform to downloable URL mappings.
32 | * Supported platforms are:
33 | *
34 | * - MAC_OSX
35 | * - WINDOWS_64
36 | * - LINUX_64
37 | * - LINUX_32
38 | *
39 | * Example:
40 | *
41 | * "MAC_OSX" :"https://host/micronaut-x.y.z-macosx.zip"
42 | * "LINUX_64" :"https://host/micronaut-x.y.z-linux64.zip"
43 | * "WINDOWS_64":"https://host/micronaut-x.y.z-win.zip"
44 | *
45 | */
46 | @Parameter(property = "sdkman.platforms")
47 | protected Map platforms;
48 |
49 | @Override
50 | protected Map getPayload() {
51 | // url is required if platforms is empty
52 | if ((platforms == null || platforms.isEmpty()) && (url == null || url.isEmpty())) {
53 | throw new IllegalArgumentException("Missing url");
54 | }
55 |
56 | Map payload = super.getPayload();
57 | payload.put("platform", "UNIVERSAL");
58 | payload.put("url", url);
59 | return payload;
60 | }
61 |
62 | @Override
63 | protected HttpEntityEnclosingRequestBase createHttpRequest() {
64 | try {
65 | return new HttpPost(createURI(RELEASE_ENDPOINT));
66 | } catch (URISyntaxException e) {
67 | throw new IllegalArgumentException(e);
68 | }
69 | }
70 |
71 | @Override
72 | protected void doExecute() throws MojoExecutionException {
73 | try {
74 | HttpResponse resp = executeRelease();
75 | int statusCode = resp.getStatusLine().getStatusCode();
76 | if (statusCode < 200 || statusCode >= 300) {
77 | throw new IllegalStateException("Server returned error " + resp.getStatusLine());
78 | }
79 | } catch (Exception e) {
80 | throw new MojoExecutionException("Sdk release failed", e);
81 | }
82 | }
83 |
84 | protected HttpResponse executeRelease() throws IOException {
85 | if (platforms == null || platforms.isEmpty()) {
86 | return execCall(getPayload(), createHttpRequest());
87 | }
88 |
89 | List responses = new ArrayList<>();
90 | for (Map.Entry platform : platforms.entrySet()) {
91 | Map payload = super.getPayload();
92 | payload.put("platform", platform.getKey());
93 | payload.put("url", platform.getValue());
94 | responses.add(execCall(payload, createHttpRequest()));
95 | }
96 |
97 | return responses.stream()
98 | .filter(resp -> {
99 | int statusCode = resp.getStatusLine().getStatusCode();
100 | return statusCode < 200 || statusCode >= 300;
101 | })
102 | .findFirst()
103 | .orElse(responses.get(responses.size() - 1));
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/io/sdkman/maven/infra/ApiEndpoints.java:
--------------------------------------------------------------------------------
1 | package io.sdkman.maven.infra;
2 |
3 | /**
4 | * @author Andres Almiray
5 | */
6 | public class ApiEndpoints {
7 | public static final String ANNOUNCE_ENDPOINT = "/announce/struct";
8 | public static final String DEFAULT_ENDPOINT = "/candidates/default";
9 | public static final String RELEASE_ENDPOINT = "/versions";
10 | }
11 |
--------------------------------------------------------------------------------