CMSynergy.java

Index Score
net.sourceforge.cruisecontrol.sourcecontrols
CruiseControl

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
EXEC_COMMENTSComments in executable code
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
COMMENTSComment lines
LINE_COMMENTNumber of line comments
SIZESize of the file in bytes
LINESNumber of lines in the source file
JAVA0166JAVA0166 Generic exception caught
UNIQUE_OPERANDSNumber of unique operands
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
LOGICAL_LINESNumber of statements
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
PROGRAM_VOCABHalstead program vocabulary
JAVA0034JAVA0034 Missing braces in if statement
OPERANDSNumber of operands
ELOCEffective lines of code
BLOCKSNumber of blocks
PROGRAM_LENGTHHalstead program length
EXITSProcedure exits
LOCLines of code
OPERATORSNumber of operators
CYCLOMATICCyclomatic complexity
FUNCTIONSNumber of function declarations
JAVA0130JAVA0130 Non-static method does not use instance fields
INTERFACE_COMPLEXITYInterface complexity
PARAMSNumber of formal parameter declarations
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0128JAVA0128 Public constructor in non-public class
PROGRAM_VOLUMEHalstead program volume
UNIQUE_OPERATORSNumber of unique operators
JAVA0136JAVA0136 N methods defined in class (maximum: M)
RETURNSNumber of return points from functions
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0043JAVA0043 Inner class does not use outer class
WHITESPACENumber of whitespace lines
JAVA0051JAVA0051 Class derives from java.lang.RuntimeException
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0145JAVA0145 Tab character used in source file
/******************************************************************************** * CruiseControl, a Continuous Integration Toolkit * Copyright (c) 2001, ThoughtWorks, Inc. * 200 E. Randolph, 25th Floor * Chicago, IL 60601 USA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * + Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * + Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the * names of its contributors may be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ package net.sourceforge.cruisecontrol.sourcecontrols; import java.io.File; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; import net.sourceforge.cruisecontrol.CruiseControlException; import net.sourceforge.cruisecontrol.SourceControl; import net.sourceforge.cruisecontrol.util.ManagedCommandline; import net.sourceforge.cruisecontrol.util.Util; import net.sourceforge.cruisecontrol.util.ValidationHelper; import org.apache.log4j.Logger; /** * Checks for modifications made to a Telelogic CM Synergy repository. It does * this by examining a provided reference project, getting the tasks from all * folders in that project, and checking the completion time of those tasks * against the last build. * * @author <a href="mailto:rjmpsmith@gmail.com">Robert J. Smith</a> */ public class CMSynergy implements SourceControl { /** * A delimiter used for data values returned from a CM Synergy query */ public static final String CCM_ATTR_DELIMITER = "@#@#@#@"; /** * A delimiter used to mark the end of a multi-lined result from a query */ public static final String CCM_END_OBJECT = "<<<#@#@#>>>"; /** * The default CM Synergy command line client executable */ public static final String CCM_EXE = "ccm"; /** * The environment variable used by CM Synergy to determine which backend * ccmSession to use when issuing commands. */ public static final String CCM_SESSION_VAR = "CCM_ADDR"; /** * The default CM Synergy session map file */ public static final String CCM_SESSION_FILE = System.getProperty("user.home") + File.separator + ".ccmsessionmap"; /** * An instance of the logging class */ private static final Logger LOG = Logger.getLogger(CMSynergy.class); /** * A collection of properties which will be passed to and set within the * builder. */ private SourceControlProperties properties = new SourceControlProperties(); /** * The name of the property which will be set and passed to the builder if * any object has changed since the last build. */ private String property = "cc.ccm.haschanged"; /** * The version number delimeter used by the database with which this CM * Synergy session is connected. */ private String ccmDelimiter = "-"; /** * The URL for your installation of Change Synergy */ private String changeSynergyURL; /** * The CCM database with which we wish to connect */ private String ccmDb; /** * The CM Synergy executable used for executing commands. If not set, we * will use the default value "ccm". */ private String ccmExe; /** * The CM Synergy project spec (2 part name). */ private String projectSpec; /** * The instance number of the project. This is almost always "1", but might * need to be overridden if you are using DCM? */ private String projectInstance = "1"; /** * The CM Synergy project four part name we will use as a template to * determine if any new tasks have been completed. */ private String projectFourPartName; /** * If set to true, the contents of the folders contained within the * project's reconfigure properties will be updated before we query to find * new tasks. */ private boolean updateFolders = true; /** * The file which contains the mapping between CM Synergy session names and * IDs. */ private File sessionFile; /** * The name of the CM Synergy session to use. */ private String sessionName; /** * The date format as returned by your installation of CM Synergy. */ private String ccmDateFormat = "EEE MMM dd HH:mm:ss yyyy"; // Fri Dec 3 // 17:51:56 2004 /** * If set to true, the project will be reconfigured when changes are * detected. */ private boolean reconfigure = false; /** * Used in conjunction with reconfigure. If set to true, all subprojects * will be reconfigured when changes are detected. */ private boolean recurse = true; /** * If set to true, the time a task came into a reconfigure folder is used * to determine modified tasks instead of the tasks completion time. Works * for Synergy 6.3SP1 and newer only. */ private boolean useBindTime = false; /** * If set to true, the work area location will not be queried and passed to * the builder. */ private boolean ignoreWorkarea = false; /** * The locale used for parsing dates. */ private Locale locale; /** * The language used to set the locale for parsing CM Synergy dates. */ private String language = "en"; /** * A reusable commandline for issuing CM Synergy commands */ private ManagedCommandline cmd; /** * The country used to set the locale for parsing CM Synergy dates. */ private String country = "US"; /** * The number of modified tasks found */ private int numTasks; /** * The number of modified objects found */ private int numObjects; /** * Sets the name of the CM Synergy executable to use when issuing commands. * * @param ccmExe * the name of the CM Synergy executable */ public void setCcmExe(String ccmExe) { this.ccmExe = ccmExe; } /** * Sets the CM Synergy project spec to be used as a template for calculating * changes. The value set here can be accessed from within the build as the * property "cc.ccm.project". * * @param projectSpec * The project spec (in 2 part name format). */ public void setProject(String projectSpec) { this.projectSpec = projectSpec; } /** * Sets the project's instance value. This value will be used in any query * which involves the project. Defaults to "1". This default should work for * most people. You might, however, need to override this value when using * DCM? * * @param projectInstance * The instance number of the project. */ public void setInstance(String projectInstance) { this.projectInstance = projectInstance; } /** * Sets the URL for your installation of Change Synergy. This is used to * create active links from the modification report to the Change Requests * associated with the modified tasks. If not set, the links will not be * created. If you wish to use this feature, you must also set the ccmdb * attribute to the remote location of the Synergy database. * * @param url * The URL of your ChangeSynergy installation */ public void setChangeSynergyURL(String url) { this.changeSynergyURL = url; } /** * Sets the remote Synergy database with which to connect. This is only * needed if you wish to create active links from the build results page to * your installation of Change Synergy. If you set this attribute, you must * also set the changesynergyurl attribute. * * @param db * The remote Synergy database with which to connect (e.g. * /ccmdb/mydb). */ public void setCcmDb(String db) { this.ccmDb = db; } /** * Sets the value of the updateFolders attribute. If set to true, the * contents of the folders contained within the project's reconfigure * properties will be updated before we query to find new tasks. */ public void setUpdateFolders(boolean updateFolders) { this.updateFolders = updateFolders; } /** * Sets the file which contains the mapping between CM Synergy session names * and IDs. This file should be in the standard properties file format. Each * line should map one name to a CM Synergy session ID (as returned by the * "ccm status" command). * <p> * example: <br> * <br> * session1=localhost:65024:192.168.1.17 * * @param sessionFile * The session file */ public void setSessionFile(String sessionFile) { this.sessionFile = new File(sessionFile); } /** * Sets the name of the CM Synergy session to use with this plugin. This * name should appear in the specified session file. * * @param sessionName * The session name * * @see #setSessionFile(String) */ public void setSessionName(String sessionName) { this.sessionName = sessionName; } /** * Sets the date format used by your installation of CM Synergy. The format * string should use the syntax described in <code>SimpleDateFormat</code>. * The default is "EEE MMM dd HH:mm:ss yyyy" The value set here can be * accessed from within the build as the property "cc.ccm.dateformat". * * @param format * the date format */ public void setCcmDateFormat(String format) { this.ccmDateFormat = format; } /** * Sets the value of the reconfigure attribute. If set to true, the project * will be reconfigured when changes are detected. Default value is false. */ public void setReconfigure(boolean reconfigure) { this.reconfigure = reconfigure; } /** * Sets the value of the useBindtime attribute. If set to true, the time the * task came into the reconfigure folders is used to query the modifications * instead of the time the task was completed. Works * for Synergy 6.3SP1 and newer only. * Default value is false. */ public void setUseBindTime(boolean useBindTime) { this.useBindTime = useBindTime; } /** * Sets the value of the recurse attribute. Used in conjuction with the * reconfigure attribute. If set to true, all subprojects will also be * reconfigured when changes are detected. Default is true. */ public void setRecurse(boolean recurse) { this.recurse = recurse; } /** * Sets the value of the ignoreWorkarea attribute. If set to true, we will * not attempt to determine the location of the project's workarea, nor will * we pass the cc.ccm.workarea attribute to the builders. Default is false. */ public void setIgnoreWorkarea(boolean ignoreWorkarea) { this.ignoreWorkarea = ignoreWorkarea; } /** * Sets the language used to create the locale for parsing CM Synergy dates. * The format should follow the ISO standard as specified by * <code>java.util.Locale</code>. The default is "en" (English). * * @param language * The language to use when creating the <code>Locale</code> */ public void setLanguage(String language) { this.language = language; } /** * Sets the country used to create the locale for parsing CM Synergy dates. * The format should follow the ISO standard as specified by * <code>java.util.Locale</code>. The default is "US" (United States). * * @param country * The ISO country code to use */ public void setCountry(String country) { this.country = country; } public Map getProperties() { return properties.getPropertiesAndReset(); } public void setProperty(String property) { this.property = property; } public void validate() throws CruiseControlException { ValidationHelper.assertIsSet(projectSpec, "project", this.getClass()); } public List getModifications(Date lastBuild, Date now) { // Create a Locale appropriate for this installation locale = new Locale(language, country); if (!locale.equals(Locale.US)) { LOG.info("Locale has been set to " + locale.toString()); } // Attempt to get the database delimiter cmd = createCcmCommand(ccmExe, sessionName, sessionFile); cmd.createArgument("delimiter"); try { cmd.execute(); cmd.assertExitCode(0); this.ccmDelimiter = cmd.getStdoutAsString().trim(); } catch (Exception e) { StringBuffer message = new StringBuffer("Could not connect to provided CM Synergy session: "); message.append(sessionName).append(" with session file:").append(sessionFile.getAbsolutePath()); LOG.error(message.toString(), e); throw new OpperationFailedException(message.toString(), e); } // Create the projectFourPartName needed for projects with instance // other than 1 to reconfigure properly projectFourPartName = projectSpec + ":project:" + projectInstance; LOG.info("Checking for modifications between " + lastBuild.toString() + " and " + now.toString()); // If we were asked to update the folders, do so if (updateFolders) { refreshReconfigureProperties(); } // Create a list of modifications based upon tasks completed // since the last build. numObjects = 0; numTasks = 0; List modifications = getModifiedTasks(lastBuild); LOG.info("Found " + numObjects + " modified object(s) in " + numTasks + " new task(s)."); // If we were asked to reconfigure the project, do so if (reconfigure && (numObjects > 0)) { reconfigureProject(); } // Pass to the build any relevent properties properties.put("cc.ccm.project", projectFourPartName); properties.put("cc.ccm.dateformat", ccmDateFormat); String sessionID = cmd.getVariable(CCM_SESSION_VAR); if (sessionID != null) { properties.put("cc.ccm.session", sessionID); } if (numObjects > 0) { properties.put(property, "true"); } if (!ignoreWorkarea) { properties.put("cc.ccm.workarea", getWorkarea()); } return modifications; } /** * Update the folders within the given project's reconfigure properties. */ private void refreshReconfigureProperties() { LOG.debug("Refreshing reconfigure properties for project " + projectFourPartName + "."); // Construct the CM Synergy command cmd.clearArgs(); cmd.createArgument("reconfigure_properties"); if (recurse) { cmd.createArgument("-recurse"); } cmd.createArguments("-refresh", projectFourPartName); try { cmd.execute(); cmd.assertExitCode(0); } catch (Exception e) { String message = "Could not refresh reconfigure properties for project \"" + projectFourPartName + "\"."; LOG.error(message, e); throw new OpperationFailedException(message, e); } } /** * Get a list of all tasks which are contained in all folders in the * reconfigure properties of the specified project and were completed after * the last build. If useBindTime is <code>true</code> not the completion time of * the task is considered but the time the task came into the folder. * * @return A list of <code>CMSynergyModifications</code> which represent * the new tasks */ private List getModifiedTasks(Date lastBuild) { // The format used for converting Java dates into CM Synergy dates // Note that the format used to submit commands differs from the // format used in the results of that command!?! SimpleDateFormat toCcmDate = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", locale); // Construct the CM Synergy command cmd.clearArgs(); cmd.createArgument("query"); cmd.createArgument("-u"); // Set up the output format cmd.createArgument("-f"); cmd.createArgument("%displayname" + CCM_ATTR_DELIMITER + // 0 "%release" + CCM_ATTR_DELIMITER + // 1 "%owner" + CCM_ATTR_DELIMITER + // 2 "%completion_date" + CCM_ATTR_DELIMITER + // 3 "%task_synopsis" + CCM_END_OBJECT); // 4 // Construct the query string if (useBindTime) { cmd.createArgument( "is_task_in_folder_of(is_folder_in_rp_of('" + projectFourPartName + "'), '>', time('" + toCcmDate.format(lastBuild) + "'))"); } else { cmd.createArgument( "is_task_in_folder_of(is_folder_in_rp_of('" + projectFourPartName + "')) and completion_date>time('" + toCcmDate.format(lastBuild) + "')"); } // Execute the command try { cmd.execute(); } catch (Exception e) { String message = "Could not query for new tasks."; LOG.error(message, e); throw new OpperationFailedException(message, e); } // create a modification list with discovered tasks List modificationList = new ArrayList(); Iterator tasks = format(cmd.getStdoutAsList()).iterator(); while (tasks.hasNext()) { numTasks++; String[] attributes = tokeniseEntry((String) tasks.next(), 5); if (attributes == null) { LOG.warn("Could not determine attributes for at least one " + "discovered task! The modification set is suspect."); continue; } CMSynergyModification mod = new CMSynergyModification(); mod.taskNumber = attributes[0]; mod.revision = attributes[1]; mod.userName = attributes[2]; mod.modifiedTime = getDateFromSynergy(attributes[3]); mod.comment = attributes[4]; // Populate the included files by quering for objects in the task getModifiedObjects(mod); // Find any Change Requests with which the task is associated getAssociatedCRs(mod); // Add the modification to the list modificationList.add(mod); } return modificationList; } /** * Split the results of a CM Synergy query into individual tokens. This * method was added for compatibility with the 1.3 JRE. * * @param line * The line to be tokenised. * @param maxTokens * The maximum number of tokens in the line * * @return The tokens found */ private String[] tokeniseEntry(String line, int maxTokens) { int minTokens = maxTokens - 1; // comment may be absent. String[] tokens = new String[maxTokens]; Arrays.fill(tokens, ""); int tokenIndex = 0; for (int oldIndex = 0, index = line.indexOf(CCM_ATTR_DELIMITER, 0); true; oldIndex = index + CCM_ATTR_DELIMITER.length(), index = line.indexOf(CCM_ATTR_DELIMITER, oldIndex), tokenIndex++) { if (tokenIndex > maxTokens) { LOG.debug("Too many tokens; skipping entry"); return null; } if (index == -1) { tokens[tokenIndex] = line.substring(oldIndex); break; } tokens[tokenIndex] = line.substring(oldIndex, index); } if (tokenIndex < minTokens) { LOG.debug("Not enough tokens; skipping entry"); return null; } return tokens; } /** * Populate the object list of a Modification by querying for objects * associated with the task. */ private void getModifiedObjects(CMSynergyModification mod) { // Construct the CM Synergy command cmd.clearArgs(); cmd.createArgument("task"); cmd.createArguments("-show", "objects"); // Set up the output format cmd.createArgument("-f"); cmd.createArgument("%name" + CCM_ATTR_DELIMITER + // 0 "%version" + CCM_ATTR_DELIMITER + // 1 "%type" + CCM_ATTR_DELIMITER + // 2 "%instance" + CCM_ATTR_DELIMITER + // 3 "%project" + CCM_ATTR_DELIMITER + // 4 "%comment" + CCM_END_OBJECT); // 5 // Construct the query string cmd.createArgument(mod.taskNumber); // Execute the command try { cmd.execute(); } catch (Exception e) { LOG.warn("Could not query for objects in task \"" + mod.taskNumber + "\". The modification list will be incomplete!", e); } // Populate the modification with the object data from the task Iterator objects = format(cmd.getStdoutAsList()).iterator(); while (objects.hasNext()) { numObjects++; String object = (String) objects.next(); String[] attributes = tokeniseEntry(object, 6); if (attributes == null) { LOG.warn("Could not determine attributes for object associated " + "with task \"" + mod.revision + "\"."); continue; } // Add each object to the CMSynergyModification mod.createModifiedObject(attributes[0], attributes[1], attributes[2], attributes[3], attributes[4], attributes[5]); } } /** * Queries the CM Synergy repository to find any Change Requests with which * a task is associated. If the Change Synergy URL and database were * provided, we will add HTML based links to those CRs. * * @param mod * The modification object */ private void getAssociatedCRs(CMSynergyModification mod) { // Construct the CM Synergy command cmd.clearArgs(); cmd.createArgument("query"); cmd.createArgument("-u"); // Set up the output format cmd.createArguments("-f", "%displayname"); // Construct the query string cmd.createArgument( "cvtype='problem' and has_associated_task('task" + mod.taskNumber + ccmDelimiter + "1:task:probtrac')"); // Execute the command try { cmd.execute(); } catch (Exception e) { LOG.warn("Could not query for associated CRs. The modification list " + "may be incomplete!", e); } // Add the Change Request(s) to the modification List crList = cmd.getStdoutAsList(); if (crList != null) { Iterator crs = crList.iterator(); while (crs.hasNext()) { String crNum = ((String) crs.next()).trim(); CMSynergyModification.ChangeRequest cr = mod.createChangeRequest(crNum); if (changeSynergyURL != null && ccmDb != null) { StringBuffer href = new StringBuffer(changeSynergyURL); href.append("/servlet/com.continuus.webpt.servlet.PTweb?"); href.append("ACTION_FLAG=frameset_form&#38;TEMPLATE_FLAG=ProblemReportView&#38;database="); href.append(ccmDb); href.append("&#38;role=User&#38;problem_number="); href.append(crNum); cr.href = href.toString(); } } } } /** * Determine the work area location for the specified project. * * @return The work area location */ private String getWorkarea() { String defaultWorkarea = "."; // Get the literal workarea from Synergy cmd.clearArgs(); cmd.createArgument("attribute"); cmd.createArguments("-show", "wa_path"); cmd.createArguments("-project", projectFourPartName); try { cmd.execute(); cmd.assertExitCode(0); } catch (Exception e) { LOG.warn("Could not determine the workarea location for project \"" + projectFourPartName + "\".", e); return defaultWorkarea; } // The command will return the literal work area, but what we are // really interested in is the top level directory within that work // area. File workareaPath = new File(cmd.getStdoutAsString().trim()); if (!workareaPath.isDirectory()) { LOG.warn("The workarea reported by Synergy does not exist or is not accessible by this session - \"" + workareaPath.toString() + "\"."); return defaultWorkarea; } String[] dirs = workareaPath.list(); if (dirs.length != 1) { LOG.warn("The workarea reported by Synergy is invalid - \"" + workareaPath.toString() + "\"."); return defaultWorkarea; } // Found it! return workareaPath.getAbsolutePath() + File.separator + dirs[0]; } /** * Reconfigure the project */ private void reconfigureProject() { LOG.debug("Reconfiguring project " + projectFourPartName + "."); // Construct the CM Synergy command cmd.clearArgs(); cmd.createArgument("reconfigure"); if (recurse) { cmd.createArgument("-recurse"); } cmd.createArguments("-project", projectFourPartName); try { cmd.execute(); cmd.assertExitCode(0); } catch (Exception e) { String message = "Could not reconfigure project \"" + projectFourPartName + "\"."; LOG.error(message, e); throw new OpperationFailedException(message, e); } } /** * Format the output of a CM Synergy query by removing newlines introduced * by comments. * * @param in * The <code>List</code> to be formated * @return The formated <code>List</code> */ private List format(List in) { // Concatenate output lines until we hit the end of object delimiter. List out = new ArrayList(); Iterator it = in.iterator(); StringBuffer buff = new StringBuffer(); while (it.hasNext()) { buff.append((String) it.next()); int index = buff.toString().lastIndexOf(CCM_END_OBJECT); if (index > -1) { buff.delete(index, buff.length()); out.add(buff.toString()); buff = new StringBuffer(); } } return out; } /** * Parse a CM Synergy date string into a Java <code>Date</code>. If the * string cannot be parsed, a warning is written to the log, and the current * date is returned. * * @param dateString * the date string to parse * @return The date * * @see #setCcmDateFormat(String) */ private Date getDateFromSynergy(String dateString) { SimpleDateFormat fromCcmDate = new SimpleDateFormat(ccmDateFormat, locale); Date date; try { date = fromCcmDate.parse(dateString); } catch (ParseException e) { LOG.warn("Could not parse CM Synergy date \"" + dateString + "\" into Java Date using format \"" + ccmDateFormat + "\".", e); date = new Date(); } return date; } /** * Given a CM Synergy session name, looks up the corresponding session ID. * * @param sessionName * The CM Synergy session name * @param sessionFile * The session map file * @return The session ID. */ public static String getSessionID(String sessionName, File sessionFile) throws CruiseControlException { // If no session file was provided, try to use the default if (sessionFile == null) { sessionFile = new File(CCM_SESSION_FILE); } // Load the persisted session information from file Properties sessionProperties; try { sessionProperties = Util.loadPropertiesFromFile(sessionFile); } catch (IOException e) { throw new CruiseControlException(e); } // Look up and return the full session ID return sessionProperties.getProperty(sessionName); } /** * Creates a <code>ManagedCommandline</code> configured to run CM Synergy * commands. * * @param ccmExe * Full path of the CM Synergy command line client (or * <code>null</code> to use the default). * @param sessionName * The name of the session as stored in the map file (or * <code>null</code> to use the default session). * @param sessionFile * The CM Synergy session map file (or <code>null</code> to use * the default). * @return A configured <code>ManagedCommandline</code> */ public static ManagedCommandline createCcmCommand(String ccmExe, String sessionName, File sessionFile) { // If no executable name was provided, use the default if (ccmExe == null) { ccmExe = CCM_EXE; } // Attempt to get the appropriate CM Synergy session String sessionID = null; if (sessionName != null) { try { sessionID = getSessionID(sessionName, sessionFile); if (sessionID == null) { LOG.error("Could not find a session ID for CM Synergy session named \"" + sessionName + "\". Attempting to use the default (current) session."); } } catch (CruiseControlException e) { LOG.error("Failed to look up CM Synergy session named \"" + sessionName + "\". Attempting to use the default (current) session.", e); } } // Create a managed command line ManagedCommandline command = new ManagedCommandline(ccmExe); // If we were able to find a CM Synergy session ID, use it if (sessionID != null) { command.setVariable(CCM_SESSION_VAR, sessionID); } return command; } class OpperationFailedException extends RuntimeException { public OpperationFailedException(String message, Exception e) { super(message, e); } } }

The table below shows all metrics for CMSynergy.java.

MetricValueDescription
BLOCKS81.00Number of blocks
BLOCK_COMMENT 0.00Number of block comment lines
COMMENTS395.00Comment lines
COMMENT_DENSITY 1.17Comment density
COMPARISONS34.00Number of comparison operators
CYCLOMATIC72.00Cyclomatic complexity
DECL_COMMENTS58.00Comments in declarations
DOC_COMMENT348.00Number of javadoc comment lines
ELOC338.00Effective lines of code
EXEC_COMMENTS40.00Comments in executable code
EXITS60.00Procedure exits
FUNCTIONS31.00Number of function declarations
HALSTEAD_DIFFICULTY70.14Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY71.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 1.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 1.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 7.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 1.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 2.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 1.00JAVA0128 Public constructor in non-public class
JAVA0130 2.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 1.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 7.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 2.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 2.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 4.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES915.00Number of lines in the source file
LINE_COMMENT47.00Number of line comments
LOC410.00Lines of code
LOGICAL_LINES232.00Number of statements
LOOPS 5.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS979.00Number of operands
OPERATORS1674.00Number of operators
PARAMS32.00Number of formal parameter declarations
PROGRAM_LENGTH2653.00Halstead program length
PROGRAM_VOCAB383.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS39.00Number of return points from functions
SIZE32569.00Size of the file in bytes
UNIQUE_OPERANDS335.00Number of unique operands
UNIQUE_OPERATORS48.00Number of unique operators
WHITESPACE110.00Number of whitespace lines