Skip to content

Commit

Permalink
Merge pull request #127 from abayer/jenkins-42360
Browse files Browse the repository at this point in the history
[JENKINS-42360] Improve validation on object method calls
  • Loading branch information
abayer committed Mar 1, 2017
2 parents faa4b12 + 2750f57 commit 5c215ff
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -882,7 +882,12 @@ class ModelParser implements Parser {
protected String parseMethodName(MethodCallExpression exp) { protected String parseMethodName(MethodCallExpression exp) {
def s = matchMethodName(exp) def s = matchMethodName(exp)
if (s==null) { 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"; s = "error";
} }
return s; return s;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ModelParser.NoArgForAgent=No argument for agent
ModelParser.NoArgForAgentKey=No argument for agent key "{0}" ModelParser.NoArgForAgentKey=No argument for agent key "{0}"
ModelParser.NoArgForMapMethodKey=No argument for map key "{0}" ModelParser.NoArgForMapMethodKey=No argument for map key "{0}"
ModelParser.NoArgForTool=No argument for tool "{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.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.PipelineBlockNotAtTop={0} block must be at the top-level, not within another block.
ModelParser.PipelineStepWithoutBlock=Expected a block with the "{0}" step ModelParser.PipelineStepWithoutBlock=Expected a block with the "{0}" step
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public void libraryObjectInScript() throws Exception {


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


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


Expand Down
Original file line number Original file line Diff line number Diff line change
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. // Test the case of calling a method on an object, i.e., foo.bar(1). This will fail.
expectError("globalLibraryObjectMethodCall") expectError("globalLibraryObjectMethodCall")
.logContains("MultipleCompilationErrorsException: startup failed:", .logContains("MultipleCompilationErrorsException: startup failed:",
Messages.ModelParser_ExpectedSymbol()) Messages.ModelParser_ObjectMethodCall())
.go(); .go();
} }


Expand Down

0 comments on commit 5c215ff

Please sign in to comment.