Skip to content

Commit e152e0d

Browse files
authored
fix: several minor fixes (#341)
* fix: several minor fixes Changed a couple of maven plugins's scope to provided as recommended by Maven. Fixed #117: during first deploy unless the allowUnauthenticated property was set to true, the gcloud command was waiting on a prompt that was not visible and could not be interacted with. This change removes the allowUnauthenticated property's default value and relies on gcloud's behavior which will default this value to false if prompting is turned off with '--quiet'. If the allowUnauthenticated is explicitly set, it will correctly append the --[no-]allow-unauthenticated flag to the command. If the gcloud command fails, the plugin will not report a successful build. * fix formatting
1 parent 4203279 commit e152e0d

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

function-maven-plugin/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@
4242
<groupId>org.apache.maven</groupId>
4343
<artifactId>maven-plugin-api</artifactId>
4444
<version>3.9.11</version>
45+
<scope>provided</scope>
4546
</dependency>
4647
<dependency>
4748
<groupId>org.apache.maven</groupId>
4849
<artifactId>maven-core</artifactId>
4950
<version>3.9.11</version>
51+
<scope>provided</scope>
5052
</dependency>
5153
<dependency>
5254
<groupId>org.apache.maven.plugin-tools</groupId>

function-maven-plugin/src/main/java/com/google/cloud/functions/plugin/DeployFunction.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ public class DeployFunction extends CloudSdkMojo {
6363
*/
6464
@Parameter(
6565
alias = "deploy.allowunauthenticated",
66-
property = "function.deploy.allowunauthenticated",
67-
defaultValue = "false")
68-
boolean allowUnauthenticated;
66+
property = "function.deploy.allowunauthenticated")
67+
Boolean allowUnauthenticated;
6968

7069
/**
7170
* Name of a Google Cloud Function (as defined in source code) that will be executed. Defaults to
@@ -314,8 +313,12 @@ public List<String> getCommands() {
314313
if (triggerEvent != null) {
315314
commands.add("--trigger-event=" + triggerEvent);
316315
}
317-
if (allowUnauthenticated) {
318-
commands.add("--allow-unauthenticated");
316+
if (allowUnauthenticated != null) {
317+
if (allowUnauthenticated) {
318+
commands.add("--allow-unauthenticated");
319+
} else {
320+
commands.add("--no-allow-unauthenticated");
321+
}
319322
}
320323
if (functionTarget != null) {
321324
commands.add("--entry-point=" + functionTarget);
@@ -371,6 +374,8 @@ public List<String> getCommands() {
371374
if (projectId != null) {
372375
commands.add("--project=" + projectId);
373376
}
377+
378+
commands.add("--quiet");
374379
return Collections.unmodifiableList(commands);
375380
}
376381

@@ -382,7 +387,9 @@ public void execute() throws MojoExecutionException {
382387
System.out.println("Executing Cloud SDK command: gcloud " + String.join(" ", params));
383388
gcloud.runCommand(params);
384389
} catch (CloudSdkNotFoundException | IOException | ProcessHandlerException ex) {
385-
Logger.getLogger(DeployFunction.class.getName()).log(Level.SEVERE, null, ex);
390+
Logger.getLogger(DeployFunction.class.getName())
391+
.log(Level.SEVERE, "Function deployment failed", ex);
392+
throw new MojoExecutionException("Function deployment failed", ex);
386393
}
387394
}
388395
}

function-maven-plugin/src/test/java/com/google/cloud/functions/plugin/DeployFunctionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public void testDeployFunctionCommandLine() {
5353
"--env-vars-file=myfile",
5454
"--set-build-env-vars=env1=a,env2=b",
5555
"--build-env-vars-file=myfile2",
56-
"--runtime=java11");
56+
"--runtime=java11",
57+
"--quiet");
5758
assertThat(mojo.getCommands()).isEqualTo(expected);
5859
}
5960
}

0 commit comments

Comments
 (0)