srcscan

package module
v0.0.0-...-09a1ad7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2014 License: Apache-2.0 Imports: 11 Imported by: 0

README

srcscan

xrefs funcs top func library users

Scans directory trees for source code packages

Documentation

Overview

Package srcscan scans directory trees for source code packages.

Index

Constants

This section is empty.

Variables

View Source
var AllProfiles = []Profile{
	Profile{
		Name: "NPM package",
		Dir:  FileInDir{"package.json"},
		Unit: readNPMPackage,
	},
	Profile{
		Name: "Bower component",
		Dir:  FileInDir{"bower.json"},
		Unit: readBowerComponent,
	},
	Profile{
		Name:         "Python package and module",
		TopLevelOnly: true,
		Dir:          FileInDir{"__init__.py"},
		File:         FileHasSuffix{".py"},
		Unit: func(abspath, relpath string, config Config, info os.FileInfo) Unit {
			if info.IsDir() {
				return &PythonPackage{relpath}
			} else {
				return &PythonModule{relpath}
			}
		},
	},
	Profile{
		Name: "Go package",
		Dir:  FileSuffixInDir{".go"},
		Unit: readGoPackage,
	},
	Profile{
		Name: "Java Maven project",
		Dir:  FileInDir{"pom.xml"},
		Unit: readJavaMavenProject,
	},
	Profile{
		Name: "Ruby Gem",
		Dir:  FileSuffixInDir{".gemspec"},
		Unit: readRubyGem,
	},
	Profile{
		Name: "Ruby app",
		Dir:  FileInDir{"config.ru"},
		Unit: readRubyApp,
	},
	Profile{
		Name: "Ruby file",
		File: FileHasSuffix{".rb"},
		Unit: func(abspath, relpath string, config Config, info os.FileInfo) Unit {
			return &RubyFile{relpath}
		},
	},
}
View Source
var Default = Config{
	SkipDirs: []string{"node_modules", "vendor", "testdata", "site-packages", "bower_components"},
	NPMPackage: NPMPackageConfig{
		TestDirs:          []string{"test", "tests", "spec", "specs", "unit", "mocha", "karma"},
		TestSuffixes:      []string{"test.js", "tests.js", "spec.js", "specs.js"},
		SupportDirs:       []string{"build_support", "testdata"},
		SupportFilenames:  []string{"Gruntfile.js", "build.js", "Makefile.dryice.js", "build.config.js"},
		ExampleDirs:       []string{"example", "examples", "sample", "samples", "doc", "docs", "demo", "demos"},
		ScriptDirs:        []string{"bin", "script", "scripts", "tool", "tools"},
		GeneratedDirs:     []string{"build", "dist", "pkg"},
		GeneratedSuffixes: []string{".min.js", "-min.js", ".optimized.js", "-optimized.js"},
		VendorDirs:        []string{"vendor", "bower_components", "node_modules", "assets", "public", "static", "resources", "dep", "deps"},
	},
	GoPackage: GoPackageConfig{
		BuildContext: build.Default,
	},
	Ruby: RubyConfig{
		TestDirs:   []string{"spec", "specs", "test", "tests"},
		GemSrcDirs: []string{"lib"},
		AppSrcDirs: []string{"app", "lib", "config", "db"},
	},
}

Functions

func UnitType

func UnitType(unit Unit) string

Types

type BowerComponent

type BowerComponent struct {
	Dir       string
	BowerJSON json.RawMessage `json:",omitempty"`
}

BowerComponent represents a node.js package.

func (*BowerComponent) Path

func (u *BowerComponent) Path() string

Path returns the directory containing the bower.json file.

type Config

type Config struct {
	// Base is the base directory that all source unit paths are made relative to. Paths within the
	// concrete source unit structs are relative to the source unit path, not Base. If Base is the
	// empty string, the current working directory is used.
	Base string

	// Profiles is the list of profiles to use when scanning for source units. If nil,
	// AllProfiles is used.
	Profiles []Profile

	// SkipDirs is a list of names of directories that are skipped while scanning.
	SkipDirs []string

	// PathIndependent, if true, indicates that all filesystem paths should be relativized, if
	// possible, or else cleared.
	PathIndependent bool

	NPMPackage NPMPackageConfig
	GoPackage  GoPackageConfig
	Ruby       RubyConfig
}

Config specifies options for Scan.

func (Config) Scan

func (c Config) Scan(dir string) (found []Unit, err error)

Scan walks the directory tree at dir, looking for source units that match profiles in the configuration. Scan returns a list of all source units found.

type DirMatcher

type DirMatcher interface {
	DirMatches(path string, filenames []string) bool
}

type FileHasSuffix

type FileHasSuffix struct{ Suffix string }

func (FileHasSuffix) FileMatches

func (c FileHasSuffix) FileMatches(path string) bool

type FileInDir

type FileInDir struct{ Filename string }

FileInDir matches directories containing a file with the specified name.

func (FileInDir) DirMatches

func (c FileInDir) DirMatches(path string, filenames []string) bool

type FileMatcher

type FileMatcher interface {
	FileMatches(path string) bool
}

type FileSuffixInDir

type FileSuffixInDir struct{ Suffix string }

FileSuffixInDir matches directories containing a file with the specified filename suffix.

func (FileSuffixInDir) DirMatches

func (c FileSuffixInDir) DirMatches(path string, filenames []string) bool

type GoPackage

type GoPackage struct {
	build.Package
}

GoPackage represents a Go package.

func (*GoPackage) Path

func (u *GoPackage) Path() string

Path returns the directory that immediately contains the Go package.

type GoPackageConfig

type GoPackageConfig struct {
	BuildContext build.Context
}

type JavaProject

type JavaProject struct {
	Dir              string
	ProjectClasspath string
	SrcFiles         []string
	TestFiles        []string
}

JavaProject represents a Java project.

func (*JavaProject) Path

func (u *JavaProject) Path() string

Path returns the directory that immediately contains the Maven pom.xml.

type MarshalableUnit

type MarshalableUnit struct {
	Unit Unit
}

func (*MarshalableUnit) MarshalJSON

func (mu *MarshalableUnit) MarshalJSON() (data []byte, err error)

func (*MarshalableUnit) UnmarshalJSON

func (mu *MarshalableUnit) UnmarshalJSON(data []byte) (err error)

type NPMPackage

type NPMPackage struct {
	Dir            string
	PackageJSON    json.RawMessage `json:",omitempty"`
	LibFiles       []string        `json:",omitempty"`
	ScriptFiles    []string        `json:",omitempty"`
	SupportFiles   []string        `json:",omitempty"`
	ExampleFiles   []string        `json:",omitempty"`
	TestFiles      []string        `json:",omitempty"`
	VendorFiles    []string        `json:",omitempty"`
	GeneratedFiles []string        `json:",omitempty"`
}

NPMPackage represents an NPM package.

func (*NPMPackage) Path

func (u *NPMPackage) Path() string

Path returns the directory containing the package.json file.

type NPMPackageConfig

type NPMPackageConfig struct {
	TestDirs          []string
	TestSuffixes      []string
	SupportDirs       []string
	SupportFilenames  []string
	ExampleDirs       []string
	ScriptDirs        []string
	GeneratedDirs     []string
	GeneratedSuffixes []string
	VendorDirs        []string
}

type Profile

type Profile struct {
	// Name describes the source unit matched by this Profile.
	Name string

	Dir DirMatcher

	File FileMatcher

	TopLevelOnly bool

	Unit func(abspath, relpath string, config Config, info os.FileInfo) Unit
}

Profile represents criteria for a source unit and instructions on how to create it. For example, a simple profile might represent the following: "if there is a directory with a package.json file, designate the directory as a node.js package and include all *.js files in its subdirectories."

func (Profile) DirMatches

func (p Profile) DirMatches(path string, filenames []string) bool

type PythonModule

type PythonModule struct {
	File string
}

PythonPackage represents a Python package.

func (*PythonModule) Path

func (u *PythonModule) Path() string

type PythonPackage

type PythonPackage struct {
	Dir string
}

PythonPackage represents a Python package.

func (*PythonPackage) Path

func (u *PythonPackage) Path() string

Path returns the directory immediately containing the Python package.

type RubyApp

type RubyApp struct {
	Dir       string
	SrcFiles  []string
	TestFiles []string
}

RubyApp represents a Ruby App.

func (*RubyApp) Path

func (u *RubyApp) Path() string

Path returns the Ruby App's root directory (which contains the *.appspec file).

type RubyConfig

type RubyConfig struct {
	TestDirs             []string
	TestFilenamePatterns []string
	VendorDirs           []string
	GemSrcDirs           []string
	AppSrcDirs           []string
}

type RubyFile

type RubyFile struct {
	File string
}

individual Ruby file (collected when there is no Gemfile)

func (*RubyFile) Path

func (u *RubyFile) Path() string

type RubyGem

type RubyGem struct {
	Dir         string
	Name        string
	GemSpecFile string
	SrcFiles    []string
	TestFiles   []string
}

RubyGem represents a Ruby Gem.

func (*RubyGem) Path

func (u *RubyGem) Path() string

Path returns the Ruby Gem's root directory (which contains the *.gemspec file).

type Unit

type Unit interface {
	// Path is the path to this source unit (which is either a directory or file), relative to the
	// scanned directory.
	Path() string
}

Unit represents a "source unit," such as a Go package, a node.js package, or a Python package.

func Scan

func Scan(dir string) (found []Unit, err error)

Scan is shorthand for Default.Scan.

func UnmarshalJSON

func UnmarshalJSON(data []byte, unitType string) (unit Unit, err error)

UnmarshalJSON attempts to unmarshal JSON data into a new source unit struct of type unitType.

type Units

type Units []Unit

Units implements sort.Interface.

func (Units) Len

func (u Units) Len() int

func (Units) Less

func (u Units) Less(i, j int) bool

func (Units) Swap

func (u Units) Swap(i, j int)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL