WeblogPublisher.java

Index Score
net.sourceforge.cruisecontrol.publishers
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
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
INTERFACE_COMPLEXITYInterface complexity
PARAMSNumber of formal parameter declarations
RETURNSNumber of return points from functions
SIZESize of the file in bytes
DOC_COMMENTNumber of javadoc comment lines
DECL_COMMENTSComments in declarations
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
BLOCKSNumber of blocks
JAVA0130JAVA0130 Non-static method does not use instance fields
OPERANDSNumber of operands
COMMENTSComment lines
LINESNumber of lines in the source file
JAVA0166JAVA0166 Generic exception caught
LOGICAL_LINESNumber of statements
ELOCEffective lines of code
PROGRAM_LENGTHHalstead program length
EXITSProcedure exits
LOCLines of code
OPERATORSNumber of operators
FUNCTIONSNumber of function declarations
CYCLOMATICCyclomatic complexity
JAVA0096JAVA0096 Field in nested class hides outer field
JAVA0160JAVA0160 Method does not throw specified exception
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0075JAVA0075 Method parameter hides field
COMPARISONSNumber of comparison operators
JAVA0034JAVA0034 Missing braces in if statement
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0138JAVA0138 N parameters defined for method (maximum: M)
JAVA0117JAVA0117 Missing javadoc: method 'method'
UNIQUE_OPERATORSNumber of unique operators
JAVA0077JAVA0077 Private field not used in declaring class
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
EXEC_COMMENTSComments in executable code
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
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.publishers; import java.io.File; import java.io.IOException; import java.io.Serializable; import java.io.StringWriter; import java.net.MalformedURLException; import java.net.URL; import java.util.Calendar; import java.util.Collection; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; import java.util.Vector; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import net.sourceforge.cruisecontrol.CruiseControlException; import net.sourceforge.cruisecontrol.Publisher; import net.sourceforge.cruisecontrol.util.XMLLogHelper; import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcClient; import org.jdom.Element; /** * <p> * Used to publish a blog entry based on the build report using the Blogger API, * MetaWeblog API or the LiveJournal API. * </p> * <p> * Here's a sample of the publisher element to put into your <tt>config.xml</tt>: * </p> * * <pre> * &lt;weblog blogurl=&quot;http://yourblogserver:port/blog/xmlrpc&quot; * api=&quot;metaweblog&quot; * blogid=&quot;yourblog&quot; * username=&quot;user1&quot; * password=&quot;secret&quot; * category=&quot;cruisecontrol&quot; * reportsuccess=&quot;fixes&quot; * subjectprefix=&quot;[CC]&quot; * buildresultsurl=&quot;http://yourbuildserver:port/cc/buildresults&quot; * logdir=&quot;/var/cruisecontrol/logs/YourProject&quot; * xsldir=&quot;/opt/cruisecontrol/reporting/jsp/xsl&quot; * css=&quot;/opt/cruisecontrol/reporting/jsp/css/cruisecontrol.css&quot; * /&gt; * </pre> * * <p> * And you also need to register the 'weblog' task with the following entry if * you're using this task with an older version of CruiseControl which doesn't * have the WeblogPublisher registered by default. * * <pre> * &lt;project name=&quot;foo&quot;&gt; * &lt;plugin name=&quot;weblog&quot; * classname=&quot;net.sourceforge.cruisecontrol.publishers.WeblogPublisher&quot;/&gt; * ... * &lt;/project&gt; * </pre> * * @author Lasse Koskela */ public class WeblogPublisher implements Publisher { private static final long serialVersionUID = -34809809594503919L; private static final Logger LOG = Logger.getLogger(WeblogPublisher.class); private static final String APP_KEY = "CruiseControl Blog Publisher"; private static final String DEFAULT_API = "metaweblog"; private static final String DEFAULT_REPORTSUCCESS = "always"; private static final boolean DEFAULT_SPAMWHILEBROKEN = true; // blogging configurations private String blogId; private String api = DEFAULT_API; private String username; private String password; private String category = ""; private String blogUrl; private String buildResultsURL; private String reportSuccess = DEFAULT_REPORTSUCCESS; private boolean spamWhileBroken = DEFAULT_SPAMWHILEBROKEN; private String subjectPrefix; // transformation resources private String xslFile; private String xslDir; private String css; private String logDir; private String[] xslFileNames = { "header.xsl", "maven.xsl", "checkstyle.xsl", "compile.xsl", "javadoc.xsl", "unittests.xsl", "modifications.xsl", "distributables.xsl" }; private static final Map API_CLIENTS = new HashMap(); static { API_CLIENTS.put("metaweblog", MetaWeblogApiClient.class); API_CLIENTS.put("blogger", BloggerApiClient.class); API_CLIENTS.put("livejournal", LiveJournalApiClient.class); } // --- ACCESSORS --- /** * If xslFile is set then both xslDir and css are ignored. Specified xslFile * must take care of entire document -- html open/close, body tags, styles, * etc. */ public void setXSLFile(String fullPathToXslFile) { xslFile = fullPathToXslFile; } /** * Directory where xsl files are located. */ public void setXSLDir(String xslDirectory) { xslDir = xslDirectory; } /** * Method to override the default list of file names that will be looked for * in the directory specified by xslDir. By default these are the standard * CruseControl xsl files: <br> * <ul> * header.xsl maven.xsl etc ... * </ul> * I expect this to be used by a derived class to allow someone to change * the order of xsl files or to add/remove one to/from the list or a * combination. * * @param fileNames */ protected void setXSLFileNames(String[] fileNames) { if (fileNames == null) { throw new IllegalArgumentException( "xslFileNames can't be null (but can be empty)"); } xslFileNames = fileNames; } /** * Provided as an alternative to setXSLFileNames for changing the list of * files to use. * * @return xsl files to use in generating the email */ protected String[] getXslFileNames() { return xslFileNames; } /** * Path to cruisecontrol.css. Only used with xslDir, not xslFile. */ public void setCSS(String cssFilename) { css = cssFilename; } /** * Path to the log file as set in the log element of the configuration xml * file. */ public void setLogDir(String directory) { if (directory == null) { throw new IllegalArgumentException("logDir cannot be null!"); } this.logDir = directory; } /** * The API used for posting to your blog. Currently, acceptable values are * <tt>blogger</tt>,<tt>metaweblog</tt> and <tt>livejournal</tt>. */ public void setApi(String api) { this.api = api; } /** * The "blog ID" for the blog you're posting to. The value depends on your * particular weblog product. */ public void setBlogId(String blogId) { this.blogId = blogId; } /** * The URL where your blog's remote API is running at. For example, the * value could look like <tt>http://www.yoursite.com/blog/xmlrpc</tt> or * <tt>http://www.livejournal.com/interface/xmlrpc</tt>. */ public void setBlogUrl(String blogUrl) { this.blogUrl = blogUrl; } /** * The username to use for authentication. */ public void setUsername(String username) { this.username = username; } /** * The password to use for authentication. */ public void setPassword(String password) { this.password = password; } /** * The category to set for the blog entry. When using the MetaWeblogAPI, you * can also use a comma-separated list of several categories. */ public void setCategory(String category) { this.category = category; } /** * The prefix to be used before the title of the blog entry. If * <tt>null</tt>, no prefix will be used. */ public void setSubjectPrefix(String prefix) { this.subjectPrefix = prefix; } /** * The base build results URL where your CruiseControl reporting application * is running. For example, <tt>http://buildserver:8080/cc/myproject</tt>. */ public void setBuildResultsURL(String url) { this.buildResultsURL = url; } /** * The rule for posting a blog entry for successful builds. Accepted values * are <tt>never</tt>,<tt>always</tt> and <tt>fixes</tt>. */ public void setReportSuccess(String reportSuccess) { this.reportSuccess = reportSuccess; } /** * The rule for posting a blog entry for each subsequent failed build. * Accepted values are <tt>true</tt> and <tt>false</tt>. */ public void setSpamWhileBroken(boolean spamWhileBroken) { this.spamWhileBroken = spamWhileBroken; } // --- METHODS --- /** * Implementing the <code>Publisher</code> interface. * * @param cruisecontrolLog * The build results XML */ public void publish(Element cruisecontrolLog) { XMLLogHelper helper = new XMLLogHelper(cruisecontrolLog); try { if (shouldSend(helper)) { postBlogEntry(createSubject(helper), createMessage(helper .getProjectName(), helper.getLogFileName())); } else { LOG.debug("shouldSend() indicated we should not" + " post a blog entry at this time"); } } catch (CruiseControlException e) { LOG.error("", e); } } /** * The interface for abstracting away the specific blogging API being used. * * @author Lasse Koskela */ interface BloggingApi extends Serializable { /** * Post a new blog entry. * * @param subject * The blog entry's subject. * @param content * The blog entry's content. * @return The newly created blog entry's identifier. */ public Object newPost(String blogUrl, String blogId, String username, String password, String category, String subject, String content); } /** * A <tt>BloggingApi</tt> implementation for the Blogger API. * * @author Lasse Koskela */ public static class BloggerApiClient implements BloggingApi { private static final long serialVersionUID = 6614787780439141028L; public Object newPost(String blogUrl, String blogId, String username, String password, String category, String subject, String content) { // the Blogger API doesn't support titles for blog entries so // we're using the common (de facto standard) workaround to embed // the title into the content and let the weblog software parse // the title from there, if supported. content = "<title>" + subject + "</title>" + content; Object postId = null; try { XmlRpcClient xmlrpc = new XmlRpcClient(blogUrl); Vector params = new Vector(); params.add(APP_KEY); params.add(blogId); params.add(username); params.add(password); params.add(content); params.add(Boolean.TRUE); postId = xmlrpc.execute("blogger.newPost", params); } catch (Exception e) { LOG.error("", e); } return postId; } } /** * A <tt>BloggingApi</tt> implementation for the MetaWeblogAPI. * * @author Lasse Koskela */ public static class MetaWeblogApiClient implements BloggingApi { private static final long serialVersionUID = 5980798548858885672L; public Object newPost(String blogUrl, String blogId, String username, String password, String category, String subject, String content) { Object postId = null; try { XmlRpcClient xmlrpc = new XmlRpcClient(blogUrl); Vector params = new Vector(); params.add(blogId); params.add(username); params.add(password); // MetaWeblogAPI expects the blog entry data elements in an // internal map-structure unlike Blogger API does. Hashtable struct = new Hashtable(); struct.put("title", subject); struct.put("description", content); Vector categories = new Vector(); if (category != null) { StringTokenizer tok = new StringTokenizer(category, ","); while (tok.hasMoreTokens()) { categories.add(tok.nextToken().trim()); } } struct.put("categories", categories); params.add(struct); params.add(Boolean.TRUE); postId = xmlrpc.execute("metaWeblog.newPost", params); } catch (Exception e) { LOG.error("", e); } return postId; } } /** * A <tt>BloggingApi</tt> implementation for the LiveJournal API. * * @author Lasse Koskela */ public static class LiveJournalApiClient implements BloggingApi { private static final long serialVersionUID = -372653261263803994L; /** * TODO: make this smarter so that it won't strip away linefeeds from * within &lt;pre&gt;formatted blocks... */ private String stripLineFeeds(String input) { StringBuffer s = new StringBuffer(); char[] chars = input.toCharArray(); for (int i = 0; i < chars.length; i++) { if (chars[i] != '\n' && chars[i] != '\r') { s.append(chars[i]); } } return s.toString(); } public Object newPost(String blogUrl, String blogId, String username, String password, String category, String subject, String content) { Object postId = null; try { XmlRpcClient xmlrpc = new XmlRpcClient(blogUrl); Vector params = new Vector(); Hashtable struct = new Hashtable(); struct.put("username", username); // TODO: use challenge-based security struct.put("auth_method", "clear"); struct.put("password", password); struct.put("subject", subject); struct.put("event", stripLineFeeds(content)); struct.put("lineendings", "\n"); struct.put("security", "public"); Calendar now = Calendar.getInstance(); struct.put("year", "" + now.get(Calendar.YEAR)); struct.put("mon", "" + (now.get(Calendar.MONTH) + 1)); struct.put("day", "" + now.get(Calendar.DAY_OF_MONTH)); struct.put("hour", "" + now.get(Calendar.HOUR_OF_DAY)); struct.put("min", "" + now.get(Calendar.MINUTE)); params.add(struct); postId = xmlrpc.execute("LJ.XMLRPC.postevent", params); } catch (Exception e) { LOG.error("", e); } return postId; } } /** * Selects a <tt>BloggingApi</tt> implementation based on a user-friendly * name. * * @param apiName * The name of the blogging API to use. One of <tt>blogger</tt>, * <tt>metaweblog</tt> or <tt>livejournal</tt>. * @return The <tt>BloggingApi</tt> implementation or <tt>null</tt> if * no matching implementation was found. * @throws CruiseControlException */ public BloggingApi getBloggingApiImplementation(String apiName) throws CruiseControlException { Class implClass = (Class) API_CLIENTS.get(apiName); if (implClass != null) { LOG.debug("Mapped " + apiName + " to " + implClass.getName()); try { return (BloggingApi) implClass.newInstance(); } catch (Exception e) { throw new CruiseControlException( "Failed to instantiate Blogging API implementation, " + implClass.getName() + ", due to a " + e.getClass().getName() + ": " + e.getMessage()); } } return null; } /** * Posts the build results to the blog. * * @param subject * The subject for the blog entry. * @param content * The content for the blog entry. */ public void postBlogEntry(String subject, String content) { LOG.debug("Posting a blog entry to " + blogUrl); LOG.debug(" blogId=" + blogId); LOG.debug(" username=" + username); LOG.debug(" subject=" + subject); LOG.debug(" content=" + content); try { BloggingApi apiClient = getBloggingApiImplementation(api); if (apiClient != null) { Object postId = apiClient.newPost(blogUrl, blogId, username, password, category, subject, content); if (postId != null) { LOG.info("Blog entry " + postId + " created at " + blogUrl); } else { LOG.debug("Blog entry ID not available from " + blogUrl); } } else { LOG.error("No API associated with '" + api + "'"); } } catch (Exception e) { LOG.error("", e); } } /** * Called after the configuration is read to make sure that all the * mandatory parameters were specified.. * * @throws CruiseControlException * if there was a configuration error. */ public void validate() throws CruiseControlException { validateRequiredField("username", username); validateRequiredField("password", password); validateRequiredField("blogid", blogId); validateRequiredField("blogurl", blogUrl); validateURL("blogurl", blogUrl); validateOneOf("api", API_CLIENTS.keySet(), api); if (buildResultsURL != null) { validateURL("buildresultsurl", buildResultsURL); } if (logDir != null) { verifyDirectory("WeblogPublisher.logDir", logDir); } else { LOG.info("Using default log directory \"logs/<projectname>\""); } if (xslFile == null) { verifyDirectory("WeblogPublisher.xslDir", xslDir); verifyFile("WeblogPublisher.css", css); String[] fileNames = getXslFileNames(); if (fileNames == null) { throw new CruiseControlException( "WeblogPublisher.getXslFileNames() can't return null"); } for (int i = 0; i < fileNames.length; i++) { verifyFile("WeblogPublisher.xslDir/" + fileNames[i], new File( xslDir, fileNames[i])); } } else { verifyFile("WeblogPublisher.xslFile", xslFile); } } private void validateOneOf(String fieldName, Collection validValues, String value) throws CruiseControlException { if (!validValues.contains(value)) { throw new CruiseControlException("Value for '" + fieldName + "' must be one of " + commaSeparated(validValues)); } } private String commaSeparated(Collection values) { StringBuffer s = new StringBuffer(); Iterator i = values.iterator(); while (i.hasNext()) { s.append("'").append(i.next()).append("'"); if (i.hasNext()) { s.append(", "); } } return s.toString(); } private void validateURL(String fieldName, String url) throws CruiseControlException { try { new URL(url); } catch (MalformedURLException e) { throw new CruiseControlException(fieldName + " must be a valid URL: " + url); } } private void validateRequiredField(String fieldName, String value) throws CruiseControlException { if (value == null) { throw new CruiseControlException("Attribute " + fieldName + " is required."); } } private void verifyDirectory(String dirName, String dir) throws CruiseControlException { if (dir == null) { throw new CruiseControlException(dirName + " not specified in configuration file"); } File dirFile = new File(dir); if (!dirFile.exists()) { throw new CruiseControlException(dirName + " does not exist : " + dirFile.getAbsolutePath()); } if (!dirFile.isDirectory()) { throw new CruiseControlException(dirName + " is not a directory : " + dirFile.getAbsolutePath()); } } private void verifyFile(String fileName, String file) throws CruiseControlException { if (file == null) { throw new CruiseControlException(fileName + " not specified in configuration file"); } verifyFile(fileName, new File(file)); } private void verifyFile(String fileName, File file) throws CruiseControlException { if (!file.exists()) { throw new CruiseControlException(fileName + " does not exist: " + file.getAbsolutePath()); } if (!file.isFile()) { throw new CruiseControlException(fileName + " is not a file: " + file.getAbsolutePath()); } } /** * Determines if the conditions are right for the blog entry to be posted. * * @param logHelper * <code>XMLLogHelper</code> wrapper for the build log. * @return whether or not the mail message should be sent. */ boolean shouldSend(XMLLogHelper logHelper) throws CruiseControlException { if (logHelper.isBuildSuccessful()) { return shouldSendForSuccessfulBuild(logHelper); } else { return shouldSendForFailedBuild(logHelper); } } /** * Determines if the conditions are right for the blog entry to be posted. * * @param logHelper * <code>XMLLogHelper</code> wrapper for the build log. * @return whether or not the mail message should be sent. */ boolean shouldSendForFailedBuild(XMLLogHelper logHelper) throws CruiseControlException { if (!logHelper.wasPreviousBuildSuccessful() && logHelper.isBuildNecessary() && !spamWhileBroken) { LOG.debug("spamWhileBroken is false, not sending email"); return false; } else { return true; } } /** * Determines if the conditions are right for the blog entry to be posted. * * @param logHelper * <code>XMLLogHelper</code> wrapper for the build log. * @return whether or not the mail message should be sent. */ boolean shouldSendForSuccessfulBuild(XMLLogHelper logHelper) throws CruiseControlException { if (reportSuccess.equalsIgnoreCase(DEFAULT_REPORTSUCCESS)) { return true; } else if (reportSuccess.equalsIgnoreCase("never")) { return false; } else if (reportSuccess.equalsIgnoreCase("fixes")) { if (logHelper.wasPreviousBuildSuccessful()) { LOG.debug("reportSuccess is set to 'fixes', " + "not sending emails for repeated " + "successful builds."); return false; } } return true; } /** * Creates the subject for the blog entry. * * @param logHelper * <code>XMLLogHelper</code> wrapper for the build log. * @return <code>String</code> containing the subject line. */ String createSubject(XMLLogHelper logHelper) throws CruiseControlException { String projectName = logHelper.getProjectName(); String label = logHelper.getLabel(); boolean buildSuccessful = logHelper.isBuildSuccessful(); boolean isFix = logHelper.isBuildFix(); return createSubject(projectName, label, buildSuccessful, isFix); } /** * Creates the subject for the blog entry. * * @return <code>String</code> containing the subject line. */ String createSubject(String projectName, String label, boolean buildSuccessful, boolean isFix) throws CruiseControlException { StringBuffer subject = new StringBuffer(); if (subjectPrefix != null && subjectPrefix.trim().length() > 0) { subject.append(subjectPrefix).append(" "); } subject.append(projectName); if (buildSuccessful) { if (label.length() > 0) { subject.append(" ").append(label); } subject.append(isFix ? " - Build Fixed" : " - Build Successful"); } else { subject.append(" - Build Failed"); } return subject.toString(); } /** * Create the text to be blogged. * * @return created message; empty string if logDir not set */ String createMessage(String projectName, String logFileName) { String message; File inFile = null; try { if (logDir == null) { logDir = getDefaultLogDir(projectName); } inFile = new File(logDir, logFileName); message = transform(inFile); } catch (Exception ex) { LOG.error("error transforming " + (inFile != null ? inFile.getAbsolutePath() : ""), ex); message = createLinkLine(logFileName); } return message; } String getDefaultLogDir(String projectName) throws CruiseControlException { // TODO: extract this duplication with ProjectXMLHelper.getLog() // into a single method somewhere return "logs" + File.separator + projectName; } String transform(File xml) throws TransformerException, IOException { StringBuffer messageBuffer = new StringBuffer(); if (xslFile != null) { transformWithSingleStylesheet(xml, messageBuffer); } else { messageBuffer.append(createLinkLine(xml.getName())); transformWithMultipleStylesheets(xml, messageBuffer); } return messageBuffer.toString(); } void transformWithMultipleStylesheets(File inFile, StringBuffer messageBuffer) throws IOException, TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); File xslDirectory = new File(xslDir); String[] fileNames = getXslFileNames(); for (int i = 0; i < fileNames.length; i++) { String fileName = fileNames[i]; File xsl = new File(xslDirectory, fileName); messageBuffer.append("<p>\n"); appendTransform(inFile, xsl, messageBuffer, tFactory); } } void transformWithSingleStylesheet(File inFile, StringBuffer messageBuffer) throws IOException, TransformerException { TransformerFactory tFactory = TransformerFactory.newInstance(); appendTransform(inFile, new File(xslFile), messageBuffer, tFactory); } void appendTransform(File xml, File xsl, StringBuffer messageBuffer, TransformerFactory tFactory) throws TransformerException { LOG.debug("Transforming file " + xml.getName() + " with " + xsl.getName() + " ..."); Transformer tformer = tFactory.newTransformer(new StreamSource(xsl)); StringWriter sw = new StringWriter(); try { tformer.transform(new StreamSource(xml), new StreamResult(sw)); LOG.debug("Transformed file " + xml.getName() + " with " + xsl.getName() + " ..."); } catch (Exception e) { LOG.error("error transforming with xslFile " + xsl.getName(), e); return; } messageBuffer.append(sw.toString()); } String createLinkLine(String logFileName) { if (buildResultsURL == null) { return ""; } String url = createBuildResultsUrl(logFileName); StringBuffer linkLine = new StringBuffer(); linkLine.append("<p>View results here -&gt; <a href=\""); linkLine.append(url); linkLine.append("\">"); linkLine.append(url); linkLine.append("</a></p>"); return linkLine.toString(); } String createBuildResultsUrl(String logFileName) { int startName = logFileName.lastIndexOf(File.separator) + 1; int endName = logFileName.lastIndexOf("."); String baseLogFileName = logFileName.substring(startName, endName); StringBuffer url = new StringBuffer(buildResultsURL); if (buildResultsURL.indexOf("?") == -1) { url.append("?"); } else { url.append("&"); } url.append("log="); url.append(baseLogFileName); return url.toString(); } }

The table below shows all metrics for WeblogPublisher.java.

MetricValueDescription
BLOCKS112.00Number of blocks
BLOCK_COMMENT 0.00Number of block comment lines
COMMENTS265.00Comment lines
COMMENT_DENSITY 0.64Comment density
COMPARISONS63.00Number of comparison operators
CYCLOMATIC98.00Cyclomatic complexity
DECL_COMMENTS38.00Comments in declarations
DOC_COMMENT252.00Number of javadoc comment lines
ELOC414.00Effective lines of code
EXEC_COMMENTS 4.00Comments in executable code
EXITS76.00Procedure exits
FUNCTIONS45.00Number of function declarations
HALSTEAD_DIFFICULTY72.23Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY178.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 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 0.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 5.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 1.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 3.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
JAVA010826.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 5.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 0.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 0.00JAVA0128 Public constructor in non-public class
JAVA0130 8.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 4.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 1.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 4.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 1.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 1.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 1.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 3.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
LINES865.00Number of lines in the source file
LINE_COMMENT13.00Number of line comments
LOC510.00Lines of code
LOGICAL_LINES258.00Number of statements
LOOPS 5.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS1252.00Number of operands
OPERATORS2106.00Number of operators
PARAMS84.00Number of formal parameter declarations
PROGRAM_LENGTH3358.00Halstead program length
PROGRAM_VOCAB493.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS94.00Number of return points from functions
SIZE30877.00Size of the file in bytes
UNIQUE_OPERANDS442.00Number of unique operands
UNIQUE_OPERATORS51.00Number of unique operators
WHITESPACE90.00Number of whitespace lines