Skip to content

Commit

Permalink
Merge pull request #406 from phax/master
Browse files Browse the repository at this point in the history
Misc optimizations
  • Loading branch information
jstaerk authored Jul 10, 2024
2 parents 56b0749 + eb67ee9 commit e5130d4
Show file tree
Hide file tree
Showing 60 changed files with 872 additions and 953 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/setup-java@v3 # the log states the default ~/.m2/toolchains.xml is being created pointing to the JDK
with:
distribution: 'adopt' # for latest JDKs use temurin https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/
java-version: '8'
java-version: '11'
cache: 'maven' #cache/restore any dependencies to improve the workflow execution time
- name: Build with Maven
run: mvn -B package --file pom.xml
21 changes: 8 additions & 13 deletions Mustang-CLI/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<version>2.12.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.compilerVersion>8</maven.compiler.compilerVersion>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.compilerVersion>11</maven.compiler.compilerVersion>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
Expand All @@ -36,11 +36,6 @@
<version>1.8.0</version>
</dependency>

<dependency>
<groupId>org.riversun</groupId>
<artifactId>bigdoc</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -100,7 +95,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
Expand Down Expand Up @@ -128,14 +123,14 @@
<!-- http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven
mvn clean compile assembly:single -->
<!-- or whatever version you use -->
<source>8</source>
<target>8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<version>3.5.3</version>
<configuration>
<transformers>
<transformer
Expand Down Expand Up @@ -218,7 +213,7 @@
<configuration>
<toolchains>
<jdk>
<version>8</version>
<version>11</version>
<vendor>adopt</vendor>
</jdk>
</toolchains>
Expand Down
43 changes: 16 additions & 27 deletions Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private static String convertInputStreamToString(InputStream is) {
public static void main(String[] args) {
try {
CommandLine cmd;
CommandLineParser parser = new BasicParser();
CommandLineParser parser = new DefaultParser();

// create Options object
Options options = new Options();
Expand Down Expand Up @@ -427,7 +427,7 @@ public static void main(String[] args) {
performUBL(sourceName, outName);
optionsRecognized = true;
} else if ((action != null) && (action.equals("validate"))) {
optionsRecognized = performValidate(sourceName, noNotices != null && noNotices, cmd.getOptionValue("logAppend"));
optionsRecognized = performValidate(sourceName, noNotices, cmd.getOptionValue("logAppend"));
} else if ((action != null) && (action.equals("validateExpectValid"))) {
optionsRecognized = performValidateExpect(true, directoryName);
} else if ((action != null) && (action.equals("validateExpectInvalid"))) {
Expand Down Expand Up @@ -519,10 +519,11 @@ private static void performConvert(String pdfName, String outName) throws IOExce
ensureFileNotExists(outName);

// All params are good! continue...
ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1().convertOnly().load(pdfName);

ze.export(outName);
System.out.println("Written to " + outName);
try (ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()) {
ze.convertOnly().load(pdfName);
ze.export(outName);
System.out.println("Written to " + outName);
}
}

private static void performExtract(String pdfName, String xmlName) throws IOException {
Expand Down Expand Up @@ -585,7 +586,7 @@ private static void performCombine(String pdfName, String xmlName, String outNam

if (attachmentFilenames == null) {
byte attachmentContents[] = null;
String attachmentFilename, attachmentMime, attachmentDescription;
String attachmentFilename, attachmentMime;
if (!noAttachments) {
attachmentFilename = getFilenameFromUser("Additional file attachments filename (empty for none)", "", "pdf", true, false);
if (attachmentFilename.length() != 0) {
Expand Down Expand Up @@ -842,13 +843,7 @@ private static void performVisualization(String sourceName, String lang, String
} else {
zvi.toPDF(sourceName, outName);
}
} catch (FileNotFoundException e) {
LOGGER.error(e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
LOGGER.error(e.getMessage(), e);
} catch (TransformerException e) {
LOGGER.error(e.getMessage(), e);
} catch (IOException e) {
} catch (TransformerException | IOException e) {
LOGGER.error(e.getMessage(), e);
}
System.out.println("Written to " + outName);
Expand Down Expand Up @@ -876,27 +871,20 @@ private static void performVisualization(String sourceName, String lang, String
* @throws Exception e.g. if the specified resource does not exist at the specified location
*/
static public String ExportResource(String resourceName) throws Exception {
InputStream stream = null;
OutputStream resStreamOut = null;
String jarFolder;
try {
stream = Main.class.getResourceAsStream(resourceName);//note that each / is a directory down in the "jar tree" been the jar the root of the tree
try (InputStream stream = Main.class.getResourceAsStream(resourceName)) {//note that each / is a directory down in the "jar tree" been the jar the root of the tree
if (stream == null) {
throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file.");
}

int readBytes;
byte[] buffer = new byte[4096];
jarFolder = System.getProperty("user.dir");
resStreamOut = new FileOutputStream(jarFolder + resourceName);
while ((readBytes = stream.read(buffer)) > 0) {
resStreamOut.write(buffer, 0, readBytes);
try (FileOutputStream resStreamOut = new FileOutputStream(jarFolder + resourceName)) {
while ((readBytes = stream.read(buffer)) > 0) {
resStreamOut.write(buffer, 0, readBytes);
}
}
} catch (Exception ex) {
throw ex;
} finally {
stream.close();
resStreamOut.close();
}

return jarFolder + resourceName;
Expand All @@ -918,7 +906,8 @@ private static Boolean fileExists(String fileName) {
if (fileName == null)
return false;
File f = new File(fileName);
return f.exists();
// "exists" also returns true for directories
return f.isFile();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlunit.builder.Input;
import org.xmlunit.xpath.JAXPXPathEngine;
import org.xmlunit.xpath.XPathEngine;
import org.mustangproject.validator.ZUGFeRDValidator;

import static org.xmlunit.assertj.XmlAssert.assertThat;
Expand Down Expand Up @@ -50,25 +47,23 @@ public FileVisitResult visitFile(Path file,
Date date = new Date();
String expectedString="valid";
if (!expectValid) {
expectedString="invalid";
}
expectedString="invalid";
}
if ((attr!=null)&&(attr.isRegularFile())) {
if (matcher.matches(file.getFileName())) {
boolean thisResultValid=true;
String thisResultString=" valid";
try {
assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status")
.asString()
.isEqualTo(expectedString);

} catch (AssertionError ae) {
thisResultValid=false;
thisResultString="invalid";
allValid=false;
}
LOGGER.info(String.format("\n@%s Testing file %d: %s (%s)", dateFormat.format(date), fileCount++, thisResultString, file));

}
try {
assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status")
.asString()
.isEqualTo(expectedString);

} catch (AssertionError ae) {
thisResultString="invalid";
allValid=false;
}
LOGGER.info(String.format("\n@%s Testing file %d: %s (%s)", dateFormat.format(date), fileCount++, thisResultString, file));

}
}
return FileVisitResult.CONTINUE;
}
Expand Down
29 changes: 20 additions & 9 deletions library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@
<github.global.server>github</github.global.server>
<additionalparam>-Xdoclint:none</additionalparam>
<!-- Skip error check for javadoc -->
<maven.compiler.compilerVersion>8</maven.compiler.compilerVersion>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.compilerVersion>11</maven.compiler.compilerVersion>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.deploy.skip>true
</maven.deploy.skip><!-- do deploy to maven central, parent project does not and inherits -->

</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
<dependency>
<groupId>net.sf.saxon</groupId>
Expand All @@ -71,6 +76,12 @@
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.9</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down Expand Up @@ -157,16 +168,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<version>3.13.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven
mvn clean compile assembly:single -->
<!-- or whatever version you use -->
<source>8</source>
<target>8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -207,7 +218,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -220,7 +231,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<version>3.5.3</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<minimizeJar>false
Expand Down Expand Up @@ -309,7 +320,7 @@
<configuration>
<toolchains>
<jdk>
<version>8</version>
<version>11</version>
<vendor>adopt</vendor>
</jdk>
</toolchains>
Expand Down
5 changes: 1 addition & 4 deletions library/src/main/java/org/mustangproject/Allowance.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.mustangproject;

import org.mustangproject.ZUGFeRD.IExportableTransaction;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;

import java.math.BigDecimal;

/***
* (absolute) allowances on item and document level
*/
public class Allowance extends Charge implements IZUGFeRDAllowanceCharge {
public class Allowance extends Charge {

/***
* bean constructor
Expand Down
28 changes: 1 addition & 27 deletions library/src/main/java/org/mustangproject/CII/CIIToUBL.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import com.helger.commons.error.list.ErrorList;
import com.helger.en16931.cii2ubl.CIIToUBL23Converter;
import com.helger.ubl21.UBL21Marshaller;
import com.helger.ubl22.UBL22Marshaller;
import com.helger.ubl23.UBL23Marshaller;

/***
Expand All @@ -23,31 +21,7 @@ public void convert(File input, File output) {
final ErrorList occurred=new ErrorList();
final CIIToUBL23Converter cc=new CIIToUBL23Converter();
final Serializable aUBL = cc.convertCIItoUBL(input, occurred);
if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType)
{
UBL21Marshaller.invoice ()
.setFormattedOutput (true)
.write ((oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) aUBL, output);
}
else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType)
{
UBL21Marshaller.creditNote ()
.setFormattedOutput (true)
.write ((oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) aUBL, output);
}
else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType)
{
UBL22Marshaller.invoice ()
.setFormattedOutput (true)
.write ((oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) aUBL, output);
}
else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType)
{
UBL22Marshaller.creditNote ()
.setFormattedOutput (true)
.write ((oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) aUBL, output);
}
else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType)
if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType)
{
UBL23Marshaller.invoice ()
.setFormattedOutput (true)
Expand Down
2 changes: 0 additions & 2 deletions library/src/main/java/org/mustangproject/Charge.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.mustangproject;

import org.mustangproject.ZUGFeRD.IAbsoluteValueProvider;
import org.mustangproject.ZUGFeRD.IExportableTransaction;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;

import java.math.BigDecimal;

Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/org/mustangproject/Invoice.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public IZUGFeRDTradeSettlement[] getTradeSettlement() {
return null;
}

return ((TradeParty) getSender()).getAsTradeSettlement();
return getSender().getAsTradeSettlement();

}

Expand Down
Loading

0 comments on commit e5130d4

Please sign in to comment.