modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
| 4 ++--
modules/core/domain/src/main/java/org/rhq/core/domain/drift/Filter.java
| 2 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
| 6 ++----
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/FilterFileVisitorTest.java
| 9 +--------
4 files changed, 6 insertions(+), 15 deletions(-)
New commits:
commit 00ea14c228bd08d6572d0f17ef8040e447b9a0dd
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Mon Jun 25 12:47:42 2012 -0400
[827647 Relative path for Drift Detections Definition Include/Excludes Path does not
handle relative path alias or trailing file separator correctly]
There were two ways to go here. One was to add special case handling for
the various filter paths that equate to ".". The other was to normalize
in the Filter constructor. Since I tried option 1 and missed a spot in my
first try to fix it, I've now opted for option 2. The downside is only that
what the user types may get normalized to ".". But I added some more
description
text to state as much. Also, existing Filter paths using "/" or
"./" will
need to be updated to "." manually, but I doubt there are any out there
currently since it wasn't working.
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
index dee6e01..5eaaeab 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
@@ -519,7 +519,7 @@ public class DriftConfigurationDefinition implements Serializable {
private static PropertyDefinitionSimple createIncludePath(boolean readOnly) {
String name = PROP_PATH;
- String description = "A file system directory path that is relative to (a
sub-directory of) the base directory of the drift definition. The default is '.',
the base directory itself.";
+ String description = "A file system directory path that is relative to (a
sub-directory of) the base directory of the drift definition. The default is '.',
the base directory itself. Note that '/' and './' will be normalized to
'.' for consistent handling.";
boolean required = false;
PropertySimpleType type = PropertySimpleType.STRING;
@@ -592,7 +592,7 @@ public class DriftConfigurationDefinition implements Serializable {
private static PropertyDefinitionSimple createExcludePath(boolean readOnly) {
String name = PROP_PATH;
- String description = "A file system path that can be a directory or a file.
The path is assumed to be relative to the base directory of the drift definition.";
+ String description = "A file system directory path that is relative to (a
sub-directory of) the base directory of the drift definition. The default is '.',
the base directory itself. Note that '/' and './' will be normalized to
'.' for consistent handling.";
boolean required = true;
PropertySimpleType type = PropertySimpleType.STRING;
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/Filter.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/Filter.java
index b57eb32..7e7bc43 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/Filter.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/Filter.java
@@ -41,7 +41,7 @@ public class Filter implements Serializable {
}
public void setPath(String path) {
- if (path == null) {
+ if (path == null || "./".equals(path) || "/".equals(path)) {
this.path = ".";
} else {
this.path = path;
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
index 92042e7..dbc7a1d 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
@@ -404,8 +404,7 @@ public class DriftDetector implements Runnable {
}
}
- // package-private for test accessibility
- static Set<File> getScanDirectories(final File basedir, List<Filter>
includes) {
+ private static Set<File> getScanDirectories(final File basedir,
List<Filter> includes) {
Set<File> directories = new HashSet<File>();
@@ -414,8 +413,7 @@ public class DriftDetector implements Runnable {
} else {
for (Filter filter : includes) {
String path = filter.getPath();
- // support various ways of expressing the base directory with relative
paths
- if (".".equals(path) || "./".equals(path) ||
"/".equals(path)) {
+ if (".".equals(path)) {
directories.add(basedir);
} else {
directories.add(new File(basedir, path));
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/FilterFileVisitorTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/FilterFileVisitorTest.java
index d6812ba..eb3678c 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/FilterFileVisitorTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/FilterFileVisitorTest.java
@@ -31,10 +31,8 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import org.apache.commons.io.FileUtils;
-import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -85,12 +83,7 @@ public class FilterFileVisitorTest {
List<Filter> includes = asList(new Filter(".", "foo*"),
new Filter("./", "*.war"), new Filter("/",
"goo*"));
List<Filter> excludes = emptyList();
TestVisitor visitor = new TestVisitor();
-
- // This call normalizes the basedir.
- Set<File> dirs = DriftDetector.getScanDirectories(basedir, includes);
- Assert.assertEquals(dirs.size(), 1, "Should just be the basedir");
- File normalizedBaseDir = dirs.iterator().next();
- forEachFile(normalizedBaseDir, new FilterFileVisitor(normalizedBaseDir, includes,
excludes, visitor));
+ forEachFile(basedir, new FilterFileVisitor(basedir, includes, excludes,
visitor));
assertCollectionEqualsNoOrder(asList(fooJar, gooJar, myapp),
visitor.visitedFiles,
"Filtering failed with multiple includes and no excludes");