Search in sources :

Example 1 with PropertiesConverter

use of com.thoughtworks.xstream.converters.collections.PropertiesConverter in project maven-plugins by apache.

the class EvaluateMojo method getXStream.

/**
     * @return lazy loading xstream object.
     */
private XStream getXStream() {
    if (xstream == null) {
        xstream = new XStream();
        addAlias(xstream);
        // handle Properties a la Maven
        xstream.registerConverter(new PropertiesConverter() {

            /** {@inheritDoc} */
            public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
                return Properties.class == type;
            }

            /** {@inheritDoc} */
            public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
                Properties properties = (Properties) source;
                // sort
                Map<?, ?> map = new TreeMap<Object, Object>(properties);
                for (Map.Entry<?, ?> entry : map.entrySet()) {
                    writer.startNode(entry.getKey().toString());
                    writer.setValue(entry.getValue().toString());
                    writer.endNode();
                }
            }
        });
    }
    return xstream;
}
Also used : JarEntry(java.util.jar.JarEntry) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) Properties(java.util.Properties) PropertiesConverter(com.thoughtworks.xstream.converters.collections.PropertiesConverter) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

XStream (com.thoughtworks.xstream.XStream)1 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)1 PropertiesConverter (com.thoughtworks.xstream.converters.collections.PropertiesConverter)1 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)1 Map (java.util.Map)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 JarEntry (java.util.jar.JarEntry)1