\r
final File root = myContext.getBuild().getCheckoutDirectory();\r
try {\r
- final Collection<File> result = DirectoryScanner.FindFiles(root, patterns, Collections.<String>emptyList());\r
+ final Collection<File> result = DirectoryScanner.findFiles(root, patterns, Collections.<String>emptyList());\r
for (File file : result) {\r
LOG.debug("Found nugkg to push: " + file);\r
found = true;\r
*/\r
package jetbrains.buildServer.nuget.agent.runner.publish.fsScanner;\r
\r
+import org.jetbrains.annotations.NotNull;\r
import org.jetbrains.annotations.Nullable;\r
\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
public class AntPatternState {\r
- public enum MatchResult {\r
- YES,\r
- NO,\r
- MAYBELATER\r
- }\r
-\r
private final List<Wildcard> myPatternParts;\r
//NDA state of mathing of pattern. Every ** produces new state\r
private final List<Integer> myPatternPositions;\r
return list;\r
}\r
\r
- public List<Integer> PatternPositions() {\r
+ public List<Integer> getPatternPositions() {\r
return myPatternPositions;\r
}\r
\r
- public static class AntPatternStateMatch {\r
- private final MatchResult myResult;\r
- private final AntPatternState myState;\r
-\r
- public AntPatternStateMatch(MatchResult result, AntPatternState state) {\r
- myResult = result;\r
- myState = state;\r
- }\r
-\r
- public MatchResult getResult() {\r
- return myResult;\r
- }\r
-\r
- public AntPatternState getState() {\r
- return myState;\r
- }\r
- }\r
-\r
/**\r
* @return list of next tokends that are matching or null of there are at least one ** in pattern\r
*/\r
if (wd == null) return null;\r
\r
if (wd.containsNoPatterns()) {\r
- result.add(wd.Pattern());\r
+ result.add(wd.getPattern());\r
} else {\r
return null;\r
}\r
}\r
\r
\r
- public AntPatternStateMatch Enter(String component) {\r
+ public AntPatternStateMatch enter(@NotNull final String component) {\r
if (myPatternParts.size() == 0) {\r
return new AntPatternStateMatch(MatchResult.NO, this);\r
}\r
final Wildcard wildcard = myPatternParts.get(pos);\r
\r
if (wildcard != null) {\r
- if (wildcard.IsMatch(component)) {\r
+ if (wildcard.isMatch(component)) {\r
if (pos == myPatternParts.size() - 1) {\r
match = MatchResult.YES;\r
} else if (pos == myPatternParts.size() - 2 && myPatternParts.get(pos + 1) == null) {\r
if (pos == myPatternParts.size() - 1) {\r
match = MatchResult.YES;\r
} else {\r
- if (myPatternParts.get(pos + 1).IsMatch(component)) {\r
+ if (myPatternParts.get(pos + 1).isMatch(component)) {\r
if (pos == myPatternParts.size() - 2) {\r
match = MatchResult.YES;\r
} else {\r
--- /dev/null
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.agent.runner.publish.fsScanner;\r
+\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+* @author Eugene Petrenko (eugene.petrenko@gmail.com)\r
+* Date: 25.08.11 11:56\r
+*/\r
+public class AntPatternStateMatch {\r
+ private final MatchResult myResult;\r
+ private final AntPatternState myState;\r
+\r
+ public AntPatternStateMatch(@NotNull final MatchResult result,\r
+ @NotNull final AntPatternState state) {\r
+ myResult = result;\r
+ myState = state;\r
+ }\r
+\r
+ @NotNull\r
+ public MatchResult getResult() {\r
+ return myResult;\r
+ }\r
+\r
+ @NotNull\r
+ public AntPatternState getState() {\r
+ return myState;\r
+ }\r
+}\r
package jetbrains.buildServer.nuget.agent.runner.publish.fsScanner;\r
\r
import jetbrains.buildServer.util.StringUtil;\r
+import org.jetbrains.annotations.NotNull;\r
\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.Collections;\r
import java.util.List;\r
\r
-public class AntPatternUtil\r
- {\r
- private static String NormalizePatternString(String pattern)\r
- {\r
- pattern = pattern.trim();\r
- pattern = pattern.replace('\\', '/');\r
- pattern = pattern.replaceAll("[//]+", "/");\r
- pattern = pattern.replaceAll("\\*\\*[\\*]+", "**");\r
- pattern = pattern.replaceAll("\\*\\*/\\*\\*", "**");\r
- if (pattern.startsWith("/")) pattern = pattern.substring(1);\r
- return pattern;\r
- }\r
+public class AntPatternUtil {\r
+ private static String normalizePatternString(@NotNull String pattern) {\r
+ pattern = pattern.trim();\r
+ pattern = pattern.replace('\\', '/');\r
+ pattern = pattern.replaceAll("[//]+", "/");\r
+ pattern = pattern.replaceAll("\\*\\*[\\*]+", "**");\r
+ pattern = pattern.replaceAll("\\*\\*/\\*\\*", "**");\r
+ if (pattern.startsWith("/")) pattern = pattern.substring(1);\r
+ return pattern;\r
+ }\r
\r
- public static boolean IsFileNameMatch(String pattern, String name)\r
- {\r
- name = name.trim();\r
- name = name.replace('\\', '/');\r
- name = name.replaceAll("[//]+", "/");\r
-\r
- List<Wildcard> wildcards = ParsePattern(pattern, false);\r
- AntPatternState state = new AntPatternState(wildcards);\r
-\r
- List<String> splitted = new ArrayList<String>(Arrays.asList(name.split("/")));\r
- List<String> nameComponents = new ArrayList<String>();\r
- for (String s : splitted)\r
- {\r
- if (!StringUtil.isEmptyOrSpaces(s))\r
- {\r
- nameComponents.add(s);\r
- }\r
- }\r
+ public static boolean isFileNameMatch(@NotNull final String pattern, @NotNull String name) {\r
+ name = name.trim();\r
+ name = name.replace('\\', '/');\r
+ name = name.replaceAll("[//]+", "/");\r
\r
- AntPatternState.MatchResult matchResult = AntPatternState.MatchResult.NO;\r
+ List<Wildcard> wildcards = parsePattern(pattern, false);\r
+ AntPatternState state = new AntPatternState(wildcards);\r
\r
- for (int i = 0; i < nameComponents.size(); i++)\r
- {\r
- if (nameComponents.get(i).equals(".") && i < nameComponents.size() - 1)\r
- continue;\r
+ List<String> splitted = new ArrayList<String>(Arrays.asList(name.split("/")));\r
+ List<String> nameComponents = new ArrayList<String>();\r
+ for (String s : splitted) {\r
+ if (!StringUtil.isEmptyOrSpaces(s)) nameComponents.add(s);\r
+ }\r
\r
- final AntPatternState.AntPatternStateMatch enter = state.Enter(nameComponents.get(i));\r
- matchResult = enter.getResult();\r
- state = enter.getState();\r
- }\r
+ MatchResult matchResult = MatchResult.NO;\r
\r
- return matchResult == AntPatternState.MatchResult.YES;\r
+ for (int i = 0; i < nameComponents.size(); i++) {\r
+ if (nameComponents.get(i).equals(".") && i < nameComponents.size() - 1)\r
+ continue;\r
+\r
+ final AntPatternStateMatch enter = state.enter(nameComponents.get(i));\r
+ matchResult = enter.getResult();\r
+ state = enter.getState();\r
}\r
\r
- public static List<Wildcard> ParsePattern(String pattern, boolean caseSensitive)\r
- {\r
- pattern = NormalizePatternString(pattern);\r
- if (pattern.length() == 0)\r
- return Collections.emptyList();\r
-\r
- List<Wildcard> result = new ArrayList<Wildcard>();\r
- for (String component : pattern.split("/"))\r
- {\r
- int astIndex = component.indexOf("**");\r
- if (astIndex < 0)\r
- {\r
- result.add(new Wildcard(component, caseSensitive));\r
- continue;\r
- }\r
-\r
- if (astIndex > 0)\r
- result.add(new Wildcard(component.substring(0, astIndex) + "*", caseSensitive));\r
-\r
- int cur = astIndex;\r
- while (astIndex >= 0)\r
- {\r
- if (astIndex - cur > 0)\r
- result.add(new Wildcard("*" + component.substring(cur, astIndex) + "*", caseSensitive));\r
-\r
- result.add(null);\r
-\r
- cur = astIndex + 2;\r
- astIndex = component.indexOf("**", cur);\r
- }\r
-\r
- if (cur < component.length())\r
- result.add(new Wildcard("*" + component.substring(cur), caseSensitive));\r
+ return matchResult == MatchResult.YES;\r
+ }\r
+\r
+ @NotNull\r
+ public static List<Wildcard> parsePattern(@NotNull String pattern, boolean caseSensitive) {\r
+ pattern = normalizePatternString(pattern);\r
+ if (pattern.length() == 0)\r
+ return Collections.emptyList();\r
+\r
+ List<Wildcard> result = new ArrayList<Wildcard>();\r
+ for (String component : pattern.split("/")) {\r
+ int astIndex = component.indexOf("**");\r
+ if (astIndex < 0) {\r
+ result.add(new Wildcard(component, caseSensitive));\r
+ continue;\r
+ }\r
+\r
+ if (astIndex > 0) {\r
+ result.add(new Wildcard(component.substring(0, astIndex) + "*", caseSensitive));\r
}\r
\r
- RemoveTwoDots(result);\r
- RemoveOneDot(result);\r
+ int cur = astIndex;\r
+ while (astIndex >= 0) {\r
+ if (astIndex - cur > 0)\r
+ result.add(new Wildcard("*" + component.substring(cur, astIndex) + "*", caseSensitive));\r
\r
- return result;\r
+ result.add(null);\r
+\r
+ cur = astIndex + 2;\r
+ astIndex = component.indexOf("**", cur);\r
+ }\r
+\r
+ if (cur < component.length()) {\r
+ result.add(new Wildcard("*" + component.substring(cur), caseSensitive));\r
+ }\r
}\r
\r
- private static void RemoveOneDot(List<Wildcard> wildcards)\r
- {\r
- int i = 0;\r
- while (i < wildcards.size() - 1)\r
- {\r
- if (wildcards.get(i) != null && wildcards.get(i).Pattern().equals("."))\r
- wildcards.remove(i);\r
- else\r
- i++;\r
+ removeTwoDots(result);\r
+ removeOneDot(result);\r
+\r
+ return result;\r
+ }\r
+\r
+ private static void removeOneDot(@NotNull final List<Wildcard> wildcards) {\r
+ int i = 0;\r
+ while (i < wildcards.size() - 1) {\r
+ if (wildcards.get(i) != null && wildcards.get(i).getPattern().equals(".")) {\r
+ wildcards.remove(i);\r
+ } else {\r
+ i++;\r
}\r
}\r
+ }\r
\r
- private static void RemoveTwoDots(List<Wildcard> wildcards)\r
- {\r
- int i = 0;\r
- while (i < wildcards.size() - 1)\r
- {\r
- if (wildcards.get(i + 1) != null && wildcards.get(i + 1).Pattern().equals(".."))\r
- {\r
- wildcards.remove(i);\r
- wildcards.remove(i);\r
-\r
- if (i > 0)\r
- i--;\r
- }\r
- else\r
- i++;\r
+ private static void removeTwoDots(List<Wildcard> wildcards) {\r
+ int i = 0;\r
+ while (i < wildcards.size() - 1) {\r
+ if (wildcards.get(i + 1) != null && wildcards.get(i + 1).getPattern().equals("..")) {\r
+ wildcards.remove(i);\r
+ wildcards.remove(i);\r
+\r
+ if (i > 0) i--;\r
+ } else {\r
+ i++;\r
}\r
+ }\r
\r
- while (wildcards.size() > 0 && wildcards.get(0) != null && wildcards.get(0).Pattern().equals(".."))\r
- wildcards.remove(0);\r
+ while (wildcards.size() > 0 && wildcards.get(0) != null && wildcards.get(0).getPattern().equals("..")) {\r
+ wildcards.remove(0);\r
}\r
}\r
+}\r
\r
import java.util.Collection;\r
\r
-public interface IDirectoryEntry {\r
+public interface DirectoryEntry {\r
@NotNull\r
- String Name();\r
+ String getName();\r
\r
@Nullable\r
- IDirectoryEntry Parent();\r
+ DirectoryEntry getParent();\r
\r
@NotNull\r
- IDirectoryEntry[] Subdirectories();\r
+ DirectoryEntry[] getSubdirectories();\r
\r
/**\r
* @param names names filter\r
* @return redured list of items filtered (if possible) by given names\r
*/\r
@NotNull\r
- IDirectoryEntry[] Subdirectories(Collection<String> names);\r
+ DirectoryEntry[] getSubdirectories(Collection<String> names);\r
\r
@NotNull\r
- IFileEntry[] Files();\r
+ FileEntry[] getFiles();\r
\r
/**\r
* @param names names filter\r
* @return returns list of existing file names, i.e. subset of given names\r
*/\r
@NotNull\r
- IFileEntry[] Files(Collection<String> names);\r
+ FileEntry[] getFiles(@NotNull Collection<String> names);\r
}\r
public class DirectoryScanner {\r
private static final Logger LOG = Logger.getInstance(DirectoryScanner.class.getName());\r
\r
- public static Collection<File> FindFiles(@NotNull File root, Collection<String> includes, Collection<String> excludes) {\r
- return FindFiles(new RealFileSystem(), new RealDirectoryEntry(new FileSystemPath(root)), includes, excludes);\r
+ public static Collection<File> findFiles(@NotNull File root,\r
+ @NotNull final Collection<String> includes,\r
+ @NotNull final Collection<String> excludes) {\r
+ return findFiles(new RealFileSystem(), new RealDirectoryEntry(new FileSystemPath(root)), includes, excludes);\r
}\r
\r
- public static Collection<File> FindFiles(IFileSystem fs, IDirectoryEntry root, Collection<String> includes, Collection<String> excludes) {\r
- List<Wildcard> basePath = BuildSearchPrefix(root, fs.CaseSensitive());\r
+ public static Collection<File> findFiles(@NotNull final FileSystem fs,\r
+ @NotNull final DirectoryEntry root,\r
+ @NotNull final Collection<String> includes,\r
+ @NotNull final Collection<String> excludes) {\r
+ List<Wildcard> basePath = buildSearchPrefix(root, fs.caseSensitive());\r
\r
List<FileSystemPath> result = new ArrayList<FileSystemPath>();\r
- FindFilesRec(\r
- fs.Root(),\r
+ findFilesRec(\r
+ fs.getRoot(),\r
result,\r
- ToAntPatternState(fs, basePath, fs.CaseSensitive(), includes),\r
- ToAntPatternState(fs, basePath, fs.CaseSensitive(), excludes)\r
+ toAntPatternState(fs, basePath, fs.caseSensitive(), includes),\r
+ toAntPatternState(fs, basePath, fs.caseSensitive(), excludes)\r
);\r
\r
Set<File> foundFiles = new TreeSet<File>();\r
for (FileSystemPath path : result) {\r
- foundFiles.add(path.FilePath());\r
+ foundFiles.add(path.getFilePath());\r
}\r
return foundFiles;\r
}\r
\r
- private static List<Wildcard> BuildSearchPrefix(@NotNull IDirectoryEntry root, boolean caseSensitive) {\r
+ private static List<Wildcard> buildSearchPrefix(@NotNull DirectoryEntry root, boolean caseSensitive) {\r
List<Wildcard> wildcardPrefix = new ArrayList<Wildcard>();\r
- while (root.Parent() != null) {\r
- wildcardPrefix.add(new Wildcard(root.Name(), caseSensitive));\r
- root = root.Parent();\r
+ while (true) {\r
+ final DirectoryEntry parent = root.getParent();\r
+ if (parent == null) break;\r
+\r
+ wildcardPrefix.add(new Wildcard(root.getName(), caseSensitive));\r
+ root = parent;\r
}\r
Collections.reverse(wildcardPrefix);\r
\r
return wildcardPrefix;\r
}\r
\r
- private static List<AntPatternState> ToAntPatternState(IFileSystem fs, List<Wildcard> wildcardPrefix, boolean caseSensitive, Collection<String> patterns) {\r
+ @NotNull\r
+ private static List<AntPatternState> toAntPatternState(@NotNull final FileSystem fs,\r
+ @NotNull final List<Wildcard> wildcardPrefix,\r
+ boolean caseSensitive,\r
+ @NotNull final Collection<String> patterns) {\r
List<AntPatternState> result = new ArrayList<AntPatternState>();\r
for (String x : patterns) {\r
result.add(new AntPatternState(ParsePattern(fs, wildcardPrefix, caseSensitive, x)));\r
return result;\r
}\r
\r
- private static List<Wildcard> ParsePattern(IFileSystem fs, List<Wildcard> rootPrefix, boolean caseSensitive, String pattern) {\r
- List<Wildcard> wildcards = AntPatternUtil.ParsePattern(pattern, caseSensitive);\r
+ @NotNull\r
+ private static List<Wildcard> ParsePattern(@NotNull final FileSystem fs,\r
+ @NotNull final List<Wildcard> rootPrefix,\r
+ boolean caseSensitive,\r
+ @NotNull final String pattern) {\r
+ List<Wildcard> wildcards = AntPatternUtil.parsePattern(pattern, caseSensitive);\r
\r
- if (fs.IsPathAbsolute(pattern))\r
+ if (fs.isPathAbsolute(pattern))\r
return wildcards;\r
\r
List<Wildcard> result = new ArrayList<Wildcard>();\r
return result;\r
}\r
\r
- private interface AnyPredicate {\r
- boolean matches(AntPatternState.MatchResult r);\r
- }\r
-\r
- private static boolean Any(List<AntPatternState> state, String component, AnyPredicate predicate, List<AntPatternState> newState) {\r
+ private static boolean any(@NotNull final List<AntPatternState> state,\r
+ @NotNull final String component,\r
+ @NotNull final AnyPredicate predicate,\r
+ @NotNull final List<AntPatternState> newState) {\r
boolean any = false;\r
newState.clear();\r
\r
for (AntPatternState aState : state) {\r
- final AntPatternState.AntPatternStateMatch enter = aState.Enter(component);\r
- AntPatternState.MatchResult match = enter.getResult();\r
+ final AntPatternStateMatch enter = aState.enter(component);\r
+ MatchResult match = enter.getResult();\r
newState.add(enter.getState());\r
\r
if (predicate.matches(match))\r
return any;\r
}\r
\r
- private static void FindFilesRec(IDirectoryEntry directory, List<FileSystemPath> result, List<AntPatternState> includeState, List<AntPatternState> excludeState) {\r
- LOG.debug("Scanning directory: " + directory.Name());\r
+ private static void findFilesRec(@NotNull final DirectoryEntry directory,\r
+ @NotNull final List<FileSystemPath> result,\r
+ @NotNull final List<AntPatternState> includeState,\r
+ @NotNull final List<AntPatternState> excludeState) {\r
+ LOG.debug("Scanning directory: " + directory.getName());\r
\r
boolean mayContainFiles = false;\r
Collection<String> explicits = new ArrayList<String>();\r
}\r
\r
if (mayContainFiles) {\r
- for (IFileEntry file : explicits != null ? directory.Files(explicits) : directory.Files()) {\r
+ for (FileEntry file : explicits != null ? directory.getFiles(explicits) : directory.getFiles()) {\r
List<AntPatternState> newState = new ArrayList<AntPatternState>();\r
\r
- if (!Any(includeState, file.Name(), equal(AntPatternState.MatchResult.YES), newState))\r
+ if (!any(includeState, file.getName(), equal(MatchResult.YES), newState))\r
continue;\r
\r
- if (Any(excludeState, file.Name(), equal(AntPatternState.MatchResult.YES), newState))\r
+ if (any(excludeState, file.getName(), equal(MatchResult.YES), newState))\r
continue;\r
\r
- result.add(file.Path());\r
+ result.add(file.getPath());\r
}\r
}\r
\r
\r
- for (IDirectoryEntry subEntry : explicits != null ? directory.Subdirectories(explicits) : directory.Subdirectories()) {\r
- String name = subEntry.Name();\r
+ for (DirectoryEntry subEntry : explicits != null ? directory.getSubdirectories(explicits) : directory.getSubdirectories()) {\r
+ String name = subEntry.getName();\r
\r
List<AntPatternState> newIncludeState = new ArrayList<AntPatternState>();\r
- if (!Any(includeState, name, notEqual(AntPatternState.MatchResult.NO), newIncludeState))\r
+ if (!any(includeState, name, notEqual(MatchResult.NO), newIncludeState))\r
continue;\r
\r
List<AntPatternState> newExcludeState = new ArrayList<AntPatternState>();\r
- if (Any(excludeState, name, equal(AntPatternState.MatchResult.YES), newExcludeState))\r
+ if (any(excludeState, name, equal(MatchResult.YES), newExcludeState))\r
continue;\r
\r
- FindFilesRec(subEntry, result, newIncludeState, newExcludeState);\r
+ findFilesRec(subEntry, result, newIncludeState, newExcludeState);\r
}\r
}\r
\r
- private static AnyPredicate notEqual(@NotNull final AntPatternState.MatchResult result) {\r
+ private interface AnyPredicate {\r
+ boolean matches(@NotNull MatchResult r);\r
+ }\r
+\r
+ private static AnyPredicate notEqual(@NotNull final MatchResult result) {\r
return new AnyPredicate() {\r
- public boolean matches(AntPatternState.MatchResult r) {\r
+ public boolean matches(@NotNull MatchResult r) {\r
return result != r;\r
}\r
};\r
}\r
\r
- private static AnyPredicate equal(@NotNull final AntPatternState.MatchResult result) {\r
+ private static AnyPredicate equal(@NotNull final MatchResult result) {\r
return new AnyPredicate() {\r
- public boolean matches(AntPatternState.MatchResult r) {\r
+ public boolean matches(@NotNull MatchResult r) {\r
return result == r;\r
}\r
};\r
*/\r
package jetbrains.buildServer.nuget.agent.runner.publish.fsScanner;\r
\r
-public interface IFileEntry\r
- {\r
- String Name();\r
- FileSystemPath Path();\r
- }
\ No newline at end of file
+import org.jetbrains.annotations.NotNull;\r
+\r
+public interface FileEntry {\r
+ @NotNull\r
+ String getName();\r
+\r
+ @NotNull\r
+ FileSystemPath getPath();\r
+}
\ No newline at end of file
\r
import org.jetbrains.annotations.NotNull;\r
\r
-public interface IFileSystem {\r
- boolean IsPathAbsolute(@NotNull String path);\r
+public interface FileSystem {\r
+ boolean isPathAbsolute(@NotNull String path);\r
\r
@NotNull\r
- IDirectoryEntry Root();\r
+ DirectoryEntry getRoot();\r
\r
- boolean CaseSensitive();\r
+ boolean caseSensitive();\r
}\r
myPath = new File(path);\r
}\r
\r
- public FileSystemPath(File path) {\r
+ public FileSystemPath(@NotNull final File path) {\r
myPath = path;\r
}\r
\r
@NotNull\r
- public String Name() {\r
+ public String getName() {\r
\r
String name = myPath.getName();\r
if (name == null || name.length() == 0) return myPath.getPath();\r
}\r
\r
@NotNull\r
- public File FilePath() {\r
+ public File getFilePath() {\r
return myPath;\r
}\r
}\r
--- /dev/null
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.agent.runner.publish.fsScanner;\r
+\r
+/**\r
+* @author Eugene Petrenko (eugene.petrenko@gmail.com)\r
+* Date: 25.08.11 11:56\r
+*/\r
+public enum MatchResult {\r
+ YES,\r
+ NO,\r
+ MAYBELATER\r
+}\r
import java.util.Collection;\r
import java.util.List;\r
\r
-public class RealDirectoryEntry implements IDirectoryEntry {\r
+public class RealDirectoryEntry implements DirectoryEntry {\r
private final FileSystemPath myPath;\r
\r
public RealDirectoryEntry(FileSystemPath path) {\r
}\r
\r
@NotNull\r
- public String Name() {\r
- {\r
- String name = myPath.Name();\r
- if (SystemInfo.isWindows) {\r
- if (name.length() == 3 && name.charAt(1) == ':')\r
- return name.charAt(0) + ":";\r
- }\r
+ public String getName() {\r
\r
- return name;\r
+ String name = myPath.getName();\r
+ if (SystemInfo.isWindows) {\r
+ if (name.length() == 3 && name.charAt(1) == ':')\r
+ return name.charAt(0) + ":";\r
}\r
+\r
+ return name;\r
+\r
}\r
\r
- public IDirectoryEntry Parent() {\r
- if (StringUtil.isEmptyOrSpaces(myPath.FilePath().getPath()))\r
+ public DirectoryEntry getParent() {\r
+ if (StringUtil.isEmptyOrSpaces(myPath.getFilePath().getPath()))\r
return RealFileSystem.ROOT;\r
\r
- String parent = myPath.FilePath().getParent();\r
+ String parent = myPath.getFilePath().getParent();\r
if (parent == null)\r
return RealFileSystem.ROOT;\r
\r
FileSystemPath parentPath = new FileSystemPath(parent);\r
- if (StringUtil.isEmptyOrSpaces(parentPath.FilePath().getPath()))\r
+ if (StringUtil.isEmptyOrSpaces(parentPath.getFilePath().getPath()))\r
return RealFileSystem.ROOT;\r
\r
return new RealDirectoryEntry(parentPath);\r
}\r
\r
@NotNull\r
- public IDirectoryEntry[] Subdirectories() {\r
+ public DirectoryEntry[] getSubdirectories() {\r
try {\r
- List<IDirectoryEntry> list = new ArrayList<IDirectoryEntry>();\r
- for (File dir : FilePath().listFiles(new FileFilter() {\r
- public boolean accept(File pathname) {\r
- return pathname.isDirectory();\r
- }\r
- })) {\r
+ List<DirectoryEntry> list = new ArrayList<DirectoryEntry>();\r
+ for (File dir : FilePath().listFiles(DIRECTORY_FILTER)) {\r
list.add(new RealDirectoryEntry(new FileSystemPath(dir)));\r
}\r
- return list.toArray(new IDirectoryEntry[list.size()]);\r
+ return list.toArray(new DirectoryEntry[list.size()]);\r
} catch (Exception e) {\r
- return new IDirectoryEntry[0];\r
+ return new DirectoryEntry[0];\r
}\r
}\r
\r
@NotNull\r
- public IDirectoryEntry[] Subdirectories(Collection<String> names) {\r
- List<IDirectoryEntry> entries = new ArrayList<IDirectoryEntry>(names.size());\r
+ public DirectoryEntry[] getSubdirectories(Collection<String> names) {\r
+ List<DirectoryEntry> entries = new ArrayList<DirectoryEntry>(names.size());\r
for (String name : names) {\r
entries.add(new RealDirectoryEntry(new FileSystemPath(new File(FilePath(), name))));\r
}\r
- return entries.toArray(new IDirectoryEntry[entries.size()]);\r
+ return entries.toArray(new DirectoryEntry[entries.size()]);\r
}\r
\r
private File FilePath() {\r
- String filePath = myPath.FilePath().getPath();\r
+ String filePath = myPath.getFilePath().getPath();\r
\r
if (SystemInfo.isWindows && filePath.endsWith(":")) {\r
return new File(filePath + "\\");\r
}\r
\r
@NotNull\r
- public IFileEntry[] Files() {\r
+ public FileEntry[] getFiles() {\r
\r
try {\r
- List<IFileEntry> list = new ArrayList<IFileEntry>();\r
- for (File dir : FilePath().listFiles(new FileFilter() {\r
- public boolean accept(File pathname) {\r
- return pathname.isFile();\r
- }\r
- })) {\r
+ List<FileEntry> list = new ArrayList<FileEntry>();\r
+ for (File dir : FilePath().listFiles(FILE_FILTER)) {\r
list.add(new RealFileEntry(new FileSystemPath(dir)));\r
}\r
- return list.toArray(new IFileEntry[list.size()]);\r
+ return list.toArray(new FileEntry[list.size()]);\r
} catch (Exception e) {\r
- return new IFileEntry[0];\r
+ return new FileEntry[0];\r
}\r
}\r
\r
@NotNull\r
- public IFileEntry[] Files(Collection<String> names) {\r
- List<IFileEntry> list = new ArrayList<IFileEntry>();\r
+ public FileEntry[] getFiles(@NotNull Collection<String> names) {\r
+ List<FileEntry> list = new ArrayList<FileEntry>();\r
for (String name : names) {\r
final File file = new File(FilePath(), name);\r
if (!file.isFile()) continue;\r
list.add(new RealFileEntry(new FileSystemPath(file)));\r
}\r
- return list.toArray(new IFileEntry[list.size()]);\r
+ return list.toArray(new FileEntry[list.size()]);\r
}\r
\r
@Override\r
public String toString() {\r
- return "{d:" + myPath.FilePath() + "|" + Name() + "}";\r
+ return "{d:" + myPath.getFilePath() + "|" + getName() + "}";\r
}\r
+\r
+ private final FileFilter DIRECTORY_FILTER = new FileFilter() {\r
+ public boolean accept(File pathname) {\r
+ return pathname.isDirectory();\r
+ }\r
+ };\r
+\r
+ private final FileFilter FILE_FILTER = new FileFilter() {\r
+ public boolean accept(File pathname) {\r
+ return pathname.isFile();\r
+ }\r
+ };\r
+\r
}\r
*/\r
package jetbrains.buildServer.nuget.agent.runner.publish.fsScanner;\r
\r
-public class RealFileEntry implements IFileEntry {\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+public class RealFileEntry implements FileEntry {\r
private final FileSystemPath myPath;\r
\r
public RealFileEntry(FileSystemPath path) {\r
myPath = path;\r
}\r
\r
- public String Name() {\r
- return myPath.Name();\r
+ @NotNull\r
+ public String getName() {\r
+ return myPath.getName();\r
}\r
\r
- public FileSystemPath Path() {\r
+ @NotNull\r
+ public FileSystemPath getPath() {\r
return myPath;\r
}\r
\r
@Override\r
public String toString() {\r
- return "{f:" + myPath.FilePath() + "|" + Name() + "}";\r
+ return "{f:" + myPath.getFilePath() + "|" + getName() + "}";\r
}\r
}
\ No newline at end of file
\r
import java.io.File;\r
\r
-public class RealFileSystem implements IFileSystem {\r
- public static final IDirectoryEntry ROOT = new RealRootDirectory();\r
+public class RealFileSystem implements FileSystem {\r
+ public static final DirectoryEntry ROOT = new RealRootDirectory();\r
\r
- public boolean IsPathAbsolute(@NotNull String path) {\r
+ public boolean isPathAbsolute(@NotNull String path) {\r
if (SystemInfo.isWindows) {\r
- if ((path.startsWith("/") || path.startsWith("\\")))\r
- return false;\r
-\r
+ if ((path.startsWith("/") || path.startsWith("\\"))) return false;\r
return new File(path).isAbsolute();\r
}\r
return path.startsWith("/");\r
}\r
\r
@NotNull\r
- public IDirectoryEntry Root() {\r
+ public DirectoryEntry getRoot() {\r
return ROOT;\r
}\r
\r
- public boolean CaseSensitive() {\r
+ public boolean caseSensitive() {\r
return SystemInfo.isFileSystemCaseSensitive;\r
}\r
}\r
import java.util.Collection;\r
import java.util.List;\r
\r
-public class RealRootDirectory implements IDirectoryEntry {\r
+public class RealRootDirectory implements DirectoryEntry {\r
@NotNull\r
- public String Name() {\r
+ public String getName() {\r
return "";\r
}\r
\r
- public IDirectoryEntry Parent() {\r
+ public DirectoryEntry getParent() {\r
return null;\r
}\r
\r
@NotNull\r
- public IDirectoryEntry[] Subdirectories() {\r
- ArrayList<IDirectoryEntry> result = new ArrayList<IDirectoryEntry>();\r
+ public DirectoryEntry[] getSubdirectories() {\r
+ ArrayList<DirectoryEntry> result = new ArrayList<DirectoryEntry>();\r
if (SystemInfo.isWindows) {\r
for (File drive : File.listRoots()) {\r
result.add(new RealDirectoryEntry(new FileSystemPath(drive)));\r
}\r
}\r
\r
- return result.toArray(new IDirectoryEntry[result.size()]);\r
+ return result.toArray(new DirectoryEntry[result.size()]);\r
}\r
\r
@NotNull\r
- public IDirectoryEntry[] Subdirectories(Collection<String> names) {\r
- List<IDirectoryEntry> entries = new ArrayList<IDirectoryEntry>(names.size());\r
+ public DirectoryEntry[] getSubdirectories(Collection<String> names) {\r
+ List<DirectoryEntry> entries = new ArrayList<DirectoryEntry>(names.size());\r
for (String name : names) {\r
entries.add(new RealDirectoryEntry(new FileSystemPath(new File(SystemInfo.isWindows ? name : "/" + name))));\r
}\r
- return entries.toArray(new IDirectoryEntry[entries.size()]);\r
+ return entries.toArray(new DirectoryEntry[entries.size()]);\r
}\r
\r
@NotNull\r
- public IFileEntry[] Files() {\r
- return new IFileEntry[0];\r
+ public FileEntry[] getFiles() {\r
+ return new FileEntry[0];\r
}\r
\r
@NotNull\r
- public IFileEntry[] Files(Collection<String> names) {\r
- return new IFileEntry[0];\r
+ public FileEntry[] getFiles(@NotNull Collection<String> names) {\r
+ return new FileEntry[0];\r
}\r
\r
@Override\r
myPattern = !caseSensitive ? pattern.toLowerCase() : pattern;\r
}\r
\r
- public String Pattern() {\r
+ public String getPattern() {\r
return myPattern;\r
}\r
\r
- public boolean IsMatch(@NotNull String str) {\r
+ public boolean isMatch(@NotNull String str) {\r
String pattern = myPattern;\r
\r
if (StringUtil.isEmptyOrSpaces(pattern))\r
if (pat == patlen - 1)\r
return true;\r
\r
- if (MatchChars(pattern.charAt(pat + 1), c)) {\r
+ if (matchChars(pattern.charAt(pat + 1), c)) {\r
if (pat == patlen - 2 && j == str.length() - 1)\r
return true;\r
positions.add(pat + 2);\r
}\r
} else {\r
- if (MatchChars(pattern.charAt(pat), c)) {\r
+ if (matchChars(pattern.charAt(pat), c)) {\r
if (pat == patlen - 1 && j == str.length() - 1)\r
return true;\r
\r
return false;\r
}\r
\r
- private static boolean MatchChars(char pat, char c) {\r
+ private static boolean matchChars(char pat, char c) {\r
return pat == '?' || pat == c;\r
}\r
\r
+++ /dev/null
-/*\r
- * Copyright 2000-2011 JetBrains s.r.o.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package jetbrains.buildServer.nuget.agent.runner.publish.fsScanner;\r
-\r
-/**\r
- * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
- * Date: 24.08.11 22:21\r
- */\r
-public class WildcardScanner2 {\r
-/*\r
- public Collection<File> matchWildcards(@NotNull final File root,\r
- @NotNull final Collection<String> includes,\r
- @NotNull final Collection<String> excludes) {\r
-\r
- }\r
-\r
-\r
- private static class MatchState {\r
- private final List<Wildcard> myUnmatchedWildcards;\r
- private final File myRoot;\r
-\r
- private MatchState(@NotNull final File root, List<Wildcard> unmatchedWildcards) {\r
- myUnmatchedWildcards = unmatchedWildcards;\r
- }\r
-\r
- @NotNull\r
- public MatchResult match() {\r
- assert myUnmatchedWildcards.size() > 0;\r
- final Wildcard wd = myUnmatchedWildcards.iterator().next();\r
-\r
- if (!wd.matches(name)) {\r
- return new MatchResult(false, Collections.<MatchState>emptyList());\r
- }\r
-\r
- List<Wildcard> next = new ArrayList<Wildcard>(myUnmatchedWildcards);\r
- List<MatchState> states = new ArrayList<MatchState>(2);\r
-\r
- if (wd.isFork()) {\r
- states.add(this);\r
- }\r
- next.remove(0);\r
-\r
- if (next.isEmpty()) {\r
- return new MatchResult(true, states);\r
- } else {\r
- states.add(new MatchState(next));\r
- return new MatchResult(false, states);\r
- }\r
- }\r
- }\r
-\r
- private static class MatchResult {\r
- private boolean myIsMatched;\r
- private Collection<MatchState> myMatches;\r
-\r
- private MatchResult(boolean isMatched, Collection<MatchState> matches) {\r
- myIsMatched = isMatched;\r
- myMatches = matches;\r
- }\r
-\r
- public boolean isIsMatched() {\r
- return myIsMatched;\r
- }\r
-\r
- public Collection<MatchState> getMatches() {\r
- return myMatches;\r
- }\r
- }\r
-\r
- private abstract static class Wildcard {\r
- protected final String myPattern;\r
-\r
- protected Wildcard(@NotNull final String pattern) {\r
- myPattern = pattern;\r
- }\r
-\r
- public abstract boolean matches(@NotNull final String name);\r
- public abstract boolean isPattern();\r
- public abstract boolean isFork();\r
- }\r
-\r
- private class NameWildcard extends Wildcard {\r
- private NameWildcard(@NotNull String pattern) {\r
- super(pattern);\r
- }\r
-\r
- @Override\r
- public boolean matches(@NotNull String name) {\r
- return myPattern.equals(name);\r
- }\r
-\r
- @Override\r
- public boolean isPattern() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public boolean isFork() {\r
- return false;\r
- }\r
- }\r
-\r
- private class PatternWildcard extends Wildcard {\r
- private final Pattern myPattern;\r
- private PatternWildcard(@NotNull String pattern) {\r
- super(pattern);\r
- myPattern = Pattern.compile("$" +\r
- pattern.replaceAll("\\.", "\\.").replaceAll("\\*", ".*").replaceAll("\\?", ".?") + "^");\r
- }\r
-\r
- @Override\r
- public boolean matches(@NotNull String name) {\r
- return myPattern.matcher(name).matches();\r
- }\r
-\r
- @Override\r
- public boolean isPattern() {\r
- return true;\r
- }\r
-\r
- @Override\r
- public boolean isFork() {\r
- return false;\r
- }\r
- }\r
-\r
- private class DoubleStarWildcard extends Wildcard {\r
- private DoubleStarWildcard() {\r
- super("**");\r
- }\r
-\r
- @Override\r
- public boolean matches(@NotNull String name) {\r
- return true;\r
- }\r
-\r
- @Override\r
- public boolean isPattern() {\r
- return true;\r
- }\r
-\r
- @Override\r
- public boolean isFork() {\r
- return true;\r
- }\r
- }\r
-*/\r
-}\r
\r
private static void DoAbsTest(String path, boolean result) {\r
RealFileSystem fs = new RealFileSystem();\r
- Assert.assertEquals(result, fs.IsPathAbsolute(path));\r
+ Assert.assertEquals(result, fs.isPathAbsolute(path));\r
}\r
}\r
@Test\r
public void test_should_not_list_folders_for_known_paths() {\r
Mockery m = new Mockery();\r
- final IFileSystem fs = m.mock(IFileSystem.class);\r
- final IDirectoryEntry root = m.mock(IDirectoryEntry.class, "root");\r
- final IDirectoryEntry a = m.mock(IDirectoryEntry.class, "a");\r
- final IDirectoryEntry proot = m.mock(IDirectoryEntry.class, "proot");\r
- final IDirectoryEntry fsRoot = m.mock(IDirectoryEntry.class, "fsRoot");\r
- final IFileEntry c_txt = m.mock(IFileEntry.class, "c.txt");\r
+ final FileSystem fs = m.mock(FileSystem.class);\r
+ final DirectoryEntry root = m.mock(DirectoryEntry.class, "root");\r
+ final DirectoryEntry a = m.mock(DirectoryEntry.class, "a");\r
+ final DirectoryEntry proot = m.mock(DirectoryEntry.class, "proot");\r
+ final DirectoryEntry fsRoot = m.mock(DirectoryEntry.class, "fsRoot");\r
+ final FileEntry c_txt = m.mock(FileEntry.class, "c.txt");\r
\r
m.checking(new Expectations(){{\r
- allowing(fs).CaseSensitive(); will(returnValue(true));\r
- allowing(fs).Root(); will(returnValue(fsRoot));\r
- oneOf(fs).IsPathAbsolute("a/c.txt"); will(returnValue(false));\r
+ allowing(fs).caseSensitive(); will(returnValue(true));\r
+ allowing(fs).getRoot(); will(returnValue(fsRoot));\r
+ oneOf(fs).isPathAbsolute("a/c.txt"); will(returnValue(false));\r
\r
- allowing(fsRoot).Name(); will(returnValue("fsRoot"));\r
- allowing(fsRoot).Parent(); will(returnValue(null));\r
- allowing(fsRoot).Subdirectories(Arrays.asList("root")); will(returnValue(new IDirectoryEntry[]{ root} ));\r
+ allowing(fsRoot).getName(); will(returnValue("fsRoot"));\r
+ allowing(fsRoot).getParent(); will(returnValue(null));\r
+ allowing(fsRoot).getSubdirectories(Arrays.asList("root")); will(returnValue(new DirectoryEntry[]{ root} ));\r
\r
- allowing(root).Parent(); will(returnValue(proot));\r
- allowing(root).Name(); will(returnValue("root"));\r
- allowing(root).Subdirectories(Arrays.asList("a")); will(returnValue(new IDirectoryEntry[] { a }));\r
- allowing(root).Files(Arrays.asList("a")); will(returnValue(new IFileEntry[0]));\r
- allowing(proot).Parent(); will(returnValue(null));\r
- allowing(proot).Name(); will(returnValue("proot"));\r
+ allowing(root).getParent(); will(returnValue(proot));\r
+ allowing(root).getName(); will(returnValue("root"));\r
+ allowing(root).getSubdirectories(Arrays.asList("a")); will(returnValue(new DirectoryEntry[] { a }));\r
+ allowing(root).getFiles(Arrays.asList("a")); will(returnValue(new FileEntry[0]));\r
+ allowing(proot).getParent(); will(returnValue(null));\r
+ allowing(proot).getName(); will(returnValue("proot"));\r
\r
- allowing(a).Name(); will(returnValue("a"));\r
- allowing(a).Files(Arrays.asList("c.txt")); will(returnValue(new IFileEntry[]{c_txt} ));\r
- allowing(a).Subdirectories(Arrays.asList("c.txt")); will(returnValue(new IDirectoryEntry[0]));\r
+ allowing(a).getName(); will(returnValue("a"));\r
+ allowing(a).getFiles(Arrays.asList("c.txt")); will(returnValue(new FileEntry[]{c_txt} ));\r
+ allowing(a).getSubdirectories(Arrays.asList("c.txt")); will(returnValue(new DirectoryEntry[0]));\r
\r
- allowing(c_txt).Name(); will(returnValue("c.txt"));\r
- allowing(c_txt).Path(); will(returnValue(new FileSystemPath("ccc")));\r
+ allowing(c_txt).getName(); will(returnValue("c.txt"));\r
+ allowing(c_txt).getPath(); will(returnValue(new FileSystemPath("ccc")));\r
}});\r
\r
- DirectoryScanner.FindFiles(fs, root, Arrays.asList("a/c.txt"), Collections.<String>emptyList());\r
+ DirectoryScanner.findFiles(fs, root, Arrays.asList("a/c.txt"), Collections.<String>emptyList());\r
\r
m.assertIsSatisfied();\r
}\r
package jetbrains.buildServer.nuget.tests.util.fsScanner;\r
\r
import jetbrains.buildServer.BaseTestCase;\r
-import jetbrains.buildServer.nuget.agent.runner.publish.fsScanner.AntPatternState;\r
-import jetbrains.buildServer.nuget.agent.runner.publish.fsScanner.AntPatternUtil;\r
-import jetbrains.buildServer.nuget.agent.runner.publish.fsScanner.Wildcard;\r
+import jetbrains.buildServer.nuget.agent.runner.publish.fsScanner.*;\r
import org.jetbrains.annotations.Nullable;\r
import org.testng.Assert;\r
import org.testng.annotations.Test;\r
\r
public class TestAntPatternState extends BaseTestCase {\r
private static void AssertPatternState(String pattern, @Nullable List<Integer> pos, String enter, String expectedResult) {\r
- List<Wildcard> wildcards = AntPatternUtil.ParsePattern(pattern, false);\r
+ List<Wildcard> wildcards = AntPatternUtil.parsePattern(pattern, false);\r
\r
AntPatternState state = pos == null\r
? new AntPatternState(wildcards)\r
: new AntPatternState(wildcards, pos);\r
\r
- final AntPatternState.AntPatternStateMatch e = state.Enter(enter);\r
- AntPatternState.MatchResult match = e.getResult();\r
+ final AntPatternStateMatch e = state.enter(enter);\r
+ MatchResult match = e.getResult();\r
AntPatternState newState = e.getState();\r
\r
StringBuilder sb = new StringBuilder();\r
sb.append(match);\r
sb.append(" ");\r
- for (int p : newState.PatternPositions()) {\r
+ for (int p : newState.getPatternPositions()) {\r
sb.append(p);\r
sb.append(":");\r
}\r
\r
public class TestAntPatternUtil extends BaseTestCase {\r
private static void AssertParseResult(String pattern, String expectedResult) {\r
- List<Wildcard> wildcards = AntPatternUtil.ParsePattern(pattern, false);\r
+ List<Wildcard> wildcards = AntPatternUtil.parsePattern(pattern, false);\r
StringBuilder sb = new StringBuilder();\r
for (Wildcard w : wildcards) {\r
- sb.append(w == null ? "**" : w.Pattern());\r
+ sb.append(w == null ? "**" : w.getPattern());\r
sb.append(":");\r
}\r
String result = StringUtil.trimEnd(sb.toString(), ":");\r
\r
@Test\r
public void IsFileNameMatch() {\r
- Assert.assertTrue(AntPatternUtil.IsFileNameMatch("a*/**b**", "abc/ss/aa/vv/ggbbhh/qq"));\r
- Assert.assertFalse(AntPatternUtil.IsFileNameMatch("a*/**b**", "abc/ss/aa/vv/gghh/qq"));\r
- Assert.assertTrue(AntPatternUtil.IsFileNameMatch("**/bin/**.exe", "My/BiN/Debug/program.exe"));\r
- Assert.assertFalse(AntPatternUtil.IsFileNameMatch("**/bin/**.exe", "My/BiN/Debug/program.dll"));\r
- Assert.assertTrue(AntPatternUtil.IsFileNameMatch("**/bin/**.exe", "bin/program.exe"));\r
+ Assert.assertTrue(AntPatternUtil.isFileNameMatch("a*/**b**", "abc/ss/aa/vv/ggbbhh/qq"));\r
+ Assert.assertFalse(AntPatternUtil.isFileNameMatch("a*/**b**", "abc/ss/aa/vv/gghh/qq"));\r
+ Assert.assertTrue(AntPatternUtil.isFileNameMatch("**/bin/**.exe", "My/BiN/Debug/program.exe"));\r
+ Assert.assertFalse(AntPatternUtil.isFileNameMatch("**/bin/**.exe", "My/BiN/Debug/program.dll"));\r
+ Assert.assertTrue(AntPatternUtil.isFileNameMatch("**/bin/**.exe", "bin/program.exe"));\r
\r
- Assert.assertTrue(AntPatternUtil.IsFileNameMatch("**aaa**ddd***ccc**", "aaa/aaa/ddd/ddd/ccc/ccc"));\r
- Assert.assertFalse(AntPatternUtil.IsFileNameMatch("**aaa**ddd***ccc**", "aaa/aaa/ccc/ccc"));\r
+ Assert.assertTrue(AntPatternUtil.isFileNameMatch("**aaa**ddd***ccc**", "aaa/aaa/ddd/ddd/ccc/ccc"));\r
+ Assert.assertFalse(AntPatternUtil.isFileNameMatch("**aaa**ddd***ccc**", "aaa/aaa/ccc/ccc"));\r
\r
- Assert.assertTrue(AntPatternUtil.IsFileNameMatch(".\\s.slN", "S.sln"));\r
- Assert.assertTrue(AntPatternUtil.IsFileNameMatch("s.slN", ".\\S.sln"));\r
+ Assert.assertTrue(AntPatternUtil.isFileNameMatch(".\\s.slN", "S.sln"));\r
+ Assert.assertTrue(AntPatternUtil.isFileNameMatch("s.slN", ".\\S.sln"));\r
\r
- Assert.assertFalse(AntPatternUtil.IsFileNameMatch(".", ""));\r
+ Assert.assertFalse(AntPatternUtil.isFileNameMatch(".", ""));\r
}\r
\r
@Test\r
File fsp = createTempDir();\r
\r
CreateDirectories(fsDescription, fsp);\r
- Collection<File> findFiles = DirectoryScanner.FindFiles(fsp, Arrays.asList(includePatterns), Arrays.asList(excludePatterns));\r
+ Collection<File> findFiles = DirectoryScanner.findFiles(fsp, Arrays.asList(includePatterns), Arrays.asList(excludePatterns));\r
\r
Set<File> expected = new TreeSet<File>();\r
for (String s : expectedResult) {\r
File atxtFsp = new File(fsp, "a.txt");\r
FileUtil.writeFile(atxtFsp, "text");\r
\r
- Collection<File> files = DirectoryScanner.FindFiles(fsp, Arrays.asList(atxtFsp.getPath()), Collections.<String>emptyList());\r
+ Collection<File> files = DirectoryScanner.findFiles(fsp, Arrays.asList(atxtFsp.getPath()), Collections.<String>emptyList());\r
Assert.assertEquals(1, files.size());\r
Assert.assertEquals(PreparePath(atxtFsp), PreparePath(files.iterator().next()));\r
}\r
\r
@Test\r
public void TestCaseSensitive() {\r
- Assert.assertEquals(!SystemInfo.isWindows, new RealFileSystem().CaseSensitive());\r
+ Assert.assertEquals(!SystemInfo.isWindows, new RealFileSystem().caseSensitive());\r
}\r
\r
private void TestFSTest(FilesAction a) throws IOException {\r
public void TestNames() throws IOException {\r
TestFSTest(new FilesAction() {\r
public void action(RealDirectoryEntry r1, RealDirectoryEntry r2, RealDirectoryEntry r3, RealDirectoryEntry r4) {\r
- Assert.assertEquals("ccc", r4.Name());\r
- Assert.assertEquals("bbb", r3.Name());\r
- Assert.assertEquals("aaa", r2.Name());\r
+ Assert.assertEquals("ccc", r4.getName());\r
+ Assert.assertEquals("bbb", r3.getName());\r
+ Assert.assertEquals("aaa", r2.getName());\r
}\r
});\r
}\r
TestFSTest(\r
new FilesAction() {\r
public void action(RealDirectoryEntry r1, RealDirectoryEntry r2, RealDirectoryEntry r3, RealDirectoryEntry r4) {\r
- AssertDirectoriesEqual(r4.Parent(), r3);\r
- AssertDirectoriesEqual(r4.Parent().Parent(), r2);\r
- AssertDirectoriesEqual(r4.Parent().Parent().Parent(), r1);\r
+ AssertDirectoriesEqual(r4.getParent(), r3);\r
+ AssertDirectoriesEqual(r4.getParent().getParent(), r2);\r
+ AssertDirectoriesEqual(r4.getParent().getParent().getParent(), r1);\r
\r
- AssertDirectoriesEqual(r3.Parent(), r2);\r
- AssertDirectoriesEqual(r3.Parent().Parent(), r1);\r
+ AssertDirectoriesEqual(r3.getParent(), r2);\r
+ AssertDirectoriesEqual(r3.getParent().getParent(), r1);\r
\r
- AssertDirectoriesEqual(r2.Parent(), r1);\r
+ AssertDirectoriesEqual(r2.getParent(), r1);\r
\r
\r
}\r
TestFSTest(\r
new FilesAction() {\r
public void action(RealDirectoryEntry r1, RealDirectoryEntry r2, RealDirectoryEntry r3, RealDirectoryEntry r4) {\r
- Assert.assertEquals(0, r4.Subdirectories().length);\r
- Assert.assertEquals(1, r3.Subdirectories().length);\r
- Assert.assertEquals(1, r2.Subdirectories().length);\r
- Assert.assertEquals(1, r1.Subdirectories().length);\r
+ Assert.assertEquals(0, r4.getSubdirectories().length);\r
+ Assert.assertEquals(1, r3.getSubdirectories().length);\r
+ Assert.assertEquals(1, r2.getSubdirectories().length);\r
+ Assert.assertEquals(1, r1.getSubdirectories().length);\r
\r
- AssertDirectoriesEqual(r3.Subdirectories()[0], r4);\r
- AssertDirectoriesEqual(r2.Subdirectories()[0], r3);\r
- AssertDirectoriesEqual(r1.Subdirectories()[0], r2);\r
+ AssertDirectoriesEqual(r3.getSubdirectories()[0], r4);\r
+ AssertDirectoriesEqual(r2.getSubdirectories()[0], r3);\r
+ AssertDirectoriesEqual(r1.getSubdirectories()[0], r2);\r
\r
}\r
});\r
@Test\r
public void TestRootSubdirectories() {\r
RealRootDirectory root = new RealRootDirectory();\r
- Assert.assertTrue(root.Subdirectories().length > 0);\r
+ Assert.assertTrue(root.getSubdirectories().length > 0);\r
}\r
\r
@Test(enabled = false)\r
public void TestRootSubdirectoriesWalk() {\r
int k = 10;\r
- for (IDirectoryEntry sub1 : new RealRootDirectory().Subdirectories()) {\r
+ for (DirectoryEntry sub1 : new RealRootDirectory().getSubdirectories()) {\r
if (k-- < 0) break;\r
int j = 10;\r
- for (IDirectoryEntry sub2 : sub1.Subdirectories()) {\r
+ for (DirectoryEntry sub2 : sub1.getSubdirectories()) {\r
if (j-- < 0) break;\r
int i = 10;\r
- for (IDirectoryEntry sub3 : sub2.Subdirectories()) {\r
+ for (DirectoryEntry sub3 : sub2.getSubdirectories()) {\r
if (i-- < 0) break;\r
System.out.println("sub3 = " + sub3);\r
}\r
\r
@Test\r
public void TestRealRoot() {\r
- IDirectoryEntry root = RealFileSystem.ROOT;\r
+ DirectoryEntry root = RealFileSystem.ROOT;\r
DumpItem(root);\r
- Assert.assertTrue(root.Subdirectories().length > 0);\r
+ Assert.assertTrue(root.getSubdirectories().length > 0);\r
}\r
\r
- private static void DumpItem(IDirectoryEntry e) {\r
+ private static void DumpItem(DirectoryEntry e) {\r
Assert.assertNotNull(e);\r
System.out.println("entry = " + e);\r
- for (IDirectoryEntry sub : e.Subdirectories()) {\r
+ for (DirectoryEntry sub : e.getSubdirectories()) {\r
System.out.println("entry->sub = " + sub);\r
}\r
- for (IFileEntry fileEntry : e.Files()) {\r
+ for (FileEntry fileEntry : e.getFiles()) {\r
System.out.println("entry->file = " + fileEntry);\r
}\r
}\r
path.mkdirs();\r
\r
\r
- IDirectoryEntry e = cd(path);\r
- IDirectoryEntry p = e.Parent();\r
+ DirectoryEntry e = cd(path);\r
+ DirectoryEntry p = e.getParent();\r
Assert.assertNotNull(p);\r
\r
- for (IDirectoryEntry dir : p.Subdirectories()) {\r
- if (dir.Name().equals(e.Name())) {\r
+ for (DirectoryEntry dir : p.getSubdirectories()) {\r
+ if (dir.getName().equals(e.getName())) {\r
AssertDirectoriesEqual(dir, e);\r
return;\r
}\r
\r
@Test\r
public void TestShouldFindRootFS() throws IOException {\r
- IDirectoryEntry r = cd(createTempDir());\r
+ DirectoryEntry r = cd(createTempDir());\r
while (true) {\r
- IDirectoryEntry p = r.Parent();\r
+ DirectoryEntry p = r.getParent();\r
if (p == null) break;\r
r = p;\r
}\r
path.mkdirs();\r
}\r
\r
- IDirectoryEntry test = new RealDirectoryEntry(new FileSystemPath(path));\r
+ DirectoryEntry test = new RealDirectoryEntry(new FileSystemPath(path));\r
\r
List<String> loop = new ArrayList<String>();\r
while (true) {\r
System.out.println("p = " + test);\r
- loop.add(test.Name());\r
- IDirectoryEntry p = test.Parent();\r
+ loop.add(test.getName());\r
+ DirectoryEntry p = test.getParent();\r
if (p == null) break;\r
test = p;\r
}\r
Collections.reverse(loop);\r
\r
\r
- IDirectoryEntry root = new RealRootDirectory();\r
- Assert.assertEquals(root.Name(), loop.get(0));\r
+ DirectoryEntry root = new RealRootDirectory();\r
+ Assert.assertEquals(root.getName(), loop.get(0));\r
loop.remove(0);\r
\r
for (String name : loop) {\r
boolean found = false;\r
- for (IDirectoryEntry sub : root.Subdirectories()) {\r
- if (sub.Name().equals(name)) {\r
+ for (DirectoryEntry sub : root.getSubdirectories()) {\r
+ if (sub.getName().equals(name)) {\r
found = true;\r
root = sub;\r
}\r
\r
}\r
\r
- private static void AssertDirectoriesEqual(IDirectoryEntry e1, IDirectoryEntry e2) {\r
+ private static void AssertDirectoriesEqual(DirectoryEntry e1, DirectoryEntry e2) {\r
Assert.assertEquals(e1.toString(), e2.toString());\r
}\r
\r
public void TestParentDirectory() throws IOException {\r
File path = createTempDir();\r
\r
- List<IDirectoryEntry> entries = new ArrayList<IDirectoryEntry>();\r
- IDirectoryEntry e = new RealDirectoryEntry(new FileSystemPath(path));\r
- while (e.Parent() != null) {\r
+ List<DirectoryEntry> entries = new ArrayList<DirectoryEntry>();\r
+ DirectoryEntry e = new RealDirectoryEntry(new FileSystemPath(path));\r
+ while (e.getParent() != null) {\r
System.out.println("e = " + e);\r
entries.add(e);\r
- e = e.Parent();\r
+ e = e.getParent();\r
}\r
}\r
}\r
public class TestWildcard {\r
@Test\r
public void test_01() {\r
- Assert.assertFalse(new Wildcard("abcd", true).IsMatch("a"));\r
- Assert.assertFalse(new Wildcard("*.cs", true).IsMatch("hello.csc"));\r
+ Assert.assertFalse(new Wildcard("abcd", true).isMatch("a"));\r
+ Assert.assertFalse(new Wildcard("*.cs", true).isMatch("hello.csc"));\r
\r
- Assert.assertTrue(new Wildcard("", true).IsMatch(""));\r
- Assert.assertFalse(new Wildcard("", true).IsMatch("asdsad"));\r
+ Assert.assertTrue(new Wildcard("", true).isMatch(""));\r
+ Assert.assertFalse(new Wildcard("", true).isMatch("asdsad"));\r
\r
- Assert.assertTrue(new Wildcard("*.cs", true).IsMatch("hello.cs"));\r
- Assert.assertTrue(new Wildcard("h*.cs", true).IsMatch("hello.cs"));\r
- Assert.assertFalse(new Wildcard("a*.cs", true).IsMatch("hello.cs"));\r
- Assert.assertTrue(new Wildcard("*.cs*", true).IsMatch("hello.cs"));\r
- Assert.assertTrue(new Wildcard("*.cs", true).IsMatch(".cs"));\r
- Assert.assertFalse(new Wildcard("*.cs", true).IsMatch("hello.s"));\r
+ Assert.assertTrue(new Wildcard("*.cs", true).isMatch("hello.cs"));\r
+ Assert.assertTrue(new Wildcard("h*.cs", true).isMatch("hello.cs"));\r
+ Assert.assertFalse(new Wildcard("a*.cs", true).isMatch("hello.cs"));\r
+ Assert.assertTrue(new Wildcard("*.cs*", true).isMatch("hello.cs"));\r
+ Assert.assertTrue(new Wildcard("*.cs", true).isMatch(".cs"));\r
+ Assert.assertFalse(new Wildcard("*.cs", true).isMatch("hello.s"));\r
\r
- Assert.assertTrue(new Wildcard("*a*c", true).IsMatch("1221abcccac"));\r
- Assert.assertTrue(new Wildcard("a", true).IsMatch("a"));\r
- Assert.assertTrue(new Wildcard("?", true).IsMatch("z"));\r
- Assert.assertFalse(new Wildcard("*?*", true).IsMatch(""));\r
- Assert.assertTrue(new Wildcard("*?*", true).IsMatch("k"));\r
+ Assert.assertTrue(new Wildcard("*a*c", true).isMatch("1221abcccac"));\r
+ Assert.assertTrue(new Wildcard("a", true).isMatch("a"));\r
+ Assert.assertTrue(new Wildcard("?", true).isMatch("z"));\r
+ Assert.assertFalse(new Wildcard("*?*", true).isMatch(""));\r
+ Assert.assertTrue(new Wildcard("*?*", true).isMatch("k"));\r
\r
}\r
\r
@Test\r
public void test_02() {\r
- Assert.assertTrue(new Wildcard("*?**", true).IsMatch("k"));\r
- Assert.assertTrue(new Wildcard("*?*", true).IsMatch("111k"));\r
- Assert.assertTrue(new Wildcard("*?*", true).IsMatch("11k22"));\r
- Assert.assertTrue(new Wildcard("*?*m*", true).IsMatch("11mk22"));\r
- Assert.assertFalse(new Wildcard("*??*m*", true).IsMatch("1mk22"));\r
+ Assert.assertTrue(new Wildcard("*?**", true).isMatch("k"));\r
+ Assert.assertTrue(new Wildcard("*?*", true).isMatch("111k"));\r
+ Assert.assertTrue(new Wildcard("*?*", true).isMatch("11k22"));\r
+ Assert.assertTrue(new Wildcard("*?*m*", true).isMatch("11mk22"));\r
+ Assert.assertFalse(new Wildcard("*??*m*", true).isMatch("1mk22"));\r
Assert.assertTrue(\r
- new Wildcard("*non-greedy character*matching", true).IsMatch(\r
+ new Wildcard("*non-greedy character*matching", true).isMatch(\r
"non-greedy character matching compared to greedy character matching"));\r
Assert.assertFalse(\r
- new Wildcard("*non-greedy character*matching2", true).IsMatch(\r
+ new Wildcard("*non-greedy character*matching2", true).isMatch(\r
"non-greedy character matching compared to greedy character matching"));\r
}\r
}\r