<commit_before>package info.spielproject.spiel
package plugins

import dalvik.system._

import java.io.File
import java.net.URL
import java.util.Collections

import collection.JavaConversions._
import collection.mutable.ListBuffer

import android.content.Context
import android.util.Log

class Plugin

object PluginManager {

  private val plugins = ListBuffer[Plugin]()

  def apply(context:Context) {
    val foundPlugins:List[Class[_]] = try {
      val classLoader = context.getClassLoader
      val findResources = classOf[BaseDexClassLoader].getDeclaredMethod("findResources", classOf[String])
      findResources.setAccessible(true)
      val dexs = Collections.list[URL](findResources.invoke(classLoader, "classes.dex").asInstanceOf[java.util.Enumeration[URL]])
      dexs.map { dex =>
        val apk = dex.getFile.split(":").last.split("!").head
        val dexFile = new DexFile(apk)
        val entries = Collections.list[String](dexFile.entries)
        entries.map(utils.classForName(_)).flatten
        .filter { c =>
          c != classOf[Plugin] && classOf[Plugin].isAssignableFrom(c)
        }.toList
      }.toList.flatten
    } catch {
      case e =>
        Log.d("spielcheck", "Automatic plugin loading failed", e)
        Nil
    }
    plugins ++= foundPlugins.map(_.newInstance().asInstanceOf[Plugin])
  }

}
<commit_msg>Add method to look up a plugin by class.<commit_after>package info.spielproject.spiel
package plugins

import dalvik.system._

import java.io.File
import java.net.URL
import java.util.Collections

import collection.JavaConversions._
import collection.mutable.ListBuffer

import android.content.Context
import android.util.Log

class Plugin

object PluginManager {

  private val plugins = ListBuffer[Plugin]()

  def apply(context:Context) {
    val foundPlugins:List[Class[_]] = try {
      val classLoader = context.getClassLoader
      val findResources = classOf[BaseDexClassLoader].getDeclaredMethod("findResources", classOf[String])
      findResources.setAccessible(true)
      val dexs = Collections.list[URL](findResources.invoke(classLoader, "classes.dex").asInstanceOf[java.util.Enumeration[URL]])
      dexs.map { dex =>
        val apk = dex.getFile.split(":").last.split("!").head
        val dexFile = new DexFile(apk)
        val entries = Collections.list[String](dexFile.entries)
        entries.map(utils.classForName(_)).flatten
        .filter { c =>
          c != classOf[Plugin] && classOf[Plugin].isAssignableFrom(c)
        }.toList
      }.toList.flatten
    } catch {
      case e =>
        Log.d("spielcheck", "Automatic plugin loading failed", e)
        Nil
    }
    plugins ++= foundPlugins.map(_.newInstance().asInstanceOf[Plugin])
  }

  def plugin[T <: Plugin:ClassManifest]:List[T] =
    plugins.filter(classManifest[T].erasure.isInstance(_)).toList.asInstanceOf[List[T]]

}

{'fraction_non_alphanumeric': 0.11993006993006992, 'fraction_numerical': 0.0, 'mean_word_length': 3.629449838187702, 'pattern_counts': {'":': 2, '<': 4, '<?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': '5422279', 'n_tokens_mistral': 872, 'n_tokens_neox': 853, 'n_words': 166}