Skip to content

Commit 96ddd42

Browse files
Merge pull request #109 from OP-TED/release/2.0.0-alpha.4
Release 2.0.0 alpha.4
2 parents 05b0a51 + 6618097 commit 96ddd42

11 files changed

Lines changed: 146 additions & 66 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
contents: read
1313
packages: write
1414
steps:
15-
- uses: actions/checkout@v3
16-
- uses: actions/setup-java@v3
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-java@v4
1717
with:
1818
java-version: '11'
1919
distribution: 'adopt'

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ jobs:
1919
contents: read
2020
packages: write
2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323
- name: Import GPG Key
24-
uses: crazy-max/ghaction-import-gpg@v5
24+
uses: crazy-max/ghaction-import-gpg@v6
2525
with:
2626
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
2727
passphrase: ${{ secrets.GPG_PASSPHRASE }}
2828
- name: Set up Java for publishing to Maven Central Repository
29-
uses: actions/setup-java@v3
29+
uses: actions/setup-java@v4
3030
with:
3131
java-version: '11'
3232
distribution: 'adopt'

CHANGELOG.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# EFX Toolkit 2.0.0-alpha.3 Release Notes
1+
# EFX Toolkit 2.0.0-alpha.4 Release Notes
22

33
_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._
44

55
---
66

77
## In this release
88

9-
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.
10-
This bug was reported by a user in [eForms Notice Viewer issue #88](https://github.com/OP-TED/eforms-notice-viewer/issues/88).
9+
This release fixes an a bug that caused variables and parameters to be in the wrong order in the generated XSL.
10+
11+
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.
12+
13+
The dependency on ANTLR was updated to version 4.13.1.
14+
1115

1216
## EFX-1 Support
1317

@@ -22,7 +26,7 @@ The new version of EFX is still under development and will be released with SDK
2226

2327
## Breaking changes
2428

25-
For users of the Toolkit that have implemented custom transpilers, this release contains a few breaking changes.
29+
For users of the Toolkit that have implemented custom transpilers, this release contains a few breaking changes from 1.3.0.
2630
More specifically:
2731

2832
- 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
3337

3438
## Future development
3539

36-
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.
40+
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.
3741

3842
---
3943

@@ -49,4 +53,4 @@ This version of the EFX Toolkit has a compile-time dependency on the following v
4953
- eForms SDK 1.x.x
5054
- eForms SDK 2.0.0-alpha.1
5155

52-
It also depends on the [eForms Core Java library](https://github.com/OP-TED/eforms-core-java) version 1.3.0.
56+
It also depends on the [eForms Core Java library](https://github.com/OP-TED/eforms-core-java) version 1.4.0.

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>eu.europa.ted.eforms</groupId>
55
<artifactId>efx-toolkit-java</artifactId>
6-
<version>2.0.0-alpha.3</version>
6+
<version>2.0.0-alpha.4</version>
77
<packaging>jar</packaging>
88

99
<name>EFX Toolkit for Java</name>
@@ -49,7 +49,7 @@
4949

5050
<properties>
5151
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
52-
<project.build.outputTimestamp>2023-07-28T16:03:53Z</project.build.outputTimestamp>
52+
<project.build.outputTimestamp>2024-08-02T09:53:37Z</project.build.outputTimestamp>
5353

5454
<sonatype.server.url>s01.oss.sonatype.org</sonatype.server.url>
5555

@@ -59,10 +59,10 @@
5959
<sdk.antlr4.dir>${project.build.directory}/eforms-sdk/antlr4</sdk.antlr4.dir>
6060

6161
<!-- Versions - eForms -->
62-
<version.eforms-core>1.3.0</version.eforms-core>
62+
<version.eforms-core>1.4.0</version.eforms-core>
6363

6464
<!-- Versions - Third-party libraries -->
65-
<version.antlr4>4.9.3</version.antlr4>
65+
<version.antlr4>4.13.1</version.antlr4>
6666
<version.commons-lang3>3.12.0</version.commons-lang3>
6767
<version.logback>1.2.11</version.logback>
6868
<version.jackson>2.13.4</version.jackson>
@@ -80,7 +80,7 @@
8080
<version.pgp.plugin>1.5</version.pgp.plugin>
8181
<version.nexus-staging.plugin>1.6.7</version.nexus-staging.plugin>
8282
<version.source.plugin>3.2.1</version.source.plugin>
83-
<version.surefire.plugin>3.0.0-M7</version.surefire.plugin> <!-- Versions prior to 3.0.x do not pick up Junit 5 tests correctly. -->
83+
<version.surefire.plugin>3.2.5</version.surefire.plugin>
8484
</properties>
8585

8686
<dependencyManagement>

src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.text.MessageFormat;
55
import java.util.HashMap;
66
import java.util.Map;
7+
import java.util.Objects;
78

89
import eu.europa.ted.eforms.sdk.component.SdkComponentFactory;
910
import eu.europa.ted.eforms.sdk.component.SdkComponentType;
@@ -19,12 +20,45 @@ private ComponentFactory() {
1920
super();
2021
}
2122

23+
class VersionQualifier {
24+
private final String sdkVersion;
25+
private final String qualifier;
26+
27+
VersionQualifier(String sdkVersion, String qualifier) {
28+
this.sdkVersion = sdkVersion;
29+
this.qualifier = qualifier;
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
return Objects.hash(sdkVersion, qualifier);
35+
}
36+
37+
@Override
38+
public boolean equals(Object obj) {
39+
if (this == obj)
40+
return true;
41+
if (obj == null)
42+
return false;
43+
if (getClass() != obj.getClass())
44+
return false;
45+
VersionQualifier other = (VersionQualifier) obj;
46+
if (!getEnclosingInstance().equals(other.getEnclosingInstance()))
47+
return false;
48+
return Objects.equals(sdkVersion, other.sdkVersion)
49+
&& Objects.equals(qualifier, other.qualifier);
50+
}
51+
52+
private ComponentFactory getEnclosingInstance() {
53+
return ComponentFactory.this;
54+
}
55+
}
2256

2357
/**
24-
* EfxToXpathSymbols is implemented as a "kind-of" singleton. One instance per version of the
25-
* eForms SDK.
58+
* Symbol resolver is a "kind-of" singleton. One instance per version of the
59+
* eForms SDK and per qualifier.
2660
*/
27-
private static final Map<String, SymbolResolver> instances = new HashMap<>();
61+
private static final Map<VersionQualifier, SymbolResolver> instances = new HashMap<>();
2862

2963
/**
3064
* Gets the single instance containing the symbols defined in the given version of the eForms SDK.
@@ -37,10 +71,27 @@ private ComponentFactory() {
3771
*/
3872
public static SymbolResolver getSymbolResolver(final String sdkVersion, final Path sdkRootPath)
3973
throws InstantiationException {
40-
return instances.computeIfAbsent(sdkVersion, k -> {
74+
return getSymbolResolver(sdkVersion, "", sdkRootPath);
75+
}
76+
77+
/**
78+
* Gets the single instance containing the symbols defined in the given version of the eForms SDK.
79+
*
80+
* @param sdkVersion Version of the SDK
81+
* @param qualifier Qualifier to choose between several implementations
82+
* @param sdkRootPath Path to the root of the SDK
83+
* @return The single instance containing the symbols defined in the given version of the eForms
84+
* SDK.
85+
* @throws InstantiationException If the SDK version is not supported.
86+
*/
87+
public static SymbolResolver getSymbolResolver(final String sdkVersion, final String qualifier,
88+
final Path sdkRootPath) throws InstantiationException {
89+
VersionQualifier key = ComponentFactory.INSTANCE.new VersionQualifier(sdkVersion, qualifier);
90+
91+
return instances.computeIfAbsent(key, k -> {
4192
try {
4293
return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion,
43-
SdkComponentType.SYMBOL_RESOLVER, SymbolResolver.class, sdkVersion,
94+
SdkComponentType.SYMBOL_RESOLVER, qualifier, SymbolResolver.class, sdkVersion,
4495
sdkRootPath);
4596
} catch (InstantiationException e) {
4697
throw new RuntimeException(MessageFormat.format(
@@ -51,13 +102,23 @@ public static SymbolResolver getSymbolResolver(final String sdkVersion, final Pa
51102

52103
public static MarkupGenerator getMarkupGenerator(final String sdkVersion, TranslatorOptions options)
53104
throws InstantiationException {
105+
return getMarkupGenerator(sdkVersion, "", options);
106+
}
107+
108+
public static MarkupGenerator getMarkupGenerator(final String sdkVersion, final String qualifier,
109+
TranslatorOptions options) throws InstantiationException {
54110
return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion,
55-
SdkComponentType.MARKUP_GENERATOR, MarkupGenerator.class, options);
111+
SdkComponentType.MARKUP_GENERATOR, qualifier, MarkupGenerator.class, options);
56112
}
57113

58114
public static ScriptGenerator getScriptGenerator(final String sdkVersion, TranslatorOptions options)
59115
throws InstantiationException {
116+
return getScriptGenerator(sdkVersion, "", options);
117+
}
118+
119+
public static ScriptGenerator getScriptGenerator(final String sdkVersion, final String qualifier,
120+
TranslatorOptions options) throws InstantiationException {
60121
return ComponentFactory.INSTANCE.getComponentImpl(sdkVersion,
61-
SdkComponentType.SCRIPT_GENERATOR, ScriptGenerator.class, options);
122+
SdkComponentType.SCRIPT_GENERATOR, qualifier, ScriptGenerator.class, options);
62123
}
63124
}

src/main/java/eu/europa/ted/efx/component/EfxTranslatorFactory.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import eu.europa.ted.eforms.sdk.component.SdkComponentType;
55
import eu.europa.ted.efx.interfaces.EfxExpressionTranslator;
66
import eu.europa.ted.efx.interfaces.EfxTemplateTranslator;
7+
import eu.europa.ted.efx.interfaces.MarkupGenerator;
8+
import eu.europa.ted.efx.interfaces.ScriptGenerator;
9+
import eu.europa.ted.efx.interfaces.SymbolResolver;
710
import eu.europa.ted.efx.interfaces.TranslatorDependencyFactory;
811
import eu.europa.ted.efx.interfaces.TranslatorOptions;
912

@@ -16,17 +19,36 @@ private EfxTranslatorFactory() {
1619

1720
public static EfxExpressionTranslator getEfxExpressionTranslator(final String sdkVersion,
1821
final TranslatorDependencyFactory factory, TranslatorOptions options) throws InstantiationException {
22+
return getEfxExpressionTranslator(sdkVersion, "", factory, options);
23+
}
24+
25+
public static EfxExpressionTranslator getEfxExpressionTranslator(final String sdkVersion,
26+
final String qualifier, final TranslatorDependencyFactory factory, TranslatorOptions options)
27+
throws InstantiationException {
28+
29+
SymbolResolver symbolResolver = factory.createSymbolResolver(sdkVersion, qualifier);
30+
ScriptGenerator scriptGenerator = factory.createScriptGenerator(sdkVersion, qualifier, options);
31+
1932
return EfxTranslatorFactory.INSTANCE.getComponentImpl(sdkVersion,
20-
SdkComponentType.EFX_EXPRESSION_TRANSLATOR, EfxExpressionTranslator.class,
21-
factory.createSymbolResolver(sdkVersion), factory.createScriptGenerator(sdkVersion, options),
22-
factory.createErrorListener());
33+
SdkComponentType.EFX_EXPRESSION_TRANSLATOR, qualifier, EfxExpressionTranslator.class,
34+
symbolResolver, scriptGenerator, factory.createErrorListener());
2335
}
2436

2537
public static EfxTemplateTranslator getEfxTemplateTranslator(final String sdkVersion,
2638
final TranslatorDependencyFactory factory, TranslatorOptions options) throws InstantiationException {
39+
return getEfxTemplateTranslator(sdkVersion, "", factory, options);
40+
}
41+
42+
public static EfxTemplateTranslator getEfxTemplateTranslator(final String sdkVersion,
43+
final String qualifier, final TranslatorDependencyFactory factory, TranslatorOptions options)
44+
throws InstantiationException {
45+
46+
MarkupGenerator markupGenerator = factory.createMarkupGenerator(sdkVersion, qualifier, options);
47+
SymbolResolver symbolResolver = factory.createSymbolResolver(sdkVersion, qualifier);
48+
ScriptGenerator scriptGenerator = factory.createScriptGenerator(sdkVersion, qualifier, options);
49+
2750
return EfxTranslatorFactory.INSTANCE.getComponentImpl(sdkVersion,
28-
SdkComponentType.EFX_TEMPLATE_TRANSLATOR, EfxTemplateTranslator.class,
29-
factory.createMarkupGenerator(sdkVersion, options), factory.createSymbolResolver(sdkVersion),
30-
factory.createScriptGenerator(sdkVersion, options), factory.createErrorListener());
51+
SdkComponentType.EFX_TEMPLATE_TRANSLATOR, qualifier, EfxTemplateTranslator.class,
52+
markupGenerator, symbolResolver, scriptGenerator, factory.createErrorListener());
3153
}
3254
}

src/main/java/eu/europa/ted/efx/interfaces/TranslatorDependencyFactory.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public interface TranslatorDependencyFactory {
3737
* @param sdkVersion The version of the SDK that contains the version of the EFX grammar that the
3838
* EFX translator will attempt to translate. This is important as the symbols used in the
3939
* EFX expression are defined in the specific version of the SDK.
40+
* @param qualifier Qualifier to choose between several implementations.
4041
* @return An instance of ScriptGenerator to be used by the EFX translator.
4142
*/
42-
public SymbolResolver createSymbolResolver(String sdkVersion);
43+
public SymbolResolver createSymbolResolver(String sdkVersion, String qualifier);
4344

4445
/**
4546
* Creates a ScriptGenerator instance.
@@ -50,10 +51,11 @@ public interface TranslatorDependencyFactory {
5051
* @param sdkVersion The version of the SDK that contains the version of the EFX grammar that the
5152
* EFX translator will attempt to translate. This is important as it defines the EFX
5253
* language features that ScriptGenerator instance should be able to handle.
54+
* @param qualifier Qualifier to choose between several implementations.
5355
* @param options The options to be used by the ScriptGenerator.
5456
* @return An instance of ScriptGenerator to be used by the EFX translator.
5557
*/
56-
public ScriptGenerator createScriptGenerator(String sdkVersion, TranslatorOptions options);
58+
public ScriptGenerator createScriptGenerator(String sdkVersion, String qualifier, TranslatorOptions options);
5759

5860
/**
5961
* Creates a MarkupGenerator instance.
@@ -64,10 +66,11 @@ public interface TranslatorDependencyFactory {
6466
* @param sdkVersion The version of the SDK that contains the version of the EFX grammar that the
6567
* EFX translator will attempt to translate. This is important as it defines the EFX
6668
* language features that MarkupGenerator instance should be able to handle.
69+
* @param qualifier Qualifier to choose between several implementations.
6770
* @param options The options to be used by the MarkupGenerator.
6871
* @return The instance of MarkupGenerator to be used by the EFX translator.
6972
*/
70-
public MarkupGenerator createMarkupGenerator(String sdkVersion, TranslatorOptions options);
73+
public MarkupGenerator createMarkupGenerator(String sdkVersion, String qualifier, TranslatorOptions options);
7174

7275
/**
7376
* Creates an error listener instance.

src/main/java/eu/europa/ted/efx/model/templates/ContentBlock.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ public Context getParentContext() {
122122

123123
public Set<Variable> getOwnVariables() {
124124
Set<Variable> variables = new LinkedHashSet<>();
125-
if (this.context != null && this.context.variable() != null) {
126-
variables.add(this.context.variable());
127-
}
128125
variables.addAll(this.variables);
129126
return variables;
130127
}
@@ -140,7 +137,7 @@ public Set<Variable> getAllVariables() {
140137
}
141138

142139
public Set<String> getTemplateParameters() {
143-
return this.getAllVariables().stream().map(v -> v.name).collect(Collectors.toSet());
140+
return this.getAllVariables().stream().map(v -> v.name).collect(Collectors.toCollection(LinkedHashSet::new));
144141
}
145142

146143
public Markup renderContent(MarkupGenerator markupGenerator) {

src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,11 @@ public void exitContextDeclaration(ContextDeclarationContext ctx) {
629629
String fieldId = getFieldIdFromChildSimpleFieldReferenceContext(ctx);
630630
if (fieldId != null) {
631631
Variable contextVariable = this.getContextVariable(ctx, contextPath);
632+
if (contextVariable != null) {
633+
VariableList variables = this.stack.pop(VariableList.class);
634+
variables.add(contextVariable);
635+
this.stack.push(variables);
636+
}
632637
this.exitFieldContextDeclaration(fieldId, contextPath, contextVariable);
633638
} else {
634639
String nodeId = getNodeIdFromChildSimpleNodeReferenceContext(ctx);
@@ -694,11 +699,6 @@ private Variable getContextVariable(ContextDeclarationContext ctx,
694699

695700
}
696701

697-
@Override
698-
public void enterTemplateVariableList(TemplateVariableListContext ctx) {
699-
this.stack.push(new VariableList());
700-
}
701-
702702
// #region Variable Initializers --------------------------------------------
703703

704704
@Override
@@ -740,7 +740,7 @@ private void exitVariableInitializer(
740740
this.script.composeVariableDeclaration(variableName, expression.getClass()),
741741
expression,
742742
this.script.composeVariableReference(variableName, expression.getClass()));
743-
variables.push(variable);
743+
variables.add(variable);
744744
this.stack.push(variables);
745745
this.stack.declareIdentifier(variable);
746746
} catch (Exception e) {
@@ -752,20 +752,14 @@ private void exitVariableInitializer(
752752

753753
// #endregion New in EFX-2 --------------------------------------------------
754754

755-
/**
756-
* This method changes the current EFX context.
757-
*
758-
* The EFX context is always assumed to be either a Field or a Node. Any predicate included in the
759-
* EFX context declaration is not relevant and is ignored.
760-
*/
761755
@Override
762-
public void exitContextDeclarationBlock(ContextDeclarationBlockContext ctx) {
763-
if (ctx.templateVariableList() == null) {
764-
this.stack.push(new VariableList());
765-
}
756+
public void enterContextDeclarationBlock(ContextDeclarationBlockContext arg0) {
757+
this.stack.push(new VariableList());
766758
}
767759

768760

761+
762+
769763
// #endregion Context Declaration Blocks {...} ------------------------------
770764

771765
// #region Template lines --------------------------------------------------

0 commit comments

Comments
 (0)