package org.zanata.client.commands.push;

import static com.google.common.collect.Sets.newTreeSet;
import static com.google.common.collect.Lists.newArrayList;
import static org.apache.commons.io.FileUtils.listFiles;
import static org.apache.commons.io.FilenameUtils.removeExtension;

import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zanata.client.config.LocaleList;
import org.zanata.client.config.LocaleMapping;

import com.google.common.collect.Constraints;

public class GettextPushStrategy extends AbstractGettextPushStrategy
{
   private static final Logger log = LoggerFactory.getLogger(GettextPushStrategy.class);

   private static <T> List<T> nonNullableArrayList()
   {
      List<T> l = newArrayList();
      return Constraints.constrainedList(l, Constraints.notNull());
   }

   @Override
   List<LocaleMapping> findLocales()
   {
      // find all .po basenames in this dir and subdirs
      final LocaleList localeList = getOpts().getLocaleMapList();
      Collection<File> files = listFiles(
            getOpts().getTransDir(), new String[]{"po"}, true);
      Set<String> localeNames = newTreeSet();
      for (File f: files)
      {
         String localeName = removeExtension(f.getName());
         localeNames.add(localeName);
      }
      List<LocaleMapping> locales = nonNullableArrayList();
      for (String localeName: localeNames)
      {
         LocaleMapping localLocale;
         if (localeList != null)
         {
            localLocale = localeList.findByLocalLocale(localeName);
            if (localLocale == null)
            {
               log.warn("Skipping locale {}; no locale entry found in zanata.xml", localeName);
               continue;
            }
         }
         else
         {
            localLocale = new LocaleMapping(localeName);
         }
         locales.add(localLocale);
      }
      return locales;
   }

   @Override
   File getTransFile(LocaleMapping localeMapping, String docName)
   {
      String localLocale = localeMapping.getLocalLocale();
      File transDir = getOpts().getTransDir();
      File docDir = new File(transDir, docName).getParentFile();
      File transFile = new File(docDir, localLocale + ".po");
      return transFile;
   }

}

@@ -96,68 +96,8 @@
 et;%0A
-import static com.google.common.collect.Lists.newArrayList;%0A
 impo
@@ -149,16 +149,16 @@
 tFiles;%0A
+
 import s
@@ -495,25 +495,19 @@
 collect.
-Constrain
+Lis
 ts;%0A%0Apub
@@ -668,174 +668,8 @@
 );%0A%0A
-   private static %3CT%3E List%3CT%3E nonNullableArrayList()%0A   %7B%0A      List%3CT%3E l = newArrayList();%0A      return Constraints.constrainedList(l, Constraints.notNull());%0A   %7D%0A%0A
    @
@@ -1172,19 +1172,17 @@
 s = 
-nonNullable
+Lists.new
 Arra

Remove use of guava Beta api