Package com.sun.pkg.client

Provides for client-side access to the Image Packaging System (IPS) for Java clients.

See: Description

Package com.sun.pkg.client Description

Provides for client-side access to the Image Packaging System (IPS) for Java clients. The primary class for using this API is the Image class.

Usage Examples

This section contains some examples of how to use this API to accomplish some typical tasks.

Install the most recent version of a given package

The objective of this example is to install the most recent version of the "foo" package into the image rooted at "bar" in the user's home directory.
    File dir = new File(System.getProperty("user.home"), "bar");
    Image img = new Image(dir);
    String pkgs[] = {"foo"};
    img.installPackages(pkgs);

Check to see if a given package is installed

The objective of this example is to determine whether the "foo" package has been installed into the image. This example uses the Image object from the previous example.
    List list = img.getInventory(pkgs, false);
    if (list.size() > 0) {
        System.out.println("package foo is installed");
    }

Update the packages in an image

The objective of this example is to print a list of the packages that have available updates in the image and then install those updates. This example uses the Image object from the previous example.
    List list2 = img.getInventory(null, false);
    ArrayList pkgs2 = new ArrayList();
    for (Image.FmriState fs : list2) {
      if (fs.upgradable) {
        pkgs2.add(fs.fmri.getName());
      }
    }
    img.installPackages(pkgs2.toArray(new String[0]));

Display the license for a package before installing it

This example shows how to access the license(s) for a package or set of packages that are to be installed.
    File dir = new File(System.getProperty("user.home"), "bar");
    Image img = new Image(dir);
    String pkgs[] = {"foo"};
    Image.ImagePlan ip = img.makeInstallPlan(pkgs);
    StringBuffer licenseText = new StringBuffer();
    for (Fmri f : ip.getProposedFmris()) {
        Manifest m = img.getManifest(f);
        List<LicenseAction> lla = m.getActionsByType(LicenseAction.class);
        for (LicenseAction la : lla) {
            licenseText.append("===== ").append(la.getName()).append(" =====\n");
            licenseText.append("\n");
            licenseText.append(lla.getText());
            licenseText.append("\n\n");
        }
    }
    System.out.println(licenseText);
    ip.execute();
  

Logging

The pkg Java API generates log information to the com.sun.pkg.client Logger. The following code can be used to manipulate the properties of this logger before calling the various methods of the API:
     Logger cl = Logger.getLogger("com.sun.pkg.client");
     cl.setLevel(Level.FINER);

Limitations

The pkg Java API is not (yet) a complete implementation of the client side capabilities of the Image Packaging System. Here is a partial list of the limitations of the API. The number in parenthesis is the issue that is tracking completion of that feature.

Related Documentation

For overviews, tutorials, examples, guides, and tool documentation, please see: