<commit_before>require 'jruby/core_ext'

module Spec
  module Example
    module ExampleGroupMethods

      def deploy path, options = {}
        @run_mode = options.fetch(:run_mode, :client)
        @deployment = path
      end
      attr_reader :deployment
      
      def run_mode
        case @run_mode
        when :client
          org.jboss.arquillian.api.RunModeType::AS_CLIENT
        when :container
          org.jboss.arquillian.api.RunModeType::IN_CONTAINER
        else
          raise "Unknown :run_mode -- acceptable values are :client or :container"
        end 
      end

      def create_deployment 
        tail = @deployment.split('/')[-1]
        base = /(.*)\./.match(tail)[1]
        archive = org.jboss.shrinkwrap.api.ShrinkWrap.create( org.jboss.shrinkwrap.api.spec.JavaArchive.java_class, "#{base}.jar" )
        deploymentDescriptorUrl = JRuby.runtime.jruby_class_loader.getResource( name )
        archive.addResource( deploymentDescriptorUrl, "/META-INF/#{tail}" )
        archive
      end

    end
  end
end

Spec::Runner.configure do |config|

  config.before(:all) do
    self.class.add_class_annotation( org.jboss.arquillian.api.Run => { "value" => self.class.run_mode } )
    # TODO: As of JRuby 1.5.3, class methods are ignored by become_java! so this won't work:
    self.class.add_method_annotation( "create_deployment", org.jboss.arquillian.api.Deployment => {} )
    @real_java_class = self.class.become_java!

    configuration = org.jboss.arquillian.impl.XmlConfigurationBuilder.new.build()
    @adaptor = org.jboss.arquillian.impl.DeployableTestBuilder.build(configuration)
    @adaptor.beforeSuite
    @adaptor.beforeClass(@real_java_class)
  end

  config.after(:all) do
    @adaptor.afterClass(@real_java_class)
    @adaptor.afterSuite
  end

end
<commit_msg>Move the suite callbacks to their appropriate handlers, and link them all via thread local storage, as self will be different in suite and class scopes.<commit_after>require 'jruby/core_ext'

module Spec
  module Example
    module ExampleGroupMethods

      def deploy path, options = {}
        @run_mode = options.fetch(:run_mode, :client)
        @deployment = path
      end
      attr_reader :deployment
      
      def run_mode
        case @run_mode
        when :client
          org.jboss.arquillian.api.RunModeType::AS_CLIENT
        when :container
          org.jboss.arquillian.api.RunModeType::IN_CONTAINER
        else
          raise "Unknown :run_mode -- acceptable values are :client or :container"
        end 
      end

      def create_deployment 
        tail = @deployment.split('/')[-1]
        base = /(.*)\./.match(tail)[1]
        archive = org.jboss.shrinkwrap.api.ShrinkWrap.create( org.jboss.shrinkwrap.api.spec.JavaArchive.java_class, "#{base}.jar" )
        deploymentDescriptorUrl = JRuby.runtime.jruby_class_loader.getResource( name )
        archive.addResource( deploymentDescriptorUrl, "/META-INF/#{tail}" )
        archive
      end

    end
  end
end

Spec::Runner.configure do |config|

  config.before(:suite) do
    configuration = org.jboss.arquillian.impl.XmlConfigurationBuilder.new.build()
    Thread.current[:test_runner_adaptor] = org.jboss.arquillian.impl.DeployableTestBuilder.build(configuration)
    Thread.current[:test_runner_adaptor].beforeSuite
  end
    
  config.before(:all) do
    self.class.add_class_annotation( org.jboss.arquillian.api.Run => { "value" => self.class.run_mode } )
    # TODO: As of JRuby 1.5.3, class methods are ignored by become_java! so this won't work:
    self.class.add_method_annotation( "create_deployment", org.jboss.arquillian.api.Deployment => {} )
    @real_java_class = self.class.become_java!
    Thread.current[:test_runner_adaptor].beforeClass(@real_java_class)
  end

  config.after(:all) do
    Thread.current[:test_runner_adaptor]..afterClass(@real_java_class)
  end

  config.after(:suite) do
    Thread.current[:test_runner_adaptor].afterSuite
  end

end

{'fraction_non_alphanumeric': 0.10665658093797277, 'fraction_numerical': 0.0025214321734745334, 'mean_word_length': 3.081275720164609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7040428', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1238, 'n_words': 241}