org.freecompany.redline
Class Builder

java.lang.Object
  extended by org.freecompany.redline.Builder

public class Builder
extends java.lang.Object

The normal entry point to the API used for building and RPM. The API provides methods to configure and add contents to a new RPM. The current version of the RPM format (3.0) requires numerous headers to be set for an RPM to be valid. All of the required fields are either set automatically or exposed through setters in this builder class. Any required fields are marked in their respective method API documentation.


Field Summary
protected  Contents contents
           
protected  java.util.Map<java.lang.String,java.lang.CharSequence> dependencies
           
protected  java.util.Map<java.lang.String,java.lang.Integer> flags
           
protected  Format format
           
protected  AbstractHeader.Entry<byte[]> immutable
           
protected  AbstractHeader.Entry<byte[]> signature
           
protected  java.util.Set<java.security.PrivateKey> signatures
           
 
Constructor Summary
Builder()
          Initializes the builder and sets some required fields to known values.
 
Method Summary
protected  void addDependency(java.lang.CharSequence name, java.lang.CharSequence version, int flag)
          Adds a dependency to the RPM package.
 void addDependencyLess(java.lang.CharSequence name, java.lang.CharSequence version)
          Adds a dependency to the RPM package.
 void addDependencyMore(java.lang.CharSequence name, java.lang.CharSequence version)
          Adds a dependency to the RPM package.
 void addDirectory(java.lang.String path)
          Adds the directory to the repository with the default mode of 644.
 void addDirectory(java.lang.String path, Directive directive)
          Adds the directory to the repository with the default mode of 644.
 void addDirectory(java.lang.String path, int permissions, Directive directive, java.lang.String uname, java.lang.String gname)
          Adds the directory to the repository.
 void addDirectory(java.lang.String path, int permissions, Directive directive, java.lang.String uname, java.lang.String gname, boolean addParents)
          Adds the directory to the repository.
 void addFile(java.lang.String path, java.io.File source)
          Adds the file to the repository with the default mode of 644.
 void addFile(java.lang.String path, java.io.File source, int mode)
          Add the specified file to the repository payload in order.
 void addFile(java.lang.String path, java.io.File source, int mode, Directive directive)
          Add the specified file to the repository payload in order.
 void addFile(java.lang.String path, java.io.File source, int mode, Directive directive, java.lang.String uname, java.lang.String gname)
          Add the specified file to the repository payload in order.
 void addLink(java.lang.String path, java.lang.String target)
          Adds a symbolic link to the repository.
 void addLink(java.lang.String path, java.lang.String target, int permissions)
          Adds a symbolic link to the repository.
 void addSignature(java.security.PrivateKey key)
          Add a key to generate a new signature for the header and payload portions of the rpm file.
 java.lang.String build(java.io.File directory)
          Generates an RPM with a standard name consisting of the RPM package name, version, release, and type in teh given directory.
 void build(java.nio.channels.FileChannel original)
          Generates the rpm file to the provided file channel.
protected  int[] convert(java.lang.Integer[] ints)
           
protected  byte[] getImmutable(int count)
           
protected  byte[] getSignature(int count)
           
protected  byte[] getSpecial(int tag, int count)
           
 void setBuildHost(java.lang.CharSequence host)
          Required Field.
 void setDescription(java.lang.CharSequence description)
          Required Field.
 void setDistribution(java.lang.CharSequence distribution)
          Required Field.
 void setFiles(Contents contents)
          Sets the group of contents to include in this RPM.
 void setGroup(java.lang.CharSequence group)
          Required Field.
 void setLicense(java.lang.CharSequence license)
          Required Field.
 void setPackage(java.lang.CharSequence name, java.lang.CharSequence version, java.lang.CharSequence release)
          Required Field.
 void setPackager(java.lang.CharSequence packager)
          Required Field.
 void setPlatform(Architecture arch, Os os)
          Required Field.
 void setPostInstallProgram(java.lang.String program)
          Declares the interpretter to be used when invoking the RPM post-installation script that can be set with the setPreInstallScript(String) method.
 void setPostInstallScript(java.lang.String script)
          Declares a script to be run as part of the RPM post-installation.
 void setPostUninstallProgram(java.lang.String program)
          Declares the interpretter to be used when invoking the RPM post-uninstallation script that can be set with the setPostUninstallScript(String) method.
 void setPostUninstallScript(java.lang.String script)
          Declares a script to be run as part of the RPM post-uninstallation.
 void setPrefixes(java.lang.String... prefixes)
          Sets the package prefix directories to allow any files installed under them to be relocatable.
 void setPreInstallProgram(java.lang.String program)
          Declares the interpretter to be used when invoking the RPM pre-installation script that can be set with the setPreInstallScript(String) method.
 void setPreInstallScript(java.lang.String script)
          Declares a script to be run as part of the RPM pre-installation.
 void setPreUninstallProgram(java.lang.String program)
          Declares the interpretter to be used when invoking the RPM pre-uninstallation script that can be set with the setPreUninstallScript(String) method.
 void setPreUninstallScript(java.lang.String script)
          Declares a script to be run as part of the RPM pre-uninstallation.
 void setProvides(java.lang.CharSequence provides)
          Declares a dependency that this package exports, and that other packages can use to provide library functions.
 void setSourceRpm(java.lang.String rpm)
          Adds a source rpm.
 void setSummary(java.lang.CharSequence summary)
          Required Field.
 void setType(RpmType type)
          Required Field.
 void setUrl(java.lang.CharSequence url)
          Required Field.
 void setVendor(java.lang.CharSequence vendor)
          Required Field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

format

protected final Format format

signatures

protected final java.util.Set<java.security.PrivateKey> signatures

dependencies

protected final java.util.Map<java.lang.String,java.lang.CharSequence> dependencies

flags

protected final java.util.Map<java.lang.String,java.lang.Integer> flags

signature

protected final AbstractHeader.Entry<byte[]> signature

immutable

protected final AbstractHeader.Entry<byte[]> immutable

contents

protected Contents contents
Constructor Detail

Builder

public Builder()
Initializes the builder and sets some required fields to known values.

Method Detail

addDependencyLess

public void addDependencyLess(java.lang.CharSequence name,
                              java.lang.CharSequence version)
Adds a dependency to the RPM package. This dependecy 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(java.lang.CharSequence name,
                              java.lang.CharSequence version)
Adds a dependency to the RPM package. This dependecy 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.

addDependency

protected void addDependency(java.lang.CharSequence name,
                             java.lang.CharSequence version,
                             int flag)
Adds a dependency to the RPM package. This dependecy 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.
version - the version identifier.

setPackage

public void setPackage(java.lang.CharSequence name,
                       java.lang.CharSequence version,
                       java.lang.CharSequence release)
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.

setType

public void setType(RpmType 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)
Required Field. 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 architectur.
os - the target operating system.

setSummary

public void setSummary(java.lang.CharSequence summary)
Required Field. 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(java.lang.CharSequence description)
Required Field. 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(java.lang.CharSequence host)
Required Field. Sets the build host for the RPM. This is an internal field.

Parameters:
host - hostname of the build machine.

setLicense

public void setLicense(java.lang.CharSequence license)
Required Field. 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(java.lang.CharSequence group)
Required Field. 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(java.lang.CharSequence distribution)
Required Field. Distribution tag listing the ditributable package.

Parameters:
distribution - the distribution.

setVendor

public void setVendor(java.lang.CharSequence vendor)
Required Field. Vendor tag listing the organization providing this software package.

Parameters:
vendor - software vendor.

setPackager

public void setPackager(java.lang.CharSequence packager)
Required Field. Build packager, usually the username of the account building this RPM.

Parameters:
packager - packager name.

setUrl

public void setUrl(java.lang.CharSequence url)
Required Field. Website URL for this package, usually a project site.

Parameters:
url -

setProvides

public void setProvides(java.lang.CharSequence provides)
Declares a dependency that this package exports, and that other packages can use to provide library functions.

Parameters:
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.

setSourceRpm

public void setSourceRpm(java.lang.String rpm)
Adds a source rpm.

Parameters:
rpm - name of rpm source file

setPrefixes

public void setPrefixes(java.lang.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

setPreInstallScript

public void setPreInstallScript(java.lang.String script)
Declares a script to be run as part of the RPM pre-installation. The script will be run using the interpretter declared with the setPreInstallProgram(String) method.

Parameters:
script - Script contents to run (i.e. shell commands)

setPreInstallProgram

public void setPreInstallProgram(java.lang.String program)
Declares the interpretter to be used when invoking the RPM pre-installation script that can be set with the setPreInstallScript(String) method.

Parameters:
program - Path to the interpretter

setPostInstallScript

public void setPostInstallScript(java.lang.String script)
Declares a script to be run as part of the RPM post-installation. The script will be run using the interpretter declared with the setPostInstallProgram(String) method.

Parameters:
script - Script contents to run (i.e. shell commands)

setPostInstallProgram

public void setPostInstallProgram(java.lang.String program)
Declares the interpretter to be used when invoking the RPM post-installation script that can be set with the setPreInstallScript(String) method.

Parameters:
program - Path to the interpretter

setPreUninstallScript

public void setPreUninstallScript(java.lang.String script)
Declares a script to be run as part of the RPM pre-uninstallation. The script will be run using the interpretter declared with the setPreUninstallProgram(String) method.

Parameters:
script - Script contents to run (i.e. shell commands)

setPreUninstallProgram

public void setPreUninstallProgram(java.lang.String program)
Declares the interpretter to be used when invoking the RPM pre-uninstallation script that can be set with the setPreUninstallScript(String) method.

Parameters:
program - Path to the interpretter

setPostUninstallScript

public void setPostUninstallScript(java.lang.String script)
Declares a script to be run as part of the RPM post-uninstallation. The script will be run using the interpretter declared with the setPostUninstallProgram(String) method.

Parameters:
script - Script contents to run (i.e. shell commands)

setPostUninstallProgram

public void setPostUninstallProgram(java.lang.String program)
Declares the interpretter to be used when invoking the RPM post-uninstallation script that can be set with the setPostUninstallScript(String) method.

Parameters:
program - Path to the interpretter

addFile

public void addFile(java.lang.String path,
                    java.io.File source,
                    int mode)
             throws java.security.NoSuchAlgorithmException,
                    java.io.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:
target - the absolute path at which this file will be installed.
file - the file content to include in this rpm.
mode - the mode of the target file in standard three octet notation
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addFile

public void addFile(java.lang.String path,
                    java.io.File source,
                    int mode,
                    Directive directive,
                    java.lang.String uname,
                    java.lang.String gname)
             throws java.security.NoSuchAlgorithmException,
                    java.io.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 content to include in this rpm.
mode - the mode of the target file in standard three octet notation
directive - directive indicating special handling for this file.
uname - user owner for the given file
gname - group owner for the given file
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addFile

public void addFile(java.lang.String path,
                    java.io.File source,
                    int mode,
                    Directive directive)
             throws java.security.NoSuchAlgorithmException,
                    java.io.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 content to include in this rpm.
mode - the mode of the target file in standard three octet notation
directive - directive indicating special handling for this file.
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addFile

public void addFile(java.lang.String path,
                    java.io.File source)
             throws java.security.NoSuchAlgorithmException,
                    java.io.IOException
Adds the file to the repository with the default mode of 644.

Parameters:
path - the absolute path at which this file will be installed.
file - the file content to include in this rpm.
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addDirectory

public void addDirectory(java.lang.String path)
                  throws java.security.NoSuchAlgorithmException,
                         java.io.IOException
Adds the directory to the repository with the default mode of 644.

Parameters:
path - the absolute path at which this file will be installed.
file - the file content to include in this rpm.
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addDirectory

public void addDirectory(java.lang.String path,
                         int permissions,
                         Directive directive,
                         java.lang.String uname,
                         java.lang.String gname)
                  throws java.security.NoSuchAlgorithmException,
                         java.io.IOException
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.
directive - directive indicating special handling for this file.
uname - user owner of the directory
gname - group owner of the directory
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addDirectory

public void addDirectory(java.lang.String path,
                         int permissions,
                         Directive directive,
                         java.lang.String uname,
                         java.lang.String gname,
                         boolean addParents)
                  throws java.security.NoSuchAlgorithmException,
                         java.io.IOException
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.
directive - directive 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
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addDirectory

public void addDirectory(java.lang.String path,
                         Directive directive)
                  throws java.security.NoSuchAlgorithmException,
                         java.io.IOException
Adds the directory to the repository with the default mode of 644.

Parameters:
path - the absolute path to add as a directory.
directive - directive indicating special handling for this file.
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addLink

public void addLink(java.lang.String path,
                    java.lang.String target)
             throws java.security.NoSuchAlgorithmException,
                    java.io.IOException
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.
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addLink

public void addLink(java.lang.String path,
                    java.lang.String target,
                    int permissions)
             throws java.security.NoSuchAlgorithmException,
                    java.io.IOException
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.
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

addSignature

public void addSignature(java.security.PrivateKey key)
Add a key to generate a new signature for the header and payload portions of the rpm file. Supported algorithms are "MD5withRSA" and "SHAwithDSA".

Parameters:
key - private key to use in generating a signature.

build

public java.lang.String build(java.io.File directory)
                       throws java.security.NoSuchAlgorithmException,
                              java.io.IOException
Generates an RPM with a standard name consisting of the RPM package name, version, release, and type in teh given directory.

Parameters:
directory - the destination directory for the new RPM file.
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

build

public void build(java.nio.channels.FileChannel original)
           throws java.security.NoSuchAlgorithmException,
                  java.io.IOException
Generates the rpm file to the provided file channel. This file channel must support memory mapping and therefore should be created from a RandomAccessFile, otherwise an IOException will be generated.

Parameters:
original - the FileChannel to which the resulting RPM will be written.
Throws:
java.security.NoSuchAlgorithmException
java.io.IOException

getSignature

protected byte[] getSignature(int count)

getImmutable

protected byte[] getImmutable(int count)

getSpecial

protected byte[] getSpecial(int tag,
                            int count)

convert

protected int[] convert(java.lang.Integer[] ints)