Suche

1. What You Will Learn

In this tutorial you will learn how to write a simple Command step by step in Java.
Each essential element is thoroughly explained and at the end you can write your own simple Commands based on the insights gained.

This guide shall show how to write a Command and will not touch the topics how to use them in the Editor or Executor applications. For these you can follow the guide Build and Run your first Command.

2. Prerequisites

To complete this guide you need:

  • Roughly 10 minutes

  • JDK11+ installed with JAVA_HOME configured appropriately

  • An IDE (we recommend IntelliJ)

  • Some kind of build tool (like gradle, maven or ant)

3. What is a Command?

A Command is some small executable code, which can be fed with inputs, executes its code and may produce an output.
The in- and outputs then can be served to other Commands which results in a chaining of Commands.

It is important for a Command to not do many tasks at once, but focus on one task and let other Commands do the rest.

4. Step by Step

In the following parts we want to develop a simple Command step by step. Beginning from the bare minimum and ending with a fully functional and documented Command.

4.1. The Example We Want to Develop

We want to show how to develop a Command along an example to better follow along. In this guide we want to develop a simple Adding Command which takes two numbers adds them up and returns the result.

This will be the base on which the essentials are explained and will be used in advanced lessons later on.

4.2. Dependencies We Need

To write a functional Command which can be used by the Java Command Interpreter of PAK, we need to have some dependencies included:

Dependencies Reason to include

de.asap.pak.jlcint:jlcint-processor

We use this dependency for the annotation processing. Include this to your annotation processor during compilation so that command-metas are generated.

de.asap.pak.jlcint:jlcint-commandapi

Provides annotations used to develop a Java Command

4.3. Bare Bones of a Command

The following code shows the skeleton of a Java Command. We will go over each element and explain its functionality.
This will be the foundation on top we will develop a Command.

@JavaCommand (2)
public class Adding { (1)

	@Run (3)
	public void run(){

	}
}
1 Every Java Command is a Java Class. By default, the name of the class is also the name of the Command. In our example we created a Command named ‚Adding‘.
2 The @JavaCommand-Annotation marks the created class as a Command. Every Class that is a Command needs that annotation.
3 Every Command executes code. To define what code the Command executes, a public void method needs to be annotated with @Run. This method will be the entry point of the Command when it is run.
The name of the method itself can be chosen freely, as long it is not named like a possible setter/getter of a class field.
When the class name is in CamelCase then the Command name will be the class name split at the capital letters. Consecutive capital letters are not split. Example: HelloWorldHello World , TheABCThe ABC

4.4. Command In- and Outputs

The Adding Command needs two numbers as inputs and a number as an output. The in- and outputs are defined through the class fields annotated with @Persistent.

@JavaCommand
public class Adding {

	@Persistent (1)
	private int numberOne;

	@Persistent (1)
	private int numberTwo;

	@Persistent(scope = FieldScope.WRITE_ONLY) (2)
	private int result;

	@Run
	public void run(){

	}
}
1 A class field annotated with a simple @Persistent represents a mandatory input of the Command. We want to have two numbers (numberOne and numberTwo) as inputs, so we annotate both fields like in the example.
2 The Command needs one output, the result of the addition. For this the field result is also annotated with @Persistent but the annotation has more information added to it.
As annotated fields are recognized as inputs by default, we need to tell the annotation that the underlying field should be handled as an output.
This can be done by defining the scope FieldScope.WRITE_ONLY.

4.5. Running Code

To have a fully functional Command only one last thing is missing. The code to run when the Command is executed. As already explained in Bare Bones of a Command the method annotated with @Run is the code entry point for execution. So we add the desired Command functionality to this method.

@JavaCommand
public class Adding {

	@Persistent
	private int numberOne;

	@Persistent
	private int numberTwo;

	@Persistent(scope = FieldScope.WRITE_ONLY)
	private int result;

	@Run
	public void run(){
	    this.result = this.numberOne + this.numberTwo; (1) (2)
	}
}
1 Due to the inputs being mandatory, they are already set in the fields at runtime of the Command. We do not need to worry about unset fields and NullpointerExceptions and can safely add the two numbers.
2 The output is set when the field is set with a value. In this case, the output field result is set to the sum of our two numbers.
In case in- or outputs are not set (null) when a Command is running, then an exception telling you that, will be thrown and the Command fails.

4.6. Documentation of a Command

The last step for a Command is to document what the Command does, what the inputs require and what the outputs produce. This is achieved by documenting the elements and using the JavaDoc-Tag
@workflowDocu.

All documentation written this way will be exposed to the users of the Command and helps guide the usage.

/**
 * @workflowDocu This Command adds two numbers together and returns the result. (1)
 */
@JavaCommand
public class Adding {

	/**
	 * @workflowDocu The first number to be added to second number. (2)
	 */
	@Persistent
	private int numberOne;

	/**
	 * @workflowDocu The second number to be added to the first number. (2)
	 */
	@Persistent
	private int numberTwo;

	/**
	 * @workflowDocu The result of the two numbers added together. (2)
	 */
	@Persistent(scope = FieldScope.WRITE_ONLY)
	private int result;

	/**
	 * Method that adds two numbers together (3)
	 */
	@Run
	public void run(){
		this.result = this.numberOne + this.numberTwo;
	}
}
1 The overall documentation of the Command, should give an overview over its functionality.
2 The documentation of the in- and outputs should provide the user an explanation what the Command expects it to be. Any constraints on the values are also added here so they can be upheld.
3 The @Run-Method doesn’t get a @workflowDocu Tag and its documentation won’t be presented to the user. But you can also document the method when you like.

5. Summary

We learned how to write a simple Java Command, that can add two numbers. This can be used as a basis for more advanced Commands and is a great start to begin the development of your own.

6. What to Do Next?

After creating your own simple Command the only thing left to do is to compile your Command with the jlcint-annotation-processor.

Sonatype Nexus

PAK features connectors and commands for Sonatype Nexus. This means the software can directly interact with Nexus repositories for storing and managing artifacts. Through these connectors, PAK can automate tasks like uploading binaries or retrieving dependencies, ensuring efficient artifact management within Nexus.

Jenkins

PAK has connectors and commands for Jenkins. This allows the software to directly communicate with Jenkins servers, enabling the automation of CI/CD (Continuous Integration/Continuous Deployment) tasks. Through these connectors, PAK can trigger builds, fetch build statuses, or manage job configurations, streamlining the CI/CD processes within Jenkins.

Git Hub

PAK possesses connectors and commands for GitHub. This means the software can interface directly with GitHub repositories, facilitating actions like code pushes, pull requests, or issue tracking. Through these connectors, PAK can automate various GitHub operations, enhancing code collaboration and repository management.

Atlassian Confluence

PAK is equipped with connectors and commands for Atlassian Confluence. This enables the software to directly interact with Confluence spaces and pages. Through these connectors, PAK can automate actions such as creating, updating, or retrieving documentation, ensuring efficient content management and collaboration within Confluence.

Codebeamer

PAK features connectors and commands for Codebeamer. This allows the software to seamlessly integrate with Codebeamer’s ALM (Application Lifecycle Management) platform. Through these connectors, PAK can automate tasks like issue tracking, test management, or requirements tracing, enhancing the coordination and management of software development processes.

JFrog Artifactory

PAK has connectors and commands for JFrog Artifactory. This means the software can directly interface with Artifactory repositories, enabling actions like artifact storage, retrieval, and management. Through these connectors, PAK can automate tasks such as deploying artifacts or managing repository configurations, streamlining the integration and management of binary artifacts within Artifactory.

Amazon Web Services (AWS)

PAK has connectors and commands for Amazon Web Services (AWS). This means the software possesses specialized interfaces to directly interact with AWS services and execute actions on the AWS platform. Through these connectors, PAK can automate AWS-specific commands, such as launching EC2 instances, managing S3 buckets, or configuring Lambda functions. This allows for efficient integration, management, and automation of AWS resources and services directly from PAK.

Atlassian Jira

PAK features integration tools and capabilities for Atlassian Jira. These tools allow for a direct connection to Jira and the execution of specific actions. Using these integration tools, PAK can automate Jira actions such as adding comments or changing ticket priorities, ensuring seamless handling and coordination of Jira processes.

Git

PAK has connectors and commands for Git. This means it has interfaces to directly communicate with Git and execute actions. Through these connectors, the software can automate Git commands such as retrieving changes or creating branches, enabling efficient integration and management of Git tasks.

Generic Human Tasks

PAK offers you a standard set of commands which require creative input from the user. Enables you to start with automating your workflows, that still need abit of human input.

Generic Commands

PAK offers a standard set of commands giving you the first steps to automate your workflows.

Nexus Maven Command Pool

Nexus is an artifact repository manager for storing binaries, libraries, and artifacts, supporting formats like Maven. Maven, a software project management tool, is based on the Project Object Model (POM) and allows developers to consistently define projects and dependencies. Our Command Pool offers commands for interactions between Maven and Nexus, such as artifact uploads or dependency retrieval.

Artifactory Maven Command Pool

Artifactory allows developers to store, retrieve, and manage binary files and artifacts, providing a
central source for all binaries used in a development process. Apache Maven is a software project
management and comprehension tool that enables developers to consistently describe a project and
its dependencies. Our Command Pool offers a collection of commands used to facilitate interactions
between Maven and Artifactory, such as uploading artifacts or retrieving dependencies.

Open API Command Interpreter

The OpenApi Command Interpreter allows you the automatic parsing of commands from an OpenApi defintion. No additional code needs to be written anymore, just add the address to the definition and our framework does the rest!

Kotlin Command Interpreter

The Kotlin Command Interpreter allows you the parsing and execution of commands within a Kotlin environment to automate various tasks or processes.

Bpmn Interpreter

Workflows come in many shapes and forms. The BPMN (Business Process Model and Notation) Interpreter enables the parsing of worklows defined in the BPMN format into the PAK intern model.

Human Task Interpreter

The Human Task Interpreter allows you the parsing and running of commands within a HTML and Javascript environment. Use this to build commands which need the creative input of a workflow user!

Java Command Interpreter

The Java Command Interpreter allows you the parsing and execution of commands within a Java
environment to automate various tasks or processes.

Core

The heart of the PAK-Framework. Contains the means to run workflows with the PAK engine, but also the possibility to enrich the frameworks interfaces with your own implementations and solutions.

RocksDB Persistence

Data that is generated by a workflow run needs to be saved for short or longer terms. Our solution to the Persistence Interface of the PAK-Framework is to use the high-performance, key-value based RocksDB developed by Facebook.

PAK online

PAK Online is a web based application and provides an Open API based REST API. It enables you to upload workflows and run them periodically or on REST demand.

Command Line App

Run tasks and workflows on the console or as part of a CI/CD Pipeline with our Command Line Interface.

Workflow Editor

With our specially developed editor, a wide variety of workflows can be easily modeled in the wide known BPMN process format.

Workflow Executor

The Workflow Executor is the application to run your workflows. It features a multilingual UI and easy managment of your favorite workflows.

Support

We offer a community website where you can exchange ideas and support each other. For our Pro packages we also offer full support via email.