Skip to content

Commit

Permalink
Change name to DEBRICKED_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-debricked committed Nov 22, 2024
1 parent 9ba411d commit 3e178b6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ jobs:
distribution: 'temurin'

- name: Install Debricked CLI
run: go install -ldflags "-X main.version=${GITHUB_REF#refs/heads/}" ./cmd/debricked
run: |
go install -ldflags "-X main.version=${DEBRICKED_VERSION:-GITHUB_REF#refs/heads/}" ./cmd/debricked
- name: Callgraph E2E
run: ./scripts/test_e2e_callgraph_java_version.sh ${{matrix.java}}
Expand Down
27 changes: 18 additions & 9 deletions internal/callgraph/language/java/soot_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (sh SootHandler) downloadCompressedSootWrapper(fs ioFs.IFileSystem, zipFile
version,
".zip",
}, "")
fmt.Println("URL=", fullURLFile)

client := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error {
Expand All @@ -101,10 +102,11 @@ func (sh SootHandler) downloadCompressedSootWrapper(fs ioFs.IFileSystem, zipFile
func (sh SootHandler) GetSootWrapper(version string, fs ioFs.IFileSystem, arc ioFs.IArchive) (string, error) {
versionInt, err := strconv.Atoi(version)
if err != nil {
return "", fmt.Errorf("error when trying to convert java version string to int")
return "", fmt.Errorf("could not convert version to int")
}
if versionInt < 11 {
return "", fmt.Errorf("lowest supported version for running callgraph generation is 11")
version, err = sh.getSootHandlerJavaVersion(versionInt)
if err != nil {
return "", err
}
debrickedDir := ".debricked"
if _, err := fs.Stat(debrickedDir); fs.IsNotExist(err) {
Expand All @@ -119,17 +121,24 @@ func (sh SootHandler) GetSootWrapper(version string, fs ioFs.IFileSystem, arc io
return "", err
}
if _, err := fs.Stat(path); fs.IsNotExist(err) {
if versionInt >= 21 {
if version == "21" {
return sh.initializeSootWrapper(fs, debrickedDir)
}
if versionInt >= 17 {
version = "17"
} else {
version = "11"
} // Handling correct jar to install

return path, sh.downloadSootWrapper(arc, fs, path, version)
}

return path, nil
}

func (sh SootHandler) getSootHandlerJavaVersion(version int) (string, error) {
if version >= 21 {
return "21", nil
} else if version >= 17 {
return "17", nil
} else if version >= 11 {
return "11", nil
} else {
return "", fmt.Errorf("lowest supported version for running callgraph generation is 11")
}
}
55 changes: 55 additions & 0 deletions internal/callgraph/language/java/soot_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,58 @@ func TestGetSootWrapperMkdirError(t *testing.T) {
assert.Error(t, err)
assert.Equal(t, err.Error(), errString)
}

func TestGetSootHandlerJavaVersion(t *testing.T) {
sootHandler := SootHandler{}
tests := []struct {
name string
version int
expectedVersion string
expectError bool
}{
{
name: "Unsupported version",
version: 8,
expectedVersion: "",
expectError: true,
},
{
name: "Version 11",
version: 11,
expectedVersion: "11",
expectError: false,
},
{
name: "Version 17",
version: 17,
expectedVersion: "17",
expectError: false,
},
{
name: "Version 21",
version: 21,
expectedVersion: "21",
expectError: false,
},
{
name: "Version not int",
version: 12,
expectedVersion: "11",
expectError: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := sootHandler.getSootHandlerJavaVersion(tt.version)

if tt.expectError {
assert.Error(t, err)
assert.Empty(t, result)
} else {
assert.NoError(t, err)
assert.NotEmpty(t, result)
}
})
}
}
2 changes: 1 addition & 1 deletion internal/cmd/callgraph/callgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func RunE(callgraph callgraph.IGenerator) func(_ *cobra.Command, args []string)
}

configs := []conf.IConfig{}
version := viper.GetString("version")
version := viper.GetString("cliVersion")

for _, language := range languages {
configs = append(configs, conf.NewConfig(language, args, map[string]string{}, !buildDisabled, languageMap[language], version))
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Complete documentation is available at https://docs.debricked.com/tools-and-inte
},
Version: version,
}
viper.Set("cliVersion", version)
viper.SetEnvPrefix("DEBRICKED")
viper.AutomaticEnv()
viper.MustBindEnv(AccessTokenFlag)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestNewRootCmd(t *testing.T) {
}
}
assert.Truef(t, match, "failed to assert that flag was present: "+OldAccessTokenFlag)
assert.Len(t, viperKeys, 22)
assert.Len(t, viperKeys, 23)
}

func TestPreRun(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if ! command -v git &> /dev/null
then
echo -e "Failed to find git, thus also the version. Version will be set to v0.0.0"
fi
version=${VERSION:-$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)}
version=${DEBRICKED_VERSION:-$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)}
ldFlags="-X main.version=${version}"
go install -ldflags "${ldFlags}" ./cmd/debricked
go generate -v -x ./cmd/debricked
Expand Down

0 comments on commit 3e178b6

Please sign in to comment.