Skip to content

Commit

Permalink
Merge branch '2-classpath-to-lib'
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Hale <[email protected]>
  • Loading branch information
nebhale committed May 26, 2020
2 parents 8fd6d2c + b375e14 commit bd3057f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tomcat/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (b Base) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
return libcnb.Layer{}, fmt.Errorf("unable to contribute logging\n%w", err)
}

if err := b.ContributeClasspathEntries(layer); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to contribute classpath entries\n%w", err)
}

if b.ExternalConfigurationDependency != nil {
if err := b.ContributeExternalConfiguration(layer); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to contribute external configuration\n%w", err)
Expand Down Expand Up @@ -158,6 +162,18 @@ func (b Base) ContributeAccessLogging(layer libcnb.Layer) error {
return nil
}

func (b Base) ContributeClasspathEntries(layer libcnb.Layer) error {
file := filepath.Join(layer.Path, "lib")
s, err := sherpa.TemplateFile("/classpath.sh", map[string]interface{}{"path": file})
if err != nil {
return fmt.Errorf("unable to load classpath.sh\n%w", err)
}

layer.Profile.Add("classpath.sh", s)

return nil
}

func (b Base) ContributeConfiguration(layer libcnb.Layer) error {
file := filepath.Join(layer.Path, "conf")
if err := os.MkdirAll(file, 0755); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions tomcat/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ printf "Tomcat Access Logging enabled\n"
export JAVA_OPTS="${JAVA_OPTS} -Daccess.logging.enabled=true"
`))
Expect(layer.Profile["classpath.sh"]).To(Equal(fmt.Sprintf(`[[ -z "${CLASSPATH+x}" ]] && return
printf "Linking \${CLASSPATH} entries to %%s\n" "%[1]s"
mkdir -p "%[1]s"
IFS=':' read -ra PATHS <<< "${CLASSPATH}"
ln -s "${PATHS[@]}" "%[1]s"
`, filepath.Join(layer.Path, "lib"))))
Expect(filepath.Join(layer.Path, "lib", "stub-tomcat-lifecycle-support.jar")).To(BeARegularFile())
Expect(filepath.Join(layer.Path, "bin", "stub-tomcat-logging-support.jar")).To(BeARegularFile())
Expect(ioutil.ReadFile(filepath.Join(layer.Path, "bin", "setenv.sh"))).To(Equal([]byte(fmt.Sprintf(`# shellcheck disable=SC2034
Expand Down
7 changes: 7 additions & 0 deletions tomcat/classpath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[ -z "${CLASSPATH+x}" ]] && return

printf "Linking \${CLASSPATH} entries to %s\n" "{{.path}}"

mkdir -p "{{.path}}"
IFS=':' read -ra PATHS <<< "${CLASSPATH}"
ln -s "${PATHS[@]}" "{{.path}}"
2 changes: 1 addition & 1 deletion tomcat/statik/statik.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd3057f

Please sign in to comment.