org.freecompany.redline

Class Builder

public class Builder extends 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 Contentscontents
protected Map<String,CharSequence>dependencies
protected Map<String,Integer>flags
protected Formatformat
protected Set<PrivateKey>signatures
Constructor Summary
Builder()
Initializes the builder and sets some required fields to known values.
Method Summary
protected voidaddDependency(CharSequence name, CharSequence version, int flag)
Adds a dependency to the RPM package.
voidaddDependencyLess(CharSequence name, CharSequence version)
Adds a dependency to the RPM package.
voidaddDependencyMore(CharSequence name, CharSequence version)
Adds a dependency to the RPM package.
voidaddDirectory(String path)
Adds the directory to the repository with the default mode of 644.
voidaddDirectory(String path, int permissions, Directive directive, String uname, String gname)
Adds the directory to the repository.
voidaddDirectory(String path, int permissions, Directive directive, String uname, String gname, boolean addParents)
Adds the directory to the repository.
voidaddDirectory(String path, Directive directive)
Adds the directory to the repository with the default mode of 644.
voidaddFile(String path, File source, int mode)
Add the specified file to the repository payload in order.
voidaddFile(String path, File source, int mode, Directive directive, String uname, String gname)
Add the specified file to the repository payload in order.
voidaddFile(String path, File source, int mode, Directive directive)
Add the specified file to the repository payload in order.
voidaddFile(String path, File source)
Adds the file to the repository with the default mode of 644.
voidaddLink(String path, String target)
Adds a symbolic link to the repository.
voidaddLink(String path, String target, int permissions)
Adds a symbolic link to the repository.
voidaddSignature(PrivateKey key)
Add a key to generate a new signature for the header and payload portions of the rpm file.
Stringbuild(File directory)
Generates an RPM with a standard name consisting of the RPM package name, version, release, and type in teh given directory.
protected int[]convert(Integer[] ints)
protected byte[]getImmutable(int count)
protected byte[]getSignature(int count)
protected byte[]getSpecial(int tag, int count)
voidsetBuildHost(CharSequence host)
Required Field.
voidsetDescription(CharSequence description)
Required Field.
voidsetDistribution(CharSequence distribution)
Required Field.
voidsetFiles(Contents contents)
Sets the group of contents to include in this RPM.
voidsetGroup(CharSequence group)
Required Field.
voidsetLicense(CharSequence license)
Required Field.
voidsetPackage(CharSequence name, CharSequence version, CharSequence release)
Required Field.
voidsetPackager(CharSequence packager)
Required Field.
voidsetPlatform(Architecture arch, Os os)
Required Field.
voidsetPostInstallProgram(String program)
Declares the interpretter to be used when invoking the RPM post-installation script that can be set with the setPreInstallScript method.
voidsetPostInstallScript(String script)
Declares a script to be run as part of the RPM post-installation.
voidsetPostUninstallProgram(String program)
Declares the interpretter to be used when invoking the RPM post-uninstallation script that can be set with the setPostUninstallScript method.
voidsetPostUninstallScript(String script)
Declares a script to be run as part of the RPM post-uninstallation.
voidsetPrefixes(String... prefixes)
Sets the package prefix directories to allow any files installed under them to be relocatable.
voidsetPreInstallProgram(String program)
Declares the interpretter to be used when invoking the RPM pre-installation script that can be set with the setPreInstallScript method.
voidsetPreInstallScript(String script)
Declares a script to be run as part of the RPM pre-installation.
voidsetPreUninstallProgram(String program)
Declares the interpretter to be used when invoking the RPM pre-uninstallation script that can be set with the setPreUninstallScript method.
voidsetPreUninstallScript(String script)
Declares a script to be run as part of the RPM pre-uninstallation.
voidsetProvides(CharSequence provides)
Declares a dependency that this package exports, and that other packages can use to provide library functions.
voidsetSourceRpm(String rpm)
Adds a source rpm.
voidsetSummary(CharSequence summary)
Required Field.
voidsetType(RpmType type)
Required Field.
voidsetUrl(CharSequence url)
Required Field.
voidsetVendor(CharSequence vendor)
Required Field.

Field Detail

contents

protected Contents contents

dependencies

protected final Map<String,CharSequence> dependencies

flags

protected final Map<String,Integer> flags

format

protected final Format format

signatures

protected final Set<PrivateKey> signatures

Constructor Detail

Builder

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

Method Detail

addDependency

protected void addDependency(CharSequence name, 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.

addDependencyLess

public void addDependencyLess(CharSequence name, 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(CharSequence name, 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.

addDirectory

public void addDirectory(String path)
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.

addDirectory

public void addDirectory(String path, int permissions, Directive directive, String uname, String gname)
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

addDirectory

public void addDirectory(String path, int permissions, Directive directive, 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. 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

addDirectory

public void addDirectory(String path, Directive directive)
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.

addFile

public void addFile(String path, File source, int mode)
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

addFile

public void addFile(String path, File source, int mode, Directive directive, String uname, String gname)
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

addFile

public void addFile(String path, File source, int mode, Directive directive)
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.

addFile

public void addFile(String path, File source)
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.

addLink

public void addLink(String path, String target)
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.

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.

addSignature

public void addSignature(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 String build(File directory)
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.

convert

protected int[] convert(Integer[] ints)

getImmutable

protected byte[] getImmutable(int count)

getSignature

protected byte[] getSignature(int count)

getSpecial

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

setBuildHost

public void setBuildHost(CharSequence host)
Required Field. Sets the build host for the RPM. This is an internal field.

Parameters: host hostname of the build machine.

setDescription

public void setDescription(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.

setDistribution

public void setDistribution(CharSequence distribution)
Required Field. Distribution tag listing the ditributable package.

Parameters: distribution the distribution.

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 Builder methods.

Parameters: contents the set of contents to use in constructing this RPM.

setGroup

public void setGroup(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.

setLicense

public void setLicense(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.

setPackage

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

setPackager

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

Parameters: packager packager name.

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.

setPostInstallProgram

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

Parameters: program Path to the interpretter

setPostInstallScript

public void setPostInstallScript(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 method.

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

setPostUninstallProgram

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

Parameters: program Path to the interpretter

setPostUninstallScript

public void setPostUninstallScript(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 method.

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

setPrefixes

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

setPreInstallProgram

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

Parameters: program Path to the interpretter

setPreInstallScript

public void setPreInstallScript(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 method.

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

setPreUninstallProgram

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

Parameters: program Path to the interpretter

setPreUninstallScript

public void setPreUninstallScript(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 method.

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

setProvides

public void setProvides(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.

setSourceRpm

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

Parameters: rpm name of rpm source file

setSummary

public void setSummary(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.

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.

setUrl

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

Parameters: url

setVendor

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

Parameters: vendor software vendor.