Skip to content
This repository was archived by the owner on May 9, 2019. It is now read-only.

Common Framework: Starting out

Ari Kamen edited this page Sep 2, 2015 · 18 revisions

Configuration Manager

To get connected to an existing Black Duck Protex or Code Center using a configuration file is a simple two line operation. You must first create a Configuration Manager which houses all your configuration options for the utility you are writing and then specify which type of Black Duck application you wish to connect to. The APPLICATION enumeration will let you choose.

Protex

APPLICATION appType = APPLICATION.PROTEX;`
ConfigurationManager cf = new ConfigurationManager(configFileLocation, appType);

Create a Protex Server Wrapper (same applies for Code Center) with the configuration manager.

boolean useAuth = true;`
ProtexServerWrapper psw = new ProtexServerWrapper(cf.getServerBean(), cf , useAuth );

Code Center

Similar as Protex.

APPLICATION appType = APPLICATION.CODECENTER;`
ConfigurationManager cf = new ConfigurationManager(configFileLocation, appType);
CodeCenterServerWrapperpsw = new CodeCenterServerWrapper(cf.getServerBean(), cf );`

That is it! If your specified configuration file contains the proper keys and values, you now have a fully connected Protex object that you can use to interact with the Protex SDK.

Configuration File

The actual configuration file must contain certain basic keys. The advantage of relying on the common framework for all the utilities is the standardization of property files. To start a very simple utility that performs a connection, create a property file with the following keys:

Protex

protex.server.name

protex.user.name

protex.password

Code Center

cc.server.name

cc.user.name

cc.password

You can specify both in one configuration file if your utility needs to connect to a Protex AND a Code Center server. See main page for working with multiple code center servers.

More uses for the Configuration Manager

Beyond using the manager for instantiating the Protex or Code Center wrappers and retrieving the default connection values you can also use it as an all purpose bean to bring in additional property values. One common adaption among the utilities is to extend the manager and load in custom properties.

We can extend and make our own with a private init and loaded a few custom keys:

public class MyConfigClass extends ConfigurationManager

then use the super class getProperty() which is a required property and will throw an Exception.

projName = getProperty("key");

or we can use a more advanced, but optional property loader:

myEmailProtocol.setEmailProtocol(getOptionalProperty("key","smtp", String.class));

which sets our custom key to the user specified email protocol and a default of 'smtp'.

Password Encryption

Using the common framework also enables automatic password encryption by default. All passwords specified in the configuration file will be automatically encrypted and the specified configuration file will change with the original ASCII password replaced by encrypted text.

Please see the Password Encryption page for the full explanation.

Clone this wiki locally