<commit_before>package org.smoothbuild.parse;

import static com.google.common.base.Throwables.getStackTraceAsString;
import static org.smoothbuild.message.message.MessageType.FATAL;

import javax.inject.Inject;

import org.smoothbuild.builtin.compress.UnzipFunction;
import org.smoothbuild.builtin.compress.ZipFunction;
import org.smoothbuild.builtin.file.FileFunction;
import org.smoothbuild.builtin.file.FilesFunction;
import org.smoothbuild.builtin.file.FilterFunction;
import org.smoothbuild.builtin.file.MergeFunction;
import org.smoothbuild.builtin.file.NewFileFunction;
import org.smoothbuild.builtin.file.SaveFunction;
import org.smoothbuild.builtin.java.JarFunction;
import org.smoothbuild.builtin.java.UnjarFunction;
import org.smoothbuild.builtin.java.javac.JavacFunction;
import org.smoothbuild.builtin.java.junit.JunitFunction;
import org.smoothbuild.db.task.TaskDb;
import org.smoothbuild.function.base.CachableFunction;
import org.smoothbuild.function.base.Function;
import org.smoothbuild.function.nativ.NativeFunctionFactory;
import org.smoothbuild.function.nativ.exc.NativeImplementationException;
import org.smoothbuild.message.listen.ErrorMessageException;
import org.smoothbuild.message.message.Message;

import com.google.inject.Provider;

public class ImportedFunctionsProvider implements Provider<ImportedFunctions> {
  private final TaskDb taskDb;
  private final NativeFunctionFactory nativeFunctionFactory;

  @Inject
  public ImportedFunctionsProvider(TaskDb taskDb, NativeFunctionFactory nativeFunctionFactory) {
    this.taskDb = taskDb;
    this.nativeFunctionFactory = nativeFunctionFactory;
  }

  @Override
  public ImportedFunctions get() {
    ImportedFunctions importedFunctions = new ImportedFunctions();

    // file related
    importedFunctions.add(createFunction(FileFunction.class));
    importedFunctions.add(createFunction(NewFileFunction.class));
    importedFunctions.add(createFunction(FilesFunction.class));
    importedFunctions.add(createFunction(FilterFunction.class));
    importedFunctions.add(createFunction(MergeFunction.class));
    importedFunctions.add(createFunction(SaveFunction.class));

    // java related
    importedFunctions.add(createFunction(JavacFunction.class));
    importedFunctions.add(createFunction(JarFunction.class));
    importedFunctions.add(createFunction(UnjarFunction.class));
    importedFunctions.add(createFunction(JunitFunction.class));

    // compression related
    importedFunctions.add(createFunction(ZipFunction.class));
    importedFunctions.add(createFunction(UnzipFunction.class));

    return importedFunctions;
  }

  private Function createFunction(Class<?> klass) {
    try {
      return new CachableFunction(taskDb, nativeFunctionFactory.create(klass, true));
    } catch (NativeImplementationException e) {
      throw new ErrorMessageException(new Message(FATAL, "Bug in smooth binary: Builtin function "
          + klass.getCanonicalName() + " has implementation problem.\nJava stack trace is:\n"
          + getStackTraceAsString(e)));
    }
  }<commit_msg>fixed ImportedFunctionsProvider so file/files function are not cachable<commit_after>package org.smoothbuild.parse;

import static com.google.common.base.Throwables.getStackTraceAsString;
import static org.smoothbuild.message.message.MessageType.FATAL;

import javax.inject.Inject;

import org.smoothbuild.builtin.compress.UnzipFunction;
import org.smoothbuild.builtin.compress.ZipFunction;
import org.smoothbuild.builtin.file.FileFunction;
import org.smoothbuild.builtin.file.FilesFunction;
import org.smoothbuild.builtin.file.FilterFunction;
import org.smoothbuild.builtin.file.MergeFunction;
import org.smoothbuild.builtin.file.NewFileFunction;
import org.smoothbuild.builtin.file.SaveFunction;
import org.smoothbuild.builtin.java.JarFunction;
import org.smoothbuild.builtin.java.UnjarFunction;
import org.smoothbuild.builtin.java.javac.JavacFunction;
import org.smoothbuild.builtin.java.junit.JunitFunction;
import org.smoothbuild.db.task.TaskDb;
import org.smoothbuild.function.base.CachableFunction;
import org.smoothbuild.function.base.Function;
import org.smoothbuild.function.nativ.NativeFunctionFactory;
import org.smoothbuild.function.nativ.exc.NativeImplementationException;
import org.smoothbuild.message.listen.ErrorMessageException;
import org.smoothbuild.message.message.Message;

import com.google.inject.Provider;

public class ImportedFunctionsProvider implements Provider<ImportedFunctions> {
  private final TaskDb taskDb;
  private final NativeFunctionFactory nativeFunctionFactory;

  @Inject
  public ImportedFunctionsProvider(TaskDb taskDb, NativeFunctionFactory nativeFunctionFactory) {
    this.taskDb = taskDb;
    this.nativeFunctionFactory = nativeFunctionFactory;
  }

  @Override
  public ImportedFunctions get() {
    ImportedFunctions importedFunctions = new ImportedFunctions();

    // file related
    importedFunctions.add(nonCachableFunction(FileFunction.class));
    importedFunctions.add(nonCachableFunction(FilesFunction.class));
    importedFunctions.add(function(NewFileFunction.class));
    importedFunctions.add(function(FilterFunction.class));
    importedFunctions.add(function(MergeFunction.class));
    importedFunctions.add(function(SaveFunction.class));

    // java related
    importedFunctions.add(function(JavacFunction.class));
    importedFunctions.add(function(JarFunction.class));
    importedFunctions.add(function(UnjarFunction.class));
    importedFunctions.add(function(JunitFunction.class));

    // compression related
    importedFunctions.add(function(ZipFunction.class));
    importedFunctions.add(function(UnzipFunction.class));

    return importedFunctions;
  }

  private Function function(Class<?> klass) {
    return new CachableFunction(taskDb, nonCachableFunction(klass));
  }

  private Function nonCachableFunction(Class<?> klass) {
    try {
      return nativeFunctionFactory.create(klass, true);
    } catch (NativeImplementationException e) {
      throw new ErrorMessageException(new Message(FATAL, "Bug in smooth binary: Builtin function "
          + klass.getCanonicalName() + " has implementation problem.\nJava stack trace is:\n"
          + getStackTraceAsString(e)));
    }
  }
{'fraction_non_alphanumeric': 0.09289266805711535, 'fraction_numerical': 0.0, 'mean_word_length': 5.911308203991131, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '827041', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1700, 'n_words': 277}