Skip to content

Commit

Permalink
Merge pull request #109 from OP-TED/release/2.0.0-alpha.4
Browse files Browse the repository at this point in the history
Release 2.0.0 alpha.4
  • Loading branch information
bertrand-lorentz authored Aug 2, 2024
2 parents 05b0a51 + 6618097 commit 96ddd42
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# 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._

---

## 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

Expand All @@ -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.
Expand All @@ -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.

---

Expand All @@ -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.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>eu.europa.ted.eforms</groupId>
<artifactId>efx-toolkit-java</artifactId>
<version>2.0.0-alpha.3</version>
<version>2.0.0-alpha.4</version>
<packaging>jar</packaging>

<name>EFX Toolkit for Java</name>
Expand Down Expand Up @@ -49,7 +49,7 @@

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

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

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

<!-- Versions - eForms -->
<version.eforms-core>1.3.0</version.eforms-core>
<version.eforms-core>1.4.0</version.eforms-core>

<!-- Versions - Third-party libraries -->
<version.antlr4>4.9.3</version.antlr4>
<version.antlr4>4.13.1</version.antlr4>
<version.commons-lang3>3.12.0</version.commons-lang3>
<version.logback>1.2.11</version.logback>
<version.jackson>2.13.4</version.jackson>
Expand All @@ -80,7 +80,7 @@
<version.pgp.plugin>1.5</version.pgp.plugin>
<version.nexus-staging.plugin>1.6.7</version.nexus-staging.plugin>
<version.source.plugin>3.2.1</version.source.plugin>
<version.surefire.plugin>3.0.0-M7</version.surefire.plugin> <!-- Versions prior to 3.0.x do not pick up Junit 5 tests correctly. -->
<version.surefire.plugin>3.2.5</version.surefire.plugin>
</properties>

<dependencyManagement>
Expand Down
75 changes: 68 additions & 7 deletions src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, SymbolResolver> instances = new HashMap<>();
private static final Map<VersionQualifier, SymbolResolver> instances = new HashMap<>();

/**
* Gets the single instance containing the symbols defined in the given version of the eForms SDK.
Expand All @@ -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(
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ public Context getParentContext() {

public Set<Variable> getOwnVariables() {
Set<Variable> variables = new LinkedHashSet<>();
if (this.context != null && this.context.variable() != null) {
variables.add(this.context.variable());
}
variables.addAll(this.variables);
return variables;
}
Expand All @@ -140,7 +137,7 @@ public Set<Variable> getAllVariables() {
}

public Set<String> 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) {
Expand Down
26 changes: 10 additions & 16 deletions src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -694,11 +699,6 @@ private Variable getContextVariable(ContextDeclarationContext ctx,

}

@Override
public void enterTemplateVariableList(TemplateVariableListContext ctx) {
this.stack.push(new VariableList());
}

// #region Variable Initializers --------------------------------------------

@Override
Expand Down Expand Up @@ -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) {
Expand All @@ -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 --------------------------------------------------
Expand Down
Loading

0 comments on commit 96ddd42

Please sign in to comment.