ConcurrentVersionsSystem.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
SIZESize of the file in bytes
DECL_COMMENTSComments in declarations
COMPARISONSNumber of comparison operators
CYCLOMATICCyclomatic complexity
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
DOC_COMMENTNumber of javadoc comment lines
BLOCKSNumber of blocks
RETURNSNumber of return points from functions
LOGICAL_LINESNumber of statements
LINESNumber of lines in the source file
UNIQUE_OPERANDSNumber of unique operands
COMMENTSComment lines
OPERANDSNumber of operands
PROGRAM_LENGTHHalstead program length
ELOCEffective lines of code
OPERATORSNumber of operators
PROGRAM_VOCABHalstead program vocabulary
JAVA0177JAVA0177 Variable declaration missing initializer
EXITSProcedure exits
LOCLines of code
INTERFACE_COMPLEXITYInterface complexity
JAVA0034JAVA0034 Missing braces in if statement
JAVA0117JAVA0117 Missing javadoc: method 'method'
FUNCTIONSNumber of function declarations
JAVA0166JAVA0166 Generic exception caught
WHITESPACENumber of whitespace lines
JAVA0096JAVA0096 Field in nested class hides outer field
JAVA0130JAVA0130 Non-static method does not use instance fields
UNIQUE_OPERATORSNumber of unique operators
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0128JAVA0128 Public constructor in non-public class
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
PARAMSNumber of formal parameter declarations
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0145JAVA0145 Tab character used in source file
/******************************************************************************** * CruiseControl, a Continuous Integration Toolkit * Copyright (c) 2001-2003, 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.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Serializable; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import net.sourceforge.cruisecontrol.CruiseControlException; import net.sourceforge.cruisecontrol.Modification; import net.sourceforge.cruisecontrol.SourceControl; import net.sourceforge.cruisecontrol.util.CVSDateUtil; import net.sourceforge.cruisecontrol.util.Commandline; import net.sourceforge.cruisecontrol.util.DiscardConsumer; import net.sourceforge.cruisecontrol.util.OSEnvironment; import net.sourceforge.cruisecontrol.util.StreamLogger; import net.sourceforge.cruisecontrol.util.StreamPumper; import net.sourceforge.cruisecontrol.util.ValidationHelper; import net.sourceforge.cruisecontrol.util.IO; import org.apache.log4j.Logger; /** * This class implements the SourceControlElement methods for a CVS repository. The call to CVS is assumed to work * without any setup. This implies that if the authentication type is pserver the call to cvs login should be done prior * to calling this class. <p/> There are also differing CVS client/server implementations (e.g. the <i>official</i> CVS * and the CVSNT fork). <p/> Note that the LOG formats of the official CVS have changed starting from version 1.12.9. * This class currently knows of 2 different outputs referred to as the 'old' and the 'new' output formats. * * @author <a href="mailto:pj@thoughtworks.com">Paul Julius</a> * @author Robert Watkins * @author Frederic Lavigne * @author <a href="mailto:jcyip@thoughtworks.com">Jason Yip</a> * @author Marc Paquette * @author <a href="mailto:johnny.cass@epiuse.com">Johnny Cass</a> * @author <a href="mailto:m@loonsoft.com">McClain Looney</a> */ public class ConcurrentVersionsSystem implements SourceControl { private static final long serialVersionUID = -3714548093682602092L; /** * name of the official cvs as returned as part of the 'cvs version' command output */ static final String OFFICIAL_CVS_NAME = "CVS"; static final Version DEFAULT_CVS_SERVER_VERSION = new Version(OFFICIAL_CVS_NAME, "1.11"); public static final String LOG_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss z"; private boolean reallyQuiet; private String compression; /** * Represents the version of a CVS client or server */ static class Version implements Serializable { private static final long serialVersionUID = -2433230091640056090L; private final String cvsName; private final String cvsVersion; public Version(String name, String version) { if (name == null) { throw new IllegalArgumentException("name can't be null"); } if (version == null) { throw new IllegalArgumentException("version can't be null"); } this.cvsName = name; this.cvsVersion = version; } public String getCvsName() { return cvsName; } public String getCvsVersion() { return cvsVersion; } public boolean equals(Object o) { if (this == o) { return true; } else if (!(o instanceof Version)) { return false; } final Version version = (Version) o; if (!cvsName.equals(version.cvsName)) { return false; } else if (!cvsVersion.equals(version.cvsVersion)) { return false; } return true; } public int hashCode() { int result; result = cvsName.hashCode(); result = 29 * result + cvsVersion.hashCode(); return result; } public String toString() { return cvsName + " " + cvsVersion; } } private SourceControlProperties properties = new SourceControlProperties(); /** * CVS allows for mapping user names to email addresses. If CVSROOT/users exists, it's contents will be parsed and * stored in this hashtable. */ private Hashtable mailAliases; /** * The caller can provide the CVSROOT to use when calling CVS, or the CVSROOT environment variable will be used. */ private String cvsroot; /** * The caller must indicate where the local copy of the repository exists. */ private String local; /** * The CVS tag we are dealing with. */ private String tag; /** * The CVS module we are dealing with. */ private String module; /** * The version of the cvs server */ private Version cvsServerVersion; /** * enable logging for this class */ private static final Logger LOG = Logger.getLogger(ConcurrentVersionsSystem.class); /** * This line delimits separate files in the CVS LOG information. */ private static final String CVS_FILE_DELIM = "===================================================================" + "=========="; /** * This is the keyword that precedes the name of the RCS filename in the CVS LOG information. */ private static final String CVS_RCSFILE_LINE = "RCS file: "; /** * This is the keyword that precedes the name of the working filename in the CVS LOG information. */ private static final String CVS_WORKINGFILE_LINE = "Working file: "; /** * This line delimits the different revisions of a file in the CVS LOG information. */ private static final String CVS_REVISION_DELIM = "----------------------------"; /** * This is the keyword that precedes the timestamp of a file revision in the CVS LOG information. */ private static final String CVS_REVISION_DATE = "date:"; /** * This is the name of the tip of the main branch, which needs special handling with the LOG entry parser */ private static final String CVS_HEAD_TAG = "HEAD"; /** * This is the keyword that tells us when we have reached the end of the header as found in the CVS LOG information. */ private static final String CVS_DESCRIPTION = "description:"; /** * This is a state keyword which indicates that a revision to a file was not relevant to the current branch, or the * revision consisted of a deletion of the file (removal from branch..). */ private static final String CVS_REVISION_DEAD = "dead"; /** * System dependent new line separator. */ private static final String NEW_LINE = System.getProperty("line.separator"); /** * This is the date format returned in the LOG information from CVS. */ private final SimpleDateFormat logDateFormatter = new SimpleDateFormat(LOG_DATE_FORMAT); /** * Sets the CVSROOT for all calls to CVS. * * @param cvsroot * CVSROOT to use. */ public void setCvsRoot(String cvsroot) { this.cvsroot = cvsroot; } /** * Sets the local working copy to use when making calls to CVS. * * @param local * String indicating the relative or absolute path to the local working copy of the module of which to * find the LOG history. */ public void setLocalWorkingCopy(String local) { this.local = local; } /** * Set the cvs tag. Note this should work with names, numbers, and anything else you can put on LOG -rTAG * * @param tag * the cvs tag */ public void setTag(String tag) { this.tag = tag; } /** * Set the cvs module name. Note that this is only used when localworkingcopy is not set. * * @param module * the cvs module */ public void setModule(String module) { this.module = module; } public void setProperty(String property) { properties.assignPropertyName(property); } public void setPropertyOnDelete(String propertyOnDelete) { properties.assignPropertyOnDeleteName(propertyOnDelete); } /** * @param reallyQuiet When true, this class should use the -Q cvs option instead of -q for the LOG command. */ public void setReallyQuiet(boolean reallyQuiet) { this.reallyQuiet = reallyQuiet; } /** * Sets the compression level used for the call to cvs, corresponding to the "-z" command line parameter. When not * set, the command line parameter is NOT included. * * @param level Valid levels are 1 (high speed, low compression) to 9 (low speed, high compression), or 0 * to disable compression. */ public void setCompression(String level) { compression = level; } protected Version getCvsServerVersion() { if (cvsServerVersion == null) { Commandline commandLine = getCommandline(); commandLine.setExecutable("cvs"); if (cvsroot != null) { commandLine.createArguments("-d", cvsroot); } commandLine.createArgument().setLine("version"); Process p = null; try { if (local != null) { commandLine.setWorkingDirectory(local); } p = commandLine.execute(); Thread stderr = logErrorStream(p); InputStream is = p.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); cvsServerVersion = extractCVSServerVersionFromCVSVersionCommandOutput(in); LOG.debug("cvs server version: " + cvsServerVersion); p.waitFor(); stderr.join(); IO.close(p); } catch (IOException e) { LOG.error("Failed reading cvs server version", e); } catch (CruiseControlException e) { LOG.error("Failed reading cvs server version", e); } catch (InterruptedException e) { LOG.error("Failed reading cvs server version", e); } if (p == null || p.exitValue() != 0 || cvsServerVersion == null) { if (p == null) { LOG.debug("Process p was null in CVS.getCvsServerVersion()"); } else { LOG.debug("Process exit value = " + p.exitValue()); } cvsServerVersion = DEFAULT_CVS_SERVER_VERSION; LOG.warn("problem getting cvs server version; using " + cvsServerVersion); } } return cvsServerVersion; } /** * This method retrieves the cvs server version from the specified output. The line it parses will have the * following format: * * <pre> * Server: Concurrent Versions System (CVS) 1.11.16 (client/server) * </pre> * * @param in * @return the version of null if the version couldn't be extracted * @throws IOException */ private Version extractCVSServerVersionFromCVSVersionCommandOutput(BufferedReader in) throws IOException { String line = in.readLine(); if (line == null) { return null; } if (line.startsWith("Client:")) { line = in.readLine(); if (line == null) { return null; } if (!line.startsWith("Server:")) { LOG.warn("Warning expected a line starting with \"Server:\" but got " + line); // we try anyway } } LOG.debug("server version line: " + line); int nameBegin = line.indexOf(" ("); int nameEnd = line.indexOf(") ", nameBegin); final String name; final String version; if (nameBegin == -1 || nameEnd < nameBegin || nameBegin + 2 >= line.length()) { LOG.warn("cvs server version name couldn't be parsed from " + line); return null; } name = line.substring(nameBegin + 2, nameEnd); int verEnd = line.indexOf(" ", nameEnd + 2); if (verEnd < nameEnd + 2) { LOG.warn("cvs server version number couldn't be parsed from " + line); return null; } version = line.substring(nameEnd + 2, verEnd); return new Version(name, version); } public boolean isCvsNewOutputFormat() { Version version = getCvsServerVersion(); if (OFFICIAL_CVS_NAME.equals(version.getCvsName())) { String csv = version.getCvsVersion(); StringTokenizer st = new StringTokenizer(csv, "."); try { st.nextToken(); int subversion = Integer.parseInt(st.nextToken()); if (subversion > 11) { if (subversion == 12) { if (Integer.parseInt(st.nextToken()) < 9) { return false; } } return true; } } catch (Throwable e) { LOG.warn("problem identifying cvs server. Assuming output is of 'old' type"); } } return false; } public Map getProperties() { return properties.getPropertiesAndReset(); } /** * for mocking * */ protected OSEnvironment getOSEnvironment() { return new OSEnvironment(); } public void validate() throws CruiseControlException { ValidationHelper.assertFalse(local == null && (cvsroot == null || module == null), "must specify either 'localWorkingCopy' or 'cvsroot' and 'module' on CVS"); ValidationHelper.assertFalse(local != null && (cvsroot != null || module != null), "if 'localWorkingCopy' is specified then cvsroot and module are not allowed on CVS"); ValidationHelper.assertFalse(local != null && !new File(local).exists(), "Local working copy \"" + local + "\" does not exist!"); if (compression != null) { ValidationHelper.assertIntegerInRange(compression, 0, 9, "'compression' must be an integer between 0 and 9, inclusive."); } } /** * Returns a List of Modifications detailing all the changes between the last build and the latest revision at the * repository * * @param lastBuild * last build time * @return maybe empty, never null. */ public List getModifications(Date lastBuild, Date now) { mailAliases = getMailAliases(); List mods = null; try { mods = execHistoryCommand(buildHistoryCommand(lastBuild, now)); } catch (Exception e) { LOG.error("Log command failed to execute successfully", e); } if (mods == null) { return new ArrayList(); } return mods; } /** * Get CVS's idea of user/address mapping. Only runs once per class instance. Won't run if the mailAlias was already * set. * * @return a Hashtable containing the mapping defined in CVSROOT/users. If CVSROOT/users doesn't exist, an empty * Hashtable is returned. */ private Hashtable getMailAliases() { if (mailAliases == null) { mailAliases = new Hashtable(); Commandline commandLine = getCommandline(); commandLine.setExecutable("cvs"); if (cvsroot != null) { commandLine.createArguments("-d", cvsroot); } commandLine.createArgument().setLine("-q co -p CVSROOT/users"); Process p = null; try { if (local != null) { commandLine.setWorkingDirectory(local); } p = commandLine.execute(); Thread stderr = logErrorStream(p); InputStream is = p.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(is)); String line; while ((line = in.readLine()) != null) { addAliasToMap(line); } p.waitFor(); stderr.join(); IO.close(p); } catch (Exception e) { LOG.error("Failed reading mail aliases", e); } if (p == null || p.exitValue() != 0) { if (p == null) { LOG.debug("Process p was null in CVS.getMailAliases()"); } else { LOG.debug("Process exit value = " + p.exitValue()); } LOG.warn("problem getting CVSROOT/users; using empty email map"); mailAliases = new Hashtable(); } } return mailAliases; } void addAliasToMap(String line) { LOG.debug("Mapping " + line); int colon = line.indexOf(':'); if (colon >= 0) { String user = line.substring(0, colon); String address = line.substring(colon + 1); mailAliases.put(user, address); } } /** * @param lastBuildTime * @param checkTime * @return CommandLine for "cvs -d CVSROOT -q LOG -N -dlastbuildtime<checktime " */ public Commandline buildHistoryCommand(Date lastBuildTime, Date checkTime) throws CruiseControlException { Commandline commandLine = getCommandline(); commandLine.setExecutable("cvs"); if (compression != null) { commandLine.createArgument("-z" + compression); } if (cvsroot != null) { commandLine.createArguments("-d", cvsroot); } commandLine.createArgument(reallyQuiet ? "-Q" : "-q"); if (local != null) { commandLine.setWorkingDirectory(local); commandLine.createArgument("log"); } else { commandLine.createArgument("rlog"); } if (useHead()) { commandLine.createArgument("-N"); } String dateRange = formatCVSDate(lastBuildTime) + "<" + formatCVSDate(checkTime); commandLine.createArgument("-d" + dateRange); if (!useHead()) { // add -b and -rTAG to list changes relative to the current branch, // not relative to the default branch, which is HEAD // note: -r cannot have a space between itself and the tag spec. commandLine.createArgument("-r" + tag); } else { // This is used to include the head only if a Tag is not specified. commandLine.createArgument("-b"); } if (local == null) { commandLine.createArgument(module); } return commandLine; } // factory method for mock... protected Commandline getCommandline() { return new Commandline(); } static String formatCVSDate(Date date) { return CVSDateUtil.formatCVSDate(date); } /** * Parses the input stream, which should be from the cvs LOG command. This method will format the data found in the * input stream into a List of Modification instances. * * @param input * InputStream to get LOG data from. * @return List of Modification elements, maybe empty never null. * @throws IOException */ protected List parseStream(InputStream input) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(input)); // Read to the first RCS file name. The first entry in the LOG // information will begin with this line. A CVS_FILE_DELIMITER is NOT // present. If no RCS file lines are found then there is nothing to do. String line = readToNotPast(reader, CVS_RCSFILE_LINE, null); ArrayList mods = new ArrayList(); while (line != null) { // Parse the single file entry, which may include several // modifications. List returnList = parseEntry(reader, line); // Add all the modifications to the local list. mods.addAll(returnList); // Read to the next RCS file line. The CVS_FILE_DELIMITER may have // been consumed by the parseEntry method, so we cannot read to it. line = readToNotPast(reader, CVS_RCSFILE_LINE, null); } return mods; } private void getRidOfLeftoverData(InputStream stream) { new StreamPumper(stream, new DiscardConsumer()).run(); } private List execHistoryCommand(Commandline command) throws Exception { Process p = command.execute(); Thread stderr = logErrorStream(p); InputStream cvsLogStream = p.getInputStream(); List mods = parseStream(cvsLogStream); getRidOfLeftoverData(cvsLogStream); p.waitFor(); stderr.join(); IO.close(p); return mods; } protected void setMailAliases(Hashtable mailAliases) { this.mailAliases = mailAliases; } private static Thread logErrorStream(Process p) { return logErrorStream(p.getErrorStream()); } static Thread logErrorStream(InputStream error) { Thread stderr = new Thread(StreamLogger.getWarnPumper(LOG, error)); stderr.start(); return stderr; } // (PENDING) Extract CVSEntryParser class /** * Parses a single file entry from the reader. This entry may contain zero or more revisions. This method may * consume the next CVS_FILE_DELIMITER line from the reader, but no further. <p/> When the LOG is related to a non * branch tag, only the last modification for each file will be listed. * * @param reader * Reader to parse data from. * @return modifications found in this entry; maybe empty, never null. * @throws IOException */ private List parseEntry(BufferedReader reader, String rcsLine) throws IOException { ArrayList mods = new ArrayList(); String nextLine = ""; // Read to the working file name line to get the filename. // If working file name line isn't found we'll extract is from the RCS file line String workingFileName; if (module != null && cvsroot != null) { final String repositoryRoot = cvsroot.substring(cvsroot.lastIndexOf(":") + 1); final int startAt = "RCS file: ".length() + repositoryRoot.length(); workingFileName = rcsLine.substring(startAt, rcsLine.length() - 2); } else { String workingFileLine = readToNotPast(reader, CVS_WORKINGFILE_LINE, null); workingFileName = workingFileLine.substring(CVS_WORKINGFILE_LINE.length()); } String branchRevisionName = parseBranchRevisionName(reader); boolean newCVSVersion = isCvsNewOutputFormat(); while (nextLine != null && !nextLine.startsWith(CVS_FILE_DELIM)) { nextLine = readToNotPast(reader, "revision", CVS_FILE_DELIM); if (nextLine == null) { // No more revisions for this file. break; } StringTokenizer tokens = new StringTokenizer(nextLine, " "); tokens.nextToken(); String revision = tokens.nextToken(); if (!useHead()) { if (!revision.equals(branchRevisionName)) { // Indeed this is a branch, not just a regular tag String itsBranchRevisionName = revision.substring(0, revision.lastIndexOf('.')); if (!itsBranchRevisionName.equals(branchRevisionName)) { break; } } } // Read to the revision date. It is ASSUMED that each revision // section will include this date information line. nextLine = readToNotPast(reader, CVS_REVISION_DATE, CVS_FILE_DELIM); if (nextLine == null) { break; } tokens = new StringTokenizer(nextLine, " \t\n\r\f;"); // First token is the keyword for date, then the next two should be // the date and time stamps. tokens.nextToken(); String dateStamp = tokens.nextToken(); String timeStamp = tokens.nextToken(); // New format sometimes has a +0000 in it. This skips it if we don't see // the start of the author: section String isThisTimeOffset = tokens.nextToken(); if (!isThisTimeOffset.equals("author:")) { tokens.nextToken(); } // The next token should be the author keyword, then the author name. String authorName = tokens.nextToken(); // The next token should be the state keyword, then the state name. tokens.nextToken(); String stateKeyword = tokens.nextToken(); // if no lines keyword then file is added boolean isAdded = !tokens.hasMoreTokens(); // All the text from now to the next revision delimiter or working // file delimiter constitutes the message. String message = ""; nextLine = reader.readLine(); boolean multiLine = false; while (nextLine != null && !nextLine.startsWith(CVS_FILE_DELIM) && !nextLine.startsWith(CVS_REVISION_DELIM)) { if (multiLine) { message += NEW_LINE; } else { multiLine = true; } message += nextLine; // Go to the next line. nextLine = reader.readLine(); } Modification nextModification = new Modification("cvs"); nextModification.revision = revision; int lastSlashIndex = workingFileName.lastIndexOf("/"); String fileName, folderName = null; fileName = workingFileName.substring(lastSlashIndex + 1); if (lastSlashIndex != -1) { folderName = workingFileName.substring(0, lastSlashIndex); } Modification.ModifiedFile modfile = nextModification.createModifiedFile(fileName, folderName); modfile.revision = nextModification.revision; try { if (newCVSVersion) { nextModification.modifiedTime = CVSDateUtil.parseCVSDate(dateStamp + " " + timeStamp + " GMT"); } else { nextModification.modifiedTime = logDateFormatter.parse(dateStamp + " " + timeStamp + " GMT"); } } catch (ParseException pe) { LOG.error("Error parsing cvs LOG for date and time", pe); return null; } nextModification.userName = authorName; String address = (String) mailAliases.get(authorName); if (address != null) { nextModification.emailAddress = address; } nextModification.comment = message; if (stateKeyword.equalsIgnoreCase(CVS_REVISION_DEAD) && message.indexOf("was initially added on branch") != -1) { LOG.debug("skipping branch addition activity for " + nextModification); // this prevents additions to a branch from showing up as action "deleted" from head continue; } if (stateKeyword.equalsIgnoreCase(CVS_REVISION_DEAD)) { modfile.action = "deleted"; properties.deletionFound(); } else if (isAdded) { modfile.action = "added"; } else { modfile.action = "modified"; } properties.modificationFound(); mods.add(nextModification); } return mods; } /** * Find the CVS branch revision name, when the tag is not HEAD The reader will consume all lines up to the next * description. * * @return the branch revision name, or <code>null</code> if not applicable or none was found. */ private String parseBranchRevisionName(BufferedReader reader) throws IOException { String branchRevisionName = null; if (!useHead()) { // Look for the revision of the form "tag: *.(0.)y ". this doesn't work for HEAD // get line with branch revision on it. String branchRevisionLine = readToNotPast(reader, "\t" + tag + ": ", CVS_DESCRIPTION); if (branchRevisionLine != null) { // Look for the revision of the form "tag: *.(0.)y ", return "*.y" branchRevisionName = branchRevisionLine.substring(tag.length() + 3); if (branchRevisionName.charAt(branchRevisionName.lastIndexOf(".") - 1) == '0') { branchRevisionName = branchRevisionName.substring(0, branchRevisionName.lastIndexOf(".") - 2) + branchRevisionName.substring(branchRevisionName.lastIndexOf(".")); } } } return branchRevisionName; } /** * This method will consume lines from the reader up to the line that begins with the String specified but not past * a line that begins with the notPast String. If the line that begins with the beginsWith String is found then it * will be returned. Otherwise null is returned. * * @param reader * Reader to read lines from. * @param beginsWith * String to match to the beginning of a line. * @param notPast * String which indicates that lines should stop being consumed, even if the begins with match has not * been found. Pass null to this method to ignore this string. * @return String that begin as indicated, or null if none matched to the end of the reader or the notPast line was * found. * @throws IOException */ private static String readToNotPast(BufferedReader reader, String beginsWith, String notPast) throws IOException { boolean checkingNotPast = notPast != null; String nextLine = reader.readLine(); while (nextLine != null && !nextLine.startsWith(beginsWith)) { if (checkingNotPast && nextLine.startsWith(notPast)) { return null; } nextLine = reader.readLine(); } return nextLine; } boolean useHead() { return tag == null || tag.equals(CVS_HEAD_TAG) || tag.equals(""); } }

The table below shows all metrics for ConcurrentVersionsSystem.java.

MetricValueDescription
BLOCKS114.00Number of blocks
BLOCK_COMMENT 0.00Number of block comment lines
COMMENTS256.00Comment lines
COMMENT_DENSITY 0.64Comment density
COMPARISONS91.00Number of comparison operators
CYCLOMATIC121.00Cyclomatic complexity
DECL_COMMENTS38.00Comments in declarations
DOC_COMMENT221.00Number of javadoc comment lines
ELOC403.00Effective lines of code
EXEC_COMMENTS22.00Comments in executable code
EXITS73.00Procedure exits
FUNCTIONS36.00Number of function declarations
HALSTEAD_DIFFICULTY82.47Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY104.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 1.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 0.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 1.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.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 2.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 1.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 2.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 1.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 2.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 1.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 9.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 3.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 1.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 6.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 0.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 0.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
LINES889.00Number of lines in the source file
LINE_COMMENT35.00Number of line comments
LOC501.00Lines of code
LOGICAL_LINES279.00Number of statements
LOOPS 5.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS1174.00Number of operands
OPERATORS2137.00Number of operators
PARAMS30.00Number of formal parameter declarations
PROGRAM_LENGTH3311.00Halstead program length
PROGRAM_VOCAB414.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS74.00Number of return points from functions
SIZE32860.00Size of the file in bytes
UNIQUE_OPERANDS363.00Number of unique operands
UNIQUE_OPERATORS51.00Number of unique operators
WHITESPACE132.00Number of whitespace lines