Globalyzer API Reference

Overview

The Globalyzer API allows you to create Globalyzer projects and scans, execute scans, and generate reports from a java program. This allows projects to be created "on the fly." One example of where you could apply the API is during code check-in; the check-in process could trigger the execution of a java program that calls the API to scan the source code, enabling timely feedback on its internationalization status.

The difference between the Globalyzer API and the Command Line Client (CLI), aside from the fact that projects and scans can be created from the API and not from CLI, is that the API executes calls more quickly. When your java program executes, it is launching one JVM that maintains state as the calls are executed. CLI, on the other hand, launches one JVM per CLI call. No state is maintained between CLI calls, so setup occurs on every call. CLI is good for build machines that run scripts nightly; the API is good for quick feedback on code check-in; the Workbench is good for customized projects and scans, as well as code fixing, including string externalization.

Note: Not all Globalyzer functionality is available from the Globalyzer API; you will still need the Globalyzer Workbench to create customized projects and scans (the API relies on defaults, though the rule sets can be customized), and the Workbench is required for string externalization.

Example Java Program

This java programs logs in, creates two projects, creates scans for the projects, executes the scans, and generates reports.
Note: The database connection must be closed at the end of your program. Click here for the Globalyzer API javadoc.

				
import com.lingoport.api.GlobalyzerAPI; 
import com.lingoport.api.GlobalyzerAPIReportTypes;

public class Test { 

	public static void main(String[] args) { 
		
		final String PROJECT1_NAME = "Project1"; 
		final String PROJECT1_PATH = "C:\\SmokeTestSource1"; 
		final String REPORT1_PATH = "C:\\SmokeTestSource1\reports"; 
		
		final String TEST_USER = "john.doe@company.com";
		final String TEST_PW = "password";
		final String TEST_SERVER = "https://www.globalyzer.com/gzserver";
		
		try{
			String[] results;
			
			// login
			GlobalyzerAPI.login(TEST_USER, TEST_PW, TEST_SERVER, null, null, null, null);
			
			// delete the project if it already exist to start fresh
			results = GlobalyzerAPI.listProjects();
			for (String pname : results) {
			    if (pname.equals(PROJECT1_NAME)) {
			        GlobalyzerAPI.deleteProject(pname);
			    }
			}
			
			// create project
			GlobalyzerAPI.createProject(PROJECT1_NAME, PROJECT1_PATH);
			
			// create scan
			String[] scanItems = {"\\java\\strings", "\\java\\methods"};
			GlobalyzerAPIScanDetails details = new GlobalyzerAPIScanDetails();
			details.setScanItems(scanItems);
			GlobalyzerAPI.createScanWithInfo(PROJECT1_NAME, "my java scan", "java", TEST_USER, details);
			
			// execute scan and generate report
			GlobalyzerAPI.executeScan(PROJECT1_NAME, "my java scan", REPORT1_PATH, GlobalyzerAPIReportTypes.ScanDetailedXML);
			
			// MUST close database connection at end of program!
			GlobalyzerAPI.closeDatabaseConnection();
		    
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}

Running your Java Program

Place your java program in the directory where the Globalyzer Client has been installed. This will ensure that your java program has everything it needs to run correctly.

If your java program needs to reside outside the Globalyzer Client install directory, please copy the following from the Globalyzer Client install directory to the location where your java program resides:

  • data (directory)
  • lib (directory)
  • globalyzer-api.jar (file)
  • globalyzer.cfg.xml (file)
  • log4j2.xml (file)

Compile and execute your java program.