Skip to content

Commit

Permalink
Merge branch 'develop' into TEDEFO-2526-ENV-Publish-workflow-does-not…
Browse files Browse the repository at this point in the history
…-run-unit-tests
  • Loading branch information
papacst committed Oct 20, 2023
2 parents d950106 + aa68fa8 commit c96caa4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

<!-- Versions - eForms -->
<version.efx-toolkit>2.0.0-SNAPSHOT</version.efx-toolkit>
<version.eforms-core>1.0.6-SNAPSHOT</version.eforms-core>
<version.eforms-core>1.2.0-SNAPSHOT</version.eforms-core>

<!-- Versions - Third-party libraries -->
<version.antlr4>4.9.3</version.antlr4>
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/eu/europa/ted/eforms/viewer/DependencyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,36 @@
import eu.europa.ted.efx.interfaces.TranslatorOptions;

public class DependencyFactory implements TranslatorDependencyFactory {
private Path sdkRoot;

@SuppressWarnings("unused")
private DependencyFactory() {}
final private Path sdkRoot;
final private boolean sdkSnapshotsAllowed;

/**
* Public constructor used by the EfxTranslator does not allow the use of
* SNAPSHOT versions of the SDK.
*
* @param sdkRoot The root directory where the SDK will be downloaded.
*/
public DependencyFactory(Path sdkRoot) {
this(sdkRoot, false);
}

/**
* Subclasses can use this constructor to allow the use of SNAPSHOT versions of
* the SDK.
*
* @param sdkRoot The root directory where the SDK will be downloaded.
* @param resolveSnapshots If true, SNAPSHOT versions of the SDK will be
* downloaded if needed.
*/
protected DependencyFactory(Path sdkRoot, boolean resolveSnapshots) {
this.sdkRoot = sdkRoot;
this.sdkSnapshotsAllowed = resolveSnapshots;
}

@Override
public SymbolResolver createSymbolResolver(String sdkVersion) {
try {
SdkDownloader.downloadSdk(sdkVersion, sdkRoot);
SdkDownloader.downloadSdk(sdkVersion, sdkRoot, this.sdkSnapshotsAllowed);

return ComponentFactory.getSymbolResolver(sdkVersion, sdkRoot);
} catch (InstantiationException | IOException e) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/templates/xsl_markup/label_from_key.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
- key: The key to use for rendering
- quantity: If pluralisation is required, then this contains the suffix that identifies the plural form of the label.
-->
<xsl:variable name="key" select="${key}"/>
<#if quantity?has_content>
<xsl:variable name="plural" select="concat(${key}, ted:plural-label-suffix(${quantity}))"/>
<span class="label"><xsl:value-of select="($labels//entry[@key=$plural]/text(), $labels//entry[@key=${key}}]/text(), concat('{', ${key}, '}'))[1]"/></span>
<xsl:variable name="plural" select="concat($key, ted:plural-label-suffix(${quantity}))"/>
<span class="label"><xsl:value-of select="($labels//entry[@key=$plural]/text(), $labels//entry[@key=$key}]/text(), concat('{', $key, '}'))[1]"/></span>
<#else>
<span class="label"><xsl:value-of select="($labels//entry[@key=${key}]/text(), concat('{', ${key}, '}'))[1]"/></span>
<span class="label"><xsl:value-of select="($labels//entry[@key=$key]/text(), concat('{', $key, '}'))[1]"/></span>
</#if>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package eu.europa.ted.eforms.viewer;

import java.nio.file.Path;

/**
* Extends {@link DependencyFactory} to allow the use of SNAPSHOT versions when
* unit testing.
*/
public class DependencyFactoryForUnitTesting extends DependencyFactory {

public DependencyFactoryForUnitTesting(Path sdkRoot) {
super(sdkRoot, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void testEfxToXsl(String sdkVersion) throws IOException, InstantiationException
final String viewId = "X02";
final Path xsl =
XslGenerator.Builder
.create(new DependencyFactory(SDK_ROOT_DIR))
.create(new DependencyFactoryForUnitTesting(SDK_ROOT_DIR))
.build()
.generateFile(sdkVersion, NoticeViewer.getEfxPath(sdkVersion, viewId, SDK_ROOT_DIR),
NoticeViewerConstants.DEFAULT_TRANSLATOR_OPTIONS, true);
Expand Down Expand Up @@ -145,7 +145,7 @@ private void testGenerateHtmlFromString(final String language, final String noti
Files.readString(noticeXmlPath, NoticeViewerConstants.DEFAULT_CHARSET);
final Path xslPath =
XslGenerator.Builder
.create(new DependencyFactory(SDK_ROOT_DIR))
.create(new DependencyFactoryForUnitTesting(SDK_ROOT_DIR))
.build()
.generateFile(sdkVersion, NoticeViewer.getEfxPath(sdkVersion, viewId, SDK_ROOT_DIR),
NoticeViewerConstants.DEFAULT_TRANSLATOR_OPTIONS, true);
Expand Down

0 comments on commit c96caa4

Please sign in to comment.