Skip to content

Commit

Permalink
Merge branch 'main' into empty-lines
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-przybyl-wttech committed May 7, 2024
2 parents 9ea4eb9 + 0855f90 commit 58ed14b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 14 deletions.
6 changes: 6 additions & 0 deletions examples/docker/src/aem/default/etc/aem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ instance:
start_level: 20
refresh_packages: true

# Force re-installing of snapshot OSGi bundles (just built / unreleased)
snapshot_patterns: [ "**/*-SNAPSHOT.jar" ]
snapshot_ignored: false
# Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged
snapshot_install_skipping: true

# Crypto Support
crypto:
key_bundle_symbolic_name: com.adobe.granite.crypto.file
Expand Down
4 changes: 4 additions & 0 deletions pkg/cfg/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (c *Config) setDefaults() {
v.SetDefault("instance.osgi.bundle.install.start_level", 20)
v.SetDefault("instance.osgi.bundle.install.refresh_packages", true)

v.SetDefault("instance.osgi.bundle.snapshot_install_skipping", true)
v.SetDefault("instance.osgi.bundle.snapshot_ignored", false)
v.SetDefault("instance.osgi.bundle.snapshot_patterns", []string{"**/*-SNAPSHOT.jar"})

v.SetDefault("instance.ssl.setup_timeout", time.Second*30)

v.SetDefault("instance.crypto.key_bundle_symbolic_name", "com.adobe.granite.crypto.file")
Expand Down
91 changes: 78 additions & 13 deletions pkg/osgi_bundle_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ import (
"fmt"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
"github.com/wttech/aemc/pkg/common/filex"
"github.com/wttech/aemc/pkg/common/fmtx"
"github.com/wttech/aemc/pkg/common/osx"
"github.com/wttech/aemc/pkg/common/pathx"
"github.com/wttech/aemc/pkg/common/stringsx"
"github.com/wttech/aemc/pkg/osgi"
"path/filepath"
"time"
)

type OSGiBundleManager struct {
instance *Instance

InstallStart bool
InstallStartLevel int
InstallRefreshPackages bool
InstallStart bool
InstallStartLevel int
InstallRefreshPackages bool
SnapshotInstallSkipping bool
SnapshotIgnored bool
SnapshotPatterns []string
}

func NewBundleManager(instance *Instance) *OSGiBundleManager {
Expand All @@ -22,9 +31,12 @@ func NewBundleManager(instance *Instance) *OSGiBundleManager {
return &OSGiBundleManager{
instance: instance,

InstallStart: cv.GetBool("instance.osgi.bundle.install.start"),
InstallStartLevel: cv.GetInt("instance.osgi.bundle.install.start_level"),
InstallRefreshPackages: cv.GetBool("instance.osgi.bundle.install.refresh_packages"),
InstallStart: cv.GetBool("instance.osgi.bundle.install.start"),
InstallStartLevel: cv.GetInt("instance.osgi.bundle.install.start_level"),
InstallRefreshPackages: cv.GetBool("instance.osgi.bundle.install.refresh_packages"),
SnapshotInstallSkipping: cv.GetBool("instance.osgi.bundle.snapshot_install_skipping"),
SnapshotIgnored: cv.GetBool("instance.osgi.bundle.snapshot_ignored"),
SnapshotPatterns: cv.GetStringSlice("instance.osgi.bundle.snapshot_patterns"),
}
}

Expand All @@ -43,7 +55,7 @@ func (bm *OSGiBundleManager) ByFile(localPath string) (*OSGiBundle, error) {
return &OSGiBundle{manager: bm, symbolicName: manifest.SymbolicName}, nil
}

func (bm OSGiBundleManager) Find(symbolicName string) (*osgi.BundleListItem, error) {
func (bm *OSGiBundleManager) Find(symbolicName string) (*osgi.BundleListItem, error) {
bundles, err := bm.List()
if err != nil {
return nil, fmt.Errorf("%s > cannot find bundle '%s'", bm.instance.IDColor(), symbolicName)
Expand Down Expand Up @@ -98,27 +110,80 @@ func (bm *OSGiBundleManager) Stop(id int) error {
return nil
}

func (bm *OSGiBundleManager) IsSnapshot(localPath string) bool {
return !bm.SnapshotIgnored && stringsx.MatchSome(pathx.Normalize(localPath), bm.SnapshotPatterns)
}

func (bm *OSGiBundleManager) InstallWithChanged(localPath string) (bool, error) {
if bm.IsSnapshot(localPath) {
return bm.installSnapshot(localPath)
}
return bm.installRegular(localPath)
}

func (bm *OSGiBundleManager) installRegular(localPath string) (bool, error) {
installed, err := bm.IsInstalled(localPath)
if err != nil {
return false, err
}
if !installed {
return true, bm.Install(localPath)
}
return false, nil
}

func (bm *OSGiBundleManager) IsInstalled(localPath string) (bool, error) {
manifest, err := osgi.ReadBundleManifest(localPath)
if err != nil {
return false, err
}
bundle := bm.New(manifest.SymbolicName)
state, err := bundle.State()
if err != nil {
return false, nil
return false, err
}
state, err := bundle.State()
return state.Exists && state.data.Version == manifest.Version, nil
}

func (bm *OSGiBundleManager) installSnapshot(localPath string) (bool, error) {
checksum, err := filex.ChecksumFile(localPath)
if err != nil {
return false, err
}
installed, err := bm.IsInstalled(localPath)
if err != nil {
return false, err
}
if !state.Exists || state.data.Version != manifest.Version {
err = bm.Install(localPath)
var lock = bm.installLock(localPath, checksum)
if installed && bm.SnapshotInstallSkipping && lock.IsLocked() {
lockData, err := lock.Locked()
if err != nil {
return false, err
}
return true, nil
if checksum == lockData.Checksum {
log.Infof("%s > skipped installing bundle '%s'", bm.instance.IDColor(), localPath)
return false, nil
}
}
return false, nil
if err := bm.Install(localPath); err != nil {
return false, err
}
if err := lock.Lock(); err != nil {
return false, err
}
return true, nil
}

func (bm *OSGiBundleManager) installLock(file string, checksum string) osx.Lock[osgiBundleInstallLock] {
name := filepath.Base(file)
return osx.NewLock(fmt.Sprintf("%s/osgi/bundle/install/%s.yml", bm.instance.LockDir(), name), func() (osgiBundleInstallLock, error) {
return osgiBundleInstallLock{Installed: time.Now(), Checksum: checksum}, nil
})
}

type osgiBundleInstallLock struct {
Installed time.Time `yaml:"installed"`
Checksum string `yaml:"checksum"`
}

func (bm *OSGiBundleManager) Install(localPath string) error {
Expand Down
6 changes: 6 additions & 0 deletions pkg/project/app_classic/aem/default/etc/aem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ instance:
start_level: 20
refresh_packages: true

# Force re-uploading/installing of snapshot OSGi bundles (just built / unreleased)
snapshot_patterns: [ "**/*-SNAPSHOT.jar" ]
snapshot_ignored: false
# Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged
snapshot_install_skipping: true

# Crypto Support
crypto:
key_bundle_symbolic_name: com.adobe.granite.crypto.file
Expand Down
6 changes: 6 additions & 0 deletions pkg/project/app_cloud/aem/default/etc/aem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ instance:
start_level: 20
refresh_packages: true

# Force re-installing of snapshot OSGi bundles (just built / unreleased)
snapshot_patterns: [ "**/*-SNAPSHOT.jar" ]
snapshot_ignored: false
# Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged
snapshot_install_skipping: true

# Crypto Support
crypto:
key_bundle_symbolic_name: com.adobe.granite.crypto.file
Expand Down
2 changes: 1 addition & 1 deletion pkg/project/common/aemw
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

VERSION=${AEM_CLI_VERSION:-"1.7.4"}
VERSION=${AEM_CLI_VERSION:-"1.7.5"}

# Define API
# ==========
Expand Down
6 changes: 6 additions & 0 deletions pkg/project/instance/aem/default/etc/aem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ instance:
start_level: 20
refresh_packages: true

# Force re-installing of snapshot OSGi bundles (just built / unreleased)
snapshot_patterns: [ "**/*-SNAPSHOT.jar" ]
snapshot_ignored: false
# Use checksums to avoid re-installations when snapshot OSGi bundles are unchanged
snapshot_install_skipping: true

# Crypto Support
crypto:
key_bundle_symbolic_name: com.adobe.granite.crypto.file
Expand Down

0 comments on commit 58ed14b

Please sign in to comment.