Module org.xbib.rpm
Package org.xbib.rpm

Class RpmBuilder

java.lang.Object
org.xbib.rpm.RpmBuilder

public class RpmBuilder extends Object
  • Constructor Details

    • RpmBuilder

      public RpmBuilder()
    • RpmBuilder

      public RpmBuilder(HashAlgo privateKeyHashAlgo, CompressionType compressionType)
      Initializes the builder and sets some required fields to known values.
      Parameters:
      privateKeyHashAlgo - the hash algo
      compressionType - compression type
  • Method Details

    • addBuiltinDirectory

      public void addBuiltinDirectory(String builtinDirectory)
    • addObsoletes

      public void addObsoletes(String name, int comparison, String version)
    • addObsoletesLess

      public void addObsoletesLess(String name, String version)
    • addObsoletesMore

      public void addObsoletesMore(String name, String version)
    • addObsoletes

      public void addObsoletes(String name, String version, int flag)
    • addConflicts

      public void addConflicts(String name, int comparison, String version)
    • addConflictsLess

      public void addConflictsLess(String name, String version)
    • addConflictsMore

      public void addConflictsMore(String name, String version)
    • addConflicts

      public void addConflicts(String name, String version, int flag)
    • addProvides

      public void addProvides(String name, String version)
    • addProvides

      public void addProvides(String name, int flag, String version)
    • addDependency

      public void addDependency(String name, int flags, String version)
      Adds a dependency to the RPM package. This dependency version will be marked as the exact requirement, and the package will require the named dependency with exactly this version at install time.
      Parameters:
      name - the name of the dependency
      flags - the comparison flag
      version - the version identifier
    • addDependencyLess

      public void addDependencyLess(String name, String version)
      Adds a dependency to the RPM package. This dependency version will be marked as the maximum allowed, and the package will require the named dependency with this version or lower at install time.
      Parameters:
      name - the name of the dependency
      version - the version identifier
    • addDependencyMore

      public void addDependencyMore(String name, String version)
      Adds a dependency to the RPM package. This dependency version will be marked as the minimum allowed, and the package will require the named dependency with this version or higher at install time.
      Parameters:
      name - the name of the dependency.
      version - the version identifier.
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, String value)
      Adds a header entry value to the header. For example use this to set the source RPM package name on your RPM
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, byte value)
      Adds a header entry byte (8-bit) value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - - if the type required by tag.type() is not byte[]
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, char value)
      Adds a header entry char (8-bit) value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - - if the type required by tag.type() is not byte[]
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, short value)
      Adds a header entry short (16-bit) value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - - if the type required by tag.type() is not short[]
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, Integer value)
      Adds a header entry int (32-bit) value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - if the type required by tag.type() is not IntegerList
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, long value)
      Adds a header entry long (64-bit) value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - - if the type required by tag.type() is not LongList
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, byte[] value)
      Adds a header entry byte array (8-bit) value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - - if the type required by tag.type() is not byte[]
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, ShortList value)
      Adds a header entry short array (16-bit) value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - - if the type required by tag.type() is not ShortList
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, IntegerList value)
      Adds a header entry int (32-bit) array value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - - if the type required by tag.type() is not IntegerList
    • addHeaderEntry

      public void addHeaderEntry(EntryType entryType, LongList value)
      Adds a header entry long (64-bit) array value to the header.
      Parameters:
      entryType - the header tag to set
      value - the value to set the header entry with
      Throws:
      ClassCastException - - if the type required by tag.type() is not LongList
    • setPackage

      public void setPackage(String name, String version, String release, Integer epoch)
      Required Field. Sets the package information, such as the rpm name, the version, and the release number.
      Parameters:
      name - the name of the RPM package.
      version - the version of the new package.
      release - the release number, specified after the version, of the new RPM.
      epoch - the epoch number of the new RPM
      Throws:
      IllegalArgumentException - if version or release contain dashes, as they are explicitly disallowed by RPM file format.
    • setPackage

      public void setPackage(String name, String version, String release)
    • setType

      public void setType(PackageType type)
      Required Field. Sets the type of the RPM to be either binary or source.
      Parameters:
      type - the type of RPM to generate.
    • setPlatform

      public void setPlatform(Architecture arch, Os os)
      Sets the platform related headers for the resulting RPM. The platform is specified as a combination of target architecture and OS.
      Parameters:
      arch - the target architecture.
      os - the target operating system.
    • setPlatform

      public void setPlatform(Architecture arch, String osName)
      Sets the platform related headers for the resulting RPM. The platform is specified as a combination of target architecture and OS.
      Parameters:
      arch - the target architecture.
      osName - the non-standard target operating system.
    • setSummary

      public void setSummary(String summary)
      Sets the summary text for the file. The summary is generally a short, one line description of the function of the package, and is often shown by RPM tools.
      Parameters:
      summary - summary text.
    • setDescription

      public void setDescription(String description)
      Sets the description text for the file. The description is often a paragraph describing the package in detail.
      Parameters:
      description - description text.
    • setBuildHost

      public void setBuildHost(String host)
      Sets the build host for the RPM. This is an internal field.
      Parameters:
      host - hostname of the build machine.
    • setLicense

      public void setLicense(String license)
      Lists the license under which this software is distributed. This field may be displayed by RPM tools.
      Parameters:
      license - the chosen distribution license.
    • setGroup

      public void setGroup(String group)
      Software group to which this package belongs. The group describes what sort of function the software package provides.
      Parameters:
      group - target group.
    • setDistribution

      public void setDistribution(String distribution)
      Distribution tag listing the distributable package.
      Parameters:
      distribution - the distribution.
    • setVendor

      public void setVendor(String vendor)
      Vendor tag listing the organization providing this software package.
      Parameters:
      vendor - software vendor.
    • setPackager

      public void setPackager(String packager)
      Build packager, usually the username of the account building this RPM.
      Parameters:
      packager - packager name.
    • setUrl

      public void setUrl(String url)
      Website URL for this package, usually a project site.
      Parameters:
      url - the URL
    • setProvides

      public void setProvides(String provides)
      Declares a dependency that this package exports, and that other packages can use to provide library functions. Note that this method causes the existing provides set to be overwritten and therefore should be called before adding any other contents via the addProvides() methods. You should use addProvides() instead.
      Parameters:
      provides - dependency provided by this package.
    • setFiles

      public void setFiles(Contents contents)
      Sets the group of contents to include in this RPM. Note that this method causes the existing file set to be overwritten and therefore should be called before adding any other contents via the addFile() methods.
      Parameters:
      contents - the set of contents to use in constructing this RPM.
    • getContents

      public Contents getContents()
      Get the contents.
      Returns:
      the contents
    • setSourceRpm

      public void setSourceRpm(String sourceRpm)
      Adds a source rpm.
      Parameters:
      sourceRpm - name of rpm source file
    • setPrefixes

      public void setPrefixes(List<String> prefixes)
      Sets the package prefix directories to allow any files installed under them to be relocatable.
      Parameters:
      prefixes - Path prefixes which may be relocated
    • setPreTrans

      public void setPreTrans(Path path) throws IOException
      Declares a script file to be run as part of the RPM pre-transaction. The script will be run using the interpreter declared with the setPreTransProgram(String) method.
      Parameters:
      path - Script to run (i.e. shell commands)
      Throws:
      IOException - there was an IO error
    • setPreTrans

      public void setPreTrans(String content)
      Declares a script to be run as part of the RPM pre-transaction. The script will be run using the interpreter declared with the setPreTransProgram(String) method.
      Parameters:
      content - Script contents to run (i.e. shell commands)
    • setPreTransProgram

      public void setPreTransProgram(String program)
      Declares the interpreter to be used when invoking the RPM pre-transaction script that can be set with the setPreTrans(String) method.
      Parameters:
      program - Path to the interpreter
    • setPreInstall

      public void setPreInstall(Path path) throws IOException
      Declares a script file to be run as part of the RPM pre-installation. The script will be run using the interpreter declared with the setPreInstallProgram(String) method.
      Parameters:
      path - Script to run (i.e. shell commands)
      Throws:
      IOException - there was an IO error
    • setPreInstall

      public void setPreInstall(String content)
      Declares a script to be run as part of the RPM pre-installation. The script will be run using the interpreter declared with the setPreInstallProgram(String) method.
      Parameters:
      content - Script contents to run (i.e. shell commands)
    • setPreInstallProgram

      public void setPreInstallProgram(String program)
      Declares the interpreter to be used when invoking the RPM pre-installation script that can be set with the setPreInstall(String) method.
      Parameters:
      program - Path to the interpretter
    • setPostInstall

      public void setPostInstall(Path path) throws IOException
      Declares a script file to be run as part of the RPM post-installation. The script will be run using the interpreter declared with the setPostInstallProgram(String) method.
      Parameters:
      path - Script to run (i.e. shell commands)
      Throws:
      IOException - there was an IO error
    • setPostInstall

      public void setPostInstall(String script)
      Declares a script to be run as part of the RPM post-installation. The script will be run using the interpreter declared with the setPostInstallProgram(String) method.
      Parameters:
      script - Script contents to run (i.e. shell commands)
    • setPostInstallProgram

      public void setPostInstallProgram(String program)
      Declares the interpreter to be used when invoking the RPM post-installation script that can be set with the setPostInstall(String) method.
      Parameters:
      program - Path to the interpreter
    • setPreUninstall

      public void setPreUninstall(Path path) throws IOException
      Declares a script file to be run as part of the RPM pre-uninstallation. The script will be run using the interpreter declared with the setPreUninstallProgram(String) method.
      Parameters:
      path - Script to run (i.e. shell commands)
      Throws:
      IOException - there was an IO error
    • setPreUninstall

      public void setPreUninstall(String script)
      Declares a script to be run as part of the RPM pre-uninstallation. The script will be run using the interpreter declared with the setPreUninstallProgram(String) method.
      Parameters:
      script - Script contents to run (i.e. shell commands)
    • setPreUninstallProgram

      public void setPreUninstallProgram(String program)
      Declares the interpreter to be used when invoking the RPM pre-uninstallation script that can be set with the setPreUninstall(String) method.
      Parameters:
      program - Path to the interpreter
    • setPostUninstall

      public void setPostUninstall(Path path) throws IOException
      Declares a script file to be run as part of the RPM post-uninstallation. The script will be run using the interpreter declared with the setPostUninstallProgram(String) method.
      Parameters:
      path - Script contents to run (i.e. shell commands)
      Throws:
      IOException - there was an IO error
    • setPostUninstall

      public void setPostUninstall(String content)
      Declares a script to be run as part of the RPM post-uninstallation. The script will be run using the interpreter declared with the setPostUninstallProgram(String) method.
      Parameters:
      content - Script contents to run (i.e. shell commands)
    • setPostUninstallProgram

      public void setPostUninstallProgram(String program)
      Declares the interpreter to be used when invoking the RPM post-uninstallation script that can be set with the setPostUninstall(String) method.
      Parameters:
      program - Path to the interpreter
    • setPostTrans

      public void setPostTrans(Path path) throws IOException
      Declares a script file to be run as part of the RPM post-transaction. The script will be run using the interpreter declared with the setPostTransProgram(String) method.
      Parameters:
      path - Script contents to run (i.e. shell commands)
      Throws:
      IOException - there was an IO error
    • setPostTrans

      public void setPostTrans(String content)
      Declares a script to be run as part of the RPM post-transaction. The script will be run using the interpreter declared with the setPostTransProgram(String) method.
      Parameters:
      content - Script contents to run (i.e. shell commands)
    • setPostTransProgram

      public void setPostTransProgram(String program)
      Declares the interpreter to be used when invoking the RPM post-transaction script that can be set with the setPostTrans(String) method.
      Parameters:
      program - Path to the interpreter
    • addTrigger

      public void addTrigger(Path script, String prog, Map<String,Trigger.IntString> depends, int flag) throws IOException
      Adds a trigger to the RPM package.
      Parameters:
      script - the script to add.
      prog - the interpreter with which to run the script.
      depends - the map of rpms and versions that will trigger the script
      flag - the trigger type (SCRIPT_TRIGGERPREIN, SCRIPT_TRIGGERIN, SCRIPT_TRIGGERUN, or SCRIPT_TRIGGERPOSTUN)
      Throws:
      IOException - there was an IO error
    • addFile

      public void addFile(String path, Path source, int mode, int dirmode, EnumSet<Directive> directive, String uname, String gname, boolean addParents) throws IOException
      Add the specified file to the repository payload in order. The required header entries will automatically be generated to record the directory names and file names, as well as their digests.
      Parameters:
      path - the absolute path at which this file will be installed.
      source - the file to include in this rpm.
      mode - the mode of the target file in standard three octet notation, or -1 for default.
      dirmode - the mode of the parent directories in standard three octet notation, or -1 for default.
      directive - directive indicating special handling for this file.
      uname - user owner of the file
      gname - group owner of the file
      addParents - whether to create parent directories for the file, defaults to true for other methods.
      Throws:
      IOException - there was an IO error
    • addFile

      public void addFile(String path, Path source, int mode, int dirmode, EnumSet<Directive> directive, String uname, String gname, boolean addParents, int verifyFlags) throws IOException
      Add the specified file to the repository payload in order. The required header entries will automatically be generated to record the directory names and file names, as well as their digests.
      Parameters:
      path - the absolute path at which this file will be installed.
      source - the file to include in this rpm.
      mode - the mode of the target file in standard three octet notation, or -1 for default.
      dirmode - the mode of the parent directories in standard three octet notation, or -1 for default.
      directive - directive indicating special handling for this file.
      uname - user owner of the directory
      gname - group owner of the directory
      addParents - whether to create parent directories for the file, defaults to true for other methods.
      verifyFlags - verify flags
      Throws:
      IOException - there was an IO error
    • addDirectory

      public void addDirectory(String path, int permissions, EnumSet<Directive> directives, String uname, String gname, boolean addParents)
      Adds the directory to the repository.
      Parameters:
      path - the absolute path to add as a directory.
      permissions - the mode of the directory in standard three octet notation.
      directives - directives indicating special handling for this file.
      uname - user owner of the directory
      gname - group owner of the directory
      addParents - whether to add parent directories to the rpm
    • addURL

      public void addURL(String path, URL source, int permissions, int dirmode, EnumSet<Directive> directives, String uname, String gname)
      Adds an URL (from a jar) to the repository.
      Parameters:
      path - the absolute path
      source - the URL source
      permissions - the file mode
      dirmode - the directory mode
      directives - directives indicating special handling for this file
      uname - user owner of the entry
      gname - group owner of the entry
    • addLink

      public void addLink(String path, String target, int permissions)
      Adds a symbolic link to the repository.
      Parameters:
      path - the absolute path at which this link will be installed.
      target - the path of the file this link will point to.
      permissions - the permissions flags
    • addLink

      public void addLink(String path, String target, int permissions, String username, String groupname)
      Adds a symbolic link to the repository.
      Parameters:
      path - the absolute path at which this link will be installed.
      target - the path of the file this link will point to.
      permissions - the permissions flags
      username - user owner of the link
      groupname - group owner of the link
    • addChangelog

      public void addChangelog(String changelogContents) throws IOException, ChangelogParseException
      Adds the supplied Changelog path as a Changelog to the header.
      Parameters:
      changelogContents - File containing the Changelog information
      Throws:
      IOException - if file does not exist or cannot be read
      ChangelogParseException - if file is not of the correct format.
    • addChangelog

      public void addChangelog(Path changelogFile) throws IOException, ChangelogParseException
      Adds the supplied Changelog path as a Changelog to the header.
      Parameters:
      changelogFile - File containing the Changelog information
      Throws:
      IOException - if file does not exist or cannot be read
      ChangelogParseException - if file is not of the correct format.
    • addChangelog

      public void addChangelog(InputStream changelogInputStream) throws IOException, ChangelogParseException
      Adds the supplied Changelog file as a Changelog to the header.
      Parameters:
      changelogInputStream - input stream containing the Changelog information
      Throws:
      IOException - if file does not exist or cannot be read
      ChangelogParseException - if file is not of the correct format.
    • setPrivateKeyRing

      public void setPrivateKeyRing(String privateKeyRing) throws IOException
      Sets the PGP key ring used for header and header + payload signature.
      Parameters:
      privateKeyRing - the private key ring input stream
      Throws:
      IOException - if file does not exist or cannot be read
    • setPrivateKeyRing

      public void setPrivateKeyRing(Path privateKeyRing) throws IOException
      Sets the PGP key ring used for header and header + payload signature.
      Parameters:
      privateKeyRing - the private key ring input stream
      Throws:
      IOException - if file does not exist or cannot be read
    • setPrivateKeyRing

      public void setPrivateKeyRing(InputStream privateKeyRing)
      Sets the PGP key ring used for header and header + payload signature.
      Parameters:
      privateKeyRing - the private key ring input stream
    • setPrivateKeyId

      public void setPrivateKeyId(String privateKeyId)
      Selects a private key from the current private key ring. If no key is specified, the first signing key will be selected.
      Parameters:
      privateKeyId - long value from hex key id
    • setPrivateKeyId

      public void setPrivateKeyId(Long privateKeyId)
      Selects a private key from the current private key ring. If no key is specified, the first signing key will be selected.
      Parameters:
      privateKeyId - long value from hex key id
    • setPrivateKeyPassphrase

      public void setPrivateKeyPassphrase(String privateKeyPassphrase)
      Passphrase for the private key.
      Parameters:
      privateKeyPassphrase - the private key pass phrase
    • setPrivateKeyHashAlgo

      public void setPrivateKeyHashAlgo(String privateKeyHashAlgo)
      Hash algo for the private key.
      Parameters:
      privateKeyHashAlgo - the private key hash algo
    • setPackageName

      public void setPackageName(String packageName)
      Set RPM package name.
      Parameters:
      packageName - the RPM package name
    • getPackageName

      public String getPackageName()
      Get package name.
      Returns:
      the RPM package name or null
    • build

      public void build(Path directory) throws RpmException, IOException, NoSuchAlgorithmException
      Generates an RPM with a standard name consisting of the RPM package name, version, release, and type in the given directory.
      Parameters:
      directory - the destination path for the new RPM file.
      Throws:
      IOException - there was an IO error
      RpmException - if RPM could not be generated
      NoSuchAlgorithmException
    • build

      Generates the RPM archive to the provided file channel.
      Parameters:
      channel - the SeekableByteChannel to which the resulting RPM archive will be written.
      Throws:
      IOException - there was an IO error
      RpmException - if RPM generation fails
      NoSuchAlgorithmException