/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed 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 jetbrains.buildServer.nuget.common;

import jetbrains.buildServer.util.filters.Filter;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileFilter;

/**
 * Created by Eugene Petrenko (eugene.petrenko@gmail.com)
 * Date: 11.08.11 16:04
 */
public class FeedConstants {
  public static final String NUGET_FEED_V1 = "http://packages.nuget.org/api/v1/FeedService.svc";
  public static final String NUGET_FEED_V2 = "http://packages.nuget.org/api/v2";

  public static final String NUGET_EXE = "nuget.exe";
  public static final String NUGET_COMMANDLINE = "NuGet.CommandLine";
  public static final String NUGET_EXTENSION = ".nupkg";
  public static final String EXE_EXTENSION = ".exe";
  public static final String NUGET_SUPPORTED_PROJECTS[] = {".csproj", ".vbproj", ".fsproj", ".nproj"}; //see PackCommand.cs
  public static final String NUGET_SYMBOLS_EXTENSION = ".symbols.nupkg";
  public static final String NUSPEC_FILE_EXTENSION = ".nuspec";

  public static final String NUGET_EXE_PACKAGE_VERSION = "3.2.0";

  public static final FileFilter PACKAGE_FILE_FILTER = new FileFilter() {
    public boolean accept(File pathname) {
      return pathname.isFile() && PACKAGE_FILE_NAME_FILTER.accept(pathname.getName());
    }
  };

  public static final FileFilter EXE_FILE_FILTER = new FileFilter() {
    public boolean accept(File pathname) {
      return pathname.isFile() && EXE_FILE_NAME_FILTER.accept(pathname.getName());
    }
  };

  public static final FileFilter NUGET_TOOL_FILE_FILTER = new FileFilter() {
    public boolean accept(File pathname) {
      return pathname.isFile() && PACKAGE_FILE_NAME_FILTER.accept(pathname.getName()) || EXE_FILE_NAME_FILTER.accept(pathname.getName());
    }
  };

  public static final Filter<String> EXE_FILE_NAME_FILTER = new Filter<String>() {
    public boolean accept(@NotNull String data) {
      return data.toLowerCase().endsWith(FeedConstants.EXE_EXTENSION.toLowerCase());
    }
  };

  public static final Filter<String> PACKAGE_FILE_NAME_FILTER = new Filter<String>() {
    public boolean accept(@NotNull String data) {
      data = data.toLowerCase();
      return data.endsWith(FeedConstants.NUGET_EXTENSION.toLowerCase()) && !data.endsWith(FeedConstants.NUGET_SYMBOLS_EXTENSION.toLowerCase());
    }
  };
}

@@ -1620,77 +1620,8 @@
 %0D%0A%0D%0A
-  public static final String NUGET_EXE_PACKAGE_VERSION = %223.2.0%22;%0D%0A%0D%0A
   pu
@@ -2184,36 +2184,122 @@
     
-return pathname.isFile() && 
+final String name = pathname.getName();%0D%0A      return pathname.isFile() && name.startsWith(NUGET_COMMANDLINE) && (
 PACK
@@ -2326,34 +2326,20 @@
 .accept(
-pathname.getName()
+name
 ) %7C%7C EXE
@@ -2363,33 +2363,20 @@
 .accept(
-pathname.getName(
+name
 ));%0D%0A   

check for file name suffix when accepting file as a valid nuget tool