net.sourceforge.cruisecontrol.labelincrementers
Class P4ChangelistLabelIncrementer

java.lang.Object
  extended bynet.sourceforge.cruisecontrol.labelincrementers.P4ChangelistLabelIncrementer
All Implemented Interfaces:
LabelIncrementer, java.io.Serializable

public class P4ChangelistLabelIncrementer
extends java.lang.Object
implements LabelIncrementer

This class uses the most current changelist of the user in Perforce as the label for the builds. It can also sync the Perforce managed files to that changelist number, as well as clean out the existing managed files.

Author:
Matt Albrecht
See Also:
Serialized Form

Nested Class Summary
protected static interface P4ChangelistLabelIncrementer.P4CmdParser
           
protected static class P4ChangelistLabelIncrementer.P4CmdParserAdapter
           
protected static class P4ChangelistLabelIncrementer.ParseChangelistNumbers
           
protected static class P4ChangelistLabelIncrementer.ParseOutputParam
           
 
Constructor Summary
P4ChangelistLabelIncrementer()
           
 
Method Summary
protected  Commandline buildBaseP4Command()
           
protected  org.apache.tools.ant.taskdefs.Delete createDelete(org.apache.tools.ant.Project p)
           
protected  org.apache.tools.ant.types.FileSet createFileSet(org.apache.tools.ant.Project p)
           
protected  org.apache.tools.ant.Project createProject()
           
protected  void deleteView()
           
protected  java.lang.String getCurrentChangelist()
           
 java.lang.String getDefaultLabel()
          The instance must be fully initialized before calling this method.
protected  org.apache.tools.ant.types.FileSet getWhereView(org.apache.tools.ant.Project p)
          If the view mapping contains a reference to a single file,
 java.lang.String incrementLabel(java.lang.String oldLabel, org.jdom.Element buildLog)
          Retrieves the current changelist, or, if given, the specified changelist, and also performs any necessary actions the user requested.
 boolean isPreBuildIncrementer()
          Some implementations of LabelIncrementer, such as those involving dates, are better suited to being incremented before building rather than after building.
 boolean isValidLabel(java.lang.String label)
          Verify that the label specified is a valid label.
protected  void parseStream(java.io.InputStream stream, P4ChangelistLabelIncrementer.P4CmdParser parser)
           
protected  void runP4Cmd(Commandline cmd, P4ChangelistLabelIncrementer.P4CmdParser parser)
           
 void setChangelist(int syncChange)
          Set the changelist number that you want to build at.
 void setClean(boolean b)
          Perform a "p4 sync -f [view]#0" before syncing anew.
 void setClient(java.lang.String p4Client)
           
 void setDelete(boolean b)
          Perform a recursive delete of the clientspec view.
 void setNoSync(boolean b)
          Disables the label incrementer from synchronizing Perforce to the view.
 void setPasswd(java.lang.String p4Passwd)
           
 void setPort(java.lang.String p4Port)
           
 void setUser(java.lang.String p4User)
           
 void setView(java.lang.String p4View)
           
protected  void syncTo(java.lang.String viewArg)
           
 void validate()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

P4ChangelistLabelIncrementer

public P4ChangelistLabelIncrementer()
Method Detail

incrementLabel

public java.lang.String incrementLabel(java.lang.String oldLabel,
                                       org.jdom.Element buildLog)
Retrieves the current changelist, or, if given, the specified changelist, and also performs any necessary actions the user requested.

Specified by:
incrementLabel in interface LabelIncrementer
Parameters:
oldLabel - Label from previous successful build.
buildLog - JDOM Element representation of the build.
Returns:
Label to use for most recent successful build.

isPreBuildIncrementer

public boolean isPreBuildIncrementer()
Description copied from interface: LabelIncrementer
Some implementations of LabelIncrementer, such as those involving dates, are better suited to being incremented before building rather than after building. This method determines whether to increment before building or after building.

Specified by:
isPreBuildIncrementer in interface LabelIncrementer

isValidLabel

public boolean isValidLabel(java.lang.String label)
Verify that the label specified is a valid label. In this case a valid label contains at least one separator character, and an integer after the last occurrence of the separator character.

Specified by:
isValidLabel in interface LabelIncrementer
Parameters:
label - user-supplied label
Returns:
true if it is a valid label.

getDefaultLabel

public java.lang.String getDefaultLabel()
The instance must be fully initialized before calling this method.

Specified by:
getDefaultLabel in interface LabelIncrementer
Returns:
defaultLabel
Throws:
java.lang.IllegalStateException - if the instance is not properly initialized

setChangelist

public void setChangelist(int syncChange)
Set the changelist number that you want to build at. If this isn't set, then the class will get the most current submitted changelist number. Note that setting this will cause the build to ALWAYS build at this changelist number.

Parameters:
syncChange - the changelist number to perform the sync to.

setPort

public void setPort(java.lang.String p4Port)

setClient

public void setClient(java.lang.String p4Client)

setUser

public void setUser(java.lang.String p4User)

setView

public void setView(java.lang.String p4View)

setPasswd

public void setPasswd(java.lang.String p4Passwd)

setNoSync

public void setNoSync(boolean b)
Disables the label incrementer from synchronizing Perforce to the view.

Parameters:
b -

setClean

public void setClean(boolean b)
Perform a "p4 sync -f [view]#0" before syncing anew. This will force the sync to happen.

Parameters:
b -

setDelete

public void setDelete(boolean b)
Perform a recursive delete of the clientspec view. This will force a clean & sync. Note that this can potentially be very destructive, so use with the utmost caution.

Parameters:
b -

validate

public void validate()
              throws CruiseControlException
Throws:
CruiseControlException

getCurrentChangelist

protected java.lang.String getCurrentChangelist()
                                         throws CruiseControlException
Throws:
CruiseControlException

syncTo

protected void syncTo(java.lang.String viewArg)
               throws CruiseControlException
Throws:
CruiseControlException

deleteView

protected void deleteView()
                   throws CruiseControlException
Throws:
CruiseControlException

getWhereView

protected org.apache.tools.ant.types.FileSet getWhereView(org.apache.tools.ant.Project p)
                                                   throws CruiseControlException
If the view mapping contains a reference to a single file,

Returns:
the collection of recursive directories inside the Perforce view.
Throws:
CruiseControlException

createProject

protected org.apache.tools.ant.Project createProject()

createDelete

protected org.apache.tools.ant.taskdefs.Delete createDelete(org.apache.tools.ant.Project p)
                                                     throws CruiseControlException
Throws:
CruiseControlException

createFileSet

protected org.apache.tools.ant.types.FileSet createFileSet(org.apache.tools.ant.Project p)
                                                    throws CruiseControlException
Throws:
CruiseControlException

buildBaseP4Command

protected Commandline buildBaseP4Command()

runP4Cmd

protected void runP4Cmd(Commandline cmd,
                        P4ChangelistLabelIncrementer.P4CmdParser parser)
                 throws CruiseControlException
Throws:
CruiseControlException

parseStream

protected void parseStream(java.io.InputStream stream,
                           P4ChangelistLabelIncrementer.P4CmdParser parser)
                    throws java.io.IOException
Throws:
java.io.IOException