java icon indicating copy to clipboard operation
java copied to clipboard

Groovy interop call yields illegal argument exception from DSL - using CLI, works from test

Open chipbite opened this issue 1 year ago • 4 comments

Expected

Context views are created from the groovy inline script, same as when running the exact same code from test. Instead, an illegalargument exception is thrown: com.structurizr.dsl.StructurizrDslParserException: Error running inline script, caused by javax.script.ScriptException: javax.script.ScriptException: java.lang.IllegalArgumentException: A key must be specified at

Actual

CLI outputs:

com.structurizr.dsl.StructurizrDslParserException: Error running inline script, caused by javax.script.ScriptException: javax.script.ScriptException: java.lang.IllegalArgumentException: A key must be specified at line 34 of C:\temp\structurizr test\structurizr for java\java\structurizr-dsl\src\test\resources\dsl\group-groovy-createviews.dsl: }
        at com.structurizr.dsl.StructurizrDslParser.parse(StructurizrDslParser.java:927)
        at com.structurizr.dsl.StructurizrDslParser.parse(StructurizrDslParser.java:143)
        at com.structurizr.cli.AbstractCommand.loadWorkspace(AbstractCommand.java:83)
        at com.structurizr.cli.export.ExportCommand.run(ExportCommand.java:107)
        at com.structurizr.cli.StructurizrCliApplication.run(StructurizrCliApplication.java:81)
        at com.structurizr.cli.StructurizrCliApplication.main(StructurizrCliApplication.java:102)

Steps to reproduce

Run the CLI on following sample structurizr DSL file with a few inline scripts:

workspace {
    !identifiers hierarchical 

    model {
        group "System Group A" {
            groupA_1 = softwareSystem "Group A 1" 
            groupA_2 = softwareSystem "Group A 2" 
            groupA_3 = softwareSystem "Group A 3"
        }
        otherSystem = softwareSystem "B"
   }

    views {
        # Generate context views, etc for all systems in group A
        !script groovy {
            workspace.model.softwareSystems.findAll { it.group == "System Group A" }.each{ 
                println("--" + it.name);
                workspace.views.createSystemContextView(it, "", "");
            };
        }
    }
}

Version/build information

C:\Users\mawid6>C:\Users\mawid6\tools\structurizr\structurizr.bat version
structurizr-cli: 1.34.0
structurizr-java: 1.27.0
structurizr-dsl: 1.33.0
structurizr-export: 1.17.0
structurizr-import: v1.6.0
Java: 17.0.11/Microsoft (C:\Program Files\Microsoft\jdk-17.0.11.9-hotspot)
OS: Windows 10 10.0 (amd64)

Severity

Minor

Priority

I have no budget and there's no rush, please fix this for free

More information

Executing this from a test in the suite works fine!

So, I added this test to DslTests.java and it executes without any problem (running against the file contents above, i e group-groovy-createviews.dsl):

  @Test
  void test_inlineScriptCreateContextViews() throws Exception {
      StructurizrDslParser parser = new StructurizrDslParser();
      parser.parse(new File("src/test/resources/dsl/group-groovy-createviews.dsl"));

      var dslmodel = parser.getWorkspace().getModel();
      long groupSystemsCount = dslmodel.getSoftwareSystems().stream()
          .filter( ss -> "System Group A".equals(ss.getGroup()) ).count();
      assertEquals(3, groupSystemsCount);

      var countOfViews = parser.getWorkspace().getViews().getViews().size();

      assertEquals(3, countOfViews);
  }

chipbite avatar Jun 28 '24 10:06 chipbite

Oops, submitted before I was done, I also want to say that:

  1. I may be making a rookie mistake, ofc. Other inline scripts are working though, and since it works from the test, it seems ok.
  2. I have also tested: (a) null's instead of empty strings, get same result. (b) Only supplying one parameter, then it does not resolve to the correct method, which makes sense ofc.
  3. Not sure if this is a defect in the library per se, I checked the code briefly - or if it is some groovy interop:ish issue. Regardless, would be good to be able to access methods like these, a workaround might be adding a method signature without the "optional" / empty string parameters, if all else fails.

chipbite avatar Jun 28 '24 10:06 chipbite

FYI/related - I just found that it also works when I build the markdown site using generatr. So the inline script as above works when it is parsed and renders from generatr.

I have not checked, but perhaps it is that generatr are not using the structurizr cli...

chipbite avatar Jun 28 '24 11:06 chipbite

structurizr-cli: 1.34.0

You're using an old version of the CLI. Upgrading will likely fix your issue.

simonbrowndotje avatar Jun 28 '24 17:06 simonbrowndotje

Oh, that sounds great. Will confirm and get back and close. Thanks Simon.

chipbite avatar Jun 28 '24 18:06 chipbite

Confirmed. Works beautifully. Thanks again!

chipbite avatar Jul 01 '24 14:07 chipbite