Develop Progsbase Code using the Command Line

This tutorial will show you how to build, run and test progsbase projects using the command line. You can use an existing project as a template for a new progsbase project. So, using this tutorial you can work on existing projects or create new projects.

Getting a Library

Go to the progsbase library repository and click on one of the libraries from the list. For example, select the JSON library. Scroll down and find the download tab. Download the “Java Project Package”. This will download a zip file with the source code of the project.

Unzip the project somewhere on your machine; for example, by running the following command:

unzip JSON-project-package.zip

Progsbase Project Structure

A progsbase project is located in a folder. For the JSON library this folder is called JSON. Within this folder is a folder with the same name as the project. For example, this project is named JSON, so there is a folder named JSON. Inside this folder are two folders. The two folders are main and test. main contains the source code of the library, and test contains the tests. There is also a file called info.json. This file contains the specifications of the progsbase library. Learn more about it in a separate article.

Fetching Dependencies

The progsbase client is used to import the dependencies. Inside the folder containing info.json, JSON/JSON in this example, run:

progsbase importdeps Java IDE

Learn how to install and setup the progsbase client here.

The code of the dependencies are downloaded and placed in JSON/imports.

Creating a Build Folder

Next, make a folder for the Java byte code. Let’s place it in JSON/target. For example, inside JSON, run:

mkdir target

Code for Running the Tests

Next, create a main file that will run the tests and output the number of failed tests. Place the file in JSON/RunTests.java.

public class RunTests{
    public static void main(String [] args){
        System.out.println(tests.tests.test());
    }
}

Compiling

We are now ready to build and test the library. Building it requires JDK 7 or later. In JSON/JSON, run the following.

javac ../RunTests.java -sourcepath main/:test/:../imports/ -d ../target

It should compile without any messages or errors.

Running the tests

To run the tests, run

java -cp ../target RunTests

If all tests pass, it should return 0.0.

Analysing

You can use the progsbase client to check for compatability with progsbase. Within JSON/JSON run

progsbase analyze

If it returns nothing, it means the code is compatible with progsbase.

Developing

Now you have what you need to develop, test and analyze progsbase code. If you want to use an IDE, you can either check out one of the other articles on how to develop with progsbase, or set up the IDE to work with the code yourself.

Leave a Reply

Your email address will not be published. Required fields are marked *