use new directory scanner
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Wed, 24 Aug 2011 16:29:18 +0000 (18:29 +0200)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Wed, 24 Aug 2011 16:29:18 +0000 (18:29 +0200)
nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/MatchFilesBuildProcess.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/fsScanner/DirectoryScanner.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/util/fsScanner/TestDirectoryScanner.java

index 5ee7ed179d29595dde14ae0a0d2b437dbf05de3f..f2457fc7b9e88c88f75b85bc018a8c462b7e7336 100644 (file)
 package jetbrains.buildServer.nuget.agent.runner.publish;\r
 \r
 import com.intellij.openapi.diagnostic.Logger;\r
-import com.intellij.openapi.util.SystemInfo;\r
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
-import jetbrains.buildServer.agent.util.AntPatternFileFinder;\r
 import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\r
+import jetbrains.buildServer.nuget.agent.runner.publish.fsScanner.DirectoryScanner;\r
 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
 import jetbrains.buildServer.util.StringUtil;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
 import java.io.File;\r
-import java.io.IOException;\r
 import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
 import java.util.List;\r
 \r
 /**\r
@@ -64,42 +64,18 @@ public class MatchFilesBuildProcess extends BuildProcessBase {
         continue;\r
       }\r
 \r
-      if (SystemInfo.isWindows\r
-              && (pattern.startsWith("/") || pattern.startsWith("\\"))\r
-              && !(pattern.startsWith("//") || pattern.startsWith("\\\\"))) {\r
-        pattern = pattern.substring(1);\r
-      }\r
-\r
-      if (!pattern.contains("*") && !pattern.contains("?")) {\r
-        final File file = new File(pattern);\r
-        if (file.isAbsolute()) {\r
-          found = true;\r
-          LOG.debug("Found .nugkg to push: " + file);\r
-          myCallback.fileFound(file);\r
-          continue;\r
-        }\r
-      }\r
-\r
-      patterns.add(pattern.replace('\\', '/'));\r
+      patterns.add(pattern);\r
     }\r
 \r
-    final String[] includes = patterns.toArray(new String[patterns.size()]);\r
-    AntPatternFileFinder finder = new AntPatternFileFinder(\r
-            includes,\r
-            new String[0],\r
-            SystemInfo.isFileSystemCaseSensitive\r
-    );\r
-\r
     final File root = myContext.getBuild().getCheckoutDirectory();\r
     try {\r
-      final File[] result = finder.findFiles(root);\r
-\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
         myCallback.fileFound(file);\r
       }\r
-    } catch (IOException e) {\r
+    } catch (Exception e) {\r
       throw new RunBuildException("Failed to find packages to publish. " + e.getMessage(), e);\r
     }\r
 \r
index 07bde59d75e486a4a353578d34f74aef3debbdbb..918b6fcb07f7b589aa86bec563665112fe180387 100644 (file)
@@ -30,11 +30,11 @@ import java.util.List;
 public class DirectoryScanner {\r
   private static final Logger LOG = Logger.getInstance(DirectoryScanner.class.getName());\r
 \r
-  public static Collection<File> FindFiles(@NotNull File root, String[] includes, String[] excludes) {\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
   }\r
 \r
-  private static Collection<File> FindFiles(IFileSystem fs, IDirectoryEntry root, String[] includes, String[] excludes) {\r
+  private static Collection<File> FindFiles(IFileSystem fs, IDirectoryEntry root, Collection<String> includes, Collection<String> excludes) {\r
     List<Wildcard> basePath = BuildSearchPrefix(root, fs.CaseSensitive());\r
 \r
     List<FileSystemPath> result = new ArrayList<FileSystemPath>();\r
@@ -63,7 +63,7 @@ public class DirectoryScanner {
     return wildcardPrefix;\r
   }\r
 \r
-  private static List<AntPatternState> ToAntPatternState(IFileSystem fs, List<Wildcard> wildcardPrefix, boolean caseSensitive, String[] patterns) {\r
+  private static List<AntPatternState> ToAntPatternState(IFileSystem fs, List<Wildcard> wildcardPrefix, boolean caseSensitive, 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
index be3dceb03e61d4ac87e76461be1eeb5b1db70cfc..0951b727cb5ee119f234def72d427f676309c146 100644 (file)
@@ -25,17 +25,14 @@ import org.testng.annotations.Test;
 \r
 import java.io.File;\r
 import java.io.IOException;\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-import java.util.Set;\r
-import java.util.TreeSet;\r
+import java.util.*;\r
 \r
 public class TestDirectoryScanner extends BaseTestCase {\r
   private void AssertScannerResult(String[] fsDescription, String[] includePatterns, String[] excludePatterns, String[] expectedResult) throws IOException {\r
     File fsp = createTempDir();\r
 \r
     CreateDirectories(fsDescription, fsp);\r
-    Collection<File> findFiles = DirectoryScanner.FindFiles(fsp, includePatterns, 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
@@ -192,7 +189,7 @@ public class TestDirectoryScanner extends BaseTestCase {
     File atxtFsp = new File(fsp, "a.txt");\r
     FileUtil.writeFile(atxtFsp, "text");\r
 \r
-    Collection<File> files = DirectoryScanner.FindFiles(fsp, new String[]{atxtFsp.getPath()}, new String[0]);\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