github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/analyzers/analyzer.go (about) 1 // Package analyzers defines analyzers for various package types. 2 package analyzers 3 4 import ( 5 "errors" 6 7 "github.com/fossas/fossa-cli/analyzers/ant" 8 "github.com/fossas/fossa-cli/analyzers/bower" 9 "github.com/fossas/fossa-cli/analyzers/buck" 10 "github.com/fossas/fossa-cli/analyzers/carthage" 11 "github.com/fossas/fossa-cli/analyzers/cocoapods" 12 "github.com/fossas/fossa-cli/analyzers/debian" 13 "github.com/fossas/fossa-cli/analyzers/golang" 14 "github.com/fossas/fossa-cli/analyzers/gradle" 15 "github.com/fossas/fossa-cli/analyzers/haskell" 16 "github.com/fossas/fossa-cli/analyzers/maven" 17 "github.com/fossas/fossa-cli/analyzers/nodejs" 18 "github.com/fossas/fossa-cli/analyzers/nuget" 19 "github.com/fossas/fossa-cli/analyzers/okbuck" 20 "github.com/fossas/fossa-cli/analyzers/php" 21 "github.com/fossas/fossa-cli/analyzers/python" 22 "github.com/fossas/fossa-cli/analyzers/ruby" 23 "github.com/fossas/fossa-cli/analyzers/rust" 24 "github.com/fossas/fossa-cli/analyzers/scala" 25 "github.com/fossas/fossa-cli/graph" 26 "github.com/fossas/fossa-cli/module" 27 "github.com/fossas/fossa-cli/pkg" 28 ) 29 30 // Errors that occur when loading analyzers. 31 var ( 32 ErrUnknownModuleType = errors.New("could not find analyzer for module type") 33 ErrAnalyzerNotImplemented = errors.New("analyzer is not implemented for package type") 34 ) 35 36 // An Analyzer is an implementation of functionality for different build 37 // systems. 38 type Analyzer interface { 39 // These methods all make best-effort attempts. 40 Clean() error // Cleans build artifacts. 41 Build() error // Builds the module. 42 IsBuilt() (bool, error) // Checks whether a module has been built. 43 44 Analyze() (graph.Deps, error) // Runs an analysis of a module. 45 } 46 47 // New returns the analyzer for any given package type. 48 func New(m module.Module) (Analyzer, error) { 49 switch m.Type { 50 case pkg.Ant: 51 return ant.New(m) 52 case pkg.Bower: 53 return bower.New(m) 54 case pkg.Carthage: 55 return carthage.New(m) 56 case pkg.Cocoapods: 57 return cocoapods.New(m) 58 case pkg.Composer: 59 return php.New(m) 60 case pkg.Debian: 61 return debian.New(m) 62 case pkg.Go: 63 return golang.New(m) 64 case pkg.Gradle: 65 return gradle.New(m) 66 case pkg.Haskell: 67 return haskell.New(m) 68 case pkg.Maven: 69 return maven.New(m) 70 case pkg.NodeJS: 71 return nodejs.New(m) 72 case pkg.NuGet: 73 return nuget.New(m) 74 case pkg.OkBuck: 75 return okbuck.New(m) 76 case pkg.Python: 77 return python.New(m) 78 case pkg.Ruby: 79 return ruby.New(m) 80 case pkg.Rust: 81 return rust.New(m) 82 case pkg.Scala: 83 return scala.New(m) 84 case pkg.Buck: 85 return buck.New(m) 86 } 87 return nil, ErrUnknownModuleType 88 }