Skip to content

Commit

Permalink
[JENKINS-42360] Improve validation on object method calls
Browse files Browse the repository at this point in the history
Actually distinguish object method calls from generalized "expected a
symbol", and report accordingly.
  • Loading branch information
abayer committed Feb 28, 2017
1 parent faa4b12 commit 2750f57
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Expand Up @@ -882,7 +882,12 @@ class ModelParser implements Parser {
protected String parseMethodName(MethodCallExpression exp) {
def s = matchMethodName(exp)
if (s==null) {
errorCollector.error(ModelASTValue.fromConstant(null, exp), Messages.ModelParser_ExpectedSymbol())
if (exp.objectExpression instanceof VariableExpression &&
!((VariableExpression)exp.objectExpression).isThisExpression()) {
errorCollector.error(ModelASTValue.fromConstant(null, exp), Messages.ModelParser_ObjectMethodCall())
} else {
errorCollector.error(ModelASTValue.fromConstant(null, exp), Messages.ModelParser_ExpectedSymbol())
}
s = "error";
}
return s;
Expand Down
Expand Up @@ -62,6 +62,7 @@ ModelParser.NoArgForAgent=No argument for agent
ModelParser.NoArgForAgentKey=No argument for agent key "{0}"
ModelParser.NoArgForMapMethodKey=No argument for map key "{0}"
ModelParser.NoArgForTool=No argument for tool "{0}"
ModelParser.ObjectMethodCall=Method calls on objects not allowed outside "script" blocks.
ModelParser.OneAgentMax=Only one agent type is allowed per agent section
ModelParser.PipelineBlockNotAtTop={0} block must be at the top-level, not within another block.
ModelParser.PipelineStepWithoutBlock=Expected a block with the "{0}" step
Expand Down
Expand Up @@ -534,7 +534,7 @@ public void libraryObjectInScript() throws Exception {

@Issue("JENKINS-40657")
@Test
public void libraryObjectOutsideScript() throws Exception {
public void libraryObjectDefinedOutsidePipeline() throws Exception {
otherRepo.init();
otherRepo.write("src/org/foo/Zot.groovy", "package org.foo;\n" +
"\n" +
Expand All @@ -553,7 +553,7 @@ public void libraryObjectOutsideScript() throws Exception {
new LibraryConfiguration("zot-stuff",
new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true)))));

expect("libraryObjectOutsideScript")
expect("libraryObjectDefinedOutsidePipeline")
.logContains("hello");
}

Expand Down
Expand Up @@ -410,7 +410,7 @@ public void globalLibraryObjectMethodCall() throws Exception {
// Test the case of calling a method on an object, i.e., foo.bar(1). This will fail.
expectError("globalLibraryObjectMethodCall")
.logContains("MultipleCompilationErrorsException: startup failed:",
Messages.ModelParser_ExpectedSymbol())
Messages.ModelParser_ObjectMethodCall())
.go();
}

Expand Down

0 comments on commit 2750f57

Please sign in to comment.