summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/scala/com/yahoo/container/plugin/classanalysis/Analyze.scala
blob: 2f2d034679dae9b7ade49ac7f2856d2e2ecae010 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.classanalysis

import org.objectweb.asm._
import java.io.{InputStream, File}
import com.yahoo.container.plugin.util.IO.withFileInputStream

/**
 * Main entry point for class analysis
 * @author  tonytv
 */
object Analyze {
  def analyzeClass(classFile : File) : ClassFileMetaData = {
    try {
      withFileInputStream(classFile) { fileInputStream =>
        analyzeClass(fileInputStream)
      }
    } catch {
      case e : RuntimeException => throw new RuntimeException("An error occurred when analyzing " + classFile.getPath, e)
    }
  }

  def analyzeClass(inputStream : InputStream) : ClassFileMetaData = {
    val visitor = new AnalyzeClassVisitor()
    new ClassReader(inputStream).accept(visitor, ClassReader.SKIP_DEBUG)
    visitor.result
  }
}