From 21cc9201e54bde8ce91f9dabb98c151bf227e1af Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Thu, 14 Mar 2024 11:27:08 +0100 Subject: [PATCH 01/10] workflows: Update major version of used actions Those new versions use Node.js 20, so this gets rid of the warning about Node.js 16 actions being deprecated. --- .github/workflows/build.yml | 4 ++-- .github/workflows/publish.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 098a49a..ab48d69 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,8 +12,8 @@ jobs: contents: read packages: write steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 with: java-version: '11' distribution: 'adopt' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4c5c702..9d15d2a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,14 +19,14 @@ jobs: contents: read packages: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Import GPG Key - uses: crazy-max/ghaction-import-gpg@v5 + uses: crazy-max/ghaction-import-gpg@v6 with: gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} passphrase: ${{ secrets.GPG_PASSPHRASE }} - name: Set up Java for publishing to Maven Central Repository - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '11' distribution: 'adopt' From 262960e6e642a42532045840def1ce8022e559cf Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Thu, 14 Mar 2024 16:13:27 +0100 Subject: [PATCH 02/10] pom: Update surefire plugin to latest release This avoids depending on a "milestone" version. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e41c5ae..0130f40 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,7 @@ 1.5 1.6.7 3.2.1 - 3.0.0-M7 + 3.2.5 From 6901fb7c6740a0fd0ecca409238b019c272406f2 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Thu, 14 Mar 2024 16:14:03 +0100 Subject: [PATCH 03/10] pom: Update antlr4 dependency to 4.13.1 Also update eforms-core to 1.4.0-SNAPSHOT, so that it uses the same version of antlr4, to avoid any potential problem, as parsers generated by antlr4 version 4.9 are not compatible with more recent versions. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0130f40..61e55fb 100644 --- a/pom.xml +++ b/pom.xml @@ -59,10 +59,10 @@ ${project.build.directory}/eforms-sdk/antlr4 - 1.3.0 + 1.4.0-SNAPSHOT - 4.9.3 + 4.13.1 3.12.0 1.2.11 2.13.4 From 38af61593702cd0fd5634667a51170cc3ae8cd5b Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Tue, 2 Apr 2024 15:40:16 +0200 Subject: [PATCH 04/10] Add method overloads to support using qualifiers for SDK components This adds a "qualifier" parameter in several methods in the TranslatorDependencyFactory interface, so implementers must be updated. Update DependencyFactoryMock in the unit tests accordingly. --- .../ted/eforms/sdk/ComponentFactory.java | 75 +++++++++++++++++-- .../efx/component/EfxTranslatorFactory.java | 34 +++++++-- .../TranslatorDependencyFactory.java | 9 ++- .../ted/efx/mock/DependencyFactoryMock.java | 17 ++--- 4 files changed, 110 insertions(+), 25 deletions(-) diff --git a/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java b/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java index 65134e8..8f4c4da 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java @@ -4,6 +4,7 @@ import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import eu.europa.ted.eforms.sdk.component.SdkComponentFactory; import eu.europa.ted.eforms.sdk.component.SdkComponentType; @@ -19,12 +20,45 @@ private ComponentFactory() { super(); } + class VersionQualifier { + private final String sdkVersion; + private final String qualifier; + + VersionQualifier(String sdkVersion, String qualifier) { + this.sdkVersion = sdkVersion; + this.qualifier = qualifier; + } + + @Override + public int hashCode() { + return Objects.hash(sdkVersion, qualifier); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VersionQualifier other = (VersionQualifier) obj; + if (!getEnclosingInstance().equals(other.getEnclosingInstance())) + return false; + return Objects.equals(sdkVersion, other.sdkVersion) + && Objects.equals(qualifier, other.qualifier); + } + + private ComponentFactory getEnclosingInstance() { + return ComponentFactory.this; + } + } /** - * EfxToXpathSymbols is implemented as a "kind-of" singleton. One instance per version of the - * eForms SDK. + * Symbol resolver is a "kind-of" singleton. One instance per version of the + * eForms SDK and per qualifier. */ - private static final Map instances = new HashMap<>(); + private static final Map instances = new HashMap<>(); /** * Gets the single instance containing the symbols defined in the given version of the eForms SDK. @@ -37,10 +71,27 @@ private ComponentFactory() { */ public static SymbolResolver getSymbolResolver(final String sdkVersion, final Path sdkRootPath) throws InstantiationException { - return instances.computeIfAbsent(sdkVersion, k -> { + return getSymbolResolver(sdkVersion, "", sdkRootPath); + } + + /** + * Gets the single instance containing the symbols defined in the given version of the eForms SDK. + * + * @param sdkVersion Version of the SDK + * @param qualifier Qualifier to choose between several implementations + * @param sdkRootPath Path to the root of the SDK + * @return The single instance containing the symbols defined in the given version of the eForms + * SDK. + * @throws InstantiationException If the SDK version is not supported. + */ + public static SymbolResolver getSymbolResolver(final String sdkVersion, final String qualifier, + final Path sdkRootPath) throws InstantiationException { + VersionQualifier key = ComponentFactory.INSTANCE.new VersionQualifier(sdkVersion, qualifier); + + return instances.computeIfAbsent(key, k -> { try { return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion, - SdkComponentType.SYMBOL_RESOLVER, SymbolResolver.class, sdkVersion, + SdkComponentType.SYMBOL_RESOLVER, qualifier, SymbolResolver.class, sdkVersion, sdkRootPath); } catch (InstantiationException e) { throw new RuntimeException(MessageFormat.format( @@ -51,13 +102,23 @@ public static SymbolResolver getSymbolResolver(final String sdkVersion, final Pa public static MarkupGenerator getMarkupGenerator(final String sdkVersion, TranslatorOptions options) throws InstantiationException { + return getMarkupGenerator(sdkVersion, "", options); + } + + public static MarkupGenerator getMarkupGenerator(final String sdkVersion, final String qualifier, + TranslatorOptions options) throws InstantiationException { return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion, - SdkComponentType.MARKUP_GENERATOR, MarkupGenerator.class, options); + SdkComponentType.MARKUP_GENERATOR, qualifier, MarkupGenerator.class, options); } public static ScriptGenerator getScriptGenerator(final String sdkVersion, TranslatorOptions options) throws InstantiationException { + return getScriptGenerator(sdkVersion, "", options); + } + + public static ScriptGenerator getScriptGenerator(final String sdkVersion, final String qualifier, + TranslatorOptions options) throws InstantiationException { return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion, - SdkComponentType.SCRIPT_GENERATOR, ScriptGenerator.class, options); + SdkComponentType.SCRIPT_GENERATOR, qualifier, ScriptGenerator.class, options); } } diff --git a/src/main/java/eu/europa/ted/efx/component/EfxTranslatorFactory.java b/src/main/java/eu/europa/ted/efx/component/EfxTranslatorFactory.java index e40ae6b..9bc5478 100644 --- a/src/main/java/eu/europa/ted/efx/component/EfxTranslatorFactory.java +++ b/src/main/java/eu/europa/ted/efx/component/EfxTranslatorFactory.java @@ -4,6 +4,9 @@ import eu.europa.ted.eforms.sdk.component.SdkComponentType; import eu.europa.ted.efx.interfaces.EfxExpressionTranslator; import eu.europa.ted.efx.interfaces.EfxTemplateTranslator; +import eu.europa.ted.efx.interfaces.MarkupGenerator; +import eu.europa.ted.efx.interfaces.ScriptGenerator; +import eu.europa.ted.efx.interfaces.SymbolResolver; import eu.europa.ted.efx.interfaces.TranslatorDependencyFactory; import eu.europa.ted.efx.interfaces.TranslatorOptions; @@ -16,17 +19,36 @@ private EfxTranslatorFactory() { public static EfxExpressionTranslator getEfxExpressionTranslator(final String sdkVersion, final TranslatorDependencyFactory factory, TranslatorOptions options) throws InstantiationException { + return getEfxExpressionTranslator(sdkVersion, "", factory, options); + } + + public static EfxExpressionTranslator getEfxExpressionTranslator(final String sdkVersion, + final String qualifier, final TranslatorDependencyFactory factory, TranslatorOptions options) + throws InstantiationException { + + SymbolResolver symbolResolver = factory.createSymbolResolver(sdkVersion, qualifier); + ScriptGenerator scriptGenerator = factory.createScriptGenerator(sdkVersion, qualifier, options); + return EfxTranslatorFactory.INSTANCE.getComponentImpl(sdkVersion, - SdkComponentType.EFX_EXPRESSION_TRANSLATOR, EfxExpressionTranslator.class, - factory.createSymbolResolver(sdkVersion), factory.createScriptGenerator(sdkVersion, options), - factory.createErrorListener()); + SdkComponentType.EFX_EXPRESSION_TRANSLATOR, qualifier, EfxExpressionTranslator.class, + symbolResolver, scriptGenerator, factory.createErrorListener()); } public static EfxTemplateTranslator getEfxTemplateTranslator(final String sdkVersion, final TranslatorDependencyFactory factory, TranslatorOptions options) throws InstantiationException { + return getEfxTemplateTranslator(sdkVersion, "", factory, options); + } + + public static EfxTemplateTranslator getEfxTemplateTranslator(final String sdkVersion, + final String qualifier, final TranslatorDependencyFactory factory, TranslatorOptions options) + throws InstantiationException { + + MarkupGenerator markupGenerator = factory.createMarkupGenerator(sdkVersion, qualifier, options); + SymbolResolver symbolResolver = factory.createSymbolResolver(sdkVersion, qualifier); + ScriptGenerator scriptGenerator = factory.createScriptGenerator(sdkVersion, qualifier, options); + return EfxTranslatorFactory.INSTANCE.getComponentImpl(sdkVersion, - SdkComponentType.EFX_TEMPLATE_TRANSLATOR, EfxTemplateTranslator.class, - factory.createMarkupGenerator(sdkVersion, options), factory.createSymbolResolver(sdkVersion), - factory.createScriptGenerator(sdkVersion, options), factory.createErrorListener()); + SdkComponentType.EFX_TEMPLATE_TRANSLATOR, qualifier, EfxTemplateTranslator.class, + markupGenerator, symbolResolver, scriptGenerator, factory.createErrorListener()); } } diff --git a/src/main/java/eu/europa/ted/efx/interfaces/TranslatorDependencyFactory.java b/src/main/java/eu/europa/ted/efx/interfaces/TranslatorDependencyFactory.java index 69320ab..59ad652 100644 --- a/src/main/java/eu/europa/ted/efx/interfaces/TranslatorDependencyFactory.java +++ b/src/main/java/eu/europa/ted/efx/interfaces/TranslatorDependencyFactory.java @@ -37,9 +37,10 @@ public interface TranslatorDependencyFactory { * @param sdkVersion The version of the SDK that contains the version of the EFX grammar that the * EFX translator will attempt to translate. This is important as the symbols used in the * EFX expression are defined in the specific version of the SDK. + * @param qualifier Qualifier to choose between several implementations. * @return An instance of ScriptGenerator to be used by the EFX translator. */ - public SymbolResolver createSymbolResolver(String sdkVersion); + public SymbolResolver createSymbolResolver(String sdkVersion, String qualifier); /** * Creates a ScriptGenerator instance. @@ -50,10 +51,11 @@ public interface TranslatorDependencyFactory { * @param sdkVersion The version of the SDK that contains the version of the EFX grammar that the * EFX translator will attempt to translate. This is important as it defines the EFX * language features that ScriptGenerator instance should be able to handle. + * @param qualifier Qualifier to choose between several implementations. * @param options The options to be used by the ScriptGenerator. * @return An instance of ScriptGenerator to be used by the EFX translator. */ - public ScriptGenerator createScriptGenerator(String sdkVersion, TranslatorOptions options); + public ScriptGenerator createScriptGenerator(String sdkVersion, String qualifier, TranslatorOptions options); /** * Creates a MarkupGenerator instance. @@ -64,10 +66,11 @@ public interface TranslatorDependencyFactory { * @param sdkVersion The version of the SDK that contains the version of the EFX grammar that the * EFX translator will attempt to translate. This is important as it defines the EFX * language features that MarkupGenerator instance should be able to handle. + * @param qualifier Qualifier to choose between several implementations. * @param options The options to be used by the MarkupGenerator. * @return The instance of MarkupGenerator to be used by the EFX translator. */ - public MarkupGenerator createMarkupGenerator(String sdkVersion, TranslatorOptions options); + public MarkupGenerator createMarkupGenerator(String sdkVersion, String qualifier, TranslatorOptions options); /** * Creates an error listener instance. diff --git a/src/test/java/eu/europa/ted/efx/mock/DependencyFactoryMock.java b/src/test/java/eu/europa/ted/efx/mock/DependencyFactoryMock.java index e05c038..65070d7 100644 --- a/src/test/java/eu/europa/ted/efx/mock/DependencyFactoryMock.java +++ b/src/test/java/eu/europa/ted/efx/mock/DependencyFactoryMock.java @@ -26,18 +26,19 @@ private DependencyFactoryMock() {} Map markupGenerators = new HashMap<>(); @Override - public SymbolResolver createSymbolResolver(String sdkVersion) { + public SymbolResolver createSymbolResolver(String sdkVersion, String qualifier) { + // Ignore the qualifier for unit tests return SymbolResolverMockFactory.getInstance(sdkVersion); } @Override - public ScriptGenerator createScriptGenerator(String sdkVersion, TranslatorOptions options) { + public ScriptGenerator createScriptGenerator(String sdkVersion, String qualifier, TranslatorOptions options) { // Default hashCode() implementation is OK here // we just need to distinguish TranslatorOptions instances - String key = sdkVersion + options.hashCode(); + String key = sdkVersion + qualifier + options.hashCode(); if (!scriptGenerators.containsKey(key)) { try { - this.scriptGenerators.put(key, ComponentFactory.getScriptGenerator(sdkVersion, options)); + this.scriptGenerators.put(key, ComponentFactory.getScriptGenerator(sdkVersion, qualifier, options)); } catch (InstantiationException e) { throw new RuntimeException(e.getMessage(), e); } @@ -46,11 +47,9 @@ public ScriptGenerator createScriptGenerator(String sdkVersion, TranslatorOption } @Override - public MarkupGenerator createMarkupGenerator(String sdkVersion, TranslatorOptions options) { - if (!this.markupGenerators.containsKey(sdkVersion)) { - this.markupGenerators.put(sdkVersion, new MarkupGeneratorMock()); - } - return this.markupGenerators.get(sdkVersion); + public MarkupGenerator createMarkupGenerator(String sdkVersion, String qualifier, TranslatorOptions options) { + String key = sdkVersion + qualifier; + return this.markupGenerators.computeIfAbsent(key, k -> new MarkupGeneratorMock()); } @Override From 9b8a7de5a6beee7ad5326058fe334f2c05c06e3b Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Thu, 18 Apr 2024 11:41:36 +0200 Subject: [PATCH 05/10] ComponentFactory: Improve SymbolResolver creation (TEDEFO-3286) Allow creating SymbolResolver implementations with constructors that take different parameters. A SymbolResolver does not necessarily need the path to SDK files, so add a method overload that takes a varargs to allow any kind of constructor parameters. --- .../ted/eforms/sdk/ComponentFactory.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java b/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java index 8f4c4da..45624dc 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java @@ -86,13 +86,30 @@ public static SymbolResolver getSymbolResolver(final String sdkVersion, final Pa */ public static SymbolResolver getSymbolResolver(final String sdkVersion, final String qualifier, final Path sdkRootPath) throws InstantiationException { + return getSymbolResolver(sdkVersion, qualifier, sdkRootPath); + } + + /** + * Gets the single instance containing the symbols defined in the given version of the eForms SDK. + * + * @param sdkVersion Version of the SDK + * @param qualifier Qualifier to choose between several implementations + * @param parameters Array of objects to be passed as arguments to the constructor of the + * SymbolResolver implementation + * @return The single instance containing the symbols defined in the given version of the eForms + * SDK. + * @throws InstantiationException If the SDK version is not supported. + */ + public static SymbolResolver getSymbolResolver(final String sdkVersion, final String qualifier, + Object... parameters) throws InstantiationException { + VersionQualifier key = ComponentFactory.INSTANCE.new VersionQualifier(sdkVersion, qualifier); return instances.computeIfAbsent(key, k -> { try { return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion, SdkComponentType.SYMBOL_RESOLVER, qualifier, SymbolResolver.class, sdkVersion, - sdkRootPath); + parameters); } catch (InstantiationException e) { throw new RuntimeException(MessageFormat.format( "Failed to instantiate SDK Symbol Resolver for SDK version [{0}]", sdkVersion), e); From b5d22aadcdc5a5f032a11da0494de3813032bccd Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Fri, 19 Apr 2024 09:56:33 +0200 Subject: [PATCH 06/10] Revert "ComponentFactory: Improve SymbolResolver creation (TEDEFO-3286)" This reverts commit 9b8a7de5a6beee7ad5326058fe334f2c05c06e3b. It introduced an infinite loop, causing a StackOverflowError. --- .../ted/eforms/sdk/ComponentFactory.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java b/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java index 45624dc..8f4c4da 100644 --- a/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java +++ b/src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java @@ -86,30 +86,13 @@ public static SymbolResolver getSymbolResolver(final String sdkVersion, final Pa */ public static SymbolResolver getSymbolResolver(final String sdkVersion, final String qualifier, final Path sdkRootPath) throws InstantiationException { - return getSymbolResolver(sdkVersion, qualifier, sdkRootPath); - } - - /** - * Gets the single instance containing the symbols defined in the given version of the eForms SDK. - * - * @param sdkVersion Version of the SDK - * @param qualifier Qualifier to choose between several implementations - * @param parameters Array of objects to be passed as arguments to the constructor of the - * SymbolResolver implementation - * @return The single instance containing the symbols defined in the given version of the eForms - * SDK. - * @throws InstantiationException If the SDK version is not supported. - */ - public static SymbolResolver getSymbolResolver(final String sdkVersion, final String qualifier, - Object... parameters) throws InstantiationException { - VersionQualifier key = ComponentFactory.INSTANCE.new VersionQualifier(sdkVersion, qualifier); return instances.computeIfAbsent(key, k -> { try { return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion, SdkComponentType.SYMBOL_RESOLVER, qualifier, SymbolResolver.class, sdkVersion, - parameters); + sdkRootPath); } catch (InstantiationException e) { throw new RuntimeException(MessageFormat.format( "Failed to instantiate SDK Symbol Resolver for SDK version [{0}]", sdkVersion), e); From 7e119d0cc8eaa0d2bd2df5c7323797be07e70a2a Mon Sep 17 00:00:00 2001 From: Ioannis Rousochatzakis Date: Sat, 11 May 2024 22:27:28 +0200 Subject: [PATCH 07/10] Fixed the ordering of context variables and parameters --- .../ted/efx/model/templates/ContentBlock.java | 5 +--- .../ted/efx/sdk2/EfxTemplateTranslatorV2.java | 26 +++++++------------ .../efx/sdk2/EfxTemplateTranslatorV2Test.java | 10 +++---- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/main/java/eu/europa/ted/efx/model/templates/ContentBlock.java b/src/main/java/eu/europa/ted/efx/model/templates/ContentBlock.java index b019ad1..360d071 100644 --- a/src/main/java/eu/europa/ted/efx/model/templates/ContentBlock.java +++ b/src/main/java/eu/europa/ted/efx/model/templates/ContentBlock.java @@ -122,9 +122,6 @@ public Context getParentContext() { public Set getOwnVariables() { Set variables = new LinkedHashSet<>(); - if (this.context != null && this.context.variable() != null) { - variables.add(this.context.variable()); - } variables.addAll(this.variables); return variables; } @@ -140,7 +137,7 @@ public Set getAllVariables() { } public Set getTemplateParameters() { - return this.getAllVariables().stream().map(v -> v.name).collect(Collectors.toSet()); + return this.getAllVariables().stream().map(v -> v.name).collect(Collectors.toCollection(LinkedHashSet::new)); } public Markup renderContent(MarkupGenerator markupGenerator) { diff --git a/src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java b/src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java index 8d87234..510852c 100644 --- a/src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java +++ b/src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java @@ -629,6 +629,11 @@ public void exitContextDeclaration(ContextDeclarationContext ctx) { String fieldId = getFieldIdFromChildSimpleFieldReferenceContext(ctx); if (fieldId != null) { Variable contextVariable = this.getContextVariable(ctx, contextPath); + if (contextVariable != null) { + VariableList variables = this.stack.pop(VariableList.class); + variables.add(contextVariable); + this.stack.push(variables); + } this.exitFieldContextDeclaration(fieldId, contextPath, contextVariable); } else { String nodeId = getNodeIdFromChildSimpleNodeReferenceContext(ctx); @@ -694,11 +699,6 @@ private Variable getContextVariable(ContextDeclarationContext ctx, } - @Override - public void enterTemplateVariableList(TemplateVariableListContext ctx) { - this.stack.push(new VariableList()); - } - // #region Variable Initializers -------------------------------------------- @Override @@ -740,7 +740,7 @@ private void exitVariableInitializer( this.script.composeVariableDeclaration(variableName, expression.getClass()), expression, this.script.composeVariableReference(variableName, expression.getClass())); - variables.push(variable); + variables.add(variable); this.stack.push(variables); this.stack.declareIdentifier(variable); } catch (Exception e) { @@ -752,20 +752,14 @@ private void exitVariableInitializer( // #endregion New in EFX-2 -------------------------------------------------- - /** - * This method changes the current EFX context. - * - * The EFX context is always assumed to be either a Field or a Node. Any predicate included in the - * EFX context declaration is not relevant and is ignored. - */ @Override - public void exitContextDeclarationBlock(ContextDeclarationBlockContext ctx) { - if (ctx.templateVariableList() == null) { - this.stack.push(new VariableList()); - } + public void enterContextDeclarationBlock(ContextDeclarationBlockContext arg0) { + this.stack.push(new VariableList()); } + + // #endregion Context Declaration Blocks {...} ------------------------------ // #region Template lines -------------------------------------------------- diff --git a/src/test/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2Test.java b/src/test/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2Test.java index 127f911..7ed9036 100644 --- a/src/test/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2Test.java +++ b/src/test/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2Test.java @@ -176,15 +176,15 @@ void testTemplateLine_VariableScope() { @Test void testTemplateLine_ContextVariable() { assertEquals( - lines("let block01(t, ctx) -> { #1: eval(for $x in ./normalize-space(text()) return concat($x, $t))", // + lines("let block01(ctx, t) -> { #1: eval(for $x in ./normalize-space(text()) return concat($x, $t))", // "for-each(.).call(block0101(ctx:$ctx, t:$t, t2:'test'))", // "for-each(.).call(block0102(ctx:$ctx, t:$t, t2:'test3')) }", // - "let block0101(t, ctx, t2) -> { #1.1: eval(for $y in ./normalize-space(text()) return concat($y, $t, $t2))", // + "let block0101(ctx, t, t2) -> { #1.1: eval(for $y in ./normalize-space(text()) return concat($y, $t, $t2))", // "for-each(.).call(block010101(ctx:$ctx, t:$t, t2:$t2))", // "for-each(.).call(block010102(ctx:$ctx, t:$t, t2:$t2)) }", // - "let block010101(t, ctx, t2) -> { eval(for $z in ./normalize-space(text()) return concat($z, $t, $ctx)) }", // - "let block010102(t, ctx, t2) -> { eval(for $z in ./normalize-space(text()) return concat($z, $t, $ctx)) }", // - "let block0102(t, ctx, t2) -> { eval(for $z in ./normalize-space(text()) return concat($z, $t2, $ctx)) }", // + "let block010101(ctx, t, t2) -> { eval(for $z in ./normalize-space(text()) return concat($z, $t, $ctx)) }", // + "let block010102(ctx, t, t2) -> { eval(for $z in ./normalize-space(text()) return concat($z, $t, $ctx)) }", // + "let block0102(ctx, t, t2) -> { eval(for $z in ./normalize-space(text()) return concat($z, $t2, $ctx)) }", // "for-each(/*/PathNode/TextField).call(block01(ctx:., t:./normalize-space(text())))"), // translateTemplate(lines( "{context:$ctx = BT-00-Text, text:$t = BT-00-Text} ${for text:$x in BT-00-Text return concat($x, $t)}", From 7a2426507de13a2a644cedb0187a35498b5ced08 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Fri, 2 Aug 2024 12:12:07 +0200 Subject: [PATCH 08/10] CHANGELOG: Update for 2.0.0-alpha.4 --- CHANGELOG.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b78fa14..802455a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# EFX Toolkit 2.0.0-alpha.3 Release Notes +# EFX Toolkit 2.0.0-alpha.4 Release Notes _The EFX Toolkit for Java developers is a library that enables the transpilation of [EFX](https://docs.ted.europa.eu/eforms/latest/efx) expressions and templates to different target languages. It also includes an implementation of an EFX-to-XPath transpiler._ @@ -6,8 +6,12 @@ _The EFX Toolkit for Java developers is a library that enables the transpilation ## In this release -This release fixes an a bug that caused an exception to be thrown by XSLT processors when trying to format sequences of dates or times. -This bug was reported by a user in [eForms Notice Viewer issue #88](https://github.com/OP-TED/eforms-notice-viewer/issues/88). +This release fixes an a bug that caused variables and parameters to be in the wrong order in the generated XSL. + +A "qualifier" parameter was added in various methods, to allow the use of the corresponding new feature in the eForms Core Library 1.4.0. + +The dependency on ANTLR was updated to version 4.13.1. + ## EFX-1 Support @@ -22,7 +26,7 @@ The new version of EFX is still under development and will be released with SDK ## Breaking changes -For users of the Toolkit that have implemented custom transpilers, this release contains a few breaking changes. +For users of the Toolkit that have implemented custom transpilers, this release contains a few breaking changes from 1.3.0. More specifically: - Some additional methods have been added to the SymbolResolver, ScriptGenerator and MarkupGenerator API. As a guide for your implementations please look a the implementations included in the EFX Toolkit for use by the EFX-to-XPath transpilation. @@ -33,7 +37,7 @@ Users of the Toolkit that only use the included EFX-to-XPath transpiler will not ## Future development -Further alpha and beta releases of SDK 2 and EFX Toolkit 2 will be issued. While in "alpha" development stage, further braking changes may be introduced. SDK 2 and EFX 2 are expected to continue to be under development through the first quarter of 2024. +Further alpha and beta releases of SDK 2 and EFX Toolkit 2 will be issued. While in "alpha" development stage, further breaking changes may be introduced. --- @@ -49,4 +53,4 @@ This version of the EFX Toolkit has a compile-time dependency on the following v - eForms SDK 1.x.x - eForms SDK 2.0.0-alpha.1 -It also depends on the [eForms Core Java library](https://github.com/OP-TED/eforms-core-java) version 1.3.0. +It also depends on the [eForms Core Java library](https://github.com/OP-TED/eforms-core-java) version 1.4.0. From 47b6b33eedeffdbb74fa86b2acd494f33f16822b Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Fri, 2 Aug 2024 12:12:35 +0200 Subject: [PATCH 09/10] pom: Update eForms Core Library dependency to 1.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 61e55fb..341f25c 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ ${project.build.directory}/eforms-sdk/antlr4 - 1.4.0-SNAPSHOT + 1.4.0 4.13.1 From 66180973e2b2ccd0602d980ddd946a641270c164 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Fri, 2 Aug 2024 12:13:56 +0200 Subject: [PATCH 10/10] pom: Update version to 2.0.0-alpha.4 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 341f25c..a89daf0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ eu.europa.ted.eforms efx-toolkit-java - 2.0.0-SNAPSHOT + 2.0.0-alpha.4 jar EFX Toolkit for Java @@ -49,7 +49,7 @@ UTF-8 - 2023-07-28T16:03:53Z + 2024-08-02T09:53:37Z s01.oss.sonatype.org