Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[1119262 jon3-7] EAP6 drifts exclude pattern not working for windows …
Browse files Browse the repository at this point in the history
…case

The issue here is that the drift template defines the plugin descriptor
and in this case, the associated excludes filter: pattern="*_history/**/*".
It can only be predefined in one format, and the plugin naturally uses
linux-style forward slashes for the directory separator.

But on Windows that is the wrong separator.

The solution is to convert to the native separator slash internally at
"detection-time", regardless of the slashing used in the pattern.  This is,
I think, in-line with ant file-pattern approach we are using.

Also,
-- added new FileUtil.useNativeSlash(String path)
  • Loading branch information
jshaughn committed Jul 23, 2014
1 parent df5ddda commit d3f63b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.commons.io.FilenameUtils;

import org.rhq.core.domain.drift.Filter;
import org.rhq.core.util.file.FileUtil;
import org.rhq.core.util.file.FileVisitor;
import org.rhq.core.util.file.PathFilter;

Expand Down Expand Up @@ -123,6 +124,10 @@ private PathFilter normalize(File basedir, Filter filter) {
filterPattern = filter.getPattern();
}

// Calling getAbsolutePath will ensure the filterPath has the native file separator characters. But
// it is also important that the pattern use native separators because the ultimate matching will be
// against native file paths.
filterPattern = FileUtil.useNativeSlash(filterPattern);
return new PathFilter(FilenameUtils.normalize(filterPath.getAbsolutePath()), filterPattern);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,26 @@ public static String useForwardSlash(String path) {
return (null != path) ? path.replace('\\', '/') : null;
}

/**
* Ensure that the path uses only forward slash.
* @param path
* @return backward-slashed path, or null if path is null
*/
public static String useBackwardSlash(String path) {

return (null != path) ? path.replace('/', '\\') : null;
}

/**
* Ensure that the path uses only the proper file separator for the OS.
* @param path
* @return appropriate forward- or back-slashed path, or null if path is null
*/
public static String useNativeSlash(String path) {

return ('/' == File.separatorChar) ? useForwardSlash(path) : useBackwardSlash(path);
}

/**
* Return just the filename portion (the portion right of the last path separator string)
* @param path
Expand Down

0 comments on commit d3f63b5

Please sign in to comment.