[JIRA] Updated: (CC-742) Simple (integer-only) label incrementer

"Theo Barker (JIRA)" <[email protected]> Thu, 21 Jun 2012 11:17:31 -0500 (CDT)
Newsgroups gmane.comp.java.cruise-control.devel
Message-ID <199899278.1340295451547.JavaMail.jira@chidmzhosting02.thoughtworks.com>
     [ http://jira.public.thoughtworks.org/browse/CC-742?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Theo Barker updated CC-742:
---------------------------

    Affects Version/s: 2.8.4
                       2.8.3
                       2.8.2
                       2.8.1
                       2.8
                       2.7.3
                       2.7.2

> Simple (integer-only) label incrementer
> ---------------------------------------
>
>                 Key: CC-742
>                 URL: http://jira.public.thoughtworks.org/browse/CC-742
>             Project: CruiseControl
>          Issue Type: New Feature
>          Components: Core Application
>    Affects Versions: 2.7.1, 2.7.2, 2.7.3, 2.8, 2.8.1, 2.8.2, 2.8.3, 2.8.4
>         Environment: Currently using Windows XP, Java 1.6.x.
>            Reporter: Theo Barker
>            Priority: Major
>
> Here's my hack of a label incrementer that only has a number in the label. Instead of "build.nnn" of the defaultLabelIncrementer, I needed a label that is just "nnn", with no separater, due to the places that the label is used. So I hacked up the DefaultLabelIncrementer.java and tried it out on my build machine and we are now using it. I've seen that others have asked about a simple incrementer on blogs and forums. Please feel free to fix the Java, as this is my first foray into Java from C++, et al.
> /********************************************************************************
>  * 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.labelincrementers;
> import net.sourceforge.cruisecontrol.LabelIncrementer;
> import org.apache.log4j.Logger;
> import org.jdom.Element;
> /**
>  * This class provides simple label incrementation.
>  * This class expects the label format to be "n",
>  * where n is an integer and there is no string or separator.
>  * Heavily based on the DefaultLabelIncrementer class
>  *
>  * @author <a href="mailto:[email protected]">alden almagro</a>
>  * @author <a href="mailto:[email protected]">Paul Julius</a>
>  * @author <a href="mailto:[email protected]">Theo Barker</a>
>  */
> public class SimpleLabelIncrementer implements LabelIncrementer {
>     private static final Logger LOG =
>         Logger.getLogger(SimpleLabelIncrementer.class);
>     private boolean preIncrement = false;
>     /* temporary variable, only used at instance setup time */
>     private String defaultLabel = null;
>     /**
>      * Increments the label when a successful build occurs.
>      * Assumes that the label will be in
>      * the format of "n", where n is an integer.
>      * No other characters are allowed
>      *
>      * @param oldLabel Label from previous successful build.
>      * @return Label to use for most recent successful build.
>      */
>     public String incrementLabel(String oldLabel, Element buildLog) {
>  
>         int i = Integer.parseInt(oldLabel);
>         String newLabel = Integer.toString(++i);
>         LOG.debug("Incrementing label: " + oldLabel + " -> " + newLabel);
>         return newLabel;
>     }
>     public boolean isPreBuildIncrementer() {
>         return preIncrement;
>     }
>     /**
>      *  Set the pre/post behavior of the label incrementer.
>      */
>     public void setPreBuildIncrementer(boolean preInc) {
>         preIncrement = preInc;
>     }
>     /**
>      * Verify that the label specified is a valid label.  In this case a valid
>      * label contains an integer expressed as a string.
>      */
>     public boolean isValidLabel(String label) {
>         try {
>             Integer.parseInt(label);
>             return true;
>         } catch (NumberFormatException e) {
>             return false;
>         }
>     }
>     public void setSeparator(String newSeparator) {
>     /* do nothing since this incrementer doesn't use a separator */
>     }
>     /**
>      * The instance must be fully initialized before calling this method.
>      * @throws IllegalStateException if the instance is not properly initialized
>      */
>     public String getDefaultLabel() {
>         String tempLabel = "1";
>         if (defaultLabel != null) {
>             tempLabel = defaultLabel;
>             defaultLabel = null;
>         }
>         return tempLabel;
>     }
>     public void setDefaultLabel(String label) {
>         defaultLabel = label;
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.public.thoughtworks.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/