Skip to content

Commit

Permalink
Notify on GPL files
Browse files Browse the repository at this point in the history
add build script
  • Loading branch information
Aviad Lichtenstadt committed Jan 14, 2019
1 parent 13099dc commit f98d13e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
14 changes: 14 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

for os in linux darwin; do
export GOOS="$os"
echo "build for $GOOS:"
for arch in 386 amd64; do
export GOARCH="$arch"
NAME=bin/thirdPartyLicenseCollector_${GOOS}_${GOARCH}
if [ $arch = "amd64" ]
then
go build -o $NAME .
fi
done
done
33 changes: 27 additions & 6 deletions license-collector/LicenseCollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package licensecollector
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"path/filepath"
Expand All @@ -23,19 +24,27 @@ func Collect(projectGO, projcetNPM string, fileName string) error {
foundManualLicense := map[string]string{}

licenseMissing = false
var err error
if len(projectGO) > 0 {
collectGoLicenseFiles(projectGO, licenseMap, foundManualLicense)
err = collectGoLicenseFiles(projectGO, licenseMap, foundManualLicense)
}
if len(projcetNPM) > 0 {
collectNpmLicenseFiles(projcetNPM, licenseMap, foundManualLicense)
err = collectNpmLicenseFiles(projcetNPM, licenseMap, foundManualLicense)
}
if err != nil {
return err
}
if len(licenseMap)+len(foundManualLicense) == 0 {
return errors.New("No licenses handled")
}
if licenseMissing {
return errors.New("License missing")
}
err := ioutil.WriteFile(fileName, []byte(generateLicenseFile(licenseMap, foundManualLicense)), 0644)
fileData, err := generateLicenseFile(licenseMap, foundManualLicense)
if err != nil {
return err
}
err = ioutil.WriteFile(fileName, []byte(fileData), 0644)
if err != nil {
return err
}
Expand Down Expand Up @@ -129,22 +138,34 @@ func doParseFile(dir, fileDir string, manualLicense map[string]string, licenseMa
}
}

func generateLicenseFile(lTypeMap map[string][]string, lContentMap map[string]string) string {
func generateLicenseFile(lTypeMap map[string][]string, lContentMap map[string]string) (string, error) {
licenseMap := initLicenseMap()
res := ""
wrongLicense := map[string][]string{}
for k, v := range lTypeMap {
fullLicense := licenseMap[k]
fullLicense, ok := licenseMap[k]
if !ok {
wrongLicense[k] = v
continue
}
projects := ""
for _, p := range v {
projects += p + "\n"
}
projects += fullLicense + "\n"
res += projects
}
if len(wrongLicense) > 0 {
errMsg := "Wrong license files for the following libs"
for k, v := range wrongLicense {
errMsg += "\n " + k + ": " + fmt.Sprintf("%v", v)
}
return "", fmt.Errorf(errMsg)
}
for project, fullLicense := range lContentMap {
res += project + "\n" + fullLicense + "\n"
}
return res
return res, nil
}

// InStringSlice checks if val string is in s slice, case insensitive.
Expand Down

0 comments on commit f98d13e

Please sign in to comment.