Skip to content

Commit

Permalink
Update schema (#1098)
Browse files Browse the repository at this point in the history
Signed-off-by: tvallin <[email protected]>
  • Loading branch information
tvallin authored Jan 8, 2025
1 parent fe506cb commit a756770
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 9 deletions.
12 changes: 4 additions & 8 deletions archetype/engine-v2/src/main/schema/archetype.xsd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, 2023 Oracle and/or its affiliates.
Copyright (c) 2021, 2025 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -81,6 +81,7 @@
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attributeGroup ref="a:if-group"/>
</xs:complexType>

<xs:complexType name="glob-type">
Expand Down Expand Up @@ -788,6 +789,7 @@
<xs:element name="inputs" type="a:input-types"/>
<xs:element name="step" type="a:step-type"/>
<xs:element name="validations" type="a:validations-type"/>
<xs:element name="output" type="a:output-type"/>
</xs:choice>
</xs:sequence>
</xs:group>
Expand Down Expand Up @@ -843,7 +845,6 @@
<xs:sequence>
<xs:element name="help" type="a:help-type" minOccurs="0"/>
<xs:group ref="a:directive-group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="output" type="a:output-type" minOccurs="0"/>
</xs:sequence>
<xs:attributeGroup ref="a:input-group"/>
<xs:attributeGroup ref="a:name-group"/>
Expand All @@ -869,7 +870,6 @@
<xs:sequence>
<xs:element name="help" type="a:help-type" minOccurs="0"/>
<xs:group ref="a:directive-group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="output" type="a:output-type" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="value" type="xs:string" use="required">
<xs:annotation>
Expand Down Expand Up @@ -910,7 +910,6 @@
<xs:sequence>
<xs:element name="help" type="a:help-type" minOccurs="0"/>
<xs:group ref="a:directive-group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="output" type="a:output-type" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="value" type="xs:string" use="required">
<xs:annotation>
Expand Down Expand Up @@ -1004,7 +1003,6 @@
<xs:element name="list" type="a:list-input-type"/>
</xs:choice>
<xs:group ref="a:directive-group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="output" type="a:output-type" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

Expand All @@ -1024,8 +1022,8 @@
<xs:element name="source" type="a:source-type"/>
<xs:element name="call" type="a:call-type"/>
<xs:element name="inputs" type="a:input-types"/>
<xs:element name="output" type="a:output-type"/>
</xs:choice>
<xs:element name="output" type="a:output-type" minOccurs="0"/>
</xs:sequence>
<xs:attributeGroup ref="a:if-group"/>
<xs:attributeGroup ref="a:name-group"/>
Expand Down Expand Up @@ -1344,7 +1342,6 @@
<xs:sequence>
<xs:element name="help" type="a:help-type" minOccurs="0"/>
<xs:group ref="a:directive-group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="output" type="a:output-type" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="required">
<xs:annotation>
Expand All @@ -1368,7 +1365,6 @@
<xs:element name="help" type="a:help-type" minOccurs="0"/>
<xs:element name="methods" type="a:method-types" minOccurs="0" />
<xs:group ref="a:directive-group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="output" type="a:output-type" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
* Copyright (c) 2021, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

package io.helidon.build.archetype.engine.v2;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -143,6 +144,41 @@ void testInvocationCondition() {
assertThat(values.size(), is(0));
}

@Test
void testOutput() {
Script script = load("controller/output.xml");
Context context = Context.builder()
.cwd(script.scriptPath().getParent())
.build();
List<String> values = modelValues(script, context);
Iterator<String> iterator = values.iterator();

assertThat(values.size(), is(12));
assertThat(iterator.next(), is("script1"));
assertThat(iterator.next(), is("script2"));
assertThat(iterator.next(), is("step1"));
assertThat(iterator.next(), is("step2"));
assertThat(iterator.next(), is("inputs1"));
assertThat(iterator.next(), is("inputs2"));
assertThat(iterator.next(), is("boolean1"));
assertThat(iterator.next(), is("boolean2"));
assertThat(iterator.next(), is("enum1"));
assertThat(iterator.next(), is("enum2"));
assertThat(iterator.next(), is("method1"));
assertThat(iterator.next(), is("method2"));
}

@Test
void testCall() {
Script script = load("controller/call.xml");
Context context = Context.builder()
.cwd(script.scriptPath().getParent())
.build();
List<String> values = modelValues(script, context);

assertThat(values, contains("blue"));
}

private static List<String> modelValues(Block block, Context context) {
List<String> values = new LinkedList<>();
Controller.walk(new Model.Visitor<>() {
Expand Down
51 changes: 51 additions & 0 deletions archetype/engine-v2/src/test/resources/controller/call.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2025 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<archetype-script xmlns="https://helidon.io/archetype/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 file:/archetype.xsd">

<methods>
<method name="blue">
<output>
<model>
<value key="color">blue</value>
</model>
</output>
</method>
<method name="red">
<output>
<model>
<value key="color">red</value>
</model>
</output>
</method>
</methods>
<step name="step">
<presets>
<boolean path="blue">true</boolean>
<boolean path="red">false</boolean>
</presets>
<inputs>
<boolean id="blue" name="Blue" default="true"/>
<boolean id="red" name="Red" default="false"/>
</inputs>
<call method="blue" if="${blue}"/>
<call method="red" if="${red}"/>
</step>
</archetype-script>
114 changes: 114 additions & 0 deletions archetype/engine-v2/src/test/resources/controller/output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2025 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<archetype-script xmlns="https://helidon.io/archetype/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd">

<methods>
<method name="method">
<output>
<model>
<value key="method1">method1</value>
</model>
</output>
<output>
<model>
<value key="method2">method2</value>
</model>
</output>
</method>
</methods>
<output>
<model>
<value key="script1">script1</value>
</model>
</output>
<output>
<model>
<value key="script2">script2</value>
</model>
</output>
<step name="Step">
<output>
<model>
<value key="step1">step1</value>
</model>
</output>
<output>
<model>
<value key="step2">step2</value>
</model>
</output>
<inputs>
<output>
<model>
<value key="inputs1">inputs1</value>
</model>
</output>
<output>
<model>
<value key="inputs2">inputs2</value>
</model>
</output>
</inputs>
<inputs>
<boolean id="bool" name="Bool">
<output>
<model>
<value key="boolean1">boolean1</value>
</model>
</output>
<output>
<model>
<value key="boolean2">boolean2</value>
</model>
</output>
</boolean>
<enum id="enum" name="Enum" default="option">
<option value="option" name="Option">
<output>
<model>
<value key="enum1">enum1</value>
</model>
</output>
<output>
<model>
<value key="enum2">enum2</value>
</model>
</output>
</option>
</enum>
<list id="list" name="List">
<option value="option" name="Option">
<output>
<model>
<value key="list1">list1</value>
</model>
</output>
<output>
<model>
<value key="list2">list2</value>
</model>
</output>
</option>
</list>
</inputs>
</step>
<call method="method"/>
</archetype-script>

0 comments on commit a756770

Please sign in to comment.