LOG4J2-435 Renamed PathFilter to PathCondition to avoid confusion with log event Filters
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/68953fe6 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/68953fe6 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/68953fe6 Branch: refs/heads/master Commit: 68953fe60dc9f450d35cbb7d403702327e5267ad Parents: 0717514 Author: rpopma <[email protected]> Authored: Sun Nov 15 21:03:12 2015 +0900 Committer: rpopma <[email protected]> Committed: Sun Nov 15 21:03:12 2015 +0900 ---------------------------------------------------------------------- .../rolling/action/AbstractPathAction.java | 20 +++++----- .../log4j/core/appender/rolling/action/And.java | 22 +++++------ .../appender/rolling/action/DeleteAction.java | 8 ++-- .../rolling/action/DeletingVisitor.java | 11 +++--- .../log4j/core/appender/rolling/action/Not.java | 24 ++++++------ .../log4j/core/appender/rolling/action/Or.java | 24 ++++++------ .../appender/rolling/action/PathCondition.java | 37 ++++++++++++++++++ .../appender/rolling/action/PathFilter.java | 37 ------------------ .../core/appender/rolling/action/AndTest.java | 14 +++---- .../rolling/action/DeleteActionTest.java | 12 +++--- .../rolling/action/DeletingVisitorTest.java | 20 +++++----- .../appender/rolling/action/FixedCondition.java | 41 ++++++++++++++++++++ .../appender/rolling/action/FixedFilter.java | 41 -------------------- .../core/appender/rolling/action/NotTest.java | 8 ++-- .../core/appender/rolling/action/OrTest.java | 14 +++---- 15 files changed, 167 insertions(+), 166 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractPathAction.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractPathAction.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractPathAction.java index d976549..1a82d13 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractPathAction.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/AbstractPathAction.java @@ -40,7 +40,7 @@ public abstract class AbstractPathAction extends AbstractAction { private final String basePathString; private final Set<FileVisitOption> options; private final int maxDepth; - private final List<PathFilter> pathFilters; + private final List<PathCondition> pathConditions; private final StrSubstitutor subst; /** @@ -55,18 +55,18 @@ public abstract class AbstractPathAction extends AbstractAction { * processed). */ protected AbstractPathAction(final String basePath, final boolean followSymbolicLinks, final int maxDepth, - final PathFilter[] pathFilters, final StrSubstitutor subst) { + final PathCondition[] pathFilters, final StrSubstitutor subst) { this.basePathString = basePath; this.options = followSymbolicLinks ? EnumSet.of(FileVisitOption.FOLLOW_LINKS) // : Collections.<FileVisitOption> emptySet(); this.maxDepth = maxDepth; - this.pathFilters = Arrays.asList(Arrays.copyOf(pathFilters, pathFilters.length)); + this.pathConditions = Arrays.asList(Arrays.copyOf(pathFilters, pathFilters.length)); this.subst = subst; } @Override public boolean execute() throws IOException { - return execute(createFileVisitor(getBasePath(), pathFilters)); + return execute(createFileVisitor(getBasePath(), pathConditions)); } public boolean execute(final FileVisitor<Path> visitor) throws IOException { @@ -89,11 +89,11 @@ public abstract class AbstractPathAction extends AbstractAction { * The visitor is responsible for processing the files it encounters that are accepted by all filters. * * @param visitorBaseDir base dir from where to start scanning for files to process - * @param visitorFilters filters that determine if a file should be processed + * @param conditions filters that determine if a file should be processed * @return a new {@code FileVisitor<Path>} */ protected abstract FileVisitor<Path> createFileVisitor(final Path visitorBaseDir, - final List<PathFilter> visitorFilters); + final List<PathCondition> conditions); /** * Returns the base path from where to start scanning for files to delete. Lookups are resolved, so if the @@ -138,17 +138,17 @@ public abstract class AbstractPathAction extends AbstractAction { } /** - * Returns the list of PathFilter objects. + * Returns the list of PathCondition objects. * * @return the pathFilters */ - public List<PathFilter> getPathFilters() { - return Collections.unmodifiableList(pathFilters); + public List<PathCondition> getPathConditions() { + return Collections.unmodifiableList(pathConditions); } @Override public String toString() { return getClass().getSimpleName() + "[basePath=" + getBasePath() + ", options=" + options + ", maxDepth=" - + maxDepth + ", filters=" + pathFilters + "]"; + + maxDepth + ", conditions=" + pathConditions + "]"; } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java index c701c8e..a103d64 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java @@ -26,18 +26,18 @@ import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; /** - * Composite {@code DeleteFilter} that only accepts objects that are accepted by <em>all</em> component filters. + * Composite {@code PathCondition} that only accepts objects that are accepted by <em>all</em> component filters. */ @Plugin(name = "And", category = "Core", printObject = true) -public final class And implements PathFilter { +public final class And implements PathCondition { - private final PathFilter[] components; + private final PathCondition[] components; - private And(final PathFilter... filters) { + private And(final PathCondition... filters) { this.components = Objects.requireNonNull(filters, "filters"); } - public PathFilter[] getDeleteFilters() { + public PathCondition[] getDeleteFilters() { return components; } @@ -49,7 +49,7 @@ public final class And implements PathFilter { */ @Override public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { - for (final PathFilter component : components) { + for (final PathCondition component : components) { if (!component.accept(baseDir, relativePath, attrs)) { return false; } @@ -58,19 +58,19 @@ public final class And implements PathFilter { } /** - * Create a Composite DeleteFilter. + * Create a Composite PathCondition that all need to accept before this condition accepts. * * @param components The component filters. - * @return A CompositeDeleteFilter. + * @return A Composite PathCondition. */ @PluginFactory - public static And createAndFilter( // - @PluginElement("Filters") final PathFilter... components) { + public static And createAndCondition( // + @PluginElement("PathConditions") final PathCondition... components) { return new And(components); } @Override public String toString() { - return "And(filters=" + Arrays.toString(components) + ")"; + return "And" + Arrays.toString(components); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java index 47fddc5..3fb625d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java @@ -47,13 +47,13 @@ public class DeleteAction extends AbstractPathAction { * deleted). */ DeleteAction(final String basePath, final boolean followSymbolicLinks, final int maxDepth, - final PathFilter[] pathFilters, final StrSubstitutor subst) { + final PathCondition[] pathFilters, final StrSubstitutor subst) { super(basePath, followSymbolicLinks, maxDepth, pathFilters, subst); } @Override - protected FileVisitor<Path> createFileVisitor(final Path visitorBaseDir, final List<PathFilter> visitorFilters) { - return new DeletingVisitor(visitorBaseDir, visitorFilters); + protected FileVisitor<Path> createFileVisitor(final Path visitorBaseDir, final List<PathCondition> conditions) { + return new DeletingVisitor(visitorBaseDir, conditions); } /** @@ -75,7 +75,7 @@ public class DeleteAction extends AbstractPathAction { @PluginAttribute("basePath") final String basePath, // @PluginAttribute(value = "followLinks", defaultBoolean = false) final boolean followLinks, @PluginAttribute(value = "maxDepth", defaultInt = 1) final int maxDepth, - @PluginElement("PathFilters") final PathFilter[] pathFilters, + @PluginElement("PathFilters") final PathCondition[] pathFilters, @PluginConfiguration final Configuration config) { // @formatter:on return new DeleteAction(basePath, followLinks, maxDepth, pathFilters, config.getStrSubstitutor()); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java index ba290d9..75a7bd2 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitor.java @@ -36,7 +36,7 @@ public class DeletingVisitor extends SimpleFileVisitor<Path> { private static final Logger LOGGER = StatusLogger.getLogger(); private final Path basePath; - private final List<? extends PathFilter> pathFilters; + private final List<? extends PathCondition> pathFilters; /** * Constructs a new DeletingVisitor. @@ -44,16 +44,17 @@ public class DeletingVisitor extends SimpleFileVisitor<Path> { * @param basePath used to relativize paths * @param pathFilters objects that need to confirm whether a file can be deleted */ - public DeletingVisitor(final Path basePath, final List<? extends PathFilter> pathFilters) { + public DeletingVisitor(final Path basePath, final List<? extends PathCondition> pathFilters) { this.basePath = Objects.requireNonNull(basePath, "basePath"); this.pathFilters = Objects.requireNonNull(pathFilters, "filters"); } @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { - for (final PathFilter pathFilter : pathFilters) { - if (!pathFilter.accept(basePath, basePath.relativize(file), attrs)) { - LOGGER.trace("Not deleting {}", file); + for (final PathCondition pathFilter : pathFilters) { + final Path relative = basePath.relativize(file); + if (!pathFilter.accept(basePath, relative, attrs)) { + LOGGER.trace("Not deleting base={}, relative={}", basePath, relative); return FileVisitResult.CONTINUE; } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java index 7265dce..8f43ef1 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java @@ -25,18 +25,18 @@ import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; /** - * Wrapper {@code DeleteFilter} that accepts objects that are rejected by the wrapped component filter. + * Wrapper {@code PathCondition} that accepts objects that are rejected by the wrapped component filter. */ @Plugin(name = "Not", category = "Core", printObject = true) -public final class Not implements PathFilter { +public final class Not implements PathCondition { - private final PathFilter negate; + private final PathCondition negate; - private Not(final PathFilter negate) { + private Not(final PathCondition negate) { this.negate = Objects.requireNonNull(negate, "filter"); } - public PathFilter getWrappedFilter() { + public PathCondition getWrappedFilter() { return negate; } @@ -52,19 +52,19 @@ public final class Not implements PathFilter { } /** - * Create a Not filter. + * Create a Not PathCondition. * - * @param filter The filter to negate. - * @return A Not filter. + * @param condition The condition to negate. + * @return A Not PathCondition. */ @PluginFactory - public static Not createNotFilter( // - @PluginElement("Filters") final PathFilter filter) { - return new Not(filter); + public static Not createNotCondition( // + @PluginElement("PathConditions") final PathCondition condition) { + return new Not(condition); } @Override public String toString() { - return "Not(filters=" + negate + ")"; + return "Not(" + negate + ")"; } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java index 68de219..542262f 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java @@ -26,18 +26,18 @@ import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; /** - * Composite {@code DeleteFilter} that accepts objects that are accepted by <em>any</em> component filters. + * Composite {@code PathCondition} that accepts objects that are accepted by <em>any</em> component filters. */ @Plugin(name = "Or", category = "Core", printObject = true) -public final class Or implements PathFilter { +public final class Or implements PathCondition { - private final PathFilter[] components; + private final PathCondition[] components; - private Or(final PathFilter... filters) { + private Or(final PathCondition... filters) { this.components = Objects.requireNonNull(filters, "filters"); } - public PathFilter[] getDeleteFilters() { + public PathCondition[] getDeleteFilters() { return components; } @@ -47,7 +47,7 @@ public final class Or implements PathFilter { */ @Override public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { - for (final PathFilter component : components) { + for (final PathCondition component : components) { if (component.accept(baseDir, relativePath, attrs)) { return true; } @@ -56,19 +56,19 @@ public final class Or implements PathFilter { } /** - * Create a Composite DeleteFilter. + * Create a Composite PathCondition: accepts if any of the nested conditions accepts. * - * @param components The component filters. - * @return A CompositeDeleteFilter. + * @param components The component conditions. + * @return A Composite PathCondition. */ @PluginFactory - public static Or createOrFilter( // - @PluginElement("Filters") final PathFilter... components) { + public static Or createOrCondition( // + @PluginElement("PathConditions") final PathCondition... components) { return new Or(components); } @Override public String toString() { - return "Or(filters=" + Arrays.toString(components) + ")"; + return "Or" + Arrays.toString(components); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathCondition.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathCondition.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathCondition.java new file mode 100644 index 0000000..ff40dfe --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathCondition.java @@ -0,0 +1,37 @@ +/* + * 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; + +/** + * Filter that accepts or rejects a candidate {@code Path} for deletion. + */ +public interface PathCondition { + + /** + * Returns {@code true} if the specified candidate path should be deleted, {@code false} otherwise. + * + * @param baseDir the directory from where to start scanning for deletion candidate files + * @param relativePath the candidate for deletion. This path is relative to the baseDir. + * @param attrs attributes of the candidate path + * @return whether the candidate path should be deleted + */ + boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs); +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathFilter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathFilter.java deleted file mode 100644 index f6b782a..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathFilter.java +++ /dev/null @@ -1,37 +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; - -/** - * Filter that accepts or rejects a candidate {@code Path} for deletion. - */ -public interface PathFilter { - - /** - * Returns {@code true} if the specified candidate path should be deleted, {@code false} otherwise. - * - * @param baseDir the directory from where to start scanning for deletion candidate files - * @param relativePath the candidate for deletion. This path is relative to the baseDir. - * @param attrs attributes of the candidate path - * @return whether the candidate path should be deleted - */ - boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs); -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java index 1f2d826..f802557 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java @@ -18,7 +18,7 @@ package org.apache.logging.log4j.core.appender.rolling.action; import org.apache.logging.log4j.core.appender.rolling.action.And; -import org.apache.logging.log4j.core.appender.rolling.action.PathFilter; +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; import org.junit.Test; import static org.junit.Assert.*; @@ -30,12 +30,12 @@ public class AndTest { @Test public void test() { - final PathFilter TRUE = new FixedFilter(true); - final PathFilter FALSE = new FixedFilter(false); - assertTrue(And.createAndFilter(TRUE, TRUE).accept(null, null, null)); - assertFalse(And.createAndFilter(FALSE, TRUE).accept(null, null, null)); - assertFalse(And.createAndFilter(TRUE, FALSE).accept(null, null, null)); - assertFalse(And.createAndFilter(FALSE, FALSE).accept(null, null, null)); + final PathCondition TRUE = new FixedCondition(true); + final PathCondition FALSE = new FixedCondition(false); + assertTrue(And.createAndCondition(TRUE, TRUE).accept(null, null, null)); + assertFalse(And.createAndCondition(FALSE, TRUE).accept(null, null, null)); + assertFalse(And.createAndCondition(TRUE, FALSE).accept(null, null, null)); + assertFalse(And.createAndCondition(FALSE, FALSE).accept(null, null, null)); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java index 9be8bda..5b9aa1e 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java @@ -28,7 +28,7 @@ import java.util.EnumSet; import org.apache.logging.log4j.core.BasicConfigurationFactory; import org.apache.logging.log4j.core.appender.rolling.action.DeleteAction; import org.apache.logging.log4j.core.appender.rolling.action.DeletingVisitor; -import org.apache.logging.log4j.core.appender.rolling.action.PathFilter; +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; import org.apache.logging.log4j.core.config.Configuration; import org.junit.Test; @@ -40,11 +40,11 @@ import static org.junit.Assert.*; public class DeleteActionTest { private static DeleteAction createAnyFilter(String path, boolean followLinks, int maxDepth) { - PathFilter[] pathFilters = {new FixedFilter(true)}; + PathCondition[] pathFilters = {new FixedCondition(true)}; return create(path, followLinks, maxDepth, pathFilters); } - private static DeleteAction create(String path, boolean followLinks, int maxDepth, PathFilter[] filters) { + private static DeleteAction create(String path, boolean followLinks, int maxDepth, PathCondition[] filters) { Configuration config = new BasicConfigurationFactory().new BasicConfiguration(); DeleteAction delete = DeleteAction.createDeleteAction(path, followLinks, maxDepth, filters, config); return delete; @@ -86,16 +86,16 @@ public class DeleteActionTest { @Test public void testGetFiltersReturnsConstructorValue() { - PathFilter[] filters = {new FixedFilter(true), new FixedFilter(false)}; + PathCondition[] filters = {new FixedCondition(true), new FixedCondition(false)}; DeleteAction delete = create("any", true, 0, filters); - assertEquals(Arrays.asList(filters), delete.getPathFilters()); + assertEquals(Arrays.asList(filters), delete.getPathConditions()); } @Test public void testCreateFileVisitorReturnsDeletingVisitor() { DeleteAction delete = createAnyFilter("any", true, 0); - FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathFilters()); + FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); assertTrue(visitor instanceof DeletingVisitor); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java index f72573e..aee976f 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java @@ -26,7 +26,7 @@ import java.util.Arrays; import java.util.List; import org.apache.logging.log4j.core.appender.rolling.action.DeletingVisitor; -import org.apache.logging.log4j.core.appender.rolling.action.PathFilter; +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; import org.junit.Test; import static org.junit.Assert.*; @@ -42,7 +42,7 @@ public class DeletingVisitorTest { static class DeletingVisitorHelper extends DeletingVisitor { List<Path> deleted = new ArrayList<Path>(); - public DeletingVisitorHelper(final Path basePath, final List<? extends PathFilter> pathFilters) { + public DeletingVisitorHelper(final Path basePath, final List<? extends PathCondition> pathFilters) { super(basePath, pathFilters); } @@ -55,7 +55,7 @@ public class DeletingVisitorTest { @Test public void testAcceptedFilesAreDeleted() throws IOException { Path base = FileSystems.getDefault().getPath("/a/b/c"); - final FixedFilter ACCEPT_ALL = new FixedFilter(true); + final FixedCondition ACCEPT_ALL = new FixedCondition(true); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(ACCEPT_ALL)); Path any = FileSystems.getDefault().getPath("/a/b/c/any"); @@ -66,7 +66,7 @@ public class DeletingVisitorTest { @Test public void testRejectedFilesAreNotDeleted() throws IOException { Path base = FileSystems.getDefault().getPath("/a/b/c"); - final FixedFilter REJECT_ALL = new FixedFilter(false); + final FixedCondition REJECT_ALL = new FixedCondition(false); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(REJECT_ALL)); Path any = FileSystems.getDefault().getPath("/a/b/c/any"); @@ -77,9 +77,9 @@ public class DeletingVisitorTest { @Test public void testAllFiltersMustAcceptOrFileIsNotDeleted() throws IOException { Path base = FileSystems.getDefault().getPath("/a/b/c"); - final FixedFilter ACCEPT_ALL = new FixedFilter(true); - final FixedFilter REJECT_ALL = new FixedFilter(false); - List<? extends PathFilter> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, REJECT_ALL); + final FixedCondition ACCEPT_ALL = new FixedCondition(true); + final FixedCondition REJECT_ALL = new FixedCondition(false); + List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, REJECT_ALL); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters); Path any = FileSystems.getDefault().getPath("/a/b/c/any"); @@ -90,8 +90,8 @@ public class DeletingVisitorTest { @Test public void testIfAllFiltersAcceptFileIsDeleted() throws IOException { Path base = FileSystems.getDefault().getPath("/a/b/c"); - final FixedFilter ACCEPT_ALL = new FixedFilter(true); - List<? extends PathFilter> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); + final FixedCondition ACCEPT_ALL = new FixedCondition(true); + List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters); Path any = FileSystems.getDefault().getPath("/a/b/c/any"); @@ -102,7 +102,7 @@ public class DeletingVisitorTest { @Test public void testVisitFileRelativizesAgainstBase() throws IOException { - PathFilter filter = new PathFilter() { + PathCondition filter = new PathCondition() { @Override public boolean accept(Path baseDir, Path relativePath, BasicFileAttributes attrs) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java new file mode 100644 index 0000000..7a9faf7 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java @@ -0,0 +1,41 @@ +/* + * 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 org.apache.logging.log4j.core.appender.rolling.action.PathCondition; + +/** + * Test helper class. + */ +public class FixedCondition implements PathCondition { + + private final boolean accept; + + public FixedCondition(boolean accept) { + this.accept = accept; + } + + @Override + public boolean accept(Path baseDir, Path path, BasicFileAttributes attrs) { + return accept; + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedFilter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedFilter.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedFilter.java deleted file mode 100644 index b86f067..0000000 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedFilter.java +++ /dev/null @@ -1,41 +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 org.apache.logging.log4j.core.appender.rolling.action.PathFilter; - -/** - * Test helper class. - */ -public class FixedFilter implements PathFilter { - - private final boolean accept; - - public FixedFilter(boolean accept) { - this.accept = accept; - } - - @Override - public boolean accept(Path baseDir, Path path, BasicFileAttributes attrs) { - return accept; - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java index ce50dd4..d20018c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java @@ -29,11 +29,11 @@ public class NotTest { @Test public void test() { - assertTrue(new FixedFilter(true).accept(null, null, null)); - assertFalse(Not.createNotFilter(new FixedFilter(true)).accept(null, null, null)); + assertTrue(new FixedCondition(true).accept(null, null, null)); + assertFalse(Not.createNotCondition(new FixedCondition(true)).accept(null, null, null)); - assertFalse(new FixedFilter(false).accept(null, null, null)); - assertTrue(Not.createNotFilter(new FixedFilter(false)).accept(null, null, null)); + assertFalse(new FixedCondition(false).accept(null, null, null)); + assertTrue(Not.createNotCondition(new FixedCondition(false)).accept(null, null, null)); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/68953fe6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java index fa9c419..7edc9ad 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java @@ -18,7 +18,7 @@ package org.apache.logging.log4j.core.appender.rolling.action; import org.apache.logging.log4j.core.appender.rolling.action.Or; -import org.apache.logging.log4j.core.appender.rolling.action.PathFilter; +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; import org.junit.Test; import static org.junit.Assert.*; @@ -30,12 +30,12 @@ public class OrTest { @Test public void test() { - final PathFilter TRUE = new FixedFilter(true); - final PathFilter FALSE = new FixedFilter(false); - assertTrue(Or.createOrFilter(TRUE, TRUE).accept(null, null, null)); - assertTrue(Or.createOrFilter(FALSE, TRUE).accept(null, null, null)); - assertTrue(Or.createOrFilter(TRUE, FALSE).accept(null, null, null)); - assertFalse(Or.createOrFilter(FALSE, FALSE).accept(null, null, null)); + final PathCondition TRUE = new FixedCondition(true); + final PathCondition FALSE = new FixedCondition(false); + assertTrue(Or.createOrCondition(TRUE, TRUE).accept(null, null, null)); + assertTrue(Or.createOrCondition(FALSE, TRUE).accept(null, null, null)); + assertTrue(Or.createOrCondition(TRUE, FALSE).accept(null, null, null)); + assertFalse(Or.createOrCondition(FALSE, FALSE).accept(null, null, null)); } }
