Skip to content

Creating a New Project

This section describes how to create a brand new Java project for a new masking driver support plugin. We will use the maskScript utility to create a skeleton project and an empty driver support 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 -t driverSupport -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 -t driverSupport -d $HOME/demo-proj -n demoProject -a <plugin author's name> -v <version>

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 driver support file proj_dir/src/main/java/com/sample/masking/driverSupport/MSSQLDriverSupport.java. It's possible to build this into a usable plugin by running:

$ cd <proj_dir>
$ ./gradlew jar

Warning

This sample driver support project is not intended to be used in a production environment and is only meant to serve as an example.

Creating a Driver Support Class

Run the maskScript utility to create a skeleton class file:

$ cd <proj_dir>
$ maskScript generate driverSupport -p com.delphix.demo -c <class_name> -s .

By convention, the class file .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 <class_name>.java
./src/main/java/com/delphix/demo/<class_name>.java

The initial content of this file is:

package com.delphix.demo;

import com.delphix.masking.api.driverSupport.DriverSupport;
import com.delphix.masking.api.driverSupport.Task;
import com.delphix.masking.api.driverSupport.jobInfo.JobInfo;
import com.delphix.masking.api.provider.ComponentService;
import com.delphix.masking.api.provider.LogService;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

public class <class_name> implements DriverSupport {

        /**
         * This method serves as a directory of Task objects provided by this plugin.
         *
         * @return an ordered list of tasks. The order that tasks are added to the returning list is the
         *     order that they will be executed in.
         */
        @Override
        public List<Task> getTasks() {
                // TODO: return list of implemented task objects
                List tasks = new ArrayList<>();
                tasks.add(new ExampleTask());

                return tasks;
        }

        public class ExampleTask implements Task {
                private JobInfo jobInfo;
                private LogService logService;
                private Connection targetConnection;

                @Override
                public String getTaskName() {
                        return "Example Task";
                }

                @Override
                public void setup(ComponentService serviceProvider) {
                        this.jobInfo = serviceProvider.getJobInfo();
                        this.targetConnection = serviceProvider.getTargetConnection();
                        this.logService = serviceProvider.getLogService();
                }

                @Override
                public void preJobExecute() {
                        // TODO: implement code to execute BEFORE masking job runs.
                }

                @Override
                public void postJobExecute() {
                        // TODO: implement code to execute AFTER masking job runs.
                }
        }
}

Implementing the Driver Support Class

The first thing to notice about the skeleton driver support class is that the getTasks method just returns an array of tasks with a single no-op task called ExampleTask. This means no actual additional transaction will be performed on the target data as part of a masking job, so this will certainly need to change.

It is recommended that you change the task class to a name that more accurately reflects what the task does as well as the string returned from the method getTaskName. Delete the TODO comments in .java once development is complete.

In order to rebuild the project to generate the driver support plugin JAR, you'll need to first update settings.gradle to include the project directory:

/*
 * Copyright (c) 2019, 2021 by Delphix. All rights reserved.
 */

pluginManagement {
        resolutionStrategy {
                eachPlugin {
                        if ( requested.id.id == 'com.diffplug.gradle.spotless' ) {
                                useModule( "com.diffplug.spotless:spotless-plugin-gradle:$spotlessVer" )
                        }
                }
        }
}

rootProject.name = '<proj_dir>'
include 'sdkTools'
include 'algorithm'
include 'assemble'
include 'driverSupport'

Then to generate the driver support plugin JAR:

$ ./gradlew jar

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