Skip to content

VS Code specific development instructions

Marek Czernek edited this page Dec 11, 2023 · 8 revisions

This is a description of how to setup Visual Studio Code for developing Uyuni, particularly to work on the Java code using the Java Extension Pack.

Preparing VS Code

  1. Install Visual Studio Code. How to do this exactly depends on your operating system and personal preferences. There are repositories available with packages for various Linux distributions from the official download site, e.g. for openSUSE.
  2. Install the Java Extension Pack from the "Extensions" view (find it in the main menu). This includes the most important extensions needed for Java development, especially the Java language server, but also support for commonly used build tools (like maven), debugging applications and running unit tests.
  3. The Ant Target Runner needs to be installed separately from the "Extensions" view, and can be used to resolve dependencies or to run build and deploy cycles while we are still using ant. You might want to configure it to ignore the original build.xml file by setting manager-build.xml as Ant: Build Filenames. In case you are running VS Code from a flatpak external commands (like ant) cannot simply be called from extensions due to the sandboxing, it should work to use flatpak-spawn --host ant as the Ant: Executable though.
  4. If you are used to working with Intellij or Eclipse you might want to consider installing the respective keybindings: Eclipse Keymap or IntelliJ IDEA Keybindings.

Preparing the repository

  1. Clone the repo from GitHub as described here.
  2. Configure the development machine as described here.
  3. Make sure to resolve the dependencies for your current branch from the commandline as described (via ant -f manager-build.xml ivy), all jar file dependencies should be in the /lib folder before proceeding. Note that switching between branches might require you to repeat this step!

Creating the workspace

  1. Start VS Code and from the welcome screen (or the "File" menu) use "Open folder...", choose the java subdirectory of the Uyuni repository.
  2. Opening any of the Java files in the editor should automatically enable the Java language server and start the compilation / project setup.
  3. Referenced libraries will automatically be found in the /lib subfolder.
  4. If everything went well you should see 0 errors, only warnings and info messages.

Connecting the debugger to a remote VM

  1. Navigate to the "Run and Debug" view (find it as the 4th entry on the main menu).
  2. Click the link there to edit the launch.json file, or click the settings icon to open launch.json.
  3. Check if the hostname in the debug configurations is actually matching your environment:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug Uyuni",
            "request": "attach",
            "hostName": "server.tf.local",
            "port": 8003
        },
        {
            "type": "java",
            "name": "Debug Taskomatic",
            "request": "attach",
            "hostName": "server.tf.local",
            "port": 8001
        }
    ]
}
  1. From the dropdown menu next to "Run and Debug", choose the configuration and start by clicking the green arrow. The usual debugging options appear on top after connecting to the VM (step over, step into, disconnect, etc.), and breakpoints can be used.

Running unit tests

  1. Create a config file from the template in java/buildconf/test: cp rhn.conf.postgresql-example rhn.conf
  2. Edit it and set db_host to match it with your environment, e.g. server.tf.local.
  3. In the editor, open the Java file that contains the unit tests that you want to run.
  4. Click on the arrow next to the class or test method definitions, the test(s) will launch in the Testing view.
Clone this wiki locally