<commit_before>=begin
                  Arachni
  Copyright (c) 2010 Tasos "Zapotek" Laskos <<EMAIL>>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end

module Arachni

#
# The namespace under which all plugins exist
#
module Plugins

    #
    # Resets the namespace unloading all module classes
    #
    def self.reset
        constants.each {
            |const|
            remove_const( const )
        }
    end
end

module Plugin

#
# Holds and manages the plugins.
#
# @author: Tasos "Zapotek" Laskos
#                                      <<EMAIL>>
#                                      <<EMAIL>>
# @version: 0.1
#
class Manager < Arachni::ComponentManager

    include Arachni::UI::Output
    include Arachni::Module::Utilities

    #
    # @param    [Arachni::Framework]    framework   framework instance
    #
    def initialize( framework )
        super( framework.opts.dir['plugins'], Arachni::Plugins )
        @framework = framework

        @jobs = []
    end

    #
    # Runs each plug-in in its own thread.
    #
    def run
        each {
            |name, plugin|

            @jobs << Thread.new {

                exception_jail {
                    Thread.current[:name] = name

                    plugin_new = create( name )
                    plugin_new.prepare
                    plugin_new.run
                    plugin_new.clean_up
                }

            }
        }

        print_status( 'Waiting for plugins to settle...' )
        ::IO::select( nil, nil, nil, 1 )
    end

    def create( name )
        opts = @framework.opts.plugins[name]
        self[name].new( @framework, prep_opts( name, self[name], opts ) )
    end

    #
    # Blocks until all plug-ins have finished executing.
    #
    def block!
        while( !@jobs.empty? )

            print_debug
            print_debug( "Waiting on the following (#{@jobs.size}) plugins to finish:" )
            print_debug( job_names.join( ', ' ) )
            print_debug

            @jobs.delete_if { |j| !j.alive? }
            ::IO::select( nil, nil, nil, 1 )
        end
    end

    #
    # Will return false if all plug-ins have finished executing.
    #
    # @return   [Bool]
    #
    def busy?
        !@jobs.reject{ |j| j.alive? }.empty?
    end

    #
    # Returns the names of the running plug-ins.
    #
    # @return   [Array]
    #
    def job_names
        @jobs.map{ |j| j[:name] }
    end

    #
    # Returns all the running threads.
    #
    # @return   [Array<Thread>]
    #
    def jobs
        @jobs
    end

    #
    # Kills a plug-in by name.
    #
    # @param    [String]    name
    #
    def kill( name )
        job = get( name )
        return job.kill if job
        return nil
    end

    #
    # Gets a running plug-in by name.
    #
    # @param    [String]    name
    #
    # @return   [Thread]
    #
    def get( name )
        @jobs.each { |job| return job if job[:name] == name }
    end


end
end
end
<commit_msg>run(): there's no sense in waiting for plugins to settle if no plugins were ran<commit_after>=begin
                  Arachni
  Copyright (c) 2010 Tasos "Zapotek" Laskos <<EMAIL>>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end

module Arachni

#
# The namespace under which all plugins exist
#
module Plugins

    #
    # Resets the namespace unloading all module classes
    #
    def self.reset
        constants.each {
            |const|
            remove_const( const )
        }
    end
end

module Plugin

#
# Holds and manages the plugins.
#
# @author: Tasos "Zapotek" Laskos
#                                      <<EMAIL>>
#                                      <<EMAIL>>
# @version: 0.1
#
class Manager < Arachni::ComponentManager

    include Arachni::UI::Output
    include Arachni::Module::Utilities

    #
    # @param    [Arachni::Framework]    framework   framework instance
    #
    def initialize( framework )
        super( framework.opts.dir['plugins'], Arachni::Plugins )
        @framework = framework

        @jobs = []
    end

    #
    # Runs each plug-in in its own thread.
    #
    def run
        i = 0
        each {
            |name, plugin|

            @jobs << Thread.new {

                exception_jail {
                    Thread.current[:name] = name

                    plugin_new = create( name )
                    plugin_new.prepare
                    plugin_new.run
                    plugin_new.clean_up
                }

            }

            i += 1
        }

        if i > 0
            print_status( 'Waiting for plugins to settle...' )
            ::IO::select( nil, nil, nil, 1 )
        end
    end

    def create( name )
        opts = @framework.opts.plugins[name]
        self[name].new( @framework, prep_opts( name, self[name], opts ) )
    end

    #
    # Blocks until all plug-ins have finished executing.
    #
    def block!
        while( !@jobs.empty? )

            print_debug
            print_debug( "Waiting on the following (#{@jobs.size}) plugins to finish:" )
            print_debug( job_names.join( ', ' ) )
            print_debug

            @jobs.delete_if { |j| !j.alive? }
            ::IO::select( nil, nil, nil, 1 )
        end
    end

    #
    # Will return false if all plug-ins have finished executing.
    #
    # @return   [Bool]
    #
    def busy?
        !@jobs.reject{ |j| j.alive? }.empty?
    end

    #
    # Returns the names of the running plug-ins.
    #
    # @return   [Array]
    #
    def job_names
        @jobs.map{ |j| j[:name] }
    end

    #
    # Returns all the running threads.
    #
    # @return   [Array<Thread>]
    #
    def jobs
        @jobs
    end

    #
    # Kills a plug-in by name.
    #
    # @param    [String]    name
    #
    def kill( name )
        job = get( name )
        return job.kill if job
        return nil
    end

    #
    # Gets a running plug-in by name.
    #
    # @param    [String]    name
    #
    # @return   [Thread]
    #
    def get( name )
        @jobs.each { |job| return job if job[:name] == name }
    end


end
end
end

{'fraction_non_alphanumeric': 0.09864757358790771, 'fraction_numerical': 0.0036595067621320605, 'mean_word_length': 1.4895049504950495, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '76319', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1873, 'n_words': 562}