Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-18994] NPE when no updt file is generated
  • Loading branch information
Vlatombe committed Aug 1, 2013
1 parent 93f310f commit a4bb13e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
Expand Up @@ -30,6 +30,10 @@
*/
public class CleartoolUpdateResult {
private final FilePath updateFile;

public CleartoolUpdateResult() {
this(null);
}

/**
* @param updateFile
Expand All @@ -43,4 +47,8 @@ public CleartoolUpdateResult(FilePath updateFile) {
public FilePath getUpdateFile() {
return updateFile;
}

public boolean hasUpdateFile(){
return updateFile != null;
}
}
Expand Up @@ -71,36 +71,26 @@ public boolean checkout(Launcher launcher, FilePath workspace, String viewTag) t
loadRulesDelta = getLoadRulesDelta(viewConfigSpec.getLoadRules(), launcher);
needSetCs = !configSpec.stripLoadRules().equals(viewConfigSpec.stripLoadRules()) || !ArrayUtils.isEmpty(loadRulesDelta.getRemoved());
}
CleartoolUpdateResult result = null;
if (needSetCs) {
try {
try {
CleartoolUpdateResult result = null;
if (needSetCs) {
result = getCleartool().setcs2(viewPath, SetcsOption.CONFIGSPEC, configSpec.setLoadRules(loadRules).getRaw());
} catch (IOException e) {
launcher.getListener().fatalError(e.toString());
return false;
}
} else {
// Perform a full update of the view to reevaluate config spec
try {
} else {
// Perform a full update of the view to reevaluate config spec
result = getCleartool().setcs2(viewPath, SetcsOption.CURRENT, null);
} catch (IOException e) {
launcher.getListener().fatalError(e.toString());
return false;
}
String[] addedLoadRules = loadRulesDelta.getAdded();
if (!ArrayUtils.isEmpty(addedLoadRules)) {
// Config spec haven't changed, but there are new load rules
try {
String[] addedLoadRules = loadRulesDelta.getAdded();
if (!ArrayUtils.isEmpty(addedLoadRules)) {
// Config spec haven't changed, but there are new load rules
result = getCleartool().update2(viewPath, addedLoadRules);
} catch (IOException e) {
launcher.getListener().fatalError(e.toString());
return false;
}
}
}
if (result != null) {
updtFile = result.getUpdateFile();
launcher.getListener().getLogger().println("[INFO] updt file name: '" + updtFile.getRemote() + "'");
if (result.hasUpdateFile()) {
updtFile = result.getUpdateFile();
launcher.getListener().getLogger().println("[INFO] updt file name: '" + updtFile.getRemote() + "'");
}
} catch (IOException e) {
launcher.getListener().fatalError(e.toString());
return false;
}

if (build != null) {
Expand Down
Expand Up @@ -26,11 +26,16 @@

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

import java.io.File;

import hudson.FilePath;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.plugins.clearcase.AbstractWorkspaceTest;
import hudson.plugins.clearcase.ClearTool;
import hudson.plugins.clearcase.ClearToolLauncher;
import hudson.plugins.clearcase.CleartoolUpdateResult;
import hudson.plugins.clearcase.MkViewParameters;
import hudson.plugins.clearcase.ClearTool.SetcsOption;
import hudson.plugins.clearcase.ConfigSpec;
Expand Down Expand Up @@ -59,6 +64,8 @@ public void setUp() throws Exception {
when(ctLauncher.getListener()).thenReturn(taskListener);
when(launcher.getListener()).thenReturn(taskListener);
when(taskListener.getLogger()).thenReturn(System.out);
when(cleartool.setcs2(anyString(), any(SetcsOption.class), anyString())).thenReturn(new CleartoolUpdateResult());
when(cleartool.update2(anyString(), any(String[].class))).thenReturn(new CleartoolUpdateResult());
createWorkspace();
}

Expand Down Expand Up @@ -275,4 +282,13 @@ public void testSecondTimeRemovedLoadRule() throws Exception {
verify(cleartool).setcs2("viewpath", SetcsOption.CONFIGSPEC, "configspec\nload /bar\n");
}

@Test
public void checkUpdtGenerated() throws Exception {
FilePath updtFile = new FilePath(new File("tmp"));
when(cleartool.setcs2(anyString(), any(SetcsOption.class), anyString())).thenReturn(new CleartoolUpdateResult(updtFile ));

CheckoutAction action = new BaseSnapshotCheckoutAction(cleartool, new ConfigSpec("configspec", true), new String[] { "bar" }, true, "viewpath", null);
action.checkout(launcher, workspace, "viewname");
assertEquals(action.getUpdtFile(), updtFile);
}
}

0 comments on commit a4bb13e

Please sign in to comment.