@@ -65,16 +65,9 @@ func buildFn(ctx *gcp.Context) error {
65
65
66
66
ctx .SetFunctionsEnvVars (layer )
67
67
68
- // Use javap to check that the class is indeed in the classpath we just determined.
69
- // On success, it will output a description of the class and its public members, which we discard.
70
- // On failure it will output an error saying what's wrong (usually that the class doesn't exist).
71
- // Success here doesn't guarantee that the function will execute. It might not implement one of the
72
- // required interfaces, for example. But it eliminates the commonest problem of specifying the wrong target.
73
- // We use an ExecUser* method so that the time taken by the javap command is counted as user time.
74
- target := os .Getenv (env .FunctionTarget )
75
- if _ , err := ctx .ExecWithErr ([]string {"javap" , "-classpath" , classpath , target }, gcp .WithUserAttribution ); err != nil {
76
- // The javap error output will typically be "Error: class not found: foo.Bar".
77
- return gcp .UserErrorf ("build succeeded but did not produce the class %q specified as the function target: %s" , target , (* err ).Error ())
68
+ // Check that the classes are indeed in the classpath we just determined.
69
+ if ! checkTargets (ctx , classpath ) {
70
+ return gcp .UserErrorf ("build succeeded but did not produce the target classes" )
78
71
}
79
72
80
73
launcherSource := filepath .Join (ctx .BuildpackRoot (), "launch.sh" )
@@ -85,6 +78,26 @@ func buildFn(ctx *gcp.Context) error {
85
78
return nil
86
79
}
87
80
81
+ // checkTargets use javap to check that the class is indeed in the classpath we just determined.
82
+ // On success, it will output a description of the class and its public members, which we discard.
83
+ // On failure it will output an error saying what's wrong (usually that the class doesn't exist).
84
+ // Success here doesn't guarantee that the function will execute. It might not implement one of the
85
+ // required interfaces, for example. But it eliminates the commonest problem of specifying the wrong target.
86
+ // We use an ExecUser* method so that the time taken by the javap command is counted as user time.
87
+ func checkTargets (ctx * gcp.Context , classpath string ) bool {
88
+ targets := strings .Split (os .Getenv (env .FunctionTarget ), "," )
89
+ success := true
90
+ for _ , target := range targets {
91
+ cmd := []string {"javap" , "-classpath" , classpath , target }
92
+ if _ , err := ctx .ExecWithErr (cmd , gcp .WithUserAttribution ); err != nil {
93
+ // The javap error output will typically be "Error: class not found: foo.Bar".
94
+ success = false
95
+ }
96
+ }
97
+
98
+ return success
99
+ }
100
+
88
101
func createLauncher (ctx * gcp.Context , launcherSource , launcherTarget string ) {
89
102
launcherContents := ctx .ReadFile (launcherSource )
90
103
ctx .WriteFile (launcherTarget , launcherContents , 0755 )
0 commit comments