Skip to content

Commit 9ad553c

Browse files
committed
Deprecate o.a.l.l.c.a.r.a.Duration class for removal
1 parent b31919f commit 9ad553c

File tree

7 files changed

+58
-18
lines changed

7 files changed

+58
-18
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

2525
import java.nio.file.attribute.FileTime;
26+
import java.time.Duration;
2627
import java.util.List;
2728
import org.apache.logging.log4j.core.config.Node;
2829
import org.apache.logging.log4j.core.config.NullConfiguration;
@@ -43,12 +44,6 @@
4344
@SetSystemProperty(key = "log4j2.status.entries", value = "10")
4445
class IfLastModifiedTest {
4546

46-
@Test
47-
public void testGetDurationReturnsConstructorValue() {
48-
final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("P7D"));
49-
assertEquals(0, filter.getAge().compareTo(Duration.parse("P7D")));
50-
}
51-
5247
@Test
5348
public void testAcceptsIfFileAgeEqualToDuration() {
5449
final IfLastModified filter = IfLastModified.createAgeCondition(Duration.parse("PT33S"));

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Duration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
* This implementation does not support fractions or negative values.
3131
*
3232
* @see #parse(CharSequence)
33+
* @deprecated since 2.24.0 use {@link java.time.Duration} instead.
3334
*/
35+
@Deprecated
3436
public class Duration implements Serializable, Comparable<Duration> {
3537
private static final long serialVersionUID = -3756810052716342061L;
3638

@@ -66,6 +68,13 @@ public class Duration implements Serializable, Comparable<Duration> {
6668
private static final Pattern PATTERN = Pattern.compile(
6769
"P?(?:([0-9]+)D)?" + "(T?(?:([0-9]+)H)?(?:([0-9]+)M)?(?:([0-9]+)?S)?)?", Pattern.CASE_INSENSITIVE);
6870

71+
/**
72+
* @since 2.24.0
73+
*/
74+
public static Duration ofMillis(final long millis) {
75+
return new Duration(millis / 1000L);
76+
}
77+
6978
/**
7079
* The number of seconds in the duration.
7180
*/

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.nio.file.Path;
2020
import java.nio.file.attribute.BasicFileAttributes;
2121
import java.nio.file.attribute.FileTime;
22+
import java.time.Duration;
2223
import java.util.Arrays;
2324
import java.util.Collections;
2425
import java.util.List;
@@ -50,8 +51,12 @@ private IfLastModified(final Duration age, final PathCondition[] nestedCondition
5051
this.nestedConditions = PathCondition.copy(nestedConditions);
5152
}
5253

53-
public Duration getAge() {
54-
return age;
54+
/**
55+
* @deprecated since 2.24.0 without a replacement.
56+
*/
57+
@Deprecated
58+
public org.apache.logging.log4j.core.appender.rolling.action.Duration getAge() {
59+
return org.apache.logging.log4j.core.appender.rolling.action.Duration.ofMillis(age.toMillis());
5560
}
5661

5762
public List<PathCondition> getNestedConditions() {
@@ -89,20 +94,29 @@ public void beforeFileTreeWalk() {
8994
IfAll.beforeFileTreeWalk(nestedConditions);
9095
}
9196

97+
/**
98+
* @deprecated since 2.24.0 use {@link #createAgeCondition(Duration, PathCondition...)} instead.
99+
*/
100+
@Deprecated
101+
public static IfLastModified createAgeCondition(
102+
final org.apache.logging.log4j.core.appender.rolling.action.Duration age,
103+
final PathCondition... pathConditions) {
104+
return createAgeCondition(Duration.ofMillis(age.toMillis()), pathConditions);
105+
}
106+
92107
/**
93108
* Create an IfLastModified condition.
94109
*
95110
* @param age The path age that is accepted by this condition. Must be a valid Duration.
96-
* @param nestedConditions nested conditions to evaluate if this condition accepts a path
111+
* @param pathConditions Nested conditions to evaluate if this condition accepts a path.
97112
* @return An IfLastModified condition.
113+
* @since 2.24.0
98114
*/
99115
@PluginFactory
100116
public static IfLastModified createAgeCondition(
101-
// @formatter:off
102117
@PluginAttribute("age") @Required(message = "No age provided for IfLastModified") final Duration age,
103-
@PluginElement("PathConditions") final PathCondition... nestedConditions) {
104-
// @formatter:on
105-
return new IfLastModified(age, nestedConditions);
118+
@PluginElement("pathConditions") final PathCondition... pathConditions) {
119+
return new IfLastModified(age, Objects.requireNonNull(pathConditions));
106120
}
107121

108122
@Override

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Support classes for the Rolling File Appender.
1919
*/
2020
@Export
21-
@Version("2.20.2")
21+
@Version("2.24.0")
2222
package org.apache.logging.log4j.core.appender.rolling.action;
2323

2424
import org.osgi.annotation.bundle.Export;

log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/TypeConverters.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
import java.nio.file.Paths;
3333
import java.security.Provider;
3434
import java.security.Security;
35+
import java.time.Duration;
3536
import java.util.UUID;
3637
import java.util.regex.Pattern;
3738
import org.apache.logging.log4j.Level;
3839
import org.apache.logging.log4j.Logger;
39-
import org.apache.logging.log4j.core.appender.rolling.action.Duration;
4040
import org.apache.logging.log4j.core.config.plugins.Plugin;
4141
import org.apache.logging.log4j.core.util.CronExpression;
4242
import org.apache.logging.log4j.status.StatusLogger;
@@ -224,11 +224,26 @@ public Double convert(final String s) {
224224
}
225225

226226
/**
227-
* Converts a {@link String} into a {@link Duration}.
227+
* Converts a {@link String} into a {@link org.apache.logging.log4j.core.appender.rolling.action.Duration}.
228228
* @since 2.5
229+
* @deprecated since 2.24.0 use {@link JavaDurationConverter}
229230
*/
230231
@Plugin(name = "Duration", category = CATEGORY)
231-
public static class DurationConverter implements TypeConverter<Duration> {
232+
@Deprecated
233+
public static class DurationConverter
234+
implements TypeConverter<org.apache.logging.log4j.core.appender.rolling.action.Duration> {
235+
@Override
236+
public org.apache.logging.log4j.core.appender.rolling.action.Duration convert(final String s) {
237+
return org.apache.logging.log4j.core.appender.rolling.action.Duration.parse(s);
238+
}
239+
}
240+
241+
/**
242+
* Converts a {@link String} into a {@link Duration}.
243+
* @since 2.24.0
244+
*/
245+
@Plugin(name = "JavaDuration", category = CATEGORY)
246+
public static class JavaDurationConverter implements TypeConverter<Duration> {
232247
@Override
233248
public Duration convert(final String s) {
234249
return Duration.parse(s);

log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/convert/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* attributes in plugin factory methods.
2121
*/
2222
@Export
23-
@Version("2.20.2")
23+
@Version("2.24.0")
2424
package org.apache.logging.log4j.core.config.plugins.convert;
2525

2626
import org.osgi.annotation.bundle.Export;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://logging.apache.org/log4j/changelog"
4+
xsi:schemaLocation="http://logging.apache.org/log4j/changelog https://logging.apache.org/log4j/changelog-0.1.3.xsd"
5+
type="changed">
6+
<description format="asciidoc">Deprecate `org.apache.logging.log4j.core.appender.rolling.action.Duration` class for removal.</description>
7+
</entry>

0 commit comments

Comments
 (0)