Scala Bazaar Tutorial

By admin

Created 2010-06-09, 13:23

Introduction

The Scala Bazaar system, "sbaz" in short, is a system used by Scala[1] enthusiasts to share computer files with each other. In particular, it makes it easy to share libraries and applications. Just like with a real-life bazaar, working within a bazaar provides you with extra opportunities offered by other people, and gives you an easy way to share any offerings you wish to make to others in the community.

This tutorial steps you through the basic essentials of working with Scala bazaars.

Setting up a Managed Directory

The sbaz system puts everything it installs into a managed directory. To create your first managed directory, use any of the standard Scala installers[2] and install Scala into a directory where you have write access. Within the standard installation directory will be an initial managed directory. Depending on the installation method you use, that directory might be the main install directory or it might be in share/scala within the main install directory. Wherever it is, there should be a directory named meta within the managed directory. For simplicity, this tutorial will call this directory sbaz, but it may be placed anywhere on your system you like.

If you already have a Scala installation but would like to make a new managed directory, you can type sbaz-setup new-sbaz-dir, where new-sbaz-dir is the directory you would like to make a managed directory.

The directory sbaz/bin includes a sbaz command that is your interface to the bazaar. This is the command that manages your sbaz directory and allows you to download packages and upload package advertisements.

Try running sbaz/bin/sbaz and see if you get a friendly help message. If it does not work, the most likely reason is that there is not a suitable java command in your PATH. If not, you need to set up a Java virtual machine on your computer and add the appropriate directory to your PATH. The details of setting up Java vary for every platform and are thus beyond the scope of this tutorial.

For maximum convenience, you should add the managed directory's bin directory to your PATH. The rest of this tutorial assumes you have done so.

Installing and Removing Packages

You can see a list of packages that are available by running sbaz available. To see information about a particular package, you can type sbaz show packname.

To install a package, simply type sbaz install packname. The system will install the newest available version of that package for you. If you change your mind, do sbaz remove packname. If you want to install a specific version of a package, you can use sbaz install packname/version.

Staying Current

Each managed directory has a local cache of available packages. If you want to get the newest list of packages, you need to run sbaz update.

To upgrade your packages, run sbaz upgrade. This command automatically runs update and then installs the newest version of every package it can. This command can potentially do a lot of work, so you may want to use the -n flag to see what it plans to do before you actually try it: sbaz -n upgrade.

If you would like to upgrade an individual package, use the install subcommand; even if some version of the package is already installed, install will.

Sharing Your Packages

Heavy Scala users occasionally develop code that they would like to share with others in the bazaar style of open source development[3]. To do so, you will need to (1) create a package, (2) post it on the WWW, and (3) register it on the bazaar.

To create a package, make a directory tree that you would like to share with people. To start with, you could include just lib/yourpackage.jar.

Then run sbaz pack to create a package out of that directory. The basic usage is:

sbaz pack packnamedirectory-to-pack --linkbase url

The url you specify should be for a directory on the web where you can post files. The package name is packname, and the directory-to-pack is the directory tree you have prepared.

After you run this command, you will have two files in the current directory: packname-0.0.sbp and packname-0.0.advert. You can test your package by doing sbaz install -f packname-0.0.sbp and then looking through your managed directory to make sure it was installed as you intended.

Once you are satisfied with your package, you should upload the sbp file to the directory you specified as url. Then, run sbaz share packname-0.0.advert. At this point, your package is publicly available!

Once you have a basic package, you can improve it in various ways:

Look at the other options to sbaz pack, and fill them in. To see the available options, type sbaz help pack.

Look through other people's sbaz packages. You can do this by installing them and then using sbaz show to get a list of the included files.

Look through the sbaz manual, located in doc/sbaz in your managed directory, and read the section on "Suggested Directory Layout".

By the way, if you ever change your mind and want to retract a package you have shared, use the retract subcommand: