# This script assumes the following beans are in place
# $directories - a list of directories containing the plugins
# $plugins - java plugin types

#include Java

import com.approximatrix.draco.application.plugin.RegressionPlugin;
import com.approximatrix.draco.application.plugin.AnalysisPlugin;
import com.approximatrix.draco.application.plugin.PluginType

import java.lang.System

require '/pengine/model/plugin'

$current_filename = nil

def register(klass)
  System.out.print("Registering: ")
  System.out.println(klass.name)
  
  if klass.type == PluginType.analysis
    $registry << AnalysisPlugin.new(klass.name,$current_filename,klass.to_s)
  elsif klass.type == PluginType.regression
    $registry << RegressionPlugin.new(klass.name,$current_filename,klass.to_s)
  else
    System.err.print("Failed to determine plugin type for class: ")
    System.err.print(klass.name)
    System.err.print("  file: ")
    System.err.println($current_filename)
  end
end

def register_files(directory)

    search = File.join(directory,'*.rb')
    
    #System.out.println(search)
    
    Dir.glob(search) { |filename|
    
      #System.out.println(filename)
      
      $current_filename = filename
      #begin
        load filename
      #rescue
      #  System.err.print("Failed on file: ")
      #  System.err.println(filename)
      #end
      
    }
    
end

$directories.each { |directory|
    register_files(directory)
}
