diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ed1ad1a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Philipp Heuer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/analyzer/composer/composer.go b/analyzer/composer/composer.go new file mode 100644 index 0000000..0263635 --- /dev/null +++ b/analyzer/composer/composer.go @@ -0,0 +1,41 @@ +package composer + +import ( + "path/filepath" + + "github.com/cidverse/repoanalyzer/analyzerapi" + "github.com/gosimple/slug" +) + +type Analyzer struct{} + +func (a Analyzer) GetName() string { + return "composer" +} + +func (a Analyzer) Analyze(ctx analyzerapi.AnalyzerContext) []*analyzerapi.ProjectModule { + var result []*analyzerapi.ProjectModule + + for _, file := range ctx.FilesByExtension["json"] { + filename := filepath.Base(file) + if filename == "composer.json" { + module := analyzerapi.ProjectModule{ + RootDirectory: ctx.ProjectDir, + Directory: filepath.Dir(file), + Name: filepath.Base(filepath.Dir(file)), + Slug: slug.Make(filepath.Base(filepath.Dir(file))), + Discovery: []analyzerapi.ProjectModuleDiscovery{{File: file}}, + BuildSystem: analyzerapi.BuildSystemComposer, + BuildSystemSyntax: analyzerapi.BuildSystemSyntaxDefault, + Language: nil, + Dependencies: nil, + Submodules: nil, + Files: ctx.Files, + FilesByExtension: ctx.FilesByExtension, + } + analyzerapi.AddModuleToResult(&result, &module) + } + } + + return result +} diff --git a/analyzer/composer/composer_test.go b/analyzer/composer/composer_test.go new file mode 100644 index 0000000..a57555f --- /dev/null +++ b/analyzer/composer/composer_test.go @@ -0,0 +1,27 @@ +package composer + +import ( + "testing" + + "github.com/cidverse/repoanalyzer/util" + "github.com/rs/zerolog/log" + + "github.com/cidverse/repoanalyzer/analyzerapi" + "github.com/stretchr/testify/assert" +) + +func TestAnalyzer_AnalyzeComposer(t *testing.T) { + ctx := analyzerapi.GetAnalyzerContext(util.GetTestDataDir(t, "composer")) + + analyzer := Analyzer{} + result := analyzer.Analyze(ctx) + + // module + assert.Len(t, result, 1) + assert.Equal(t, "composer", result[0].Name) + assert.Equal(t, "composer", string(result[0].BuildSystem)) + assert.Equal(t, "default", string(result[0].BuildSystemSyntax)) + + // print result + log.Info().Interface("result", result).Msg("output") +} diff --git a/analyzerapi/types.go b/analyzerapi/types.go index 086e716..a6c4c86 100644 --- a/analyzerapi/types.go +++ b/analyzerapi/types.go @@ -80,6 +80,7 @@ const ( BuildSystemSetupPy ProjectBuildSystem = "setup.py" BuildSystemPoetry ProjectBuildSystem = "poetry" BuildSystemMkdocs ProjectBuildSystem = "mkdocs" + BuildSystemComposer ProjectBuildSystem = "composer" ) type ProjectBuildSystemSyntax string diff --git a/go.sum b/go.sum index b54ffc8..da0cb48 100644 --- a/go.sum +++ b/go.sum @@ -32,8 +32,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/thoas/go-funk v0.9.2 h1:oKlNYv0AY5nyf9g+/GhMgS/UO2ces0QRdPKwkhY3VCk= -github.com/thoas/go-funk v0.9.2/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw= github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= golang.org/x/exp v0.0.0-20220927162542-c76eaa363f9d h1:3wgmvnqHUJ8SxiNWwea5NCzTwAVfhTtuV+0ClVFlClc= diff --git a/testdata/composer/composer.json b/testdata/composer/composer.json new file mode 100644 index 0000000..9737eb9 --- /dev/null +++ b/testdata/composer/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "monolog/monolog": "2.0.0" + } +} \ No newline at end of file