Skip to content
Permalink
Browse files
Fixed JENKINS-19658
  • Loading branch information
MadsNielsen committed Mar 5, 2014
1 parent e2efade commit 474130a5e460ff945a0d9bf72090e0f7b773db0e
@@ -39,12 +39,12 @@ public class NameTemplate {
*/
public static void validateTemplates( CCUCMBuildAction action) {
logger.finer( "Validating templates for " + action );
//Only evaluate those that are actually chosen
Set<String> keys = getChosenTemplates(action.getNameTemplate());
for( String key : keys ) {
//Only evaluate those that are actually chosen
HashMap<String,String> keys = getChosenTemplates(action.getNameTemplate());
for( String key : keys.keySet() ) {
try {
logger.finer( "Validating " + key );
templates.get( key ).parse( action, "" );
templates.get( key ).parse( action, keys.get(key) );
} catch (TemplateException e) {
logger.warning( "Could not validate " + key );
}
@@ -55,7 +55,6 @@ public static String trim( String template ) {
if( template.matches( "^\".+\"$" ) ) {
template = template.substring( 1, template.length()-1 );
}

return template;
}

@@ -64,19 +63,24 @@ public static String trim( String template ) {
* @param templatestring
* @return a Set containing the name of the templates chosen.
*/
public static Set<String> getChosenTemplates(String templatestring) {
Set<String> chosenTemplates = new HashSet<String>();
public static HashMap<String,String> getChosenTemplates(String templatestring) {
HashMap<String,String> chosenTemplates = new HashMap<String,String>();
Matcher m = rx_.matcher( templatestring );

while( m.find() ) {
String replace = m.group(1);
String templateName = replace.toLowerCase().substring( 1, replace.length()-1 );
String templateValue = "";
if( templateName.contains( "=" ) ) {
String[] s = templateName.split( "=" );
templateName = s[0];
templateName = s[0];
templateValue = s[1];

}
chosenTemplates.add(templateName);

if(!chosenTemplates.containsKey(templateName)) {
chosenTemplates.put(templateName, templateValue);
}
}
return chosenTemplates;
}
@@ -182,13 +182,9 @@ public FreeStyleProject setupProject( String projectName, String type, String co
public FreeStyleProject setupProject( String projectName, String type, String component, String stream, boolean recommend, boolean tag, boolean description, boolean createBaseline, boolean forceDeliver, String template ) throws Exception {
return setupProject(projectName, type, component, stream, recommend, tag, description, createBaseline, forceDeliver, template, "INITIAL" );
}

public FreeStyleProject setupProject( String projectName, String type, String component, String stream, boolean recommend, boolean tag, boolean description, boolean createBaseline, boolean forceDeliver, String template, String promotionLevel ) throws Exception {

logger.info( "Setting up build for self polling, recommend:" + recommend + ", tag:" + tag + ", description:" + description );

System.out.println( "==== [Setting up ClearCase UCM project] ====" );
System.out.println( " * Stream : " + stream );

private void printInfo(String projectName, String type, String component, String stream, boolean recommend, boolean tag, boolean description, boolean createBaseline, boolean forceDeliver, String template, String promotionLevel) {
System.out.println( " * Stream : " + stream );
System.out.println( " * Component : " + component );
System.out.println( " * Level : " + promotionLevel );
System.out.println( " * Polling : " + type );
@@ -198,12 +194,18 @@ public FreeStyleProject setupProject( String projectName, String type, String co
System.out.println( " * Create baseline: " + createBaseline );
System.out.println( " * Template : " + template );
System.out.println( " * Force deliver : " + forceDeliver );
}

public FreeStyleProject setupProject( String projectName, String type, String component, String stream, boolean recommend, boolean tag, boolean description, boolean createBaseline, boolean forceDeliver, String template, String promotionLevel ) throws Exception {

logger.info( "Setting up build for self polling, recommend:" + recommend + ", tag:" + tag + ", description:" + description );

System.out.println( "==== [Setting up ClearCase UCM project] ====" );
printInfo(projectName, type, component, stream, recommend, tag, description, createBaseline, forceDeliver, template, promotionLevel);
System.out.println( "============================================" );

FreeStyleProject project = createFreeStyleProject( "ccucm-project-" + projectName );

// boolean createBaseline, String nameTemplate, boolean forceDeliver, boolean recommend, boolean makeTag, boolean setDescription
//CCUCMScm scm = new CCUCMScm( component, "INITIAL", "ALL", false, type, stream, "successful", createBaseline, "[project]_build_[number]", forceDeliver, recommend, tag, description, "jenkins" );

CCUCMScm scm = new CCUCMScm( component, promotionLevel, "ALL", false, type, stream, "successful", createBaseline, template, forceDeliver, recommend, tag, description, "", true, false );
this.scm = scm;
project.setScm( scm );
@@ -238,20 +240,7 @@ public FreeStyleProject setupProjectWithASlave( String projectName, String type,

public FreeStyleProject setupProjectWithASlave( String projectName, String type, String component, String stream, boolean recommend, boolean tag, boolean description, boolean createBaseline, boolean forceDeliver, String template, String promotionLevel ) throws Exception {
logger.info( "Setting up build for self polling, recommend:" + recommend + ", tag:" + tag + ", description:" + description );

System.out.println( "==== [Setting up ClearCase UCM project] ====" );
System.out.println( " * Stream : " + stream );
System.out.println( " * Component : " + component );
System.out.println( " * Level : " + promotionLevel );
System.out.println( " * Polling : " + type );
System.out.println( " * Recommend : " + recommend );
System.out.println( " * Tag : " + tag );
System.out.println( " * Description : " + description );
System.out.println( " * Create baseline: " + createBaseline );
System.out.println( " * Template : " + template );
System.out.println( " * Force deliver : " + forceDeliver );


printInfo(projectName, type, component, stream, recommend, tag, description, createBaseline, forceDeliver, template, promotionLevel);
FreeStyleProject project = createFreeStyleProject( "ccucm-project-" + projectName );
DumbSlave slave = createSlave();
project.setAssignedLabel(slave.getSelfLabel());
@@ -280,10 +269,8 @@ public CCUCMScm getCCUCM( String type, String component, String stream, String p
System.out.println( " * Create baseline: " + createBaseline );
System.out.println( " * Template : " + template );
System.out.println( " * Force deliver : " + forceDeliver );
System.out.println( "============================================" );

CCUCMScm scm = new CCUCMScm( component, promotionLevel, "ALL", false, type, stream, "successful", createBaseline, template, forceDeliver, recommend, tag, description, "", true, false );

System.out.println( "============================================" );
CCUCMScm scm = new CCUCMScm( component, promotionLevel, "ALL", false, type, stream, "successful", createBaseline, template, forceDeliver, recommend, tag, description, "", true, false );
return scm;
}

@@ -311,7 +298,7 @@ public CCUCMScm getScm() {
}

public AbstractBuild<?, ?> initiateBuild( String projectName, String type, String component, String stream, boolean recommend, boolean tag, boolean description, boolean fail, boolean createBaseline, boolean forceDeliver, String template, String promotionLevel ) throws Exception {
FreeStyleProject project = setupProject( projectName, type, component, stream, recommend, tag, description, createBaseline, forceDeliver, template, promotionLevel );
FreeStyleProject project = setupProjectWithASlave( projectName, type, component, stream, recommend, tag, description, createBaseline, forceDeliver, template, promotionLevel );

FreeStyleBuild build = null;

@@ -393,25 +380,16 @@ public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListe
return false;
}
}

public AbstractBuild<?, ?> buildProject( AbstractProject<?, ?> project, boolean fail ) throws IOException {

public AbstractBuild<?, ?> buildProject( AbstractProject<?, ?> project, boolean fail ) throws IOException, Exception {
return buildProject( project, fail, createSlave() );
}

public AbstractBuild<?, ?> buildProject( AbstractProject<?, ?> project, boolean fail, Slave slave ) throws IOException {

if( slave != null ) {
System.out.println( String.format( "[SLAVE-CONFIG] Running on %s", slave.getSelfLabel().getName() ) );
logger.fine( String.format( "Running on %s", slave.getSelfLabel().getName() ) );
project.setAssignedLabel(slave.getSelfLabel());
}

EnableLoggerAction action = null;
if( outputDir != null ) {
logger.fine( "Enabling logging" );
action = new EnableLoggerAction( outputDir );
}

AbstractBuild<?, ?> build = null;
try {
build = project.scheduleBuild2(0, new Cause.UserCause(), action ).get();
@@ -16,26 +16,23 @@ public class Story06WithSlaves extends Story06Base {
public void story06_4() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Stream dev2 = ccenv.context.streams.get( "two_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( dev1, dev2, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_two_dev", slave, false );
runWithSlave( dev1, dev2, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_two_dev", false );
}

@Test
@ClearCaseUniqueVobName( name = "dip5" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from same stream, different view", configurations = { "Force deliver = true", "Poll childs", "On slave" } )
public void story06_5() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( dev1, dev1, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_one_dev", slave, false );
runWithSlave( dev1, dev1, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_one_dev", false );
}

@Test
@ClearCaseUniqueVobName( name = "dip6" )
@TestDescription( title = "Story 6", text = "New baseline on dev stream. Deliver in progress from previous build, different view", configurations = { "Force deliver = true", "Poll childs", "On slave" } )
public void story06_6() throws Exception {
Stream dev1 = ccenv.context.streams.get( "one_dev" );
Slave slave = jenkins.createSlave( new LabelAtom( "ClearCaseSlave" ) );
run( null, dev1, null, ccenv.getUniqueName() + "_one_dev", slave, true );
runWithSlave( null, dev1, null, ccenv.getUniqueName() + "_one_dev", true );
}

}
@@ -6,6 +6,7 @@
import net.praqma.clearcase.test.junit.ClearCaseRule;
import net.praqma.hudson.test.BaseTestClass;
import net.praqma.util.debug.Logger;
import net.praqma.util.test.junit.TestDescription;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
@@ -18,11 +19,23 @@ public class Polling extends BaseTestClass {
private static Logger logger = Logger.getLogger();

@Test
@TestDescription(title = "Self polling, create baseline", text="This is a test that should return no-changes, if a baseline is specified")
@ClearCaseUniqueVobName( name = "self-create-baseline")
public void testPollingNoChangesWithCreateBaselines() throws Exception {
FreeStyleProject project = jenkins.setupProjectWithASlave( "polling-test-with-baselines-" + ccenv.getUniqueName(), "self", "_System@" + ccenv.getPVob(), "one_int@" + ccenv.getPVob(), false, false, false, true );


/** Initial build **/
try {
project.scheduleBuild2( 0 ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}

PollingResult result = project.poll(jenkins.createTaskListener());
assertFalse(result.hasChanges());

System.out.println("Changes: "+result.hasChanges());
assertFalse("We expect no changes. According to the fix i made for JENKINS-18107", result.hasChanges());
}

@Test
@@ -50,8 +63,7 @@ public void testPollingSelfWithNoBaselines() throws Exception {
project.scheduleBuild2( 0 ).get();
} catch( Exception e ) {
logger.info( "Build failed: " + e.getMessage() );
}

}
/* BUILD 2 */
try {
project.scheduleBuild2( 0 ).get();
@@ -10,7 +10,6 @@
import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import net.praqma.hudson.test.SystemValidator;
import net.praqma.util.debug.Logger;

import net.praqma.clearcase.test.junit.ClearCaseRule;

@@ -43,6 +42,5 @@ public void basicSibling() throws Exception {
validateCreatedBaseline( true );
validator.validate();
}



}
@@ -1,11 +1,8 @@
package net.praqma.hudson.test.integration.userstories;

import java.io.File;
import java.util.logging.Level;

import net.praqma.hudson.test.BaseTestClass;
import net.praqma.util.test.junit.LoggingRule;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

@@ -16,7 +13,6 @@
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.clearcase.util.ExceptionUtils;
import net.praqma.hudson.test.CCUCMRule;
import net.praqma.hudson.test.SystemValidator;
import net.praqma.util.test.junit.TestDescription;
import net.praqma.util.debug.Logger;
@@ -25,7 +21,6 @@
import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
import net.praqma.clearcase.test.junit.ClearCaseRule;

import static org.junit.Assert.*;

public class Story04 extends BaseTestClass {

@@ -1,10 +1,9 @@
package net.praqma.hudson.test.integration.userstories;

import net.praqma.clearcase.test.annotations.ClearCaseUniqueVobName;
import org.junit.Test;

import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.util.test.junit.TestDescription;
import org.junit.Test;

public class Story06 extends Story06Base {

@@ -15,22 +14,22 @@ public class Story06 extends Story06Base {
public void story06_1() throws Exception {
Stream dev1 = ccenv.context.streams.get("one_dev");
Stream dev2 = ccenv.context.streams.get("two_dev");
run(dev1, dev2, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_two_dev", null, false);
run(dev1, dev2, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_two_dev", false);
}

@Test
@ClearCaseUniqueVobName(name = "dip2")
@TestDescription(title = "Story 6", text = "New baseline on dev stream. Deliver in progress from same stream, different view", configurations = {"Force deliver = true", "Poll childs"})
public void story06_2() throws Exception {
Stream dev1 = ccenv.context.streams.get("one_dev");
run(dev1, dev1, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_one_dev", null, false);
run(dev1, dev1, ccenv.getUniqueName() + "_one_dev", ccenv.getUniqueName() + "_one_dev", false);
}

@Test
@ClearCaseUniqueVobName(name = "dip3")
@TestDescription(title = "Story 6", text = "New baseline on dev stream. Deliver in progress from previous build, different view", configurations = {"Force deliver = true", "Poll childs"})
public void story06_3() throws Exception {
Stream dev1 = ccenv.context.streams.get("one_dev");
run(null, dev1, null, ccenv.getUniqueName() + "_one_dev", null, true);
run(null, dev1, null, ccenv.getUniqueName() + "_one_dev", true);
}
}

0 comments on commit 474130a

Please sign in to comment.