|
13 | 13 | * #L% |
14 | 14 | */ |
15 | 15 |
|
| 16 | + |
| 17 | +import java.io.BufferedReader; |
16 | 18 | import java.io.IOException; |
17 | 19 | import java.io.InputStream; |
| 20 | +import java.io.InputStreamReader; |
18 | 21 | import java.io.OutputStream; |
19 | 22 | import java.net.URI; |
20 | 23 | import java.net.URLEncoder; |
|
25 | 28 | import java.nio.file.Files; |
26 | 29 | import java.nio.file.Path; |
27 | 30 | import java.util.Base64; |
| 31 | +import java.util.Collection; |
28 | 32 | import java.util.Date; |
29 | 33 | import java.util.EnumSet; |
| 34 | +import java.util.LinkedList; |
30 | 35 | import java.util.List; |
31 | 36 | import java.util.Map; |
32 | 37 | import java.util.jar.Attributes; |
@@ -94,12 +99,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { |
94 | 99 | Log log = getLog(); |
95 | 100 | HttpClient httpClient = HttpClient.newHttpClient(); |
96 | 101 | try { |
97 | | - String aemVersion = getAemVersion(httpClient); |
| 102 | + Collection<String> products = getProducts(httpClient); |
98 | 103 |
|
99 | 104 | log.warn("Make sure that the relevant search index definitions are deployed on AEM at " + baseUrl + ". Otherwise this goal will fail!"); |
100 | 105 | log.info("Start retrieving the classification and deprecation data from " + baseUrl); |
101 | 106 |
|
102 | | - MutableContentClassificationMap map = new MutableContentClassificationMapImpl("AEM " + aemVersion); |
| 107 | + MutableContentClassificationMap map = new MutableContentClassificationMapImpl(products.stream().collect(Collectors.joining(", "))); |
103 | 108 | // always make sure that the root node is PUBLIC (even though this might not be part of the classification map extracted from a repo) |
104 | 109 | map.put("/", ContentClassification.PUBLIC, null); |
105 | 110 | // 1. retrieve classifications from mixins and store in map |
@@ -138,19 +143,30 @@ public void execute() throws MojoExecutionException, MojoFailureException { |
138 | 143 | } |
139 | 144 | } |
140 | 145 |
|
141 | | - String getAemVersion(HttpClient httpClient) throws IOException, InterruptedException { |
142 | | - try (InputStream input = downloadFromAem(httpClient, "/libs/granite/operations/content/systemoverview/export.json")) { |
143 | | - JSONParser parser = new JSONParser(input); |
144 | | - Map<String, Object> response = parser.getParsed(); |
145 | | - getLog().debug("Received JSON response " + response); |
146 | | - |
147 | | - Object results = response.get("Instance"); |
148 | | - if (!(results instanceof Map<?, ?>)) { |
149 | | - throw new IllegalStateException("JSON response did not have an array of results"); |
| 146 | + Collection<String> getProducts(HttpClient httpClient) throws IOException, InterruptedException { |
| 147 | + // http://localhost:4502/system/console/status-productinfo does not provide proper JSON, therefore parse TXT |
| 148 | + try (InputStream input = downloadFromAem(httpClient, "/system/console/status-productinfo.txt")) { |
| 149 | + return extractProductsFromProductInfo(input); |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + static Collection<String> extractProductsFromProductInfo(InputStream input) throws IOException { |
| 154 | + try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) { |
| 155 | + String line; |
| 156 | + Collection<String> products = new LinkedList<>(); |
| 157 | + boolean isRelevantLine = false; |
| 158 | + while ((line = reader.readLine()) != null) { |
| 159 | + if (line.equals("Installed Products")) { |
| 160 | + // the rest is relevant |
| 161 | + isRelevantLine = true; |
| 162 | + } else if(isRelevantLine){ |
| 163 | + String product = line.trim(); |
| 164 | + if (!product.isEmpty()) { |
| 165 | + products.add(product); |
| 166 | + } |
| 167 | + } |
150 | 168 | } |
151 | | - @SuppressWarnings("unchecked") |
152 | | - Map<String, Object> subResult = (Map<String, Object>)results; |
153 | | - return (String) subResult.get("Adobe Experience Manager"); |
| 169 | + return products; |
154 | 170 | } |
155 | 171 | } |
156 | 172 |
|
|
0 commit comments