aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-maven-plugin
diff options
context:
space:
mode:
authorMorten Tokle <mortent@verizonmedia.com>2020-08-27 13:33:45 +0200
committerMorten Tokle <mortent@verizonmedia.com>2020-08-27 13:33:45 +0200
commite1972378b8dc3cc8ae0c5b4b3ccaf31638d755e9 (patch)
tree0f2a7bf1dc7ade27aeacdc053bb103f51d7fd57c /vespa-maven-plugin
parenta183d1b84ed8752dcf8f9486f7e9a36982db99b1 (diff)
Handle empty values
Diffstat (limited to 'vespa-maven-plugin')
-rw-r--r--vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaDeploymentMojo.java8
-rw-r--r--vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java13
-rw-r--r--vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeleteMojo.java4
-rw-r--r--vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java2
4 files changed, 14 insertions, 13 deletions
diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaDeploymentMojo.java b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaDeploymentMojo.java
index f9c07d29ee1..b369732c6d6 100644
--- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaDeploymentMojo.java
+++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaDeploymentMojo.java
@@ -21,11 +21,11 @@ public abstract class AbstractVespaDeploymentMojo extends AbstractVespaMojo {
protected String region;
protected ZoneId zoneOf(String environment, String region) {
- if (region == null)
- return zone = controller.defaultZone(environment != null ? Environment.from(environment)
- : Environment.dev);
+ if (isNullOrBlank(region))
+ return zone = controller.defaultZone(isNullOrBlank(environment) ? Environment.dev
+ : Environment.from(environment));
- if (environment == null)
+ if (isNullOrBlank(environment))
throw new IllegalArgumentException("Environment must be specified if region is specified");
return zone = ZoneId.from(environment, region);
diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java
index 72e7f2861cb..137bee54b8f 100644
--- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java
+++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaMojo.java
@@ -10,9 +10,7 @@ import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
-import java.io.IOException;
import java.net.URI;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
@@ -79,10 +77,10 @@ public abstract class AbstractVespaMojo extends AbstractMojo {
instance = firstNonBlank(instance, project.getProperties().getProperty("instance"), Properties.user());
id = ApplicationId.from(tenant, application, instance);
- if (apiKey != null) {
+ if (!isNullOrBlank(apiKey)) {
controller = ControllerHttpClient.withSignatureKey(URI.create(endpoint), apiKey, id);
- } else if (apiKeyFile != null) {
- controller = apiCertificateFile == null
+ } else if (!isNullOrBlank(apiKeyFile)) {
+ controller = isNullOrBlank(apiCertificateFile)
? ControllerHttpClient.withSignatureKey(URI.create(endpoint), Paths.get(apiKeyFile), id)
: ControllerHttpClient.withKeyAndCertificate(URI.create(endpoint), Paths.get(apiKeyFile), Paths.get(apiCertificateFile));
} else {
@@ -114,4 +112,9 @@ public abstract class AbstractVespaMojo extends AbstractMojo {
.map(mapper);
}
+ protected static boolean isNullOrBlank(String value) {
+ return Optional.ofNullable(value)
+ .filter(s -> !s.isBlank())
+ .isEmpty();
+ }
}
diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeleteMojo.java b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeleteMojo.java
index eae681009cf..03b4dab246f 100644
--- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeleteMojo.java
+++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeleteMojo.java
@@ -2,9 +2,7 @@
package ai.vespa.hosted.plugin;
import com.yahoo.config.provision.Environment;
-import com.yahoo.config.provision.zone.ZoneId;
import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
/**
* Deletes a Vespa application deployment, provided the deployment is in a manually deployed environment.
@@ -16,7 +14,7 @@ public class DeleteMojo extends AbstractVespaDeploymentMojo {
@Override
protected void doExecute() {
- if (environment != null && ! Environment.from(environment).isManuallyDeployed())
+ if (!isNullOrBlank(environment) && ! Environment.from(environment).isManuallyDeployed())
throw new IllegalArgumentException("Manual deletion is not permitted in " + environment);
getLog().info(controller.deactivate(id, zoneOf(environment, region)));
diff --git a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java
index a798c2ad6df..69d4d6001d0 100644
--- a/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java
+++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java
@@ -50,7 +50,7 @@ public class DeployMojo extends AbstractVespaDeploymentMojo {
loggable = DeploymentLog.Level.valueOf(vespaLogLevel);
Deployment deployment = Deployment.ofPackage(Paths.get(firstNonBlank(applicationZip,
projectPathOf("target", "application.zip"))));
- if (vespaVersion != null) deployment = deployment.atVersion(vespaVersion);
+ if (!isNullOrBlank(vespaVersion)) deployment = deployment.atVersion(vespaVersion);
ZoneId zone = zoneOf(environment, region);
DeploymentResult result = controller.deploy(deployment, id, zone);