Skip to content

Commit b19cbf9

Browse files
committed
v1.3.2, add some new API points using more modern types and deprecate
the old ones
1 parent 9c0e9b9 commit b19cbf9

File tree

7 files changed

+94
-23
lines changed

7 files changed

+94
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The artifact can be found at maven central:
5959
<dependency>
6060
<groupId>eu.hoefel</groupId>
6161
<artifactId>jatex</artifactId>
62-
<version>1.3.0</version>
62+
<version>1.3.2</version>
6363
</dependency>
6464
```
6565

pom.xml

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

66
<groupId>eu.hoefel</groupId>
77
<artifactId>jatex</artifactId>
8-
<version>1.3.1</version>
8+
<version>1.3.2</version>
99
<packaging>jar</packaging>
1010

1111
<name>jatex</name>
@@ -15,8 +15,8 @@
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1616
<uhoefel.git.url>https://github.com/uhoefel/</uhoefel.git.url>
1717
<uhoefel.git.root>scm:git:ssh://git@github.com/uhoefel/</uhoefel.git.root>
18-
<junit.jupiter.version>5.9.3</junit.jupiter.version>
19-
<junit.platform.version>1.9.3</junit.platform.version>
18+
<junit.jupiter.version>5.10.0</junit.jupiter.version>
19+
<junit.platform.version>1.10.0</junit.platform.version>
2020
<jdk.version>17</jdk.version>
2121
<jvm.extraArgs></jvm.extraArgs>
2222
</properties>
@@ -78,6 +78,26 @@
7878

7979
<build>
8080
<plugins>
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-enforcer-plugin</artifactId>
84+
<version>3.4.0</version>
85+
<executions>
86+
<execution>
87+
<id>enforce-maven-version</id>
88+
<goals>
89+
<goal>enforce</goal>
90+
</goals>
91+
<configuration>
92+
<rules>
93+
<requireMavenVersion>
94+
<version>[3.5.4,)</version> <!-- This requires Maven 3.5.4 or above -->
95+
</requireMavenVersion>
96+
</rules>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
81101
<plugin>
82102
<groupId>org.apache.maven.plugins</groupId>
83103
<artifactId>maven-compiler-plugin</artifactId>
@@ -144,7 +164,7 @@
144164
<plugin>
145165
<groupId>org.codehaus.mojo</groupId>
146166
<artifactId>buildnumber-maven-plugin</artifactId>
147-
<version>3.1.0</version>
167+
<version>3.2.0</version>
148168
<executions>
149169
<execution>
150170
<phase>validate</phase>
@@ -180,7 +200,7 @@
180200

181201
<plugin>
182202
<artifactId>maven-surefire-plugin</artifactId>
183-
<version>3.1.0</version>
203+
<version>3.1.2</version>
184204
</plugin>
185205

186206
<plugin>

src/main/java/eu/hoefel/jatex/Latex.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,12 @@ public int exec() {
621621
* @return the LaTeX object
622622
*/
623623
public Latex filename(String name) {
624-
this.name = name;
624+
var path = Paths.get(name);
625+
var folder = path.getParent();
626+
if (folder != null) {
627+
folder(Paths.get(this.folder).resolve(folder).toString());
628+
}
629+
this.name = path.getFileName().toString();
625630
nameSet = true;
626631
return this;
627632
}

src/main/java/eu/hoefel/jatex/letter/KomaLetter.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package eu.hoefel.jatex.letter;
22

33
import java.io.File;
4+
import java.nio.file.Path;
5+
import java.time.LocalDate;
6+
import java.time.ZoneId;
47
import java.util.Calendar;
58
import java.util.Map;
69

@@ -31,7 +34,7 @@ public final class KomaLetter {
3134
private String yourMail;
3235
private String customer;
3336
private String invoice;
34-
private Calendar date;
37+
private LocalDate date;
3538
private String opening;
3639
private String closing;
3740
private String ps;
@@ -40,7 +43,7 @@ public final class KomaLetter {
4043

4144
private String[] body;
4245

43-
private File file;
46+
private Path file;
4447

4548
/** Hiding any public constructor. */
4649
private KomaLetter() {
@@ -133,11 +136,23 @@ private static Latex setup() {
133136
*
134137
* @param file the file to save to
135138
* @return the new KomaLetter
139+
* @deprecated Use {@link #as(Path)}
136140
*/
141+
@Deprecated(forRemoval = true, since = "1.3.2")
137142
public static KomaLetter as(File file) {
138143
return new KomaLetter().file(file);
139144
}
140145

146+
/**
147+
* Creates a new KomaLetter bound to file.
148+
*
149+
* @param file the file to save to
150+
* @return the new KomaLetter
151+
*/
152+
public static KomaLetter as(Path file) {
153+
return new KomaLetter().file(file);
154+
}
155+
141156
/**
142157
* Creates a new KomaLetter bound to file.
143158
*
@@ -153,8 +168,21 @@ public static KomaLetter as(String file) {
153168
*
154169
* @param file the file to save to
155170
* @return the new KomaLetter
171+
* @deprecated Use {@link #file(Path)}
156172
*/
173+
@Deprecated(forRemoval = true, since = "1.3.2")
157174
public KomaLetter file(File file) {
175+
this.file = file == null ? null : file.toPath();
176+
return this;
177+
}
178+
179+
/**
180+
* Creates a new KomaLetter bound to file.
181+
*
182+
* @param file the file to save to
183+
* @return the new KomaLetter
184+
*/
185+
public KomaLetter file(Path file) {
158186
this.file = file;
159187
return this;
160188
}
@@ -330,8 +358,21 @@ public KomaLetter invoice(String invoice) {
330358
*
331359
* @param date the letter date
332360
* @return the current KOMA letter instance
361+
* @deprecated Use {@link #date(LocalDate)}
333362
*/
363+
@Deprecated(forRemoval = true, since = "1.3.2")
334364
public KomaLetter date(Calendar date) {
365+
this.date = date == null ? null : LocalDate.ofInstant(date.toInstant(), ZoneId.systemDefault());
366+
return this;
367+
}
368+
369+
/**
370+
* Sets the date of the letter. Not necessary if the date of today should be used.
371+
*
372+
* @param date the letter date
373+
* @return the current KOMA letter instance
374+
*/
375+
public KomaLetter date(LocalDate date) {
335376
this.date = date;
336377
return this;
337378
}
@@ -399,7 +440,7 @@ public KomaLetter cc(String... cc) {
399440
* if an error occurred
400441
*/
401442
public int exec() {
402-
if (date == null) date = Calendar.getInstance();
443+
if (date == null) date = LocalDate.now();
403444

404445
String address = (toStreet == null ? "" : toStreet + "\\\\")
405446
+ (toCity == null ? "" : toCity + "\\\\")
@@ -415,8 +456,8 @@ public int exec() {
415456
locale = language;
416457
}
417458

418-
Latex tex = setup().folder(file.getParent())
419-
.filename(file.getName());
459+
Latex tex = setup().folder(file.getParent().toString())
460+
.filename(file.getFileName().toString());
420461

421462
if (user != null) tex.add(user);
422463

@@ -437,8 +478,7 @@ public int exec() {
437478
.addToPreamble("\\setkomavar{myref}{" + (myRef == null ? "" : myRef) + "}")
438479
.addToPreamble("\\setkomavar{customer}{" + (customer == null ? "" : customer) + "}")
439480
.addToPreamble("\\setkomavar{invoice}{" + (invoice == null ? "" : invoice) + "}")
440-
.addToPreamble("\\setkomavar{date}{\\DTMdisplaydate{" + date.get(Calendar.YEAR) + "}{"
441-
+ (date.get(Calendar.MONTH) + 1) + "}{" + date.get(Calendar.DAY_OF_MONTH) + "}{-1}}")
481+
.addToPreamble("\\setkomavar{date}{\\DTMdisplaydate{"+date.getYear()+"}{"+(date.getMonthValue())+"}{"+date.getDayOfMonth()+"}{-1}}")
442482
.addToPreamble(Latex.MINOR_SEPARATOR)
443483
.addToPreamble(Latex.EMPTY_LINE)
444484
.addToPreamble("\\layout")

src/test/java/eu/hoefel/jatex/LatexExecutableCondition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
2020
AnnotatedElement element = context.getElement().orElseThrow(IllegalStateException::new);
2121
return findAnnotation(element, EnabledIfLatexExecutable.class)
2222
.map(annotation -> disableIfUnreachable(annotation, element))
23-
.orElse(ConditionEvaluationResult.disabled("@EnabledIfReachable not used"));
23+
.orElse(ConditionEvaluationResult.disabled("@EnabledIfLatexExecutable not used"));
2424
}
2525

2626
/**

src/test/java/eu/hoefel/jatex/LatexTests.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.junit.jupiter.api.DisplayName;
1212
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.io.CleanupMode;
1314
import org.junit.jupiter.api.io.TempDir;
1415

1516

@@ -43,7 +44,7 @@ void executable() {
4344
* @param n the number of steps
4445
* @return n steps from x0 to x1
4546
*/
46-
private static final double[] linSpace(double x0, double x1, int n) {
47+
private static final double[] linspace(double x0, double x1, int n) {
4748
if (n == 1) return new double[] { (x0 + x1) / 2 };
4849

4950
double[] f = new double[n];
@@ -61,9 +62,9 @@ private static final double[] linSpace(double x0, double x1, int n) {
6162
*/
6263
@Test
6364
@EnabledIfLatexExecutable(compiler = TexCompiler.LUALATEX)
64-
void plotExample1(@TempDir Path folder) {
65-
double[][] data1 = { linSpace(0, 1, 10), linSpace(-5, 5, 10) };
66-
double[][] data2 = { linSpace(0, 1, 10), linSpace( 5, -5, 10) };
65+
void plotExample1(@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path folder) {
66+
double[][] data1 = { linspace(0, 1, 10), linspace(-5, 5, 10) };
67+
double[][] data2 = { linspace(0, 1, 10), linspace( 5, -5, 10) };
6768

6869
Latex tex = Latex.standard();
6970
tex.folder(folder.toString());
@@ -77,7 +78,12 @@ void plotExample1(@TempDir Path folder) {
7778

7879
@Test
7980
@EnabledIfLatexExecutable(compiler = TexCompiler.PDFLATEX)
80-
void testMinimal() {
81-
Latex.minimal().add("$a=\\alpha_2\\times\\beta$").run("abc.tex");
81+
void testMinimal(@TempDir(cleanup = CleanupMode.ON_SUCCESS) Path folder) {
82+
var file = folder.resolve("abc.tex");
83+
assertDoesNotThrow(() -> {
84+
Latex.minimal()
85+
.add("$a=\\alpha_2\\times\\beta$")
86+
.run(file.toString());
87+
});
8288
}
8389
}

src/test/java/eu/hoefel/jatex/letter/KomaLetterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class KomaLetterTests {
3131
@EnabledIfLatexExecutable(compiler = TexCompiler.LUALATEX)
3232
void testLetter(@TempDir Path folder) {
3333
Path file = Paths.get(folder.toString(), "letter.tex");
34-
KomaLetter letter = KomaLetter.as(file.toString())
34+
KomaLetter letter = KomaLetter.as(file)
3535
.language("ngerman")
3636
.user(JohnDoe.defaults()) // fill in specifics for yourself
3737
.toName("Mr. Bob Doe")
@@ -48,7 +48,7 @@ void testLetter(@TempDir Path folder) {
4848
.subject("subject")
4949
.opening("Dear Testreader,")
5050
.write("This letter is not really a letter. I just test for example if the paragraph building works.",
51-
"Let's see\\ldots")
51+
"Let's see\\ldots")
5252
.closing("Mit freundlichen Grüßen,")
5353
.ps("Here some postscriptum text")
5454
.encl("Document1.pdf", "Document2.pdf");

0 commit comments

Comments
 (0)