<commit_before>class MavenJnlp::MavenJnlpFamily < ActiveRecord::Base
  self.table_name = "maven_jnlp_maven_jnlp_families"
  
  has_many :projects, :class_name => "Admin::Project"
  
  belongs_to :maven_jnlp_server, :class_name => "MavenJnlp::MavenJnlpServer"

  has_many :versioned_jnlp_urls, :class_name => "MavenJnlp::VersionedJnlpUrl"

  has_many :recent_versioned_jnlp_urls, :class_name => "MavenJnlp::VersionedJnlpUrl", :order => 'date_str DESC', :limit => 20
  
  # has_many :versioned_jnlps, :through => :versioned_jnlp_urls, :class_name => "MavenJnlp::VersionedJnlpUrl"
  
  acts_as_replicatable
  
  include Changeable
  
  self.extend SearchableModel
  
  @@searchable_attributes = %w{uuid name}
  
  class <<self
    def searchable_attributes
      @@searchable_attributes
    end
  end
  
  def create_versioned_jnlp_urls(mjf_object)
    count = 0; print '.'; STDOUT.flush
    mjf_object.versions.each do |version_object|
      vju = self.versioned_jnlp_urls.build(
        :path        => version_object.path,
        :url         => version_object.url,
        :version_str => version_object.version)
      vju.save!
      count += 1
      if count % 20 == 0
        print '.'
        STDOUT.flush
      end
    end
  end
  
  def update_snapshot_jnlp_url
    jnlp_url = snapshot_jnlp_url
    current = snapshot_version
    newest = newest_snapshot_version
    if current != newest
      jnlp_url = snapshot_jnlp_url.clone
      jnlp_url.url = jnlp_url.url.gsub(jnlp_url.version_str, newest)
      jnlp_url.path = jnlp_url.path.gsub(jnlp_url.version_str, newest)
      jnlp_url.version_str = newest
      jnlp_url.save!
      self.snapshot_version = newest
      self.save!
    end
    jnlp_url
  end

  def snapshot_jnlp_url
    MavenJnlp::VersionedJnlpUrl.find_by_version_str(snapshot_version)
  end

  def newest_snapshot_version
    begin
      Timeout::timeout(10) do
        open("#{url}/#{name}-CURRENT_VERSION.txt").read
      end
    rescue ::OpenURI::HTTPError, SocketError, Timeout::Error
      puts "couldn't read from #{url}/#{name}-CURRENT_VERSION.txt"
      snapshot_version
    end
  end
  
end<commit_msg>fix 'clone' bug when updating jnlp snapshot<commit_after>class MavenJnlp::MavenJnlpFamily < ActiveRecord::Base
  self.table_name = "maven_jnlp_maven_jnlp_families"
  
  has_many :projects, :class_name => "Admin::Project"
  
  belongs_to :maven_jnlp_server, :class_name => "MavenJnlp::MavenJnlpServer"

  has_many :versioned_jnlp_urls, :class_name => "MavenJnlp::VersionedJnlpUrl"

  has_many :recent_versioned_jnlp_urls, :class_name => "MavenJnlp::VersionedJnlpUrl", :order => 'date_str DESC', :limit => 20
  
  # has_many :versioned_jnlps, :through => :versioned_jnlp_urls, :class_name => "MavenJnlp::VersionedJnlpUrl"
  
  acts_as_replicatable
  
  include Changeable
  
  self.extend SearchableModel
  
  @@searchable_attributes = %w{uuid name}
  
  class <<self
    def searchable_attributes
      @@searchable_attributes
    end
  end
  
  def create_versioned_jnlp_urls(mjf_object)
    count = 0; print '.'; STDOUT.flush
    mjf_object.versions.each do |version_object|
      vju = self.versioned_jnlp_urls.build(
        :path        => version_object.path,
        :url         => version_object.url,
        :version_str => version_object.version)
      vju.save!
      count += 1
      if count % 20 == 0
        print '.'
        STDOUT.flush
      end
    end
  end
  
  def update_snapshot_jnlp_url
    jnlp_url = snapshot_jnlp_url
    current = snapshot_version
    newest = newest_snapshot_version
    if current != newest
      new_jnlp_url = self.versioned_jnlp_urls.build(
        :path        => jnlp_url.path.gsub(jnlp_url.version_str, newest),
        :url         => jnlp_url.url.gsub(jnlp_url.version_str, newest),
        :version_str => newest)
      )
      new_jnlp_url.save!
      self.snapshot_version = newest
      self.save!
      jnlp_url = new_jnlp_url
    end
    jnlp_url
  end

  def snapshot_jnlp_url
    MavenJnlp::VersionedJnlpUrl.find_by_version_str(snapshot_version)
  end

  def newest_snapshot_version
    begin
      Timeout::timeout(10) do
        open("#{url}/#{name}-CURRENT_VERSION.txt").read
      end
    rescue ::OpenURI::HTTPError, SocketError, Timeout::Error
      puts "couldn't read from #{url}/#{name}-CURRENT_VERSION.txt"
      snapshot_version
    end
  end
  
end
{'fraction_non_alphanumeric': 0.09497591190640055, 'fraction_numerical': 0.0041293874741913286, 'mean_word_length': 3.2248062015503876, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 28, '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': '1776833', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1609, 'n_words': 263}