Skip to content

Commit 0d1e4b3

Browse files
committed
Adding missing descriptions in top elements.
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
1 parent 610036b commit 0d1e4b3

File tree

2 files changed

+162
-144
lines changed

2 files changed

+162
-144
lines changed

feature-spec-gen/src/main/java/org/wildfly/galleon/plugin/featurespec/generator/FeatureSpecGenerator.java

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ public class FeatureSpecGenerator implements ForkCallback {
7474
private Path standaloneSpecsFile;
7575
private Path domainSpecsFile;
7676
private String mimimumStability;
77+
private String description;
7778

7879
String getBranchId(String spec, int dots) {
7980
int i = 0;
8081
int index = 0;
81-
while (i <= dots) {
82+
while(i <= dots) {
8283
index = spec.indexOf('.', index + 1);
83-
if (index < 0) {
84+
if(index < 0) {
8485
return spec;
8586
}
8687
++i;
@@ -98,8 +99,8 @@ FeatureSpecNode getSpec(String name) {
9899

99100
void addReferencedSpec(String referencedSpecName, String referencingSpec, FeatureSpecNode referencingNode) {
100101
Map<String, FeatureSpecNode> specs = referencedSpecs.get(referencedSpecName);
101-
if (specs != null) {
102-
if (specs.size() == 1) {
102+
if(specs != null) {
103+
if(specs.size() == 1) {
103104
specs = new HashMap<>(specs);
104105
referencedSpecs.put(referencedSpecName, specs);
105106
}
@@ -141,13 +142,14 @@ public FeatureSpecGenerator() {
141142
}
142143

143144
public FeatureSpecGenerator(String installation, Path outputDir, Map<String, Path> inheritedSpecs,
144-
String mimimumStability, boolean fork, boolean debug) {
145+
String mimimumStability, String description, boolean fork, boolean debug) {
145146
this.installation = installation;
146147
this.outputDir = outputDir;
147148
this.fork = fork;
148149
this.debug = debug;
149150
this.inheritedSpecs = inheritedSpecs;
150151
this.mimimumStability = mimimumStability;
152+
this.description = description == null ? "" : description;
151153
}
152154

153155
public int generateSpecs() throws ProvisioningException {
@@ -156,24 +158,24 @@ public int generateSpecs() throws ProvisioningException {
156158
doGenerate();
157159
} finally {
158160
final List<String> toClear = new ArrayList<>();
159-
for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
161+
for(Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
160162
final Object value = originalProps.get(prop.getKey());
161163
if (value != null) {
162164
System.setProperty(prop.getKey().toString(), value.toString());
163165
} else {
164166
toClear.add(prop.getKey().toString());
165167
}
166168
}
167-
for (String prop : toClear) {
169+
for(String prop : toClear) {
168170
System.clearProperty(prop);
169171
}
170-
if (systemProps != null) {
172+
if(systemProps != null) {
171173
IoUtils.recursiveDelete(systemProps);
172174
}
173-
if (standaloneSpecsFile != null) {
175+
if(standaloneSpecsFile != null) {
174176
IoUtils.recursiveDelete(standaloneSpecsFile);
175177
}
176-
if (domainSpecsFile != null) {
178+
if(domainSpecsFile != null) {
177179
IoUtils.recursiveDelete(domainSpecsFile);
178180
}
179181
}
@@ -183,9 +185,9 @@ public int generateSpecs() throws ProvisioningException {
183185
private void doGenerate() throws ProvisioningException {
184186
final ModelNode standaloneFeatures;
185187
ModelNode domainRoots = null;
186-
if (fork) {
188+
if(fork) {
187189
String minStab = mimimumStability == null ? "" : mimimumStability;
188-
ForkedEmbeddedUtil.fork(this, getStoredSystemProps(), installation, getStandaloneSpecsFile().toString(), getDomainSpecsFile().toString(), minStab);
190+
ForkedEmbeddedUtil.fork(this, getStoredSystemProps(), installation, getStandaloneSpecsFile().toString(), getDomainSpecsFile().toString(), description , minStab);
189191
standaloneFeatures = readSpecsFile(getStandaloneSpecsFile());
190192
Path model = getStandaloneSpecsFile().getParent().resolve("model.json");
191193
try {
@@ -194,14 +196,14 @@ private void doGenerate() throws ProvisioningException {
194196
} catch (IOException ex) {
195197
throw new ProvisioningException(ex);
196198
}
197-
if (Files.exists(Paths.get(installation).resolve(WfConstants.DOMAIN).resolve(WfConstants.CONFIGURATION))) {
199+
if(Files.exists(Paths.get(installation).resolve(WfConstants.DOMAIN).resolve(WfConstants.CONFIGURATION))) {
198200
domainRoots = readSpecsFile(getDomainSpecsFile());
199201
}
200202
} else {
201203
final Path home = Paths.get(installation);
202-
if (Files.exists(home.resolve(WfConstants.STANDALONE).resolve(WfConstants.CONFIGURATION))) {
204+
if(Files.exists(home.resolve(WfConstants.STANDALONE).resolve(WfConstants.CONFIGURATION))) {
203205
standaloneFeatures = readFeatureSpecs(createStandaloneServer(installation, mimimumStability, null));
204-
ModelNode result = generateModel(createStandaloneServer(installation, mimimumStability, "standalone-local.xml"));
206+
ModelNode result = generateModel(createStandaloneServer(installation, mimimumStability, "standalone-local.xml"), description);
205207
try {
206208
if (!Files.exists(outputDir)) {
207209
Files.createDirectories(outputDir);
@@ -213,7 +215,7 @@ private void doGenerate() throws ProvisioningException {
213215
} else {
214216
throw new ProvisioningException("The installation does not include standalone configuration");
215217
}
216-
if (Files.exists(home.resolve(WfConstants.DOMAIN).resolve(WfConstants.CONFIGURATION))) {
218+
if(Files.exists(home.resolve(WfConstants.DOMAIN).resolve(WfConstants.CONFIGURATION))) {
217219
domainRoots = readFeatureSpecs(createEmbeddedHc(installation, mimimumStability));
218220
}
219221
}
@@ -236,7 +238,7 @@ private void doGenerate() throws ProvisioningException {
236238
}
237239

238240
rootNode.processChildren(FeatureSpecNode.STANDALONE_MODEL);
239-
if (domainRoots != null) {
241+
if(domainRoots != null) {
240242
rootNode.processChildren(FeatureSpecNode.PROFILE_MODEL);
241243
rootNode.processChildren(FeatureSpecNode.DOMAIN_MODEL);
242244
rootNode.processChildren(FeatureSpecNode.HOST_MODEL);
@@ -247,16 +249,18 @@ private void doGenerate() throws ProvisioningException {
247249

248250
@Override
249251
public void forkedForEmbedded(String... args) throws ConfigGeneratorException {
250-
if (args.length != 3 && args.length != 4) {
252+
System.out.println("**************************** Arguments " + Arrays.toString(args));
253+
if(args.length != 4 && args.length != 5) {
251254
final StringBuilder buf = new StringBuilder();
252255
StringUtils.append(buf, Arrays.asList(args));
253-
throw new IllegalArgumentException("Expected 3-4 arguments but got " + Arrays.asList(args));
256+
throw new IllegalArgumentException("Expected 4-5 arguments but got " + Arrays.asList(args));
254257
}
255258
try {
256-
String mimimumStability = args.length == 4 ? args[3] : null;
259+
String description = args.length > 3 ? args[3] : null;
260+
String mimimumStability = args.length == 5 ? args[4] : null;
257261
ModelNode result = readFeatureSpecs(createStandaloneServer(args[0], mimimumStability, null));
258262
writeSpecsFile(Paths.get(args[1]), result);
259-
ModelNode resultModel = generateModel(createStandaloneServer(args[0], mimimumStability, "standalone-local.xml"));
263+
ModelNode resultModel = generateModel(createStandaloneServer(args[0], mimimumStability, "standalone-local.xml"), description);
260264
writeModelFile(Paths.get(args[1]).toAbsolutePath().getParent().resolve("model.json"), resultModel);
261265
System.out.println("FORKED TO " + Paths.get(args[1]).toAbsolutePath().getParent().resolve("model.json"));
262266
if (Files.exists(Paths.get(args[0]).resolve(WfConstants.DOMAIN).resolve(WfConstants.CONFIGURATION))) {
@@ -270,20 +274,20 @@ public void forkedForEmbedded(String... args) throws ConfigGeneratorException {
270274

271275
@Override
272276
public void forkedEmbeddedMessage(String msg) {
273-
if (debug) {
277+
if(debug) {
274278
System.out.println(msg);
275279
}
276280
}
277281

278282
protected Path getStoredSystemProps() throws ProvisioningException {
279-
if (systemProps == null) {
283+
if(systemProps == null) {
280284
systemProps = ForkedEmbeddedUtil.storeSystemProps();
281285
}
282286
return systemProps;
283287
}
284288

285289
protected Path getStandaloneSpecsFile() throws ProvisioningException {
286-
if (standaloneSpecsFile == null) {
290+
if(standaloneSpecsFile == null) {
287291
try {
288292
standaloneSpecsFile = Files.createTempFile("wfgp", "standalone-specs");
289293
} catch (IOException e) {
@@ -294,7 +298,7 @@ protected Path getStandaloneSpecsFile() throws ProvisioningException {
294298
}
295299

296300
protected Path getDomainSpecsFile() throws ProvisioningException {
297-
if (domainSpecsFile == null) {
301+
if(domainSpecsFile == null) {
298302
try {
299303
domainSpecsFile = Files.createTempFile("wfgp", "domain-specs");
300304
} catch (IOException e) {
@@ -306,14 +310,14 @@ protected Path getDomainSpecsFile() throws ProvisioningException {
306310

307311
protected FeatureSpec getInheritedSpec(String name) throws ProvisioningException {
308312
FeatureSpec spec = parsedInheritedSpecs.get(name);
309-
if (spec != null) {
313+
if(spec != null) {
310314
return spec;
311315
}
312316
final Path path = inheritedSpecs.get(name);
313-
if (path == null) {
317+
if(path == null) {
314318
return null;
315319
}
316-
try (BufferedReader reader = Files.newBufferedReader(path)) {
320+
try(BufferedReader reader = Files.newBufferedReader(path)) {
317321
spec = FeatureSpecXmlParser.getInstance().parse(reader);
318322
} catch (IOException | XMLStreamException e) {
319323
throw new ProvisioningException("Failed to parse " + name + " spec " + path, e);
@@ -339,43 +343,47 @@ private static String[] getCmdArgs(String mimimumStability, String serverConfig)
339343
args.add("--stability=" + mimimumStability);
340344
}
341345
if (serverConfig != null) {
342-
args.add("--server-config=" + serverConfig);
346+
args.add("--server-config=" + serverConfig);
343347
}
344348
return args.toArray(String[]::new);
345349
}
346350

347-
private static ModelNode generateModel(final EmbeddedManagedProcess server) throws ProvisioningException {
351+
private static ModelNode generateModel(final EmbeddedManagedProcess server, String description) throws ProvisioningException {
348352
try {
349353
server.start();
350354
Boolean all = Boolean.getBoolean("org.wildfly.galleon.complete.model");
351355
if (!all) {
352-
return readModel(server);
356+
return readModel(server, description);
353357
}
354-
return readAll(server);
358+
return readAll(server, description);
355359
} catch (EmbeddedProcessStartException ex) {
356360
throw new ProvisioningException("Failed to read feature spec descriptions", ex);
357361
} finally {
358362
server.stop();
359363
}
360364
}
361365

362-
private static ModelNode readModel(final EmbeddedManagedProcess server) throws ProvisioningException {
366+
private static ModelNode readModel(final EmbeddedManagedProcess server, String description) throws ProvisioningException {
363367
List<String> subsystems = listSubsystems(server);
364-
ModelNode result = new ModelNode();
368+
ModelNode result = new ModelNode().setEmptyObject();
365369
ModelNode subsystemNodes = result.get("children").get(ClientConstants.SUBSYSTEM).get("model-description");
366-
for (String subsystem : subsystems) {
370+
for(String subsystem : subsystems) {
367371
ModelNode address = Operations.createAddress(ClientConstants.SUBSYSTEM, subsystem);
368-
ModelNode subsystemDescription = readResourceDescription(server, address);
372+
ModelNode subsystemDescription = readResourceDescription(server, address, true);
369373
subsystemDescription.get(ClientConstants.ADDRESS).add(address);
370374
subsystemNodes.get(subsystem).set(subsystemDescription);
371375
}
372376
ModelNode address = Operations.createAddress(ClientConstants.DEPLOYMENT);
373-
result.get("children").get(ClientConstants.DEPLOYMENT).get("model-description").get("*").set(readResourceDescription(server, address));
377+
result.get("children").get(ClientConstants.DEPLOYMENT).get("model-description").get("*").set(readResourceDescription(server, address, true));
374378
result.remove(ClientConstants.RESULT);
379+
ModelNode subsystemsDescription = readResourceDescription(server, Operations.createAddress().setEmptyList(), false);
380+
result.get("children").get(ClientConstants.SUBSYSTEM).get("description").set(subsystemsDescription.get("children").get(ClientConstants.SUBSYSTEM).get("description"));
381+
result.get("children").get(ClientConstants.DEPLOYMENT).get("description").set(subsystemsDescription.get("children").get(ClientConstants.DEPLOYMENT).get("description"));
382+
result.get("description").set(description);
375383
return result;
376384
}
377385

378-
private static ModelNode readAll(final EmbeddedManagedProcess server) throws ProvisioningException {
386+
private static ModelNode readAll(final EmbeddedManagedProcess server, String description) throws ProvisioningException {
379387
ModelNode rootAddress = Operations.createAddress().setEmptyList();
380388
final ModelNode op = Operations.createOperation("read-resource-description", rootAddress);
381389
op.get(ClientConstants.RECURSIVE).set(true);
@@ -385,10 +393,12 @@ private static ModelNode readAll(final EmbeddedManagedProcess server) throws Pro
385393
} catch (IOException e) {
386394
throw new ProvisioningException("Failed to read feature descriptions", e);
387395
}
388-
if (!Operations.isSuccessfulOutcome(result)) {
396+
if(!Operations.isSuccessfulOutcome(result)) {
389397
throw new ProvisioningException(Operations.getFailureDescription(result).asString());
390398
}
391-
return result.get(ClientConstants.RESULT);
399+
final ModelNode effectiveResult = result.get(ClientConstants.RESULT);
400+
effectiveResult.get("description").set(description);
401+
return effectiveResult;
392402
}
393403

394404
private static List<String> listSubsystems(final EmbeddedManagedProcess server) throws ProvisioningException {
@@ -402,33 +412,33 @@ private static List<String> listSubsystems(final EmbeddedManagedProcess server)
402412
} catch (IOException e) {
403413
throw new ProvisioningException("Failed to read feature descriptions", e);
404414
}
405-
if (!Operations.isSuccessfulOutcome(result)) {
415+
if(!Operations.isSuccessfulOutcome(result)) {
406416
throw new ProvisioningException(Operations.getFailureDescription(result).asString());
407417
}
408418
List<String> names = new ArrayList<>();
409-
for (ModelNode name : result.get(ClientConstants.RESULT).asList()) {
419+
for(ModelNode name : result.get(ClientConstants.RESULT).asList()) {
410420
names.add(name.asString());
411421
}
412422
return names;
413423
}
414424

415-
private static ModelNode readResourceDescription(final EmbeddedManagedProcess server, ModelNode address) throws ProvisioningException {
425+
private static ModelNode readResourceDescription(final EmbeddedManagedProcess server, ModelNode address, boolean recursive) throws ProvisioningException {
416426
final ModelNode op = Operations.createOperation("read-resource-description", address);
417-
op.get(ClientConstants.RECURSIVE).set(true);
427+
op.get(ClientConstants.RECURSIVE).set(recursive);
418428
final ModelNode opResult;
419429
try {
420430
opResult = server.getModelControllerClient().execute(op);
421431
} catch (IOException e) {
422432
throw new ProvisioningException("Failed to read feature descriptions", e);
423433
}
424-
if (!Operations.isSuccessfulOutcome(opResult)) {
434+
if(!Operations.isSuccessfulOutcome(opResult)) {
425435
throw new ProvisioningException(Operations.getFailureDescription(opResult).asString());
426436
}
427437
final ModelNode result = opResult.get(ClientConstants.RESULT);
428-
if (ModelType.LIST == result.getType()) {
438+
if(ModelType.LIST == result.getType()) {
429439
ModelNode finalResult = new ModelNode().setEmptyList();
430-
for (ModelNode node : result.asList()) {
431-
if (node.hasDefined(ClientConstants.RESULT)) {
440+
for(ModelNode node : result.asList()) {
441+
if(node.hasDefined(ClientConstants.RESULT)) {
432442
finalResult.add(node.get(ClientConstants.RESULT));
433443
}
434444
}
@@ -448,7 +458,7 @@ private static ModelNode readFeatureSpecs(final EmbeddedManagedProcess server) t
448458
} catch (IOException e) {
449459
throw new ProvisioningException("Failed to read feature descriptions", e);
450460
}
451-
if (!Operations.isSuccessfulOutcome(result)) {
461+
if(!Operations.isSuccessfulOutcome(result)) {
452462
throw new ProvisioningException(Operations.getFailureDescription(result).asString());
453463
}
454464
return result.require(ClientConstants.RESULT).require("feature");
@@ -468,15 +478,15 @@ private ModelNode readSpecsFile(Path specsFile) throws ProvisioningException {
468478
}
469479

470480
private void writeSpecsFile(Path specsFile, ModelNode specs) throws ProvisioningException {
471-
try (BufferedWriter writer = Files.newBufferedWriter(specsFile)) {
481+
try(BufferedWriter writer = Files.newBufferedWriter(specsFile)) {
472482
writer.write(specs.asString());
473483
} catch (IOException e) {
474484
throw new ProvisioningException(Errors.writeFile(specsFile), e);
475485
}
476486
}
477487

478488
private void writeModelFile(Path specsFile, ModelNode specs) throws ProvisioningException {
479-
try (BufferedWriter writer = Files.newBufferedWriter(specsFile)) {
489+
try(BufferedWriter writer = Files.newBufferedWriter(specsFile)) {
480490
writer.write(specs.toJSONString(false));
481491
} catch (IOException e) {
482492
throw new ProvisioningException(Errors.writeFile(specsFile), e);

0 commit comments

Comments
 (0)