public ConfigurationMetadata read(InputStream inputStream) throws IOException { ConfigurationMetadata metadata = new ConfigurationMetadata(); JSONObject object = new JSONObject(toString(inputStream)); JSONArray groups = object.optJSONArray("groups"); if (groups != null) { for (int i = 0; i < groups.length(); i++) { metadata.add(toItemMetadata((JSONObject) groups.get(i), ItemType.GROUP)); } } JSONArray properties = object.optJSONArray("properties"); if (properties != null) { for (int i = 0; i < properties.length(); i++) { metadata.add(toItemMetadata((JSONObject) properties.get(i), ItemType.PROPERTY)); } } JSONArray hints = object.optJSONArray("hints"); if (hints != null) { for (int i = 0; i < hints.length(); i++) { metadata.add(toItemHint((JSONObject) hints.get(i))); } } return metadata; }
public static void main(String[] args) throws IOException { String basePath = System.getProperty("project.root"); ConfigurationMetadata metadata = readMetadata(new FileInputStream(new File(basePath, "target/classes/META-INF/spring-configuration-metadata.json"))); metadata.getItems().stream() .map(ItemMetadata::new) .filter(i -> i.isOfItemType(ItemType.PROPERTY)) .distinct() .sorted(Comparator.comparing(ItemMetadata::getGroup).thenComparing(ItemMetadata::getName)) .forEach(i -> System.out.printf("|%s\t|%s\t|%s\t|\n", i.getName(), i.getDefaultValue(), i.getDescription())); }
public void write(ConfigurationMetadata metadata, OutputStream outputStream) throws IOException { JSONObject object = new JSONOrderedObject(); object.put("groups", toJsonArray(metadata, ItemType.GROUP)); object.put("properties", toJsonArray(metadata, ItemType.PROPERTY)); object.put("hints", toJsonArray(metadata.getHints())); outputStream.write(object.toString(2).getBytes(UTF_8)); }
private JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) { JSONArray jsonArray = new JSONArray(); for (ItemMetadata item : metadata.getItems()) { if (item.isOfItemType(itemType)) { jsonArray.put(toJsonObject(item)); } } return jsonArray; }
private ItemMetadata toItemMetadata(JSONObject object, ItemType itemType) { String name = object.getString("name"); String type = object.optString("type", null); String description = object.optString("description", null); String sourceType = object.optString("sourceType", null); String sourceMethod = object.optString("sourceMethod", null); Object defaultValue = readItemValue(object.opt("defaultValue")); ItemDeprecation deprecation = toItemDeprecation(object); return new ItemMetadata(itemType, name, null, type, sourceType, sourceMethod, description, defaultValue, deprecation); }
public MetadataItemCondition(ItemType itemType, String name, String type, Class<?> sourceType, String description, Object defaultValue, ItemDeprecation deprecation) { this.itemType = itemType; this.name = name; this.type = type; this.sourceType = sourceType; this.description = description; this.defaultValue = defaultValue; this.deprecation = deprecation; describedAs(createDescription()); }
public ContainsItemMatcher(ItemType itemType, String name, String type, Class<?> sourceType, String description, Matcher<?> defaultValue, ItemDeprecation deprecation) { this.itemType = itemType; this.name = name; this.type = type; this.sourceType = sourceType; this.description = description; this.defaultValue = defaultValue; this.deprecation = deprecation; }
public boolean isOfItemType(ItemType type) { return delegate.isOfItemType(type); }
public static MetadataItemCondition withGroup(String name) { return new MetadataItemCondition(ItemType.GROUP, name); }
public static MetadataItemCondition withGroup(String name, Class<?> type) { return new MetadataItemCondition(ItemType.GROUP, name).ofType(type); }
public static MetadataItemCondition withGroup(String name, String type) { return new MetadataItemCondition(ItemType.GROUP, name).ofType(type); }
public static MetadataItemCondition withProperty(String name) { return new MetadataItemCondition(ItemType.PROPERTY, name); }
public static MetadataItemCondition withProperty(String name, Class<?> type) { return new MetadataItemCondition(ItemType.PROPERTY, name).ofType(type); }
public static MetadataItemCondition withProperty(String name, String type) { return new MetadataItemCondition(ItemType.PROPERTY, name).ofType(type); }
public MetadataItemCondition(ItemType itemType, String name) { this(itemType, name, null, null, null, null, null); }
public static ContainsItemMatcher containsGroup(String name) { return new ContainsItemMatcher(ItemType.GROUP, name); }
public static ContainsItemMatcher containsGroup(String name, Class<?> type) { return new ContainsItemMatcher(ItemType.GROUP, name).ofType(type); }
public static ContainsItemMatcher containsGroup(String name, String type) { return new ContainsItemMatcher(ItemType.GROUP, name).ofType(type); }
public static ContainsItemMatcher containsProperty(String name) { return new ContainsItemMatcher(ItemType.PROPERTY, name); }
public static ContainsItemMatcher containsProperty(String name, Class<?> type) { return new ContainsItemMatcher(ItemType.PROPERTY, name).ofType(type); }
public static ContainsItemMatcher containsProperty(String name, String type) { return new ContainsItemMatcher(ItemType.PROPERTY, name).ofType(type); }
public ContainsItemMatcher(ItemType itemType, String name) { this(itemType, name, null, null, null, null, null); }