LOG4J2-435 Renamed FileLastModifiedFilter (plugin name "LastModified")
to IfLastModified (plugin name "IfLastModified" to be consistent with
the IfFileName condition

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d38dc8ac
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d38dc8ac
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d38dc8ac

Branch: refs/heads/master
Commit: d38dc8ac036e1aa0d36349377c81b0307f346632
Parents: c4b0b63
Author: rpopma <[email protected]>
Authored: Sun Nov 15 21:06:53 2015 +0900
Committer: rpopma <[email protected]>
Committed: Sun Nov 15 21:06:53 2015 +0900

----------------------------------------------------------------------
 .../rolling/action/FileLastModifiedFilter.java  | 77 ------------------
 .../appender/rolling/action/IfLastModified.java | 84 ++++++++++++++++++++
 .../action/FileLastModifiedFilterTest.java      | 65 ---------------
 .../rolling/action/IfLastModifiedTest.java      | 65 +++++++++++++++
 4 files changed, 149 insertions(+), 142 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d38dc8ac/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/FileLastModifiedFilter.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/FileLastModifiedFilter.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/FileLastModifiedFilter.java
deleted file mode 100644
index 6904ade..0000000
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/FileLastModifiedFilter.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.rolling.action;
-
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.nio.file.attribute.FileTime;
-import java.util.Objects;
-
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.util.Clock;
-import org.apache.logging.log4j.core.util.ClockFactory;
-
-/**
- * PathFilter that accepts paths that are older than the specified duration.
- */
-@Plugin(name = "LastModified", category = "Core", printObject = true)
-public final class FileLastModifiedFilter implements PathFilter {
-    private static final Clock CLOCK = ClockFactory.getClock();
-
-    private final Duration duration;
-
-    private FileLastModifiedFilter(final Duration duration) {
-        this.duration = Objects.requireNonNull(duration, "duration");
-    }
-
-    public Duration getDuration() {
-        return duration;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see 
org.apache.logging.log4j.core.appender.rolling.action.PathFilter#accept(java.nio.file.Path,
-     * java.nio.file.Path)
-     */
-    @Override
-    public boolean accept(final Path baseDir, final Path relativePath, final 
BasicFileAttributes attrs) {
-        final FileTime fileTime = attrs.lastModifiedTime();
-        final long millis = fileTime.toMillis();
-        final long ageMillis = CLOCK.currentTimeMillis() - millis;
-        return ageMillis >= duration.toMillis();
-    }
-
-    /**
-     * Create a FileLastModifiedFilter filter.
-     * 
-     * @param duration The path age that is accepted by this filter. Must be a 
valid Duration.
-     * @return A FileLastModifiedFilter filter.
-     */
-    @PluginFactory
-    public static FileLastModifiedFilter createAgeFilter( //
-            @PluginAttribute("duration") final Duration duration) {
-        return new FileLastModifiedFilter(duration);
-    }
-
-    @Override
-    public String toString() {
-        return "FileLastModifiedFilter(age=" + duration + ")";
-    }
-}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d38dc8ac/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java
new file mode 100644
index 0000000..e5019a9
--- /dev/null
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModified.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender.rolling.action;
+
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.nio.file.attribute.FileTime;
+import java.util.Objects;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.util.Clock;
+import org.apache.logging.log4j.core.util.ClockFactory;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * PathFilter that accepts paths that are older than the specified duration.
+ */
+@Plugin(name = "IfLastModified", category = "Core", printObject = true)
+public final class IfLastModified implements PathCondition {
+    private static final Logger LOGGER = StatusLogger.getLogger();
+    private static final Clock CLOCK = ClockFactory.getClock();
+
+    private final Duration duration;
+
+    private IfLastModified(final Duration duration) {
+        this.duration = Objects.requireNonNull(duration, "duration");
+    }
+
+    public Duration getDuration() {
+        return duration;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see 
org.apache.logging.log4j.core.appender.rolling.action.PathFilter#accept(java.nio.file.Path,
+     * java.nio.file.Path)
+     */
+    @Override
+    public boolean accept(final Path baseDir, final Path relativePath, final 
BasicFileAttributes attrs) {
+        final FileTime fileTime = attrs.lastModifiedTime();
+        final long millis = fileTime.toMillis();
+        final long ageMillis = CLOCK.currentTimeMillis() - millis;
+        final boolean result = ageMillis >= duration.toMillis();
+        final String match = result ? ">=" : "<";
+        LOGGER.trace("LastModifiedFilter: {} ageMillis '{}' {} duration '{}'", 
relativePath, ageMillis, match,
+                duration);
+        return result;
+    }
+
+    /**
+     * Create a FileLastModifiedFilter filter.
+     * 
+     * @param duration The path age that is accepted by this filter. Must be a 
valid Duration.
+     * @return A FileLastModifiedFilter filter.
+     */
+    @PluginFactory
+    public static IfLastModified createAgeFilter( //
+            @PluginAttribute("duration") final Duration duration) {
+        return new IfLastModified(duration);
+    }
+
+    @Override
+    public String toString() {
+        return "FileLastModifiedFilter(age=" + duration + ")";
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d38dc8ac/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileLastModifiedFilterTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileLastModifiedFilterTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileLastModifiedFilterTest.java
deleted file mode 100644
index 28a3ba8..0000000
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FileLastModifiedFilterTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.core.appender.rolling.action;
-
-import java.nio.file.attribute.FileTime;
-
-import org.apache.logging.log4j.core.appender.rolling.action.Duration;
-import 
org.apache.logging.log4j.core.appender.rolling.action.FileLastModifiedFilter;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests the FileAgeFilter class.
- */
-public class FileLastModifiedFilterTest {
-
-    @Test
-    public void testGetDurationReturnsConstructorValue() {
-        FileLastModifiedFilter filter = 
FileLastModifiedFilter.createAgeFilter(Duration.parse("P7D"));
-        assertEquals(0, filter.getDuration().compareTo(Duration.parse("P7D")));
-    }
-
-    @Test
-    public void testAcceptsIfFileAgeEqualToDuration() {
-        FileLastModifiedFilter filter = 
FileLastModifiedFilter.createAgeFilter(Duration.parse("PT33S"));
-        DummyFileAttributes attrs = new DummyFileAttributes();
-        final long age = 33 * 1000;
-        attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - 
age);
-        assertTrue(filter.accept(null, null, attrs));
-    }
-
-    @Test
-    public void testAcceptsIfFileAgeExceedsDuration() {
-        FileLastModifiedFilter filter = 
FileLastModifiedFilter.createAgeFilter(Duration.parse("PT33S"));
-        DummyFileAttributes attrs = new DummyFileAttributes();
-        final long age = 33 * 1000 + 5;
-        attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - 
age);
-        assertTrue(filter.accept(null, null, attrs));
-    }
-
-    @Test
-    public void testDoesNotAcceptIfFileAgeLessThanDuration() {
-        FileLastModifiedFilter filter = 
FileLastModifiedFilter.createAgeFilter(Duration.parse("PT33S"));
-        DummyFileAttributes attrs = new DummyFileAttributes();
-        final long age = 33 * 1000 - 5;
-        attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - 
age);
-        assertFalse(filter.accept(null, null, attrs));
-    }
-}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d38dc8ac/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java
new file mode 100644
index 0000000..90f6fdb
--- /dev/null
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfLastModifiedTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.appender.rolling.action;
+
+import java.nio.file.attribute.FileTime;
+
+import org.apache.logging.log4j.core.appender.rolling.action.Duration;
+import org.apache.logging.log4j.core.appender.rolling.action.IfLastModified;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the FileAgeFilter class.
+ */
+public class IfLastModifiedTest {
+
+    @Test
+    public void testGetDurationReturnsConstructorValue() {
+        IfLastModified filter = 
IfLastModified.createAgeFilter(Duration.parse("P7D"));
+        assertEquals(0, filter.getDuration().compareTo(Duration.parse("P7D")));
+    }
+
+    @Test
+    public void testAcceptsIfFileAgeEqualToDuration() {
+        IfLastModified filter = 
IfLastModified.createAgeFilter(Duration.parse("PT33S"));
+        DummyFileAttributes attrs = new DummyFileAttributes();
+        final long age = 33 * 1000;
+        attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - 
age);
+        assertTrue(filter.accept(null, null, attrs));
+    }
+
+    @Test
+    public void testAcceptsIfFileAgeExceedsDuration() {
+        IfLastModified filter = 
IfLastModified.createAgeFilter(Duration.parse("PT33S"));
+        DummyFileAttributes attrs = new DummyFileAttributes();
+        final long age = 33 * 1000 + 5;
+        attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - 
age);
+        assertTrue(filter.accept(null, null, attrs));
+    }
+
+    @Test
+    public void testDoesNotAcceptIfFileAgeLessThanDuration() {
+        IfLastModified filter = 
IfLastModified.createAgeFilter(Duration.parse("PT33S"));
+        DummyFileAttributes attrs = new DummyFileAttributes();
+        final long age = 33 * 1000 - 5;
+        attrs.lastModified = FileTime.fromMillis(System.currentTimeMillis() - 
age);
+        assertFalse(filter.accept(null, null, attrs));
+    }
+}

Reply via email to