com.atlassian.bamboo.builder
Class AbstractBuilder

java.lang.Object
  extended by com.atlassian.bamboo.command.Command
      extended by com.atlassian.bamboo.builder.AbstractBuilder
All Implemented Interfaces:
Builder, EnvironmentVariablesAwareBuilder, MutableEnvironmentVariablesAwareBuilder, BambooPluginModule, BuilderV2, ConfigurablePlugin, java.io.Serializable
Direct Known Subclasses:
AbstractMavenBuilder, AntBuilder, CustomCommandBuilder, PhpUnitBuilder, ScriptBuilder

public abstract class AbstractBuilder
extends Command
implements Builder, MutableEnvironmentVariablesAwareBuilder

Common builder functionality.

See Also:
Serialized Form

Field Summary
protected static java.lang.String BUILD_FAILED_MARKER
           
protected static java.lang.String BUILD_SUCCESSFUL_MARKER
           
protected  BuildDirectoryManager buildDirectoryManager
           
protected static java.lang.String DEFAULT_TEST_REPORTS_XML
           
protected  ErrorUpdateHandler errorUpdateHandler
           
protected static int FIND_FAILURE_MESSAGE_IN_LAST
           
protected static int FIND_SUCCESS_MESSAGE_IN_LAST
          Bamboo will look at this constant to find how far back in the logs to look for a successful message
static java.lang.String PARAM_BUILD_LABEL
           
static java.lang.String PARAM_BUILDJDK
           
static java.lang.String PARAM_ENV_VAR
           
static java.lang.String PARAM_HASTESTS
           
static java.lang.String PARAM_HOME
           
static java.lang.String PARAM_TEST_RESULTS_DIRECTORY
           
static java.lang.String PARAM_WORKING_SUB_DIR
           
protected static boolean SEARCH_BUILD_SUCCESS_FAIL_MESSAGE_EVERYWHERE
           
protected  TemplateRenderer templateRenderer
           
 
Fields inherited from class com.atlassian.bamboo.command.Command
buildLoggerManager, substitutionBean
 
Fields inherited from interface com.atlassian.bamboo.builder.Builder
CAPABILITY_BUILDER_PREFIX, CAPABILITY_BUILDER_TYPE
 
Constructor Summary
protected AbstractBuilder()
           
 
Method Summary
 void collateTestResults(BuildIdentifier buildIdentifier, CurrentBuildResult buildResult, BuildLogger buildLogger)
           
 java.util.Map<java.lang.String,java.lang.String> customiseLabelTypeMap(java.util.Map<java.lang.String,java.lang.String> labelTypeMap)
          Allows the builder to add extra label -> builder type key mappings
 void customizeBuildRequirements(BuildConfiguration buildConfiguration, RequirementSet requirementSet)
          Extension point for adding/customizing requiremnents when editing a build's builder configuration.
 void executeBuild(BuildContext buildContext, ReadOnlyCapabilitySet capabilitySet)
          Runs the build, and updates the build results in the build context.
 java.io.File getBuildDir()
          Location of build directory
 java.lang.String getBuildJdk()
          Provide the UI form with the JDK the build needs to be built on
 java.lang.String getCompleteKey()
          Returns the full plugin descriptor key
 java.lang.String getEditHtml(BuildConfiguration buildConfiguration, Build build)
          Returns HTML that represents the form fragment for editing the repository.
 java.lang.String getEnvironmentVariables()
          Provides the ui form with the build's system environment variables
protected  FilteredMap getFilteredParams()
           
 java.util.Map<java.lang.String,java.lang.String> getFullParams()
          Gets the full params that's used to persist.
 java.lang.String getKey()
          Returns the short simple key for this builder (e.g.
 java.lang.String getKeyPrefix()
           
 java.lang.String getLabel()
          What is the label used to getPrettyPrint this item in the GUI?
 java.lang.String getPath(ReadOnlyCapabilitySet capabilitySet)
          The home path of the builder's command line
 java.lang.String getPathHelp()
          Help text for the builder type
protected  java.util.Map getTemplateContext()
           
 java.lang.String getTestChecked()
          Informs the UI if the build is testless.
 java.lang.String getTestResultsDirectory()
          What are the build's junit test results stored? Can be a comma separated list
 java.lang.String getViewHtml(Build build)
          Returns the HTML that represents the view of the repository configuration
 java.io.File getWorkingDirectory()
          Get the location of the build file (includes the working sub directory of if it exists)
 java.lang.String getWorkingSubDirectory()
          Return the optional working subdirectory
 boolean hasPassed(int returnCode, int buildNumber, java.lang.String planKey)
          Determines based on the return code and/or logs whether the build has passed.
 boolean hasTests()
          Does the build have any tests to be included in the build results web pages?
 void init(com.atlassian.plugin.ModuleDescriptor moduleDescriptor)
          Initialises the Plugin with the plugin module descriptor
 boolean isJdkValid()
           
 boolean isLabelPathMapConfigurable()
          Returns true if the Builder can have its LabelPathMap configurable.
protected  boolean outputEndsWith(int positionFromEnd, java.lang.String expectedText, java.lang.String planKey, int buildNumber)
          Utility method to check the buildlogs contained the expected success text
 void populateBuildErrors(CurrentBuildResult buildResult, java.util.List<java.lang.String> errorOutput, java.lang.String planKey, int buildNumber)
          An extension point for implementors to modify the Error Summary
 void prepareConfigObject(BuildConfiguration buildConfiguration)
          Do any preprocessing work before validation occurs
 CurrentBuildResult runBuild(BuildContext buildContext, ReadOnlyCapabilitySet capabilitySet)
           
 void setAdministrationConfiguration(AdministrationConfiguration administrationConfiguration)
           
 void setBuildDir(java.io.File buildDirectory)
          Where is the build file file?
 void setBuildDirectoryManager(BuildDirectoryManager buildDirectoryManager)
           
 void setBuildJdk(java.lang.String buildJdk)
          Define the JDK the build beeds to be built on.
 void setBuildLogFileAccessorFactory(BuildLogFileAccessorFactory buildLogFileAccessorFactory)
           
 void setEnvironmentVariables(java.lang.String envVars)
          Define the system environment variabled required to build the build.
 void setErrorUpdateHandler(ErrorUpdateHandler errorUpdateHandler)
           
 void setHasTests(boolean hasTests)
          Does the build have any tests to be included in the build results web pages?
 void setJdkManager(JdkManager jdkManager)
           
 void setKey(java.lang.String key)
           
 void setLabel(java.lang.String label)
          Sets the label being used by the builder
 void setParams(FilteredMap filteredParams)
          Updates the current builder object with
 void setTemplateRenderer(TemplateRenderer templateRenderer)
           
 void setTestChecked(java.lang.String enabled)
          The user has selected that the build has tests (via a checkbox)
 void setTestResultsDirectory(java.lang.String testResultDirectory)
          Let the builder specify the location of the build's test result files.
 void setWorkingSubDirectory(java.lang.String workingSubDirectory)
          Specify the working sub directory
 java.lang.String toString()
          Default toString simply displays the name so they can be slotted into drop down lists and such like.
protected abstract  ErrorCollection validate(FilteredMap filteredParams)
           
 ErrorCollection validate(ReadOnlyCapabilitySet capabilities)
          Validate the Builder's current internal settings are still valid
 
Methods inherited from class com.atlassian.bamboo.command.Command
decorateCommandLine, executeCommand, getBuildLoggerManager, getCommandArguments, getCommandExecutable, getCommandLine, getCustomEnvironmentVars, getEnvironmentSetting, getSubstitutedCommandLine, getVariableSubstitutionBean, isWindowsPlatform, setBuildLoggerManager, setPluginAccessor, setVariableSubstitutionBean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.atlassian.bamboo.builder.Builder
addDefaultLabelPathMaps, getName, isPathValid
 
Methods inherited from interface com.atlassian.bamboo.v2.build.ConfigurablePlugin
addDefaultValues, validate
 

Field Detail

DEFAULT_TEST_REPORTS_XML

protected static final java.lang.String DEFAULT_TEST_REPORTS_XML
See Also:
Constant Field Values

PARAM_BUILD_LABEL

public static final java.lang.String PARAM_BUILD_LABEL
See Also:
Constant Field Values

PARAM_HASTESTS

public static final java.lang.String PARAM_HASTESTS
See Also:
Constant Field Values

PARAM_TEST_RESULTS_DIRECTORY

public static final java.lang.String PARAM_TEST_RESULTS_DIRECTORY
See Also:
Constant Field Values

PARAM_BUILDJDK

public static final java.lang.String PARAM_BUILDJDK
See Also:
Constant Field Values

PARAM_HOME

public static final java.lang.String PARAM_HOME
See Also:
Constant Field Values

PARAM_WORKING_SUB_DIR

public static final java.lang.String PARAM_WORKING_SUB_DIR
See Also:
Constant Field Values

PARAM_ENV_VAR

public static final java.lang.String PARAM_ENV_VAR
See Also:
Constant Field Values

FIND_SUCCESS_MESSAGE_IN_LAST

protected static final int FIND_SUCCESS_MESSAGE_IN_LAST
Bamboo will look at this constant to find how far back in the logs to look for a successful message


FIND_FAILURE_MESSAGE_IN_LAST

protected static final int FIND_FAILURE_MESSAGE_IN_LAST

BUILD_SUCCESSFUL_MARKER

protected static final java.lang.String BUILD_SUCCESSFUL_MARKER
See Also:
Constant Field Values

BUILD_FAILED_MARKER

protected static final java.lang.String BUILD_FAILED_MARKER
See Also:
Constant Field Values

SEARCH_BUILD_SUCCESS_FAIL_MESSAGE_EVERYWHERE

protected static final boolean SEARCH_BUILD_SUCCESS_FAIL_MESSAGE_EVERYWHERE

templateRenderer

protected transient TemplateRenderer templateRenderer

errorUpdateHandler

protected transient ErrorUpdateHandler errorUpdateHandler

buildDirectoryManager

protected transient BuildDirectoryManager buildDirectoryManager
Constructor Detail

AbstractBuilder

protected AbstractBuilder()
Method Detail

setAdministrationConfiguration

public void setAdministrationConfiguration(AdministrationConfiguration administrationConfiguration)

setTemplateRenderer

public void setTemplateRenderer(TemplateRenderer templateRenderer)

setErrorUpdateHandler

public void setErrorUpdateHandler(ErrorUpdateHandler errorUpdateHandler)

init

public void init(@NotNull
                 com.atlassian.plugin.ModuleDescriptor moduleDescriptor)
Description copied from interface: ConfigurablePlugin
Initialises the Plugin with the plugin module descriptor

Specified by:
init in interface ConfigurablePlugin

getKey

@NotNull
public java.lang.String getKey()
Description copied from interface: Builder
Returns the short simple key for this builder (e.g. mvn, ant). Needs to be unique across the system for each type

Specified by:
getKey in interface Builder
Returns:
The simple key of this builder.

setKey

public void setKey(@NotNull
                   java.lang.String key)

getKeyPrefix

public java.lang.String getKeyPrefix()

getCompleteKey

@NotNull
public java.lang.String getCompleteKey()
Description copied from interface: Builder
Returns the full plugin descriptor key

Specified by:
getCompleteKey in interface Builder
Returns:

getPath

@Nullable
public java.lang.String getPath(ReadOnlyCapabilitySet capabilitySet)
Description copied from interface: Builder
The home path of the builder's command line

Specified by:
getPath in interface Builder
Returns:
The path

getEditHtml

@NotNull
public java.lang.String getEditHtml(@NotNull
                                            BuildConfiguration buildConfiguration,
                                            @NotNull
                                            Build build)
Description copied from interface: ConfigurablePlugin
Returns HTML that represents the form fragment for editing the repository. No opening and closing form tags are required.

Specified by:
getEditHtml in interface ConfigurablePlugin
Returns:
HTMK string. May be null.

prepareConfigObject

public void prepareConfigObject(@NotNull
                                BuildConfiguration buildConfiguration)
Description copied from interface: ConfigurablePlugin
Do any preprocessing work before validation occurs

Specified by:
prepareConfigObject in interface ConfigurablePlugin
Parameters:
buildConfiguration - - @NotNull

customizeBuildRequirements

public void customizeBuildRequirements(@NotNull
                                       BuildConfiguration buildConfiguration,
                                       @NotNull
                                       RequirementSet requirementSet)
Description copied from interface: ConfigurablePlugin
Extension point for adding/customizing requiremnents when editing a build's builder configuration.

Specified by:
customizeBuildRequirements in interface ConfigurablePlugin

isLabelPathMapConfigurable

public boolean isLabelPathMapConfigurable()
Description copied from interface: Builder
Returns true if the Builder can have its LabelPathMap configurable. If it can't be, it won't be displayed on the ConfigureBuilder page.

Specified by:
isLabelPathMapConfigurable in interface Builder
Returns:
true if LabelPathMap is configurable

customiseLabelTypeMap

public java.util.Map<java.lang.String,java.lang.String> customiseLabelTypeMap(java.util.Map<java.lang.String,java.lang.String> labelTypeMap)
Description copied from interface: Builder
Allows the builder to add extra label -> builder type key mappings

Specified by:
customiseLabelTypeMap in interface Builder
Parameters:
labelTypeMap - may be null

getTemplateContext

protected java.util.Map getTemplateContext()

executeBuild

public void executeBuild(@NotNull
                         BuildContext buildContext,
                         ReadOnlyCapabilitySet capabilitySet)
                  throws java.lang.InterruptedException,
                         RepositoryException
Description copied from interface: BuilderV2
Runs the build, and updates the build results in the build context. This method is also responsible for collating the test results in a build

Specified by:
executeBuild in interface BuilderV2
Throws:
java.lang.InterruptedException
RepositoryException

runBuild

public CurrentBuildResult runBuild(@NotNull
                                   BuildContext buildContext,
                                   @NotNull
                                   ReadOnlyCapabilitySet capabilitySet)
                            throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

populateBuildErrors

public void populateBuildErrors(CurrentBuildResult buildResult,
                                java.util.List<java.lang.String> errorOutput,
                                java.lang.String planKey,
                                int buildNumber)
An extension point for implementors to modify the Error Summary

Specified by:
populateBuildErrors in interface BuilderV2
Parameters:
buildResult - - CurrentBuildResult representing the results of the current build
errorOutput - - ErrorLogEntry objects representing the current std error output

collateTestResults

public void collateTestResults(BuildIdentifier buildIdentifier,
                               CurrentBuildResult buildResult,
                               BuildLogger buildLogger)
                        throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

hasPassed

public boolean hasPassed(int returnCode,
                         int buildNumber,
                         java.lang.String planKey)
Description copied from interface: BuilderV2
Determines based on the return code and/or logs whether the build has passed. Implementors should log how they came up with their conclusions -

Specified by:
hasPassed in interface BuilderV2
Parameters:
returnCode - return code from build execution command
planKey - @return true if build has passed

setBuildDir

public void setBuildDir(java.io.File buildDirectory)
Where is the build file file?

Parameters:
buildDirectory - The directory containing the build file

getBuildDir

public java.io.File getBuildDir()
Location of build directory

Returns:

getWorkingDirectory

public java.io.File getWorkingDirectory()
Get the location of the build file (includes the working sub directory of if it exists)

Specified by:
getWorkingDirectory in class Command
Returns:
The build file directory

getLabel

@NotNull
public java.lang.String getLabel()
What is the label used to getPrettyPrint this item in the GUI?

Specified by:
getLabel in interface Builder
Returns:
The label

setLabel

public void setLabel(@NotNull
                     java.lang.String label)
Description copied from interface: Builder
Sets the label being used by the builder

Specified by:
setLabel in interface Builder

getTestResultsDirectory

public java.lang.String getTestResultsDirectory()
What are the build's junit test results stored? Can be a comma separated list

Returns:
Directory containing the Junit xml test files

setTestResultsDirectory

public void setTestResultsDirectory(java.lang.String testResultDirectory)
Let the builder specify the location of the build's test result files.

Parameters:
testResultDirectory - The location of the junit test result xml files

getWorkingSubDirectory

public java.lang.String getWorkingSubDirectory()
Return the optional working subdirectory

Returns:
The subirectory, null if the working directory id the build root

setWorkingSubDirectory

public void setWorkingSubDirectory(java.lang.String workingSubDirectory)
Specify the working sub directory


toString

public java.lang.String toString()
Default toString simply displays the name so they can be slotted into drop down lists and such like.

Overrides:
toString in class java.lang.Object
Returns:
the string

hasTests

public boolean hasTests()
Does the build have any tests to be included in the build results web pages?

Specified by:
hasTests in interface Builder
Returns:
true if the build should have tests.

setHasTests

public void setHasTests(boolean hasTests)
Does the build have any tests to be included in the build results web pages?

Parameters:
hasTests - True if the build should have tests.

setTestChecked

public void setTestChecked(java.lang.String enabled)
The user has selected that the build has tests (via a checkbox)

Parameters:
enabled - set to "on" by the webwork framework

getTestChecked

public java.lang.String getTestChecked()
Informs the UI if the build is testless.

Returns:
true if the build should have tests, false if it's testless.

setEnvironmentVariables

public void setEnvironmentVariables(java.lang.String envVars)
Description copied from interface: MutableEnvironmentVariablesAwareBuilder
Define the system environment variabled required to build the build.

Specified by:
setEnvironmentVariables in interface MutableEnvironmentVariablesAwareBuilder
Parameters:
envVars - The params

getEnvironmentVariables

public java.lang.String getEnvironmentVariables()
Description copied from interface: EnvironmentVariablesAwareBuilder
Provides the ui form with the build's system environment variables

Specified by:
getEnvironmentVariables in interface EnvironmentVariablesAwareBuilder
Returns:
build environment variables

getBuildJdk

@Nullable
public java.lang.String getBuildJdk()
Provide the UI form with the JDK the build needs to be built on

Specified by:
getBuildJdk in interface Builder
Returns:
The JAVA_HOME of the JDK

setBuildJdk

public void setBuildJdk(@NotNull
                        java.lang.String buildJdk)
Define the JDK the build beeds to be built on.

Specified by:
setBuildJdk in interface Builder
Parameters:
buildJdk - The JAVA_HOME JDK

isJdkValid

public boolean isJdkValid()

outputEndsWith

protected boolean outputEndsWith(int positionFromEnd,
                                 java.lang.String expectedText,
                                 java.lang.String planKey,
                                 int buildNumber)
Utility method to check the buildlogs contained the expected success text

Parameters:
positionFromEnd - The expectedText should be wihtin positionFromEnd lines of the end of the output. If 0 the text will not be looked through at all, if -1 the entire text will be searched
expectedText - The text to look for
planKey - The key for the build to check output
buildNumber - The build number to chek the output of
Returns:
true or false; whether the specified text was found in the build logs within the position from end If there is an exception or problem accessing the file, false is returned

setParams

public void setParams(@NotNull
                      FilteredMap filteredParams)
Description copied from interface: Builder
Updates the current builder object with

Specified by:
setParams in interface Builder
Parameters:
filteredParams - - Filtered Map with the prefix builder key stripped out

validate

@NotNull
public ErrorCollection validate(ReadOnlyCapabilitySet capabilities)
Description copied from interface: Builder
Validate the Builder's current internal settings are still valid

Specified by:
validate in interface Builder
Returns:

validate

protected abstract ErrorCollection validate(FilteredMap filteredParams)

getFullParams

@NotNull
public java.util.Map<java.lang.String,java.lang.String> getFullParams()
Description copied from interface: Builder
Gets the full params that's used to persist.

Specified by:
getFullParams in interface Builder
Returns:
Map key by the full param key (e.g. builder.ant.label). Never null

getFilteredParams

protected FilteredMap getFilteredParams()

getViewHtml

@NotNull
public java.lang.String getViewHtml(@NotNull
                                            Build build)
Description copied from interface: ConfigurablePlugin
Returns the HTML that represents the view of the repository configuration

Specified by:
getViewHtml in interface ConfigurablePlugin
Returns:
HTML string. May be null.

getPathHelp

@NotNull
public java.lang.String getPathHelp()
Description copied from interface: Builder
Help text for the builder type

Specified by:
getPathHelp in interface Builder
Returns:

setBuildDirectoryManager

public void setBuildDirectoryManager(BuildDirectoryManager buildDirectoryManager)

setJdkManager

public void setJdkManager(JdkManager jdkManager)

setBuildLogFileAccessorFactory

public void setBuildLogFileAccessorFactory(BuildLogFileAccessorFactory buildLogFileAccessorFactory)


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.