Skip to content

Commit

Permalink
Merge pull request #69 from LukeShu/lukeshu/detect
Browse files Browse the repository at this point in the history
Fix detection for all dependencies of Emissary
  • Loading branch information
rick-a-lane-ii authored Feb 7, 2025
2 parents cfbbfcd + 4ff6b66 commit dc54059
Show file tree
Hide file tree
Showing 15 changed files with 1,382 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pkg/detectlicense/license_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const (
` in the documentation and/or other materials provided with the` + "\n" +
` distribution\.` + "\n"
bsdClause3 = `` +
` (?:3?[*.-] )?(?:Neither the .{1,80} nor the names of its contributors may|(?:My name, .{1,80}|The names of its contributors) may not)` + "\n" +
` (?:3?[*.-] )?(?:Neither (?:the )?.{1,80} nor the names of its contributors may|(?:My name, .{1,80}|The names of its contributors) may not)` + "\n" +
` be used to endorse or promote products derived from this software` + "\n" +
` without specific prior written permission\.` + "\n"
bsdSuffix = `` +
`THIS SOFTWARE IS PROVIDED BY .{1,80} AND CONTRIBUTORS` + "\n" +
`"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT` + "\n" +
`(?:"|`+"``"+`)AS IS(?:"|'') AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT` + "\n" +
`LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR` + "\n" +
`A PARTICULAR PURPOSE ARE DISCLAIMED\. IN NO EVENT SHALL THE COPYRIGHT` + "\n" +
`(OWNER|HOLDER)( OR CONTRIBUTORS)? BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,` + "\n" +
`A PARTICULAR PURPOSE ARE DISCLAIMED\. IN NO EVENT SHALL THE (COPYRIGHT` + "\n" +
`(OWNER|HOLDER)|REGENTS)( OR CONTRIBUTORS)? BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,` + "\n" +
`SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \(INCLUDING, BUT NOT` + "\n" +
`LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,` + "\n" +
`DATA, OR PROFITS; OR BUSINESS INTERRUPTION\) HOWEVER CAUSED AND ON ANY` + "\n" +
Expand Down
4 changes: 3 additions & 1 deletion pkg/detectlicense/license_mit.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ var (
`NONINFRINGEMENT\. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE`+"\n"+
`LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION`+"\n"+
`OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION`+"\n"+
`WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE\.?\s*`)))
`WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE\.?\s*`) +
// Allow a footer.
`(` + reQuote(`<http://www.opensource.org/licenses/mit-license.php>`) + `\s*)?`))
)
3 changes: 2 additions & 1 deletion pkg/detectlicense/license_mpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ func starify(str string) string {
return regexp.MustCompile(`\s+`).ReplaceAllLiteralString(str, `\s+(?:\*+\s+)*`)
}

var reMPL = regexp.MustCompile(`\s*` + reWrap(`Mozilla Public License,? [Vv]ersion 2\.0
var reMPL = regexp.MustCompile(`(?:Copyright [^\n]*\n)*\s*` +
reWrap(`Mozilla Public License,? [Vv]ersion 2\.0
=*
1\. Definitions
Expand Down
32 changes: 32 additions & 0 deletions pkg/detectlicense/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,32 @@ func IdentifyLicenses(body []byte) map[License]struct{} {
// sigs.k8s.io/yaml/LICENSE
licenses[MIT] = struct{}{}
licenses[BSD3] = struct{}{}
case reMatch(regexp.MustCompile(reMIT.String()+
reBSD3.String()+
reWrap(`# The forked go-yaml\.v3 library under this project is covered by two different licenses \(MIT and Apache\):`)+`\s*`+
`#+ MIT License #+\s*`+
reWrap(yamlHeader)+`\s*`+
reMIT.String()+`\s*`+
`#+ Apache License #+\s*`+
reQuote(`All the remaining project files are covered by the Apache license:`)+`\s*`+
reApacheStatement.String()+
reWrap(`# The forked go-yaml\.v2 library under the project is covered by an Apache license:`)+`\s*`+
reApacheLicense.String()),
body):
// sigs.k8s.io/yaml/LICENSE
licenses[Apache2] = struct{}{}
licenses[BSD3] = struct{}{}
licenses[MIT] = struct{}{}
case reMatch(regexp.MustCompile(`\s*`+
`(([-=]*|[^\n]*[Ff]iles [^\n]*licensed under:)\n)*\s*`+
reApacheLicense.String()+
`(([-=]*|[^\n]*[Ff]iles [^\n]*licensed under:|The common/types/pb/equal\.go modification of proto\.Equal logic)\n)*\s*`+
reBSD3.String()),
body):
// sigs.k8s.io/json/LICENSE
// github.com/google/cel-go
licenses[Apache2] = struct{}{}
licenses[BSD3] = struct{}{}
case reMatch(regexp.MustCompile(reMIT.String()+`\s*- Based on \S*, which has the following license:\n"""\s*`+reMIT.String()+`\s*"""\s*`), body):
// github.com/shopspring/decimal/LICENSE
licenses[MIT] = struct{}{}
Expand All @@ -468,6 +494,12 @@ func IdentifyLicenses(body []byte) map[License]struct{} {
licenses[Apache2] = struct{}{}
licenses[BSD3] = struct{}{}
licenses[MIT] = struct{}{}
case reMatch(regexp.MustCompile(reBSD3.String()+`\s*=+\s*`+reBSD3.String()), body):
// github.com/cloudflare/circl/LICENSE
licenses[BSD3] = struct{}{}
case reMatch(regexp.MustCompile(`goproperties - properties file decoder for Go\s*`+reBSD2.String()), body):
// github.com/magiconair/properties/LICENSE
licenses[BSD2] = struct{}{}
case string(body) == xzPublicDomain:
// github.com/xi2/xz/LICENSE
licenses[PublicDomain] = struct{}{}
Expand Down
Loading

0 comments on commit dc54059

Please sign in to comment.