Class StreamDiffHandler

  • All Implemented Interfaces:
    DiffHandler

    public class StreamDiffHandler
    extends java.lang.Object
    implements DiffHandler
    A specific type of DiffHandler which uses an OutputStream to create an XML document describing the changes in the diff. This is needed for java 1.2 compatibility for the ant task.
    Author:
    Antony Riley
    • Field Detail

      • XML_URI

        public static final java.lang.String XML_URI
        The XML namespace used.
        See Also:
        Constant Field Values
      • out

        private final java.io.BufferedWriter out
        The javax.xml.transform.sax.Transformer used to convert the DOM to text.
    • Constructor Detail

      • StreamDiffHandler

        public StreamDiffHandler()
                          throws DiffException
        Create a new StreamDiffHandler which writes to System.out
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • StreamDiffHandler

        public StreamDiffHandler​(java.io.OutputStream out)
                          throws DiffException
        Create a new StreamDiffHandler with the specified OutputStream.
        Parameters:
        out - Where to write output.
        Throws:
        DiffException
    • Method Detail

      • startDiff

        public void startDiff​(java.lang.String oldJar,
                              java.lang.String newJar)
                       throws DiffException
        Start the diff. This writes out the start of a <diff> node.
        Specified by:
        startDiff in interface DiffHandler
        Parameters:
        oldJar - name of old jar file.
        newJar - name of new jar file.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startOldContents

        public void startOldContents()
                              throws DiffException
        Start the list of old contents.
        Specified by:
        startOldContents in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startNewContents

        public void startNewContents()
                              throws DiffException
        Start the list of old contents.
        Specified by:
        startNewContents in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • contains

        public void contains​(ClassInfo info)
                      throws DiffException
        Add a contained class.
        Specified by:
        contains in interface DiffHandler
        Parameters:
        info - information about a class
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endOldContents

        public void endOldContents()
                            throws DiffException
        End the list of old contents.
        Specified by:
        endOldContents in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endNewContents

        public void endNewContents()
                            throws DiffException
        End the list of new contents.
        Specified by:
        endNewContents in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startRemoved

        public void startRemoved()
                          throws DiffException
        Start the removed node. This writes out a <removed> node.
        Specified by:
        startRemoved in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • classRemoved

        public void classRemoved​(ClassInfo info)
                          throws DiffException
        Write out class info for a removed class. This writes out the nodes describing a class
        Specified by:
        classRemoved in interface DiffHandler
        Parameters:
        info - The info to write out.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endRemoved

        public void endRemoved()
                        throws DiffException
        End the removed section. This closes the <removed> tag.
        Specified by:
        endRemoved in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startAdded

        public void startAdded()
                        throws DiffException
        Start the added section. This opens the <added> tag.
        Specified by:
        startAdded in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • classAdded

        public void classAdded​(ClassInfo info)
                        throws DiffException
        Write out the class info for an added class. This writes out the nodes describing an added class.
        Specified by:
        classAdded in interface DiffHandler
        Parameters:
        info - The class info describing the added class.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endAdded

        public void endAdded()
                      throws DiffException
        End the added section. This closes the <added> tag.
        Specified by:
        endAdded in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startChanged

        public void startChanged()
                          throws DiffException
        Start the changed section. This writes out the <changed> node.
        Specified by:
        startChanged in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • startClassChanged

        public void startClassChanged​(java.lang.String internalName)
                               throws DiffException
        Start a changed section for an individual class. This writes out an <classchanged> node with the real class name as the name attribute.
        Specified by:
        startClassChanged in interface DiffHandler
        Parameters:
        internalName - the internal name of the class that has changed.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • fieldRemoved

        public void fieldRemoved​(FieldInfo info)
                          throws DiffException
        Write out info about a removed field. This just writes out the field info, it will be inside a start/end removed section.
        Specified by:
        fieldRemoved in interface DiffHandler
        Parameters:
        info - Info about the field that's been removed.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • methodRemoved

        public void methodRemoved​(MethodInfo info)
                           throws DiffException
        Write out info about a removed method. This just writes out the method info, it will be inside a start/end removed section.
        Specified by:
        methodRemoved in interface DiffHandler
        Parameters:
        info - Info about the method that's been removed.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • fieldAdded

        public void fieldAdded​(FieldInfo info)
                        throws DiffException
        Write out info about an added field. This just writes out the field info, it will be inside a start/end added section.
        Specified by:
        fieldAdded in interface DiffHandler
        Parameters:
        info - Info about the added field.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • methodAdded

        public void methodAdded​(MethodInfo info)
                         throws DiffException
        Write out info about a added method. This just writes out the method info, it will be inside a start/end added section.
        Specified by:
        methodAdded in interface DiffHandler
        Parameters:
        info - Info about the added method.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • classChanged

        public void classChanged​(ClassInfo oldInfo,
                                 ClassInfo newInfo)
                          throws DiffException
        Write out info aboout a changed class. This writes out a <classchange> node, followed by a <from> node, with the old information about the class followed by a <to> node with the new information about the class.
        Specified by:
        classChanged in interface DiffHandler
        Parameters:
        oldInfo - Info about the old class.
        newInfo - Info about the new class.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • fieldChanged

        public void fieldChanged​(FieldInfo oldInfo,
                                 FieldInfo newInfo)
                          throws DiffException
        Write out info aboout a changed field. This writes out a <fieldchange> node, followed by a <from> node, with the old information about the field followed by a <to> node with the new information about the field.
        Specified by:
        fieldChanged in interface DiffHandler
        Parameters:
        oldInfo - Info about the old field.
        newInfo - Info about the new field.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • methodChanged

        public void methodChanged​(MethodInfo oldInfo,
                                  MethodInfo newInfo)
                           throws DiffException
        Write out info aboout a changed method. This writes out a <methodchange> node, followed by a <from> node, with the old information about the method followed by a <to> node with the new information about the method.
        Specified by:
        methodChanged in interface DiffHandler
        Parameters:
        oldInfo - Info about the old method.
        newInfo - Info about the new method.
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endClassChanged

        public void endClassChanged()
                             throws DiffException
        End the changed section for an individual class. This closes the <classchanged> node.
        Specified by:
        endClassChanged in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endChanged

        public void endChanged()
                        throws DiffException
        End the changed section. This closes the <changed> node.
        Specified by:
        endChanged in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • endDiff

        public void endDiff()
                     throws DiffException
        End the diff. This closes the <diff> node.
        Specified by:
        endDiff in interface DiffHandler
        Throws:
        DiffException - when there is an underlying exception, e.g. writing to a file caused an IOException
      • writeClassInfo

        protected void writeClassInfo​(ClassInfo info)
                               throws java.io.IOException
        Write out information about a class. This writes out a <class> node, which contains information about what interfaces are implemented each in a <implements> node.
        Parameters:
        info - Info about the class to write out.
        Throws:
        java.io.IOException - when there is an underlying IOException.
      • writeMethodInfo

        protected void writeMethodInfo​(MethodInfo info)
                                throws java.io.IOException
        Write out information about a method. This writes out a <method> node which contains information about the arguments, the return type, and the exceptions thrown by the method.
        Parameters:
        info - Info about the method.
        Throws:
        java.io.IOException - when there is an underlying IOException.
      • writeFieldInfo

        protected void writeFieldInfo​(FieldInfo info)
                               throws java.io.IOException
        Write out information about a field. This writes out a <field> node with attributes describing the field.
        Parameters:
        info - Info about the field.
        Throws:
        java.io.IOException - when there is an underlying IOException.
      • addAccessFlags

        protected void addAccessFlags​(AbstractInfo info)
                               throws java.io.IOException
        Add attributes describing some access flags. This adds the attributes to the attr field.
        Parameters:
        info - Info describing the access flags.
        Throws:
        java.io.IOException - when there is an underlying IOException.
      • addMethodNodes

        protected void addMethodNodes​(java.lang.String desc)
                               throws java.io.IOException
        Add the method nodes for the method descriptor. This writes out an <arguments> node containing the argument types for the method, followed by a <return> node containing the return type.
        Parameters:
        desc - The descriptor for the method to write out.
        Throws:
        java.io.IOException - when there is an underlying IOException.
      • addTypeNode

        protected void addTypeNode​(java.lang.String desc)
                            throws java.io.IOException
        Add a type node for the specified descriptor.
        Parameters:
        desc - A type descriptor.
        Throws:
        java.io.IOException - when there is an underlying IOException.
      • addTypeNode

        protected void addTypeNode​(org.objectweb.asm.Type type)
                            throws java.io.IOException
        Add a type node for the specified type. This writes out a <type> node with attributes describing the type.
        Parameters:
        type - The type to describe.
        Throws:
        java.io.IOException - when there is an underlying IOException.
      • xmlEscape

        private final java.lang.String xmlEscape​(java.lang.String str)
        Escape some text into a format suitable for output as xml.
        Parameters:
        str - the text to format
        Returns:
        the formatted text