Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/java/frameworks/client_certificate_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package frameworks

import (
"fmt"
"github.com/cloudfoundry/java-buildpack/src/java/common"
"os"
"path/filepath"

"github.com/cloudfoundry/java-buildpack/src/java/common"
)

// ClientCertificateMapperFramework implements mTLS client certificate mapper support
Expand Down Expand Up @@ -69,17 +70,15 @@ func (c *ClientCertificateMapperFramework) Finalize() error {
return nil
}

// Add to classpath via CLASSPATH environment variable
classpath := os.Getenv("CLASSPATH")
if classpath != "" {
classpath += ":"
}
classpath += matches[0]
depsIdx := c.context.Stager.DepsIdx()
runtimePath := fmt.Sprintf("$DEPS_DIR/%s/client_certificate_mapper/%s", depsIdx, filepath.Base(matches[0]))

if err := c.context.Stager.WriteEnvFile("CLASSPATH", classpath); err != nil {
return fmt.Errorf("failed to set CLASSPATH for Client Certificate Mapper: %w", err)
profileScript := fmt.Sprintf("export CLASSPATH=\"%s:${CLASSPATH:-}\"\n", runtimePath)
if err := c.context.Stager.WriteProfileD("client_certificate_mapper.sh", profileScript); err != nil {
return fmt.Errorf("failed to write client_certificate_mapper.sh profile.d script: %w", err)
}

c.context.Log.Debug("Client Certificate Mapper JAR will be added to classpath at runtime: %s", runtimePath)
return nil
}

Expand Down
16 changes: 7 additions & 9 deletions src/java/frameworks/java_cf_env.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package frameworks

import (
"github.com/cloudfoundry/java-buildpack/src/java/common"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/cloudfoundry/java-buildpack/src/java/common"
"github.com/cloudfoundry/libbuildpack"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -81,17 +81,15 @@ func (j *JavaCfEnvFramework) Finalize() error {
return nil
}

// Add to classpath via CLASSPATH environment variable
classpath := os.Getenv("CLASSPATH")
if classpath != "" {
classpath += ":"
}
classpath += matches[0]
depsIdx := j.context.Stager.DepsIdx()
runtimePath := fmt.Sprintf("$DEPS_DIR/%s/java_cf_env/%s", depsIdx, filepath.Base(matches[0]))

if err := j.context.Stager.WriteEnvFile("CLASSPATH", classpath); err != nil {
return fmt.Errorf("failed to set CLASSPATH for Java CF Env: %w", err)
profileScript := fmt.Sprintf("export CLASSPATH=\"%s:${CLASSPATH:-}\"\n", runtimePath)
if err := j.context.Stager.WriteProfileD("java_cf_env.sh", profileScript); err != nil {
return fmt.Errorf("failed to write java_cf_env.sh profile.d script: %w", err)
}

j.context.Log.Debug("Java CF Env JAR will be added to classpath at runtime: %s", runtimePath)
return nil
}

Expand Down
7 changes: 5 additions & 2 deletions src/java/frameworks/maria_db_jdbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ func (f *MariaDBJDBCFramework) Finalize() error {

f.context.Log.BeginStep("Configuring MariaDB JDBC driver")

// Add to CLASSPATH environment variable
if err := f.context.Stager.WriteEnvFile("CLASSPATH", f.jarPath); err != nil {
depsIdx := f.context.Stager.DepsIdx()
runtimePath := fmt.Sprintf("$DEPS_DIR/%s/mariadb_jdbc/%s", depsIdx, filepath.Base(f.jarPath))

profileScript := fmt.Sprintf("export CLASSPATH=\"%s:${CLASSPATH:-}\"\n", runtimePath)
if err := f.context.Stager.WriteProfileD("mariadb_jdbc.sh", profileScript); err != nil {
f.context.Log.Warning("Failed to add MariaDB JDBC to CLASSPATH: %s", err)
return nil // Non-blocking
}
Expand Down
17 changes: 7 additions & 10 deletions src/java/frameworks/postgresql_jdbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package frameworks

import (
"fmt"
"github.com/cloudfoundry/java-buildpack/src/java/common"
"os"
"path/filepath"
"strings"

"github.com/cloudfoundry/java-buildpack/src/java/common"
"github.com/cloudfoundry/libbuildpack"
)

Expand Down Expand Up @@ -73,17 +72,15 @@ func (p *PostgresqlJdbcFramework) Finalize() error {
return nil
}

// Add to classpath via CLASSPATH environment variable
classpath := os.Getenv("CLASSPATH")
if classpath != "" {
classpath += ":"
}
classpath += matches[0]
depsIdx := p.context.Stager.DepsIdx()
runtimePath := fmt.Sprintf("$DEPS_DIR/%s/postgresql_jdbc/%s", depsIdx, filepath.Base(matches[0]))

if err := p.context.Stager.WriteEnvFile("CLASSPATH", classpath); err != nil {
return fmt.Errorf("failed to set CLASSPATH for PostgreSQL JDBC: %w", err)
profileScript := fmt.Sprintf("export CLASSPATH=\"%s:${CLASSPATH:-}\"\n", runtimePath)
if err := p.context.Stager.WriteProfileD("postgresql_jdbc.sh", profileScript); err != nil {
return fmt.Errorf("failed to write postgresql_jdbc.sh profile.d script: %w", err)
}

p.context.Log.Debug("PostgreSQL JDBC JAR will be added to classpath at runtime: %s", runtimePath)
return nil
}

Expand Down
14 changes: 6 additions & 8 deletions src/java/frameworks/spring_auto_reconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,15 @@ func (s *SpringAutoReconfigurationFramework) Finalize() error {
return nil
}

// Add to classpath via CLASSPATH environment variable
classpath := os.Getenv("CLASSPATH")
if classpath != "" {
classpath += ":"
}
classpath += matches[0]
depsIdx := s.context.Stager.DepsIdx()
runtimePath := fmt.Sprintf("$DEPS_DIR/%s/spring_auto_reconfiguration/%s", depsIdx, filepath.Base(matches[0]))

if err := s.context.Stager.WriteEnvFile("CLASSPATH", classpath); err != nil {
return fmt.Errorf("failed to set CLASSPATH for Spring Auto-reconfiguration: %w", err)
profileScript := fmt.Sprintf("export CLASSPATH=\"%s:${CLASSPATH:-}\"\n", runtimePath)
if err := s.context.Stager.WriteProfileD("spring_auto_reconfiguration.sh", profileScript); err != nil {
return fmt.Errorf("failed to write spring_auto_reconfiguration.sh profile.d script: %w", err)
}

s.context.Log.Debug("Spring Auto-reconfiguration JAR will be added to classpath at runtime: %s", runtimePath)
return nil
}

Expand Down