Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed Jun 7, 2018
1 parent 52f7fd3 commit e8bfc5c
Show file tree
Hide file tree
Showing 26 changed files with 310 additions and 284 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ builds:
- linux
goarch:
- amd64
ldflags: -s -w -X github.com/fossas/fossa-cli/cmd/fossa/version.version={{.Version}} -X github.com/fossas/fossa-cli/cmd/fossa/version.commit={{.Commit}} -X "github.com/fossas/fossa-cli/cmd/fossa/version.goversion={{.Env.GOVERSION}}" -X github.com/fossas/fossa-cli/cmd/fossa/version.buildType=production
ldflags: -s -w -X github.com/fossas/fossa-cli/cmd/fossa/version.version={{.Version}} -X github.com/fossas/fossa-cli/cmd/fossa/version.commit={{.Commit}} -X "github.com/fossas/fossa-cli/cmd/fossa/version.goversion={{.Env.GOVERSION}}" -X github.com/fossas/fossa-cli/cmd/fossa/version.buildType=release
archive:
format_overrides:
- goos: windows
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ RUN wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip -O
sudo chmod -R 775 /opt/android-sdk
ENV PATH=$PATH:/opt/android-sdk/tools/bin ANDROID_HOME=/opt/android-sdk

# Install Cocoapods
RUN sudo gem install cocoapods -v 0.39.0

# Install Go compiler
RUN wget https://dl.google.com/go/go1.9.4.linux-amd64.tar.gz -O /tmp/go.tar.gz && \
sudo tar -xf /tmp/go.tar.gz -C /usr/local
Expand Down Expand Up @@ -89,6 +86,9 @@ RUN sudo apt-get install -y ruby-full
# Install Ruby build tools
RUN sudo gem install bundler

# Install Cocoapods
RUN sudo gem install cocoapods -v 0.39.0

# Install PHP runtime
RUN sudo apt-get install -y php7.2 php7.2-gd php7.2-curl php7.2-intl

Expand Down
25 changes: 20 additions & 5 deletions analyzers/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ package golang
import (
"os"

"github.com/fossas/fossa-cli/buildtools/golang"
"github.com/fossas/fossa-cli/buildtools/gocmd"
"github.com/fossas/fossa-cli/exec"
"github.com/fossas/fossa-cli/pkg"
"github.com/fossas/fossa-cli/project"
"github.com/pkg/errors"
)

// An Analyzer contains structs used in the analysis of Go packages.
type Analyzer struct {
Go golang.Go
Go gocmd.Go
GoVersion string
}

Expand All @@ -30,7 +32,7 @@ func New(options project.GoOptions) (*Analyzer, error) {
return nil, err
}
return &Analyzer{
Go: golang.Go{
Go: gocmd.Go{
Cmd: cmd,
OS: options.BuildOS,
Arch: options.BuildArch,
Expand All @@ -41,8 +43,21 @@ func New(options project.GoOptions) (*Analyzer, error) {

// Discover runs `go list ./...`.
func (a *Analyzer) Discover(dir string) ([]project.Project, error) {
a.Go.List([]string{"./..."})
return nil, nil
found, err := a.Go.List([]string{"./..."})
if err != nil {
return nil, errors.Wrap(err, "could not find Go projects")
}

var projects []project.Project
for _, p := range found {
projects = append(projects, project.Project{
Name: p.Name,
Type: pkg.Go,
IsExecutable: p.Name == "main",
BuildTarget: p.ImportPath,
})
}
return projects, nil
}

// Clean runs `go clean $PKG`.
Expand Down
10 changes: 5 additions & 5 deletions api/fossa/fossa.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var (
apiKey string
)

// Initialize sets up an API instance.
func Initialize(server, APIKey string) error {
// Init sets up an API instance.
func Init(server, APIKey string) error {
var err error
serverURL, err = url.Parse(server)
if err != nil {
Expand All @@ -25,9 +25,9 @@ func Initialize(server, APIKey string) error {
return nil
}

// MustInitialize crashes and logs a fatal exception if `Initialize` fails.
func MustInitialize(server, APIKey string) {
err := Initialize(server, APIKey)
// MustInit crashes and logs a fatal exception if `Init` fails.
func MustInit(server, APIKey string) {
err := Init(server, APIKey)
if err != nil {
log.Logger.Fatal(log.Entry{
Message: "could not initialize API",
Expand Down
1 change: 1 addition & 0 deletions buildtools/bower/bower.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package bower
4 changes: 2 additions & 2 deletions buildtools/golang/golang.go → buildtools/gocmd/go.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package golang provides functions for working with the Go tool. This package
// Package gocmd provides functions for working with the Go tool. This package
// is not named "go" because that name collides with a reserved keyword.
package golang
package gocmd

import (
"encoding/json"
Expand Down
24 changes: 24 additions & 0 deletions buildtools/gocmd/go_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gocmd_test

import "testing"

// foo bar
func TestHandleErrBuildTags(t *testing.T) {
t.Skip("unimplemented")
}

func TestHandleErrImportComments(t *testing.T) {
t.Skip("unimplemented")
}

func TestNoRecursionWhenCallingProjectName(t *testing.T) {
t.Skip("unimplemented")
}

func TestNoRecursionWhenCallingWithinRepo(t *testing.T) {
t.Skip("unimplemented")
}

func TestNoRecursionWhenCallingIsInternal(t *testing.T) {
t.Skip("unimplemented")
}
20 changes: 0 additions & 20 deletions buildtools/golang/golang_test.go

This file was deleted.

18 changes: 0 additions & 18 deletions cmd/fossa/cliutil/init.go

This file was deleted.

18 changes: 0 additions & 18 deletions cmd/fossa/cmd.go

This file was deleted.

19 changes: 17 additions & 2 deletions cmd/fossa/init.go → cmd/fossa/cmd/init/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package init

import (
"fmt"
Expand All @@ -10,11 +10,26 @@ import (
"github.com/urfave/cli"

"github.com/fossas/fossa-cli/builders"
config "github.com/fossas/fossa-cli/config"
"github.com/fossas/fossa-cli/cmd/fossa/flags"
"github.com/fossas/fossa-cli/config"
"github.com/fossas/fossa-cli/log"
"github.com/fossas/fossa-cli/module"
)

var Cmd = cli.Command{
Name: "init",
Usage: "Initialize a .fossa.yml configuration file",
Action: Run,
Flags: flags.WithGlobalFlags([]cli.Flag{
cli.BoolFlag{Name: "O, overwrite", Usage: "overwrite modules in config even if they exist"},
cli.BoolFlag{Name: "include-all", Usage: "include suspicious modules (`docs`, `test` or `example` in name)"},
}),
}

func Run(ctx *cli.Context) {}

func Do() {}

func initCmd(c *cli.Context) {
conf, err := config.New(c)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/fossa/cmd/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/urfave/cli"

"github.com/fossas/fossa-cli/api/fossa"
"github.com/fossas/fossa-cli/cmd/fossa/cliutil"
"github.com/fossas/fossa-cli/cmd/fossa/cmdutil"
"github.com/fossas/fossa-cli/cmd/fossa/flags"
"github.com/fossas/fossa-cli/config"
"github.com/fossas/fossa-cli/log"
Expand Down Expand Up @@ -89,7 +89,8 @@ func getInput(ctx *cli.Context, usingLocators bool) ([]fossa.SourceUnit, error)
}

func Run(ctx *cli.Context) {
c := cliutil.Initialize(ctx, true)
cmdutil.Init(ctx)
c := config.MustNew(ctx)

data, err := getInput(ctx, c.UploadCmd.UseLocators)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions cmd/fossa/cmdutil/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmdutil

import (
"github.com/urfave/cli"

"github.com/fossas/fossa-cli/api/fossa"
"github.com/fossas/fossa-cli/config"
"github.com/fossas/fossa-cli/log"
)

func Init(ctx *cli.Context) {
config.Init(ctx)
log.Init(config.Interactive(), config.Debug())
}

func InitWithAPI(ctx *cli.Context) {
Init(ctx)
fossa.MustInit(config.Endpoint(), config.APIKey())
}
41 changes: 30 additions & 11 deletions cmd/fossa/flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
package flags

import "github.com/urfave/cli"
import (
"fmt"

var Config = cli.StringFlag{Name: "c, config", Usage: "path to config file (default: '.fossa.{yml,yaml}')"}
"github.com/urfave/cli"
)

func abbr(fullname string) string {
return fmt.Sprintf("%s, %s", fullname[0], fullname)
}

func WithAPIFlags(f []cli.Flag) []cli.Flag {
return append(f, API...)
}

var (
API = []cli.Flag{Endpoint, Fetcher, Project, Revision, Branch}
Endpoint = cli.StringFlag{Name: "e, endpoint", Usage: "the FOSSA server endpoint (default: 'https://app.fossa.io')"}
Fetcher = cli.StringFlag{Name: "f, fetcher", Usage: "type of fetcher to use for fossa. (default: 'custom')"}
Project = cli.StringFlag{Name: "p, project", Usage: "this repository's URL or VCS endpoint (default: VCS remote 'origin')"}
Revision = cli.StringFlag{Name: "r, revision", Usage: "this repository's current revision hash (default: VCS hash HEAD)"}
Branch = cli.StringFlag{Name: "b, branch", Usage: "this repository's current branch (default: current VCS branch)"}
API = []cli.Flag{Endpoint, Fetcher, Project, Revision, Branch}
EndpointFlagName = "endpoint"
Endpoint = cli.StringFlag{Name: abbr(EndpointFlagName), Usage: "the FOSSA server endpoint (default: 'https://app.fossa.io')"}
FetcherFlagName = "fetcher"
Fetcher = cli.StringFlag{Name: abbr(FetcherFlagName), Usage: "type of fetcher to use for fossa. (default: 'custom')"}
ProjectFlagName = "project"
Project = cli.StringFlag{Name: abbr(ProjectFlagName), Usage: "this repository's URL or VCS endpoint (default: VCS remote 'origin')"}
RevisionFlagName = "revision"
Revision = cli.StringFlag{Name: abbr(RevisionFlagName), Usage: "this repository's current revision hash (default: VCS hash HEAD)"}
BranchFlagName = "branch"
Branch = cli.StringFlag{Name: abbr(BranchFlagName), Usage: "this repository's current branch (default: current VCS branch)"}
)

func WithGlobalFlags(f []cli.Flag) []cli.Flag {
return append(f, Global...)
}

var (
Global = []cli.Flag{NoAnsi, Debug}
NoAnsi = cli.BoolFlag{Name: "no-ansi", Usage: "do not use interactive mode (ANSI codes)"}
Debug = cli.BoolFlag{Name: "debug", Usage: "print debug information to stderr"}
Global = []cli.Flag{Config, NoAnsi, Debug}
ConfigFlagName = "config"
Config = cli.StringFlag{Name: abbr(ConfigFlagName), Usage: "path to config file (default: '.fossa.{yml,yaml}')"}
NoAnsiFlagName = "no-ansi"
NoAnsi = cli.BoolFlag{Name: NoAnsiFlagName, Usage: "do not use interactive mode (ANSI codes)"}
DebugFlagName = "debug"
Debug = cli.BoolFlag{Name: DebugFlagName, Usage: "print debug information to stderr"}
)

var (
AnalysisShowOutput = cli.BoolFlag{Name: "o, output", Usage: "print results to stdout instead of uploading to FOSSA"}
)

0 comments on commit e8bfc5c

Please sign in to comment.