<commit_before>/*
 * Copyright 2000-2011 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.server.toolRegistry.impl;

import jetbrains.buildServer.nuget.server.feed.reader.FeedConstants;
import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage;
import jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader;
import jetbrains.buildServer.nuget.server.toolRegistry.NuGetTool;
import jetbrains.buildServer.util.CollectionsUtil;
import jetbrains.buildServer.util.Converter;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;

/**
 * Created by <NAME> (<EMAIL>)
 * Date: 15.08.11 16:33
 */
public class AvailableToolsState {
  private final NuGetFeedReader myReader;

  public AvailableToolsState(@NotNull final NuGetFeedReader reader) {
    myReader = reader;
  }

  public Collection<NuGetTool> getAvailable() {
    try {
      final Collection<FeedPackage> packages = myReader.queryPackageVersions(FeedConstants.FEED_URL, FeedConstants.NUGET_COMMANDLINE);
      return CollectionsUtil.convertCollection(
              packages,
              new Converter<NuGetTool, FeedPackage>() {
                public NuGetTool createFrom(@NotNull FeedPackage source) {
                  return new InstallableTool(source);
                }
              }
              );

    } catch (IOException e) {
      e.printStackTrace();
      //TODO: handle exception
      return Collections.emptyList();
    }
  }

  private static class InstallableTool implements NuGetTool {
    private final FeedPackage myPackage;

    private InstallableTool(@NotNull final FeedPackage aPackage) {
      myPackage = aPackage;
    }

    @NotNull
    public String getId() {
      return myPackage.getAtomId();
    }

    @NotNull
    public String getVersion() {
      return myPackage.getInfo().getVersion();
    }

    @NotNull
    public FeedPackage getPackage() {
      return myPackage;
    }
  }
}<commit_msg>filter nuget.commandline versions<commit_after>/*
 * Copyright 2000-2011 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.server.toolRegistry.impl;

import jetbrains.buildServer.nuget.server.feed.reader.FeedConstants;
import jetbrains.buildServer.nuget.server.feed.reader.FeedPackage;
import jetbrains.buildServer.nuget.server.feed.reader.NuGetFeedReader;
import jetbrains.buildServer.nuget.server.toolRegistry.NuGetTool;
import jetbrains.buildServer.util.CollectionsUtil;
import jetbrains.buildServer.util.Converter;
import jetbrains.buildServer.util.filters.Filter;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;

/**
 * Created by <NAME> (<EMAIL>)
 * Date: 15.08.11 16:33
 */
public class AvailableToolsState {
  private final NuGetFeedReader myReader;

  public AvailableToolsState(@NotNull final NuGetFeedReader reader) {
    myReader = reader;
  }

  public Collection<NuGetTool> getAvailable() {
    try {
      final Collection<FeedPackage> packages = myReader.queryPackageVersions(FeedConstants.FEED_URL, FeedConstants.NUGET_COMMANDLINE);
      return CollectionsUtil.filterAndConvertCollection(
              packages,
              new Converter<NuGetTool, FeedPackage>() {
                public NuGetTool createFrom(@NotNull FeedPackage source) {
                  return new InstallableTool(source);
                }
              },
              new Filter<FeedPackage>() {
                public boolean accept(@NotNull FeedPackage data) {
                  final String[] version = data.getInfo().getVersion().split("\\.");
                  if (version.length < 2) return false;
                  int major = parse(version[0]);
                  if (major < 1) return false;

                  int minor = parse(version[1]);
                  if (minor < 4) return false;

                  return true;
                }

                private int parse(String s) {
                  try {
                    return Integer.parseInt(s.trim());
                  } catch (Exception e) {
                    return -1;
                  }
                }
              }
      );

    } catch (IOException e) {
      e.printStackTrace();
      //TODO: handle exception
      return Collections.emptyList();
    }
  }

  private static class InstallableTool implements NuGetTool {
    private final FeedPackage myPackage;

    private InstallableTool(@NotNull final FeedPackage aPackage) {
      myPackage = aPackage;
    }

    @NotNull
    public String getId() {
      return myPackage.getAtomId();
    }

    @NotNull
    public String getVersion() {
      return myPackage.getInfo().getVersion();
    }

    @NotNull
    public FeedPackage getPackage() {
      return myPackage;
    }
  }
}
{'fraction_non_alphanumeric': 0.08781725888324873, 'fraction_numerical': 0.008460236886632826, 'mean_word_length': 2.8110896196002577, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1896030', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1516, 'n_words': 436}