Github user neykov commented on a diff in the pull request: https://github.com/apache/incubator-brooklyn/pull/1176#discussion_r50986073 --- Diff: brooklyn-server/server-cli/src/main/java/org/apache/brooklyn/cli/ItemLister.java --- @@ -98,88 +115,150 @@ public Void call() throws Exception { List<URL> urls = getUrls(); LOG.info("Retrieving objects from "+urls); - // TODO Remove duplication from separate ListPolicyCommand etc - List<Class<? extends Entity>> entityTypes = getTypes(urls, Entity.class); - List<Class<? extends Policy>> policyTypes = getTypes(urls, Policy.class); - List<Class<? extends Enricher>> enricherTypes = getTypes(urls, Enricher.class); - List<Class<? extends Location>> locationTypes = getTypes(urls, Location.class, Boolean.FALSE); + Map<String, Object> result = MutableMap.of(); + List<String> jsonList = new ArrayList<>(); - Map<String, Object> result = ImmutableMap.<String, Object>builder() - .put("entities", ItemDescriptors.toItemDescriptors(entityTypes, headingsOnly, "name")) - .put("policies", ItemDescriptors.toItemDescriptors(policyTypes, headingsOnly, "name")) - .put("enrichers", ItemDescriptors.toItemDescriptors(enricherTypes, headingsOnly, "name")) - .put("locations", ItemDescriptors.toItemDescriptors(locationTypes, headingsOnly, "type")) - .put("locationResolvers", ItemDescriptors.toItemDescriptors(ImmutableList.copyOf(ServiceLoader.load(LocationResolver.class)), true)) - .build(); + if (!jars.isEmpty()) { + // TODO Remove duplication from separate ListPolicyCommand etc + List<Class<? extends Entity>> entityTypes = getTypes(urls, Entity.class); + List<Class<? extends Policy>> policyTypes = getTypes(urls, Policy.class); + List<Class<? extends Enricher>> enricherTypes = getTypes(urls, Enricher.class); + List<Class<? extends Location>> locationTypes = getTypes(urls, Location.class, Boolean.FALSE); - String json = toJson(result); + result = ImmutableMap.<String, Object>builder() + .put("entities", ItemDescriptors.toItemDescriptors(entityTypes, headingsOnly, "name")) + .put("policies", ItemDescriptors.toItemDescriptors(policyTypes, headingsOnly, "name")) + .put("enrichers", ItemDescriptors.toItemDescriptors(enricherTypes, headingsOnly, "name")) + .put("locations", ItemDescriptors.toItemDescriptors(locationTypes, headingsOnly, "type")) + .put("locationResolvers", ItemDescriptors.toItemDescriptors(ImmutableList.copyOf(ServiceLoader.load(LocationResolver.class)), true)) + .build(); + jsonList.add(toJson(result)); + } else if (!yaml.isEmpty()) { + LocalManagementContext lmgmt = new LocalManagementContext(); + BrooklynCampPlatform platform = new BrooklynCampPlatform( + PlatformRootSummary.builder().name("Brooklyn CAMP Platform").build(),lmgmt) + .setConfigKeyAtManagmentContext(); + BrooklynCatalog catalog = lmgmt.getCatalog(); - if (outputFolder == null) { - System.out.println(json); - } else { - LOG.info("Outputting item list (size "+itemCount+") to " + outputFolder); - String outputPath = Os.mergePaths(outputFolder, "index.html"); - String parentDir = (new File(outputPath).getParentFile()).getAbsolutePath(); - mkdir(parentDir, "entities"); - mkdir(parentDir, "policies"); - mkdir(parentDir, "enrichers"); - mkdir(parentDir, "locations"); - mkdir(parentDir, "locationResolvers"); //TODO nothing written here yet... - - mkdir(parentDir, "style"); - mkdir(Os.mergePaths(parentDir, "style"), "js"); - mkdir(Os.mergePaths(parentDir, "style", "js"), "catalog"); - - Files.write("var items = " + json, new File(Os.mergePaths(outputFolder, "items.js")), Charsets.UTF_8); - ResourceUtils resourceUtils = ResourceUtils.create(this); - - // root - just loads the above JSON - copyFromItemListerClasspathBaseStaticsToOutputDir(resourceUtils, "brooklyn-object-list.html", "index.html"); - - // statics - structure mirrors docs (not for any real reason however... the json is usually enough for our docs) - copyFromItemListerClasspathBaseStaticsToOutputDir(resourceUtils, "common.js"); - copyFromItemListerClasspathBaseStaticsToOutputDir(resourceUtils, "items.css"); - copyFromItemListerClasspathBaseStaticsToOutputDir(resourceUtils, "style/js/underscore-min.js"); - copyFromItemListerClasspathBaseStaticsToOutputDir(resourceUtils, "style/js/underscore-min.map"); - copyFromItemListerClasspathBaseStaticsToOutputDir(resourceUtils, "style/js/catalog/typeahead.js"); - - // now make pages for each item - - List<Map<String, Object>> entities = (List<Map<String, Object>>) result.get("entities"); - String entityTemplateHtml = resourceUtils.getResourceAsString(Urls.mergePaths(BASE_TEMPLATES, "entity.html")); - for (Map<String, Object> entity : entities) { - String type = (String) entity.get("type"); - String name = (String) entity.get("name"); - String entityHtml = TemplateProcessor.processTemplateContents(entityTemplateHtml, ImmutableMap.of("type", type, "name", name)); - Files.write(entityHtml, new File(Os.mergePaths(outputFolder, "entities", type + ".html")), Charsets.UTF_8); - } - - List<Map<String, Object>> policies = (List<Map<String, Object>>) result.get("policies"); - String policyTemplateHtml = resourceUtils.getResourceAsString(Urls.mergePaths(BASE_TEMPLATES, "policy.html")); - for (Map<String, Object> policy : policies) { - String type = (String) policy.get("type"); - String name = (String) policy.get("name"); - String policyHtml = TemplateProcessor.processTemplateContents(policyTemplateHtml, ImmutableMap.of("type", type, "name", name)); - Files.write(policyHtml, new File(Os.mergePaths(outputFolder, "policies", type + ".html")), Charsets.UTF_8); - } - - List<Map<String, Object>> enrichers = (List<Map<String, Object>>) result.get("enrichers"); - String enricherTemplateHtml = resourceUtils.getResourceAsString(Urls.mergePaths(BASE_TEMPLATES, "enricher.html")); - for (Map<String, Object> enricher : enrichers) { - String type = (String) enricher.get("type"); - String name = (String) enricher.get("name"); - String enricherHtml = TemplateProcessor.processTemplateContents(enricherTemplateHtml, ImmutableMap.of("type", type, "name", name)); - Files.write(enricherHtml, new File(Os.mergePaths(outputFolder, "enrichers", type + ".html")), Charsets.UTF_8); + for (URL url: urls) { + List<Map<?,?>> entities = new ArrayList<>(); + List<Map<?,?>> policies = new ArrayList<>(); + List<Map<?,?>> enrichers = new ArrayList<>(); + List<Map<?,?>> locations = new ArrayList<>(); + List<Map<?,?>> locationResolvers = new ArrayList<>(); + + String yamlContent = Files.toString(new File(url.getFile()), Charset.forName("UTF-8")); + + catalog.addItems(yamlContent); + for (CatalogItem item: catalog.getCatalogItems()) { + AbstractBrooklynObjectSpec<?,?> spec = catalog.createSpec(item); + Map<String,Object> itemDescriptor = ItemDescriptors.toItemDescriptor((Class<? extends BrooklynObject>) spec.getType(), false); + List<EntityConfigSummary> config = new ArrayList<>(); + + if (!itemDescriptor.containsKey("name")) { + itemDescriptor.put("name", item.getDisplayName()); + } + if (!itemDescriptor.containsKey("description")) { + itemDescriptor.put("description", item.getDescription()); + } + if (!itemDescriptor.containsKey("iconUrl")) { + itemDescriptor.put("iconUrl", item.getIconUrl()); + } + for (SpecParameter<?> param: spec.getParameters()) { + EntityConfigSummary entityConfigSummary = EntityTransformer.entityConfigSummary(param.getType(), + param.getLabel(), null, MutableMap.<String,URI>of()); + config.add(entityConfigSummary); + } + itemDescriptor.put("config", config); + if (item.getCatalogItemType().name().equals("ENTITY")) { + entities.add(itemDescriptor); + } else if (item.getCatalogItemType().name().equals("POLICY")) { + policies.add(itemDescriptor); + } else if (item.getCatalogItemType().name().equals("LOCATION")) { + locations.add(itemDescriptor); + } + } + result = ImmutableMap.<String, Object>builder() + .put("entities", entities) + .put("policies", policies) + .put("enrichers", enrichers) + .put("locations", locations) + .put("locationResolvers", locationResolvers) + .build(); + + jsonList.add(toJson(result)); } - - List<Map<String, Object>> locations = (List<Map<String, Object>>) result.get("locations"); - String locationTemplateHtml = resourceUtils.getResourceAsString(Urls.mergePaths(BASE_TEMPLATES, "location.html")); - for (Map<String, Object> location : locations) { - String type = (String) location.get("type"); - String locationHtml = TemplateProcessor.processTemplateContents(locationTemplateHtml, ImmutableMap.of("type", type)); - Files.write(locationHtml, new File(Os.mergePaths(outputFolder, "locations", type + ".html")), Charsets.UTF_8); + } + + for (String json: jsonList) { + + if (outputFolder == null) { + System.out.println(json); + } else { + LOG.info("Outputting item list (size "+itemCount+") to " + outputFolder); + String outputPath = Os.mergePaths(outputFolder, "index.html"); + String parentDir = (new File(outputPath).getParentFile()).getAbsolutePath(); + mkdir(parentDir, "entities"); + mkdir(parentDir, "policies"); + mkdir(parentDir, "enrichers"); + mkdir(parentDir, "locations"); + mkdir(parentDir, "locationResolvers"); //TODO nothing written here yet... + + mkdir(parentDir, "style"); + mkdir(Os.mergePaths(parentDir, "style"), "js"); + mkdir(Os.mergePaths(parentDir, "style", "js"), "catalog"); + + Files.write("var items = " + json, new File(Os.mergePaths(outputFolder, "items.js")), Charsets.UTF_8); --- End diff -- Wouldn't this overwrite the file for each catalog entry? Also no need to re-generate the whole doc structure for each item as it's identical. Maybe better to have a separate case for generating the output if coming from yaml, creating just the .js files? @tbouron wdyt?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---