Skip to content

Commit

Permalink
Merge pull request #25 from OP-TED/feature/fixes_optimisations
Browse files Browse the repository at this point in the history
Fixes and optimisations.
  • Loading branch information
meletev committed Aug 1, 2022
2 parents 9e949e1 + bbf4b61 commit acf66d6
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 83 deletions.
150 changes: 128 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,41 @@
<shrinkwrap.resolvers.version>3.1.4</shrinkwrap.resolvers.version>
<slf4j.version>1.7.36</slf4j.version>
<version.commons-collections>3.2.2</version.commons-collections>
<version.commons-io>2.11.0</version.commons-io>
<version.ph-commons>10.0.0</version.ph-commons>
<version.ph-genericode>6.2.0</version.ph-genericode>

<!-- Plugins -->
<compiler.plugin.version>3.10.1</compiler.plugin.version>
<surefire.plugin.version>3.0.0-M7</surefire.plugin.version> <!-- Versions prior to 3.0.x do not pick up Junit 5 tests correctly. -->
<version.jar.plugin>3.2.2</version.jar.plugin>
<version.shade.plugin>3.3.0</version.shade.plugin>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
<version>${shrinkwrap.resolvers.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>${shrinkwrap.resolvers.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
Expand Down Expand Up @@ -100,7 +122,30 @@
<artifactId>commons-collections</artifactId>
<version>${version.commons-collections}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${version.commons-io}</version>
</dependency>

<!-- For genericode .gc files (SDK codelist related) -->
<dependency>
<groupId>com.helger</groupId>
<artifactId>ph-genericode</artifactId>
<version>${version.ph-genericode}</version>
<exclusions>
<exclusion>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.helger.commons</groupId>
<artifactId>ph-commons</artifactId>
<version>${version.ph-commons}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -132,6 +177,14 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
Expand All @@ -147,7 +200,6 @@
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>11.3</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
Expand All @@ -160,7 +212,11 @@
<dependency>
<groupId>com.helger</groupId>
<artifactId>ph-genericode</artifactId>
<version>6.2.0</version>
</dependency>

<dependency>
<groupId>com.helger.commons</groupId>
<artifactId>ph-commons</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
Expand All @@ -174,6 +230,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>org.antlr</groupId>
Expand All @@ -187,30 +247,27 @@

<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<version>${shrinkwrap.resolvers.version}</version>
<type>pom</type>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>${shrinkwrap.resolvers.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${version.jar.plugin}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
Expand Down Expand Up @@ -272,33 +329,82 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${version.shade.plugin}</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>create-jar</id>
<id>create-app-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
<goal>shade</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>app</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>eu.europa.ted.eforms.viewer.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<manifestEntries>
<Specification-Title>${project.artifactId}</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Implementation-Title>${project.artifactId}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
</manifestEntries>
</transformer>
<transformer implementation="org.atteo.classindex.ClassIndexTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>logback.xml</resource>
<file>${basedir}/src/main/resources/logback.xml</file>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/DEPENDENCIES</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.atteo.classindex</groupId>
<artifactId>classindex-transformer</artifactId>
<version>${classindex.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/logback.xml</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import eu.europa.ted.eforms.sdk.SdkConstants;

public class SdkDownloader {
private static final Logger log = LoggerFactory.getLogger(SdkDownloader.class);
private static final Logger logger = LoggerFactory.getLogger(SdkDownloader.class);

static {
String mavenOpts = System.getenv("MAVEN_OPTS");
Expand All @@ -47,15 +47,15 @@ public static void downloadSdk(String sdkVersion, String rootDir) throws IOExcep
String artifactVersion = getLatestSdkVersion(sdkVersion);

if (sdkExistsAt(artifactVersion, sdkDir)) {
log.debug("SDK [{}] found at [{}]. No download required.", sdkVersion, sdkDir);
logger.debug("SDK [{}] found at [{}]. No download required.", sdkVersion, sdkDir);
} else {
log.info("Downloading eForms SDK [{}]", sdkVersion);
log.debug("Target directory: {}", sdkDir.toAbsolutePath());
logger.info("Downloading eForms SDK [{}]", sdkVersion);
logger.debug("Target directory: {}", sdkDir.toAbsolutePath());

SdkUnpacker.unpack(resolve(artifactVersion), sdkDir);
resolve(artifactVersion);

log.debug("Successfully downloaded eForms SDK [{}] onto [{}].", sdkVersion,
logger.info("Successfully downloaded eForms SDK [{}] onto [{}].", sdkVersion,
sdkDir.toAbsolutePath());
}
}
Expand All @@ -73,7 +73,7 @@ private static ConfigurableMavenResolverSystem getMavenResolver() {
if (StringUtils.isNotBlank(userHome)) {
Path settingsFile = Path.of(userHome, ".m2", "settings.xml");
if (settingsFile.toFile().exists()) {
log.debug("Using Maven settings file [{}]", settingsFile);
logger.debug("Using Maven settings file [{}]", settingsFile);
maven.fromFile(settingsFile.toFile());
}
}
Expand All @@ -84,16 +84,16 @@ private static ConfigurableMavenResolverSystem getMavenResolver() {
private static File resolve(String artifactVersion) {
Validate.notBlank(artifactVersion, "Undefined SDK version.");

log.debug("Resolving eforms-sdk artifact with version [{}]", artifactVersion);
logger.debug("Resolving eforms-sdk artifact with version [{}]", artifactVersion);

MavenCoordinate coords =
MavenCoordinates.createCoordinate(SdkConstants.SDK_GROUP_ID, SdkConstants.SDK_ARTIFACT_ID,
artifactVersion, PackagingType.of(SdkConstants.SDK_PACKAGING), StringUtils.EMPTY);
log.debug("Maven coordinates for eforms-sdk artifact: {}", coords.toCanonicalForm());
logger.debug("Maven coordinates for eforms-sdk artifact: {}", coords.toCanonicalForm());

File artifactFile =
getMavenResolver().resolve(coords.toCanonicalForm()).withoutTransitivity().asSingleFile();
log.info("Resolved [{}] as [{}].", coords.toCanonicalForm(), artifactFile);
logger.debug("Resolved [{}] as [{}].", coords.toCanonicalForm(), artifactFile);

return artifactFile;
}
Expand Down Expand Up @@ -148,7 +148,7 @@ private static String getLatestSdkVersion(final String baseVersion) {
}
} catch (NoSuchElementException e) {
String snapshotVersion = MessageFormat.format("{0}.0-SNAPSHOT", baseVersion);
log.warn("No artifacts were found for SDK version [{}]. Trying with [{}]", baseVersion,
logger.warn("No artifacts were found for SDK version [{}]. Trying with [{}]", baseVersion,
snapshotVersion);

List<MavenCoordinate> snapshotCoords = getMavenResolver()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
import org.slf4j.LoggerFactory;

public class SdkUnpacker {
private static final Logger log = LoggerFactory.getLogger(SdkUnpacker.class);
private static final Logger logger = LoggerFactory.getLogger(SdkUnpacker.class);

private SdkUnpacker() {}

public static void unpack(File archive, Path targetDir) throws IOException {
if (archive == null) {
log.warn("Undefined archive. Nothing to do!");
logger.warn("Undefined archive for unpacking. Nothing to do!");
return;
}

Validate.isTrue(Files.isRegularFile(archive.toPath()),
MessageFormat.format("[{0}] is not a file.", archive));

log.info("Unpacking file [{}] onto [{}]", archive, targetDir.toAbsolutePath());
logger.debug("Unpacking file [{}] onto [{}]", archive, targetDir.toAbsolutePath());

try (ZipFile file = new ZipFile(archive)) {
Files.createDirectories(targetDir);
Expand All @@ -41,15 +41,15 @@ public static void unpack(File archive, Path targetDir) throws IOException {

try {
if (entry.isDirectory()) {
log.trace("Creating directory [{}]", targetEntryPath);
logger.trace("Creating directory [{}]", targetEntryPath);
Files.createDirectories(targetEntryPath);
} else {
try (InputStream fileInput = file.getInputStream(entry);
FileOutputStream fileOutput = new FileOutputStream(targetEntryPath.toFile());) {
IOUtils.copy(fileInput, fileOutput);
}

log.trace("Written file [{}]", targetEntryPath);
logger.trace("Written file [{}]", targetEntryPath);
}
} catch (IOException e) {
throw new RuntimeException(MessageFormat.format(
Expand All @@ -58,7 +58,7 @@ public static void unpack(File archive, Path targetDir) throws IOException {
});
}

log.info("Successfully unpacked artifact file [{}] onto [{}]", archive,
logger.debug("Successfully unpacked artifact file [{}] onto [{}]", archive,
targetDir.toAbsolutePath());
}
}
5 changes: 4 additions & 1 deletion src/main/java/eu/europa/ted/eforms/viewer/CliCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class CliCommand implements Callable<Integer> {
@Option(names = {"-r", "--sdkRoot"}, description = "SDK resources root folder.")
private String sdkResourcesRoot;

@Option(names = {"-p", "--profileXslt"}, description = "Enable XSLT profiling.")
private boolean profileXslt;

@Parameters(index = "0", description = "Two letter language code.")
public void setLanguage(String language) {
if (StringUtils.isBlank(language) || language.length() != 2) {
Expand All @@ -60,7 +63,7 @@ public Integer call() throws IOException, SAXException, ParserConfigurationExcep
SdkResourceLoader.INSTANCE.setRoot(sdkResourcesRoot);

final Path htmlPath =
NoticeViewer.generateHtml(language, noticeXmlPath, Optional.ofNullable(viewId));
NoticeViewer.generateHtml(language, noticeXmlPath, Optional.ofNullable(viewId), profileXslt);
logger.info("Created HTML file: {}", htmlPath);

return 0;
Expand Down

0 comments on commit acf66d6

Please sign in to comment.