Skip to content

Commit

Permalink
[FIXED JENKINS-27243] - Properly handle axis values cache to avoid is…
Browse files Browse the repository at this point in the history
…sues on nested calls.

The change also improves logging in the plugin.

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
  • Loading branch information
oleg-nenashev committed Mar 8, 2015
1 parent 229a41c commit 9b4b0d5
Showing 1 changed file with 19 additions and 9 deletions.
Expand Up @@ -24,6 +24,7 @@

import com.google.common.collect.Lists;
import hudson.Util;
import java.util.logging.Level;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -69,6 +70,7 @@ private void checkForDefaultValues()
{
if( axisValues.isEmpty() )
{
LOGGER.fine( "Axis values list is empty. Adding 'default' value" );
axisValues.add( "default" );
}
}
Expand Down Expand Up @@ -104,13 +106,14 @@ private void checkForDefaultValues()
* environment variable name to get list of axis values to use for the
* current build.
* @see hudson.matrix.Axis#rebuild(hudson.matrix.MatrixBuild.MatrixBuildExecution)
* @return New list of axis values
*/
@Override
public synchronized @Nonnull List<String> rebuild( MatrixBuild.MatrixBuildExecution context )
public synchronized @Nonnull List<String> rebuild( @CheckForNull MatrixBuild.MatrixBuildExecution context )
{
// clear any existing values to ensure we do not return old ones
LOGGER.fine( "Rebuilding axis names from variable '" + varName + "'" );
axisValues.clear();
LOGGER.log( Level.FINE, "Rebuilding axis names from variable ''{0}''", varName);
final List<String> newAxisValues = new ArrayList<String>(axisValues.size());
if( context != null )
{
try
Expand All @@ -123,10 +126,10 @@ private void checkForDefaultValues()
String varValue = vars.get( varName );
if( varValue != null )
{
LOGGER.fine( "Variable value is '" + varValue + "'" );
LOGGER.log( Level.FINE, "Variable value is ''{0}''", varValue);
for( String item : Util.tokenize(varValue) )
{
axisValues.add( item );
newAxisValues.add( item );
}
}
}
Expand All @@ -138,10 +141,17 @@ private void checkForDefaultValues()
}

// validate result list before returning it
checkForDefaultValues();
LOGGER.fine( "Returning axis list " + axisValues );
// must return a new object because axisValues might change
return new ArrayList<String>(axisValues);
if (newAxisValues.isEmpty()) {
LOGGER.fine( "Axis values list is empty. Adding 'default' value" );
newAxisValues.add( "default" );
}
LOGGER.log( Level.FINE, "Returning axis list {0}", newAxisValues);

// Add values to the cache
axisValues.clear();
axisValues.addAll(newAxisValues);

return newAxisValues;
}

/**
Expand Down

0 comments on commit 9b4b0d5

Please sign in to comment.