Skip to content

Commit

Permalink
fixed JENKINS-14239
Browse files Browse the repository at this point in the history
  • Loading branch information
les-praqma committed Jun 28, 2012
1 parent 4706bd4 commit bd89620
Showing 1 changed file with 26 additions and 66 deletions.
92 changes: 26 additions & 66 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -597,13 +597,7 @@ private boolean pollStream( FilePath workspace, AbstractProject<?, ?> project, S
baselines = getBaselinesFromStreams( workspace, listener, out, state, state.getStream(), state.getComponent(), polling.isPollingChilds() );
}

int total = baselines.size();
int pruned = filterBaselines( baselines );
baselines = filterBuildingBaselines( project, baselines );

if( pruned > 0 ) {
out.println( "[" + Config.nameShort + "] Removed " + pruned + " of " + total + " Baselines." );
}
filterBaselines( project,state.getStream(), baselines );

/* if we did not find any baselines we should return false */
if( baselines.size() < 1 ) {
Expand Down Expand Up @@ -999,8 +993,7 @@ public boolean accept( File file, String name ) {
logger.debug( "I found " + baselines.size() + " baseline" + ( baselines.size() == 1 ? "" : "s" ) );

/* Discard baselines */
filterBaselines( baselines );
baselines = filterBuildingBaselines( project, baselines );
filterBaselines( project,state.getStream(), baselines );

logger.debug( "When filtered, I have " + baselines.size() + " baseline" + ( baselines.size() == 1 ? "" : "s" ) );

Expand Down Expand Up @@ -1181,78 +1174,45 @@ private List<Baseline> getValidBaselinesFromStream( FilePath workspace, State st
}

/**
* Discards baselines being build
* Filter out baselines that is involved in a deliver or does not have a
* label
*
* @param project
* @param baselines
* @return
* @throws ScmException
*/
public List<Baseline> filterBuildingBaselines( AbstractProject<?, ?> project, List<Baseline> baselines ) throws ScmException {
logger.debug( id + "CCUCM=" + ccucm.stringify(), id );
private void filterBaselines( AbstractProject<?, ?> project, Stream stream, List<Baseline> baselines ) {

List<Baseline> validBaselines = new ArrayList<Baseline>();
/* Remove deliver baselines */
Iterator<Baseline> it = baselines.iterator();
while( it.hasNext() ) {
Baseline baseline = it.next();

/* For each baseline in the list */
for( Baseline b : baselines ) {
/* Get the state for the current baseline */
State cstate = ccucm.getStateByBaseline( jobName, b.getFullyQualifiedName() );
//logger.debug( "CSTATE: " + cstate );
State cstate = ccucm.getStateByBaseline( jobName, baseline.getFullyQualifiedName() );

/*
* The baseline is in progress, determine if the job is still
* running
*/
if( cstate != null ) {
if( baseline.getShortname().startsWith( "deliverbl." ) || baseline.getLabelStatus().equals( LabelStatus.UNLABLED ) ) {
it.remove();
} else if( !baseline.getMastership().equals( stream.getMastership() ) ) {
it.remove();
} else if( cstate != null ) {
/* The baseline is in progress, determine if the job is still running */
Integer bnum = cstate.getJobNumber();
Object o = project.getBuildByNumber( bnum );
Build bld = (Build) o;
Build bld = (Build) project.getBuildByNumber( bnum );

/* prevent null pointer exceptions */
if( bld != null ) {
if( b.getPromotionLevel( true ).equals( cstate.getBaseline().getPromotionLevel( true ) ) ) {
logger.debug( id + b.getShortname() + " has the same promotion level" );
continue;
}

/* The job is not running */
if( !bld.isLogUpdated() ) {
logger.debug( id + "Job " + bld.getNumber() + " is not building", id );
validBaselines.add( b );
} else {
if( baseline.getPromotionLevel( true ).equals( cstate.getBaseline().getPromotionLevel( true ) ) ) {
logger.debug( id + baseline.getShortname() + " has the same promotion level" );
it.remove();
} else if( bld.isLogUpdated() ) {
logger.debug( id + "Job " + bld.getNumber() + " is building " + cstate.getBaseline().getFullyQualifiedName(), id );
}
} else {
/* What to do!? Let's skip it! */
it.remove();
} else {
/* The job is not running */
logger.debug( id + "Job " + bld.getNumber() + " is not building", id );
}
}
} else {
validBaselines.add( b );
}
}

return validBaselines;
}

/**
* Filter out baselines that is involved in a deliver or does not have a
* label
*
* @param baselines
*/
private int filterBaselines( List<Baseline> baselines ) {

int pruned = 0;

/* Remove deliver baselines */
Iterator<Baseline> it = baselines.iterator();
while( it.hasNext() ) {
Baseline baseline = it.next();
if( baseline.getShortname().startsWith( "deliverbl." ) || baseline.getLabelStatus().equals( LabelStatus.UNLABLED ) ) {
it.remove();
pruned++;
}
}
return pruned;
}

/**
Expand Down

0 comments on commit bd89620

Please sign in to comment.