Skip to content

Commit d3453f8

Browse files
Merge pull request #321 from wttech/sdk-os-configurable
SDK OS configurable
2 parents 9ef3c6c + 5876e6d commit d3453f8

File tree

9 files changed

+102
-3
lines changed

9 files changed

+102
-3
lines changed

cmd/aem/vendor.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func (c *CLI) vendorCmd() *cobra.Command {
1414
}
1515
cmd.AddCommand(c.vendorListCmd())
1616
cmd.AddCommand(c.vendorPrepareCmd())
17+
cmd.AddCommand(c.vendorCleanCmd())
1718

1819
return cmd
1920
}
@@ -74,3 +75,24 @@ func (c *CLI) vendorPrepareCmd() *cobra.Command {
7475
}
7576
return cmd
7677
}
78+
79+
func (c *CLI) vendorCleanCmd() *cobra.Command {
80+
cmd := &cobra.Command{
81+
Use: "clean",
82+
Short: "Clean vendor tools",
83+
Aliases: []string{"cl"},
84+
Run: func(cmd *cobra.Command, args []string) {
85+
changed, err := c.aem.VendorManager().CleanWithChanged()
86+
if err != nil {
87+
c.Error(err)
88+
return
89+
}
90+
if changed {
91+
c.Changed("vendor tools cleaned")
92+
} else {
93+
c.Ok("vendor tools already cleaned")
94+
}
95+
},
96+
}
97+
return cmd
98+
}

examples/docker/src/aem/default/etc/aem.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ vendor:
241241
# AEM License properties file
242242
license_file: "aem/home/lib/license.properties"
243243

244+
# AEM SDK source files
245+
sdk:
246+
# Controls which distribution of dispatcher is unpacked (auto|unix|windows)
247+
os: auto
248+
244249
# JDK used to: run AEM instances, build OSGi bundles, assemble AEM packages
245250
java:
246251
# Require following versions before e.g running AEM instances

pkg/cfg/defaults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/wttech/aemc/pkg/common/fmtx"
88
"github.com/wttech/aemc/pkg/instance"
99
"github.com/wttech/aemc/pkg/pkg"
10+
"github.com/wttech/aemc/pkg/sdk"
1011
"time"
1112
)
1213

@@ -36,6 +37,8 @@ func (c *Config) setDefaults() {
3637
v.SetDefault("vendor.quickstart.dist_file", common.QuickstartDistFile)
3738
v.SetDefault("vendor.quickstart.license_file", common.QuickstartLicenseFile)
3839

40+
v.SetDefault("vendor.sdk.os", sdk.OSAuto)
41+
3942
v.SetDefault("vendor.java.home_dir", "")
4043
v.SetDefault("vendor.java.version_constraints", []string{"=> 1.8, < 1.9", "=> 11, < 12", ">= 17, < 18", "=> 21, < 22"})
4144
v.SetDefault("vendor.java.download.url", c.tplString("https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.25%2B9/OpenJDK11U-jdk_[[.Arch]]_[[.Os]]_hotspot_11.0.25_9.[[.ArchiveExt]]"))

pkg/project/app_classic/aem/default/etc/aem.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ vendor:
243243
# AEM License properties file
244244
license_file: "aem/home/lib/license.properties"
245245

246+
# AEM SDK source files
247+
sdk:
248+
# Controls which distribution of dispatcher is unpacked (auto|unix|windows)
249+
os: auto
250+
246251
# JDK used to: run AEM instances, build OSGi bundles, assemble AEM packages
247252
java:
248253
# Require following versions before e.g running AEM instances

pkg/project/app_cloud/aem/default/etc/aem.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ vendor:
243243
# AEM License properties file
244244
license_file: "aem/home/lib/license.properties"
245245

246+
# AEM SDK source files
247+
sdk:
248+
# Controls which distribution of dispatcher is unpacked (auto|unix|windows)
249+
os: auto
250+
246251
# JDK used to: run AEM instances, build OSGi bundles, assemble AEM packages
247252
java:
248253
# Require following versions before e.g running AEM instances

pkg/project/instance/aem/default/etc/aem.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ vendor:
238238
# AEM License properties file
239239
license_file: "aem/home/lib/license.properties"
240240

241+
# AEM SDK source files
242+
sdk:
243+
# Controls which distribution of dispatcher is unpacked (auto|unix|windows)
244+
os: auto
245+
241246
# JDK used to: run AEM instances, build OSGi bundles, assemble AEM packages
242247
java:
243248
# Require following versions before e.g running AEM instances

pkg/sdk.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@ package pkg
22

33
import (
44
"fmt"
5+
"github.com/samber/lo"
56
log "github.com/sirupsen/logrus"
67
"github.com/wttech/aemc/pkg/common/execx"
78
"github.com/wttech/aemc/pkg/common/filex"
89
"github.com/wttech/aemc/pkg/common/osx"
910
"github.com/wttech/aemc/pkg/common/pathx"
11+
"github.com/wttech/aemc/pkg/sdk"
1012
"path/filepath"
13+
"strings"
1114
)
1215

1316
func NewSDK(vendorManager *VendorManager) *SDK {
14-
return &SDK{vendorManager: vendorManager}
17+
cv := vendorManager.aem.Config().Values()
18+
19+
return &SDK{
20+
vendorManager: vendorManager,
21+
22+
OS: cv.GetString("vendor.sdk.os"),
23+
}
1524
}
1625

1726
type SDK struct {
1827
vendorManager *VendorManager
28+
29+
OS string
1930
}
2031

2132
func (s SDK) Dir() string {
@@ -118,7 +129,12 @@ func (s SDK) findFile(pattern string) (string, error) {
118129
}
119130

120131
func (s SDK) unpackDispatcher() error {
121-
if osx.IsWindows() {
132+
os, err := s.determineOs()
133+
if err != nil {
134+
return err
135+
}
136+
137+
if os == sdk.OSWindows {
122138
zip, err := s.dispatcherToolsWindowsZip()
123139
if err != nil {
124140
return err
@@ -145,6 +161,20 @@ func (s SDK) unpackDispatcher() error {
145161
return nil
146162
}
147163

164+
func (s SDK) determineOs() (string, error) {
165+
os := s.OS
166+
if !lo.Contains(sdk.OsTypes(), os) {
167+
return "", fmt.Errorf("unsupported SDK OS type '%s', supported types are: %s", os, strings.Join(sdk.OsTypes(), ", "))
168+
}
169+
if os != sdk.OSAuto {
170+
return os, nil
171+
}
172+
if osx.IsWindows() {
173+
return sdk.OSWindows, nil
174+
}
175+
return sdk.OSUnix, nil
176+
}
177+
148178
func (s SDK) Destroy() error {
149179
return pathx.Delete(s.Dir())
150180
}

pkg/sdk/constants.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package sdk
2+
3+
const (
4+
OSAuto = "auto"
5+
OSUnix = "unix"
6+
OSWindows = "windows"
7+
)
8+
9+
func OsTypes() []string {
10+
return []string{OSAuto, OSUnix, OSWindows}
11+
}

pkg/vendor_manager.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package pkg
22

3+
import "github.com/wttech/aemc/pkg/common/pathx"
4+
35
// VendorManager manages third-party tools like JDK, OakRun, and Vault CLI
46
type VendorManager struct {
57
aem *AEM
@@ -34,7 +36,7 @@ func (vm *VendorManager) PrepareWithChanged(requireLibs bool) (bool, error) {
3436
changed := false
3537

3638
javaChanged, err := vm.javaManager.PrepareWithChanged()
37-
changed = changed || javaChanged
39+
changed = javaChanged
3840
if err != nil {
3941
return changed, err
4042
}
@@ -62,6 +64,17 @@ func (vm *VendorManager) PrepareWithChanged(requireLibs bool) (bool, error) {
6264
return changed, nil
6365
}
6466

67+
func (vm *VendorManager) CleanWithChanged() (bool, error) {
68+
dir := vm.aem.BaseOpts().ToolDir
69+
if !pathx.Exists(dir) {
70+
return false, nil
71+
}
72+
if err := pathx.Delete(dir); err != nil {
73+
return false, err
74+
}
75+
return true, nil
76+
}
77+
6578
func (vm *VendorManager) JavaManager() *JavaManager {
6679
return vm.javaManager
6780
}

0 commit comments

Comments
 (0)