You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/08/07 18:26:40 UTC
logging-log4j2 git commit: Parameterize MAX_TRIES.
Repository: logging-log4j2
Updated Branches:
refs/heads/master a3b5f73a6 -> 96f7d65c7
Parameterize MAX_TRIES.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/96f7d65c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/96f7d65c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/96f7d65c
Branch: refs/heads/master
Commit: 96f7d65c7c14dd92022a42a09d9787f7f81e67bb
Parents: a3b5f73
Author: Gary Gregory <gg...@apache.org>
Authored: Sun Aug 7 11:26:39 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Sun Aug 7 11:26:39 2016 -0700
----------------------------------------------------------------------
.../junit/AbstractExternalFileCleaner.java | 169 ++++++++++---------
.../apache/logging/log4j/junit/CleanFiles.java | 14 +-
.../logging/log4j/junit/CleanFolders.java | 14 +-
.../logging/log4j/junit/LoggerContextRule.java | 4 +-
4 files changed, 104 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/96f7d65c/log4j-core/src/test/java/org/apache/logging/log4j/junit/AbstractExternalFileCleaner.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/AbstractExternalFileCleaner.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/AbstractExternalFileCleaner.java
index 393b847..7860917 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/AbstractExternalFileCleaner.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/AbstractExternalFileCleaner.java
@@ -1,81 +1,88 @@
-/*
- * 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.junit;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.rules.ExternalResource;
-
-public abstract class AbstractExternalFileCleaner extends ExternalResource {
-
- private final boolean cleanAfter;
- private final boolean cleanBefore;
- private final List<File> files;
-
- public AbstractExternalFileCleaner(final boolean before, final boolean after, final File... files) {
- this.cleanBefore = before;
- this.cleanAfter = after;
- this.files = Arrays.asList(files);
- }
-
- public AbstractExternalFileCleaner(final boolean before, final boolean after, final String... fileNames) {
- this.cleanBefore = before;
- this.cleanAfter = after;
- this.files = new ArrayList<>(fileNames.length);
- for (final String fileName : fileNames) {
- this.files.add(new File(fileName));
- }
- }
-
- @Override
- protected void after() {
- if (cleanAfter()) {
- this.clean();
- }
- }
-
- @Override
- protected void before() {
- if (cleanBefore()) {
- this.clean();
- }
- }
-
- abstract protected void clean();
-
- public boolean cleanAfter() {
- return cleanAfter;
- }
-
- public boolean cleanBefore() {
- return cleanBefore;
- }
-
- public List<File> getFiles() {
- return files;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + " [files=" + files + ", cleanAfter=" + cleanAfter + ", cleanBefore="
- + cleanBefore + "]";
- }
-
-}
+/*
+ * 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.junit;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.rules.ExternalResource;
+
+public abstract class AbstractExternalFileCleaner extends ExternalResource {
+
+ private final boolean cleanAfter;
+ private final boolean cleanBefore;
+ private final List<File> files;
+ private final int maxTries;
+
+ public AbstractExternalFileCleaner(final boolean before, final boolean after, final int maxTries, final File... files) {
+ this.cleanBefore = before;
+ this.cleanAfter = after;
+ this.files = Arrays.asList(files);
+ this.maxTries = maxTries;
+ }
+
+ public AbstractExternalFileCleaner(final boolean before, final boolean after, final int maxTries, final String... fileNames) {
+ this.cleanBefore = before;
+ this.cleanAfter = after;
+ this.files = new ArrayList<>(fileNames.length);
+ for (final String fileName : fileNames) {
+ this.files.add(new File(fileName));
+ }
+ this.maxTries = maxTries;
+ }
+
+ @Override
+ protected void after() {
+ if (cleanAfter()) {
+ this.clean();
+ }
+ }
+
+ @Override
+ protected void before() {
+ if (cleanBefore()) {
+ this.clean();
+ }
+ }
+
+ abstract protected void clean();
+
+ public boolean cleanAfter() {
+ return cleanAfter;
+ }
+
+ public boolean cleanBefore() {
+ return cleanBefore;
+ }
+
+ public List<File> getFiles() {
+ return files;
+ }
+
+ public int getMaxTries() {
+ return maxTries;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + " [files=" + files + ", cleanAfter=" + cleanAfter + ", cleanBefore="
+ + cleanBefore + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/96f7d65c/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
index 1021bf1..d38ca85 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFiles.java
@@ -28,27 +28,27 @@ import org.junit.Assert;
public class CleanFiles extends AbstractExternalFileCleaner {
private static final int MAX_TRIES = 10;
- public CleanFiles(final boolean before, final boolean after, final File... files) {
- super(before, after, files);
+ public CleanFiles(final boolean before, final boolean after, final int maxTries, final File... files) {
+ super(before, after, maxTries, files);
}
- public CleanFiles(final boolean before, final boolean after, final String... fileNames) {
- super(before, after, fileNames);
+ public CleanFiles(final boolean before, final boolean after, final int maxTries, final String... fileNames) {
+ super(before, after, maxTries, fileNames);
}
public CleanFiles(final File... files) {
- super(true, true, files);
+ super(true, true, MAX_TRIES, files);
}
public CleanFiles(final String... fileNames) {
- super(true, true, fileNames);
+ super(true, true, MAX_TRIES, fileNames);
}
@Override
protected void clean() {
for (final File file : getFiles()) {
if (file.exists()) {
- for (int i = 0; i < MAX_TRIES; i++) {
+ for (int i = 0; i < getMaxTries(); i++) {
try {
if (Files.deleteIfExists(file.toPath())) {
// Break from MAX_TRIES and move on to the next file.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/96f7d65c/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFolders.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFolders.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFolders.java
index 6a2f8d6..a4d9023 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFolders.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/CleanFolders.java
@@ -34,20 +34,20 @@ import org.junit.Assert;
public class CleanFolders extends AbstractExternalFileCleaner {
private static final int MAX_TRIES = 10;
- public CleanFolders(final boolean before, final boolean after, final File... files) {
- super(before, after, files);
+ public CleanFolders(final boolean before, final boolean after, final int maxTries, final File... files) {
+ super(before, after, maxTries, files);
}
- public CleanFolders(final boolean before, final boolean after, final String... fileNames) {
- super(before, after, fileNames);
+ public CleanFolders(final boolean before, final boolean after, final int maxTries, final String... fileNames) {
+ super(before, after, maxTries, fileNames);
}
public CleanFolders(final File... folders) {
- super(true, true, folders);
+ super(true, true, MAX_TRIES, folders);
}
public CleanFolders(final String... folderNames) {
- super(true, true, folderNames);
+ super(true, true, MAX_TRIES, folderNames);
}
@Override
@@ -57,7 +57,7 @@ public class CleanFolders extends AbstractExternalFileCleaner {
for (final File folder : getFiles()) {
if (folder.exists()) {
final Path path = folder.toPath();
- for (int i = 0; i < MAX_TRIES; i++) {
+ for (int i = 0; i < getMaxTries(); i++) {
try {
cleanFolder(path);
if (failures.containsKey(path)) {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/96f7d65c/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
index 3468e3f..c9b07aa 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
@@ -248,8 +248,8 @@ public class LoggerContextRule implements TestRule {
return RuleChain.outerRule(new CleanFiles(files)).around(this);
}
- public RuleChain withCleanFoldersRule(final boolean before, final boolean after, final String... folders) {
- return RuleChain.outerRule(new CleanFolders(before, after, folders)).around(this);
+ public RuleChain withCleanFoldersRule(final boolean before, final boolean after, final int maxTries, final String... folders) {
+ return RuleChain.outerRule(new CleanFolders(before, after, maxTries, folders)).around(this);
}
public RuleChain withCleanFoldersRule(final String... folders) {