Skip to content

Creating a New Project

This section describes how to create a brand new Java project for a new masking algorithm plugin. We will use the maskScript utility to create a skeleton project and an empty algorithm class in that project.

Creating the Project

Before you begin, you'll want to pick a name for your project, and an empty directory (outside of the Masking SDK source tree) where your project will be created. Once you've done this, run this maskScript command:

$ maskScript init -d <project path> -n <project name> -a <author name> -v <version>

For example, this command will create a project named demoProject in the demo-proj subdirectory of your home directory.

$ maskScript init -d $HOME/demo-proj -n demoProject -a "Demo Author" -v 1.0.0

For the rest of this section, we'll assume a new project has been created under proj_dir. Change your working directory to proj_dir. You'll notice that the project is created with a sample algorithm file proj_dir/src/main/java/com/sample/SampleAlgorithm.java. It's possible to build this into a usable plugin by running:

$ cd <proj_dir>
$ ./gradlew jar

But let's create our own, brand new algorithm.

Creating an Algorithm Class

For this part of the tour, we're going to create a new algorithm named Clobber. First, we'll run the maskScript utility to create a skeleton class file:

$ cd <proj_dir>
$ maskScript generate -p com.delphix.demo -c Clobber -v String -s .

By convention, the class file Clobber.java will be created under a sub-directory path based on the package name, so it might be he helpful to use the find command to locate it:

$ find . -name Clobber.java
./src/main/java/com/delphix/demo/Clobber.java

The initial content of this file is:

$ cat ./src/main/java/com/delphix/demo/Clobber.java

package com.delphix.demo;

import com.delphix.masking.api.plugin.MaskingAlgorithm;
import java.lang.String;
import javax.annotation.Nullable;

public class Clobber implements MaskingAlgorithm<String> {

   /**
    * Masks String object 
    * @param input The String object to be masked. This method should handle null inputs.
    * @return Returns the masked value.
    */
   @Override
   public String mask(@Nullable String input) {
       // TODO: change the default implementation.
           return input;
   }

   /**
    * Get the recommended name of this Algorithm.
    * @return The name of this algorithm
    */
   @Override
   public String getName() {
      // TODO: Change this if you'd like to name your algorithm differently from the Java class.
       return "Clobber";
   }
}

Customizing the Algorithm Class

The first thing to notice about the skeleton algorithm is that the mask method just returns the input. This means no masking will be done, so this will certainly need to change. We're going to create an algorithm that overwrites the entire input String with the first letter of that String. This replaces the skeleton mask method with:

    @Override
    public String mask(@Nullable String input) {
        // Always be ready to handle null or empty input
        if (input == null || input.length() < 2) {
            return input;
        }

        char firstChar = input.charAt(0);
        StringBuilder result = new StringBuilder();

        for (int i = 0; i < input.length(); i++) {
            result.append(firstChar);
        }

        return result.toString();
    }

The algorithm name "Clobber" is fine, so we can just delete the TODO comment in the getName() method.

Now, we'll rebuild the project to include this new algorithm in the plugin JAR:

$ ./gradlew jar

This creates or updates the plugin JAR file proj_dir/build/libs/demoProject.jar