<commit_before>#!/usr/bin/env ruby -wKU
# encoding: utf-8

module FlexMate
  
  # Utility methods for collecting ActionScript 3/Flex specific environmental
  # settings.
  #
  class Settings
    
    # By default the bundle assumes that the env variable TM_PROJECT_DIRECTORY 
    # points to the root directory of the flex/actionscript project. However TM
    # sets the value based on the closest file to the root of the filesystem. To
    # combat this, and enable users to collect files from places outside of the
    # normal project we also check the location of the 'tmproj' file and assume
    # that if there is one, it has been placed in the root of the flex/actionscript
    # project.
    #
    def proj_root

      proj_file = ENV['TM_PROJECT_FILEPATH'] || ''
      proj_dir = ENV['TM_PROJECT_DIRECTORY'] || ''
      
      return File.dirname(proj_file) unless proj_file.empty?
      return proj_dir unless proj_dir.empty?
      return ''
      
    end
    
    # Inspects the available environmental variables and gathers the settings
    # necessary for the compiler to run.
    #
    def file_specs
      
      proj_dir = proj_root
      file_specs = ENV['TM_FLEX_FILE_SPECS']

      if proj_dir && file_specs
        file_specs = proj_dir + '/' + file_specs
        return file_specs if File.exist?(file_specs)
      end

      if proj_dir
        file_specs = guess_file_specs(proj_dir)
        return file_specs unless file_specs.nil?
      end

      file_specs = ENV['TM_FILEPATH']

    end

    # When TM_FLEX_OUTPUT and TM_PROJECT_DIRECTORY are defined use them to
    # build flex output. Otherwise derive the output from the file specs.
    #
    def flex_output

      flex_output = ENV['TM_FLEX_OUTPUT']
      proj_dir = proj_root

      if flex_output && proj_dir
        return proj_dir + '/' + flex_output
      end

      fx_out = file_specs.sub(/\.(mxml|as)/, ".swf")

      #TODO: Link to usual src dirs and improve sub with a regexp that
      #matches src backwards (ie foo/src/bar/src/class) from the end of line.
      if File.exist?( proj_dir.to_s + '/bin' )
        fx_out.sub!('src','bin')
      end

      fx_out

    end

    # Locate and return the compiler config file associated with the current
    # project.
    #
    def compiler_config
      build_file = ENV['TM_FLEX_FILE_SPECS'] || ''
      unless build_file.empty?
        cp = build_file.sub(/\.(as|mxml)$/,'')
        proj = proj_root+'/' || ''
        return "#{proj}#{cp}-config.xml"
      end
      return nil
    end
    
    protected
    
    # Where we have Project Directory but no TM_FLEX_FILE_SPECS set take a look
    # inside the src/ dir and see if we can work out which file should be
    # compiled.<commit_msg>• When estimating the output file path and 'src' appears twice in the file path (ie foo/src/bar/src/class) we now use the last occurrence of 'src' to translate, not the first.<commit_after>#!/usr/bin/env ruby -wKU
# encoding: utf-8

module FlexMate
  
  # Utility methods for collecting ActionScript 3/Flex specific environmental
  # settings.
  #
  class Settings
    
    # By default the bundle assumes that the env variable TM_PROJECT_DIRECTORY 
    # points to the root directory of the flex/actionscript project. However TM
    # sets the value based on the closest file to the root of the filesystem. To
    # combat this, and enable users to collect files from places outside of the
    # normal project we also check the location of the 'tmproj' file and assume
    # that if there is one, it has been placed in the root of the
    # flex/actionscript project.
    #
    def proj_root

      proj_file = ENV['TM_PROJECT_FILEPATH'] || ''
      proj_dir = ENV['TM_PROJECT_DIRECTORY'] || ''
      
      return File.dirname(proj_file) unless proj_file.empty?
      return proj_dir unless proj_dir.empty?
      return ''
      
    end
    
    # Inspects the available environmental variables and gathers the settings
    # necessary for the compiler to run.
    #
    def file_specs
      
      proj_dir = proj_root
      file_specs = ENV['TM_FLEX_FILE_SPECS']

      if proj_dir && file_specs
        file_specs = proj_dir + '/' + file_specs
        return file_specs if File.exist?(file_specs)
      end

      if proj_dir
        file_specs = guess_file_specs(proj_dir)
        return file_specs unless file_specs.nil?
      end

      file_specs = ENV['TM_FILEPATH']

    end

    # When TM_FLEX_OUTPUT and TM_PROJECT_DIRECTORY are defined use them to
    # build flex output. Otherwise derive the output from the file specs.
    #
    def flex_output

      flex_output = ENV['TM_FLEX_OUTPUT']
      proj_dir = proj_root

      if flex_output && proj_dir
        return proj_dir + '/' + flex_output
      end

      fx_out = file_specs.sub(/\.(mxml|as)/, ".swf")

      if File.exist?( proj_dir.to_s + '/bin' )
        #match src backwards from the end of line. This covers us in these
        #cases foo/src/bar/src/class.
        sd = SourceTools.common_src_dir_list.reverse.gsub(':','|')
        fx_out.reverse!.sub!(/(#{sd})/,'nib').reverse!
      end

      fx_out

    end

    # Locate and return the compiler config file associated with the current
    # project.
    #
    def compiler_config
      build_file = ENV['TM_FLEX_FILE_SPECS'] || ''
      unless build_file.empty?
        cp = build_file.sub(/\.(as|mxml)$/,'')
        proj = proj_root+'/' || ''
        return "#{proj}#{cp}-config.xml"
      end
      return nil
    end
    
    protected
    
    # Where we have Project Directory but no TM_FLEX_FILE_SPECS set take a look
    # inside the src/ dir and see if we can work out which file should be
    # compiled.
{'fraction_non_alphanumeric': 0.07903538109487766, 'fraction_numerical': 0.0007041013906002464, 'mean_word_length': 2.4646341463414636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '5971071', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1751, 'n_words': 582}