Navigation Menu

Skip to content

Commit

Permalink
[Fixed JENKINS-9433] Job name is lost in ClearCase view tag when
Browse files Browse the repository at this point in the history
running matrix job configuration

Now resolving JOB_NAME to Project#getFullName instead of
Project#getName
  • Loading branch information
Vlatombe committed Apr 23, 2011
1 parent 6c444cc commit cde42ca
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
Expand Up @@ -350,7 +350,7 @@ public String getViewName(VariableResolver<String> variableResolver) {
String normalized = null;
String v = getViewName();
if (v != null) {
normalized = Util.replaceMacro(v.replaceAll("[\\s\\\\\\/:\\?\\*\\|]+", "_"), variableResolver);
normalized = Util.replaceMacro(v, variableResolver).replaceAll("[\\s\\\\\\/:\\?\\*\\|]+", "_");
setNormalizedViewName(normalized);
}
return normalized;
Expand Down Expand Up @@ -730,7 +730,7 @@ public String getViewPath(VariableResolver<String> variableResolver) {
String normalized = null;
String viewPath = StringUtils.defaultIfEmpty(getViewPath(), getViewName());
if (viewPath != null) {
normalized = Util.replaceMacro(viewPath.replaceAll("[\\s\\\\\\/:\\?\\*\\|]+", "_"), variableResolver);
normalized = Util.replaceMacro(viewPath, variableResolver).replaceAll("[\\s\\\\\\/:\\?\\*\\|]+", "_");
setNormalizedViewPath(normalized);
}
return normalized;
Expand Down
Expand Up @@ -89,7 +89,7 @@ public String resolve(String key) {
}
LogTaskListener ltl = new LogTaskListener(LOGGER, Level.INFO);
if ("JOB_NAME".equals(key) && build != null && build.getProject() != null) {
return build.getProject().getName();
return build.getProject().getFullName();
}

if ("HOST".equals(key)) {
Expand Down
Expand Up @@ -205,7 +205,7 @@ public void assertViewNameMacrosAreWorking() throws IOException, InterruptedExce

when(build.getBuiltOn()).thenReturn(node);
when(build.getProject()).thenReturn(project);
when(project.getName()).thenReturn("Hudson");
when(project.getFullName()).thenReturn("Hudson");
when(node.toComputer()).thenReturn(computer);
when(node.getNodeName()).thenReturn("test-node");
when(computer.getSystemProperties()).thenReturn(System.getProperties());
Expand All @@ -222,7 +222,7 @@ public void assertViewNameMacrosAreWorking() throws IOException, InterruptedExce
public void testViewNameMacrosUsingBuildEnv() throws IOException, InterruptedException {
when(build.getBuiltOn()).thenReturn(node);
when(build.getProject()).thenReturn(project);
when(project.getName()).thenReturn("Hudson");
when(project.getFullName()).thenReturn("Hudson");
when(node.toComputer()).thenReturn(computer);
when(node.getNodeName()).thenReturn("test-node");
when(build.getBuildVariables()).thenReturn(Collections.emptyMap());
Expand Down Expand Up @@ -298,7 +298,7 @@ public void assertBuildEnvVarsUsesNormalizedViewName() throws IOException, Inter
when(node.getNodeName()).thenReturn("test-node");
when(build.getBuildVariables()).thenReturn(Collections.emptyMap());
when(computer.getSystemProperties()).thenReturn(System.getProperties());
when(project.getName()).thenReturn("CCHudson");
when(project.getFullName()).thenReturn("CCHudson");

AbstractClearCaseScm scm = new AbstractClearCaseScmDummy("viewname-${JOB_NAME}-${NODE_NAME}", "vob", "");
Map<String, String> env = new HashMap<String, String>();
Expand Down Expand Up @@ -427,7 +427,7 @@ public void assertCheckoutUsesNormalizedViewName() throws Exception {
when(node.toComputer()).thenReturn(computer);
when(node.getNodeName()).thenReturn("test-node");
when(build.getProject()).thenReturn(project);
when(project.getName()).thenReturn("CCHudson");
when(project.getFullName()).thenReturn("CCHudson");
when(build.getBuildVariables()).thenReturn(Collections.emptyMap());
when(build.getEnvironment(any(LogTaskListener.class))).thenReturn(new EnvVars("JOB_NAME", "Hudson", "NODE_NAME", "test-node"));
when(computer.getSystemProperties()).thenReturn(System.getProperties());
Expand Down Expand Up @@ -548,13 +548,13 @@ public void testPollChangesWithBuffer() throws Exception {
@Test
public void assertPollChangesUsesNormalizedViewName() throws Exception {
createWorkspace();
when(historyAction.hasChanges(any(Date.class), eq("view-CCHudson-test-node"), eq("view-CCHudson-test-node"), any(String[].class), any(String[].class)))
when(historyAction.hasChanges(any(Date.class), eq("view-MatrixProject_CCHudson-test-node"), eq("view-MatrixProject_CCHudson-test-node"), any(String[].class), any(String[].class)))
.thenReturn(Boolean.TRUE);
when(build.getBuiltOn()).thenReturn(node);
when(node.toComputer()).thenReturn(computer);
when(node.getNodeName()).thenReturn("test-node");
when(build.getProject()).thenReturn(project);
when(project.getName()).thenReturn("CCHudson");
when(project.getFullName()).thenReturn("MatrixProject/CCHudson");
when(project.getSomeBuildWithWorkspace()).thenReturn(build);
when(build.getTimestamp()).thenReturn(Calendar.getInstance());
when(build.getBuildVariables()).thenReturn(Collections.emptyMap());
Expand All @@ -565,10 +565,10 @@ public void assertPollChangesUsesNormalizedViewName() throws Exception {

AbstractClearCaseScm scm = new AbstractClearCaseScmDummy("view-${JOB_NAME}-${NODE_NAME}", "vob", "");
scm.compareRemoteRevisionWith(project, launcher, workspace, taskListener, scmRevisionState);
verify(historyAction).hasChanges(any(Date.class), eq("view-CCHudson-test-node"), eq("view-CCHudson-test-node"), any(String[].class),
verify(historyAction).hasChanges(any(Date.class), eq("view-MatrixProject_CCHudson-test-node"), eq("view-MatrixProject_CCHudson-test-node"), any(String[].class),
any(String[].class));
}

@Test
public void testPollChangesFirstTime() throws Exception {
when(project.getSomeBuildWithWorkspace()).thenReturn(null);
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/hudson/plugins/clearcase/ClearCaseSCMTest.java
Expand Up @@ -55,12 +55,12 @@
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(Node.class)
@PrepareForTest({Node.class, AbstractProject.class})
public class ClearCaseSCMTest extends AbstractWorkspaceTest {

@Mock
private ClearTool cleartool;
@Mock

private AbstractProject project;
@Mock
private Build build;
Expand All @@ -79,6 +79,7 @@ public class ClearCaseSCMTest extends AbstractWorkspaceTest {
public void setUp() throws Exception {
createWorkspace();
node = PowerMockito.mock(Node.class);
project = PowerMockito.mock(AbstractProject.class);
}

@After
Expand Down Expand Up @@ -236,7 +237,7 @@ public void assertExtendedViewPathUsesNormalizedViewName() throws Exception {
when(node.toComputer()).thenReturn(computer);
when(node.getNodeName()).thenReturn("test-node");
when(build.getProject()).thenReturn(project);
when(project.getName()).thenReturn("ClearCase");
when(project.getFullName()).thenReturn("ClearCase");
when(build.getBuildVariables()).thenReturn(new HashMap());
when(build.getEnvironment(any(LogTaskListener.class))).thenReturn(new EnvVars("JOB_NAME", "ClearCase"));
when(computer.getSystemProperties()).thenReturn(System.getProperties());
Expand Down Expand Up @@ -264,7 +265,7 @@ public void assertConfigSpecCanUseVariables() throws Exception {
when(node.toComputer()).thenReturn(computer);
when(node.getNodeName()).thenReturn("test-node");
when(build.getProject()).thenReturn(project);
when(project.getName()).thenReturn("ClearCase");
when(project.getFullName()).thenReturn("ClearCase");
when(build.getParent()).thenReturn(project);
when(launcher.isUnix()).thenReturn(true);
when(build.getBuildVariables()).thenReturn(new HashMap<Object, Object>());
Expand Down
Expand Up @@ -52,11 +52,11 @@
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(Node.class)
@PrepareForTest({Node.class, AbstractProject.class})
public class ClearCaseUcmSCMTest extends AbstractWorkspaceTest {
@Mock
private ClearTool cleartool;
@Mock

private AbstractProject project;
@Mock
private Build build;
Expand All @@ -76,6 +76,7 @@ public class ClearCaseUcmSCMTest extends AbstractWorkspaceTest {
public void setUp() throws Exception {
createWorkspace();
node = PowerMockito.mock(Node.class);
project = PowerMockito.mock(AbstractProject.class);
}

@After
Expand Down Expand Up @@ -196,7 +197,7 @@ public void assertExtendedViewPathUsesNormalizedViewName() throws Exception {
when(node.getNodeName()).thenReturn("test-node");
when(build.getBuiltOn()).thenReturn(node);
when(build.getProject()).thenReturn(project);
when(project.getName()).thenReturn("ClearCase");
when(project.getFullName()).thenReturn("ClearCase");
when(build.getParent()).thenReturn(project);
when(launcher.isUnix()).thenReturn(Boolean.TRUE);
when(build.getBuildVariables()).thenReturn(Collections.emptyMap());
Expand Down

0 comments on commit cde42ca

Please sign in to comment.