Class MergeableManifest2

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class MergeableManifest2
    extends java.lang.Object
    implements java.lang.Cloneable
    Functionality to read and write Manifest files. Guarantees that modifying does not destroy the order of the elements to ensure minimal diffs for load/save cycles. Re-implementation from MergeableManifest but without reflection. Reflection causes warnings that it might get be removed in future versions. Hence we implement the functionality with all the inherited one by ourself.
    • Constructor Detail

      • MergeableManifest2

        public MergeableManifest2​(java.io.InputStream stream,
                                  java.lang.String name)
                           throws java.io.IOException
        Create a new manifest from the given stream and with the given name. As the stream is created by the caller the caller is also responsible for closing it.
        Parameters:
        stream - The stream to read the manifest content from.
        name - The name of the manifest, written to "Bundle-SymbolicName".
        Throws:
        java.io.IOException
      • MergeableManifest2

        public MergeableManifest2​(java.io.InputStream stream)
                           throws java.io.IOException
        Create a new manifest from the given stream. As the stream is created by the caller the caller is also responsible for closing it.
        Parameters:
        stream - The stream to read the manifest content from.
        Throws:
        java.io.IOException
      • MergeableManifest2

        public MergeableManifest2​(MergeableManifest2 toCopy)
        Create a copy from the given one.
        Parameters:
        toCopy - The original manifest to copy.
    • Method Detail

      • getMainAttributes

        public MergeableManifest2.Attributes getMainAttributes()
        Returns:
        the attributes read from the header. Does not include the entries that are started with "Name: [...]" line.
      • getAttributes

        public MergeableManifest2.Attributes getAttributes​(java.lang.String name)
        Returns:
        the attribute section that has been started with the name from the "Name: [...]" line.
      • getEntries

        public java.util.Map<java.lang.String,​MergeableManifest2.Attributes> getEntries()
        Returns:
        all entries started with "Name: [...]" line but not the main attributes.
      • isModified

        public boolean isModified()
        Returns:
        true in case any modification has been applied to the manifest since it was read.
      • clear

        public void clear()
        Remove all main entries and all section entries.
      • addRequiredBundles

        public void addRequiredBundles​(java.util.Set<java.lang.String> requiredBundles)
        Add the set with given bundles to the "Require-Bundle" main attribute.
        Parameters:
        requiredBundles - The set with all bundles to add.
      • addRequiredBundles

        public void addRequiredBundles​(java.lang.String... requiredBundles)
        Add the list with given bundles to the "Require-Bundle" main attribute.
        Parameters:
        requiredBundles - The list of all bundles to add.
      • addImportedPackages

        public void addImportedPackages​(java.util.Set<java.lang.String> importedPackages)
        Add the set with given bundles to the "Import-Package" main attribute.
        Parameters:
        importedPackages - The set of all packages to add.
      • addImportedPackages

        public void addImportedPackages​(java.lang.String... importedPackages)
        Add the list with given bundles to the "Import-Package" main attribute.
        Parameters:
        importedPackages - The list of all packages to add.
      • addExportedPackages

        public void addExportedPackages​(java.util.Set<java.lang.String> exportedPackages)
        Add the set with given bundles to the "Export-Package" main attribute.
        Parameters:
        exportedPackages - The set of all packages to add.
      • addExportedPackages

        public void addExportedPackages​(java.lang.String... exportedPackages)
        Add the list with given bundles to the "Export-Package" main attribute.
        Parameters:
        exportedPackages - The list of all packages to add.
      • setBREE

        public void setBREE​(java.lang.String bree)
        Set the main attribute "Bundle-RequiredExecutionEnvironment" to the given value.
        Parameters:
        bree - The new value
      • getBREE

        public java.lang.String getBREE()
        Returns:
        the value of the main attribute "Bundle-RequiredExecutionEnvironment".
      • setBundleActivator

        public void setBundleActivator​(java.lang.String bundleActivator)
        Set the main attribute "Bundle-Activator" to the given value.
        Parameters:
        bundleActivator - The new value
      • getBundleActivator

        public java.lang.String getBundleActivator()
        Returns:
        the value of the main attribute "Bundle-Activator".
      • setLineDelimiter

        public void setLineDelimiter​(java.lang.String lineDelimeter)
        Set the line delimiter to a specific value. Is only used for writing, NOT for reading!
        Parameters:
        lineDelimeter - typically either "\n" or "\r\n".
      • write

        public void write​(java.io.OutputStream stream)
                   throws java.io.IOException
        Write the contents to the manifest to the given stream. As the stream is created by the caller the caller is also responsible for closing it.
        Parameters:
        stream - the stream to write the output to.
        Throws:
        java.io.IOException
      • clone

        public MergeableManifest2 clone()
                                 throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException
      • make512Safe

        public static java.lang.String make512Safe​(java.lang.StringBuffer input,
                                                   java.lang.String newline)
        Return a string that ensures that no line is longer then 512 characters and lines are broken according to manifest specification.
        Parameters:
        input - The buffer containing the content that should be made safe
        newline - The string to use to create newlines (usually "\n" or "\r\n")
        Returns:
        The string with no longer lines then 512, ready to be read again by MergeableManifest2.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object