Skip to content

Commit 31c1f55

Browse files
committed
add xz compression support with tests
Signed-off-by: Ceki Gulcu <[email protected]>
1 parent 8968d0f commit 31c1f55

27 files changed

+665
-200
lines changed

logback-classic/pom.xml

+1-20
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,7 @@
209209
</dependencies>
210210

211211
<executions>
212-
<!-- Disabled osgi tests given current OSGi/ServiceLoader integration failure -->
213-
<!--
214-
<execution>
215-
216-
<id>ant-osgi-test</id>
217-
<phase>package</phase>
218-
<configuration>
219-
<target>
220-
<property name="currentVersion" value="${project.version}"/>
221-
<property name="slf4j.version" value="${slf4j.version}"/>
222-
<property name="basedir" value="${basedir}"/>
223-
<ant antfile="${basedir}/osgi-build.xml"/>
224-
</target>
225-
</configuration>
226-
<goals>
227-
<goal>run</goal>
228-
</goals>
229-
</execution>
230-
-->
231-
<execution>
212+
<execution>
232213
<id>ant-integration-test</id>
233214
<phase>package</phase>
234215
<configuration>

logback-classic/src/test/input/fqcn.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ ch.qos.logback.core.rolling.ConfigParameters
972972
ch.qos.logback.core.rolling.DefaultRolloverChecker
973973
ch.qos.logback.core.rolling.FileMatchFunction
974974
ch.qos.logback.core.rolling.FileOpener
975-
ch.qos.logback.core.rolling.helper.CompressTest
975+
ch.qos.logback.core.blackbox.rolling.helper.CompressTest
976976
ch.qos.logback.core.rolling.helper.FileNamePatternTest
977977
ch.qos.logback.core.rolling.helper.FileStoreUtilTest
978978
ch.qos.logback.core.rolling.helper.RollingCalendarTest

logback-core-blackbox/pom.xml

+15-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
<scope>compile</scope>
3636
</dependency>
3737

38+
<dependency>
39+
<groupId>org.tukaani</groupId>
40+
<artifactId>xz</artifactId>
41+
<scope>compile</scope>
42+
</dependency>
43+
3844
</dependencies>
3945

4046
<build>
@@ -46,15 +52,21 @@
4652
<execution>
4753
<id>default-test</id>
4854
<configuration>
49-
<argLine>--add-opens java.base/java.io=ch.qos.logback.core.blackbox</argLine>
55+
<!--
56+
<argLine>
57+
==add-opens ch.qos.logback.core/ch.qos.logback.core.util=org.tukaani.xz
58+
==add-opens ch.qos.logback.core/ch.qos.logback.core.rolling.helper=org.tukaani.xz
59+
==add-opens ch.qos.logback.core.blackbox/ch.qos.logback.core.blackbox.rolling.helper=org.tukaani.xz
60+
==add-reads ch.qos.logback.core=org.tukaani.xz
61+
==add-reads ch.qos.logback.core.blackbox=org.tukaani.xz
62+
</argLine>
63+
-->
5064
<reuseForks>true</reuseForks>
5165
<reportFormat>plain</reportFormat>
5266
<trimStackTrace>false</trimStackTrace>
53-
5467
</configuration>
5568
</execution>
5669

57-
5870
</executions>
5971
</plugin>
6072

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<document>
3+
4+
<properties>
5+
<title>LOGBack Home</title>
6+
</properties>
7+
8+
9+
<body>
10+
11+
<h1>LOGBack project</h1>
12+
13+
<p>LOGBack is intended as a successor to the popular log4j
14+
project. It was also designed by Ceki G&#252;lc&#252;, the founder
15+
of the log4j project. It builds upon exerience gained in building
16+
industrial-strength logging systems going back as far as 1999.
17+
</p>
18+
19+
<p>LOGBack's basic architecture is sufficiently generic so as to
20+
apply under different circumstances. At present time, LOGBack is
21+
divided into three modules, Core, Classic and Access.
22+
</p>
23+
24+
<p>The Core module lays the groundwork for the other two
25+
modules. The Classic module can be assimilated to an improved
26+
version of log4j. The Access module integrates with Servlet
27+
containers to provide HTPP-access log functionality. Note that you
28+
can easily build your own modules on top of the Core module.
29+
</p>
30+
31+
32+
</body>
33+
</document>
34+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Logback: the reliable, generic, fast and flexible logging framework.
3+
* Copyright (C) 1999-2025, QOS.ch. All rights reserved.
4+
*
5+
* This program and the accompanying materials are dual-licensed under
6+
* either the terms of the Eclipse Public License v1.0 as published by
7+
* the Eclipse Foundation
8+
*
9+
* or (per the licensee's choosing)
10+
*
11+
* under the terms of the GNU Lesser General Public License version 2.1
12+
* as published by the Free Software Foundation.
13+
*/
14+
15+
package ch.qos.logback.core.blackbox.joran;
16+
17+
import ch.qos.logback.core.Context;
18+
import ch.qos.logback.core.status.StatusManager;
19+
import ch.qos.logback.core.status.StatusUtil;
20+
import org.junit.jupiter.api.Assertions;
21+
22+
public class CoreBlackboxStatusChecker extends StatusUtil {
23+
24+
public CoreBlackboxStatusChecker(StatusManager sm) {
25+
super(sm);
26+
}
27+
28+
29+
public CoreBlackboxStatusChecker(Context context) {
30+
super(context);
31+
}
32+
33+
public void assertContainsMatch(int level, String regex) {
34+
Assertions.assertTrue(containsMatch(level, regex));
35+
}
36+
37+
public void assertNoMatch(String regex) {
38+
Assertions.assertFalse(containsMatch(regex));
39+
}
40+
41+
public void assertContainsMatch(String regex) {
42+
Assertions.assertTrue(containsMatch(regex));
43+
}
44+
45+
public void assertContainsException(Class<?> scanExceptionClass) {
46+
Assertions.assertTrue(containsException(scanExceptionClass));
47+
}
48+
49+
public void assertContainsException(Class<?> scanExceptionClass, String msg) {
50+
Assertions.assertTrue(containsException(scanExceptionClass, msg));
51+
}
52+
53+
public void assertIsErrorFree() {
54+
Assertions.assertTrue(isErrorFree(0));
55+
}
56+
57+
public void assertIsErrorFree(long treshhold) {
58+
Assertions.assertTrue(isErrorFree(treshhold));
59+
}
60+
61+
public void assertIsWarningOrErrorFree() {
62+
Assertions.assertTrue(isWarningOrErrorFree(0));
63+
}
64+
65+
public void assertErrorCount(int i) {
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Logback: the reliable, generic, fast and flexible logging framework.
3+
* Copyright (C) 1999-2025, QOS.ch. All rights reserved.
4+
*
5+
* This program and the accompanying materials are dual-licensed under
6+
* either the terms of the Eclipse Public License v1.0 as published by
7+
* the Eclipse Foundation
8+
*
9+
* or (per the licensee's choosing)
10+
*
11+
* under the terms of the GNU Lesser General Public License version 2.1
12+
* as published by the Free Software Foundation.
13+
*/
14+
15+
package ch.qos.logback.core.blackbox.rolling.helper;
16+
17+
import ch.qos.logback.core.Context;
18+
import ch.qos.logback.core.ContextBase;
19+
import ch.qos.logback.core.blackbox.joran.CoreBlackboxStatusChecker;
20+
import ch.qos.logback.core.rolling.helper.CompressionMode;
21+
import ch.qos.logback.core.rolling.helper.Compressor;
22+
//import ch.qos.logback.core.status.testUtil.StatusChecker;
23+
import ch.qos.logback.core.util.StatusPrinter2;
24+
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Disabled;
27+
import org.junit.jupiter.api.Test;
28+
29+
import java.io.*;
30+
31+
import static ch.qos.logback.core.blackbox.BlackboxCoreTestConstants.TEST_SRC_PREFIX;
32+
import static ch.qos.logback.core.testUtil.CoreTestConstants.OUTPUT_DIR_PREFIX;
33+
34+
public class BlackboxWithXZCompressTest {
35+
Context context = new ContextBase();
36+
StatusPrinter2 statusPrinter2 = new StatusPrinter2();
37+
38+
final String original1 = TEST_SRC_PREFIX + "blackboxInput/compress1.original";
39+
final String copy1 = TEST_SRC_PREFIX + "blackboxInput/compress1.txt";
40+
final String compressed1 = OUTPUT_DIR_PREFIX + "compress1.txt.gz";
41+
42+
final String original2 = TEST_SRC_PREFIX + "blackboxInput/compress2.original";
43+
final String copy2 = TEST_SRC_PREFIX + "blackboxInput/compress2.txt";
44+
final String compressed2 = OUTPUT_DIR_PREFIX + "compress2.txt.gz";
45+
46+
final String original3 = TEST_SRC_PREFIX + "blackboxInput/compress3.original";
47+
final String copy3 = TEST_SRC_PREFIX + "blackboxInput/compress3.txt";
48+
final String compressed3 = OUTPUT_DIR_PREFIX + "compress3.txt.zip";
49+
50+
final String original4 = TEST_SRC_PREFIX + "blackboxInput/compress4.original";
51+
final String copy4 = TEST_SRC_PREFIX + "blackboxInput/compress4.txt";
52+
final String compressed4 = OUTPUT_DIR_PREFIX + "compress4.txt.xz";
53+
54+
@BeforeEach
55+
public void setUp() throws IOException {
56+
57+
}
58+
59+
protected void copySourceFilesAndDeleteCompressedOutputFiles(String originalPathStr, String copyPathStr, String compressedStr) throws IOException {
60+
// Copy source files
61+
// Delete output files
62+
63+
File originalFile = new File(originalPathStr);
64+
File copyFile = new File(copyPathStr);
65+
copy(originalFile, copyFile);
66+
File compressedFile = new File(compressedStr);
67+
compressedFile.mkdirs();
68+
compressedFile.delete();
69+
}
70+
71+
protected void copy(File src, File dst) throws IOException {
72+
try (InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst);) {
73+
byte[] buf = new byte[1024];
74+
int len;
75+
while ((len = in.read(buf)) > 0) {
76+
out.write(buf, 0, len);
77+
}
78+
}
79+
}
80+
81+
@Test
82+
public void gzTest1() throws Exception {
83+
copySourceFilesAndDeleteCompressedOutputFiles(original1, copy1, compressed1);
84+
Compressor compressor = new Compressor(CompressionMode.GZ);
85+
compressor.setContext(context);
86+
compressor.compress(copy1, compressed1, null);
87+
88+
89+
CoreBlackboxStatusChecker checker = new CoreBlackboxStatusChecker(context);
90+
Assertions.assertTrue(checker.isErrorFree(0));
91+
//Assertions.assertTrue(Compare.gzCompare(compressed1, TEST_SRC_PREFIX + "witness/compress1.txt.gz"));
92+
}
93+
94+
@Test
95+
public void gzTest2() throws Exception {
96+
copySourceFilesAndDeleteCompressedOutputFiles(original2, copy2, compressed2);
97+
Compressor compressor = new Compressor(CompressionMode.GZ);
98+
compressor.setContext(context);
99+
compressor.compress(copy2, compressed2, null);
100+
101+
CoreBlackboxStatusChecker checker = new CoreBlackboxStatusChecker(context);
102+
Assertions.assertTrue(checker.isErrorFree(0));
103+
104+
//Assertions.assertTrue(Compare.gzCompare(compressed2, TEST_SRC_PREFIX + "witness/compress2.txt.gz"));
105+
}
106+
107+
@Test
108+
public void zipTest() throws Exception {
109+
copySourceFilesAndDeleteCompressedOutputFiles(original3, copy3, compressed3);
110+
Compressor compressor = new Compressor(CompressionMode.ZIP);
111+
compressor.setContext(context);
112+
compressor.compress(copy3, compressed3, "compress3.txt");
113+
CoreBlackboxStatusChecker checker = new CoreBlackboxStatusChecker(context);
114+
Assertions.assertTrue(checker.isErrorFree(0));
115+
116+
// we don't know how to compare .zip files
117+
// Assertions.assertTrue(Compare.compare(CoreTestConstants.OUTPUT_DIR_PREFIX
118+
// + "compress3.txt.zip", CoreTestConstants.TEST_SRC_PREFIX
119+
// + "witness/compress3.txt.zip"));
120+
}
121+
122+
@Test
123+
public void xzTest() throws Exception {
124+
copySourceFilesAndDeleteCompressedOutputFiles(original4, copy4, compressed4);
125+
Compressor compressor = new Compressor(CompressionMode.XZ);
126+
compressor.setContext(context);
127+
compressor.compress(copy4, compressed4, null);
128+
statusPrinter2.print(context);
129+
CoreBlackboxStatusChecker checker = new CoreBlackboxStatusChecker(context);
130+
Assertions.assertTrue(checker.isErrorFree(0));
131+
}
132+
}

logback-core-blackbox/src/test/java/module-info.java

+4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
requires janino;
99
requires org.fusesource.jansi;
1010

11+
requires org.tukaani.xz;
12+
1113
exports ch.qos.logback.core.blackbox.joran.conditional;
1214
exports ch.qos.logback.core.blackbox.joran;
1315
exports ch.qos.logback.core.blackbox.appender;
16+
exports ch.qos.logback.core.blackbox.rolling.helper;
17+
1418
}

0 commit comments

Comments
 (0)