diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2019-08-22 14:22:36 +0200 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2019-08-22 15:08:14 +0200 |
commit | 37cc1486513e3d530c9e6a6534f1297b61f65ba7 (patch) | |
tree | 1263ca10ae995943e2540c4440ddffe61dc48e55 | |
parent | eacb70bcd42801f4226c9e781bee27c9ab22df34 (diff) |
Factor out abstract mojo on deployment level
4 files changed, 33 insertions, 27 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 new file mode 100644 index 00000000000..1dbe306d549 --- /dev/null +++ b/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/AbstractVespaDeploymentMojo.java @@ -0,0 +1,31 @@ +package ai.vespa.hosted.plugin; + +import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.zone.ZoneId; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Base class for hosted Vespa plugin mojos which refer to a particular deployment. + * + * @author jonmv + */ +public abstract class AbstractVespaDeploymentMojo extends AbstractVespaMojo { + + @Parameter(property = "environment") + protected String environment; + + @Parameter(property = "region") + protected String region; + + protected ZoneId zoneOf(String environment, String region) { + if (region == null) + return controller.defaultZone(environment != null ? Environment.from(environment) + : Environment.dev); + + if (environment == null) + throw new IllegalArgumentException("Environment must be specified if region is specified"); + + return 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 6b7af01a3ea..e2bbbb86706 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 @@ -2,8 +2,6 @@ package ai.vespa.hosted.plugin; import ai.vespa.hosted.api.ControllerHttpClient; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.Environment; -import com.yahoo.config.provision.zone.ZoneId; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; @@ -70,17 +68,6 @@ public abstract class AbstractVespaMojo extends AbstractMojo { : ControllerHttpClient.withKeyAndCertificate(URI.create(endpoint), Paths.get(privateKeyFile), Paths.get(certificateFile)); } - protected ZoneId zoneOf(String environment, String region) { - if (region == null) - return controller.defaultZone(environment != null ? Environment.from(environment) - : Environment.dev); - - if (environment == null) - throw new IllegalArgumentException("Environment must be specified if region is specified"); - - return ZoneId.from(environment, region); - } - protected String projectPathOf(String first, String... rest) { return project.getBasedir().toPath().resolve(Path.of(first, rest)).toString(); } 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 6d9c4cb2972..c7062899678 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 @@ -11,13 +11,7 @@ import org.apache.maven.plugins.annotations.Parameter; * @author jonmv */ @Mojo(name = "delete") -public class DeleteMojo extends AbstractVespaMojo { - - @Parameter(property = "environment") - private String environment; - - @Parameter(property = "region") - private String region; +public class DeleteMojo extends AbstractVespaDeploymentMojo { @Override protected void doExecute() { 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 d6d98b945c9..9ef31cafb1b 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 @@ -18,7 +18,7 @@ import java.time.format.DateTimeFormatter; * @author jonmv */ @Mojo(name = "deploy") -public class DeployMojo extends AbstractVespaMojo { +public class DeployMojo extends AbstractVespaDeploymentMojo { @Parameter(property = "applicationZip") private String applicationZip; @@ -26,12 +26,6 @@ public class DeployMojo extends AbstractVespaMojo { @Parameter(property = "vespaVersion") private String vespaVersion; - @Parameter(property = "environment") - private String environment; - - @Parameter(property = "region") - private String region; - @Parameter(property = "follow", defaultValue = "true") private boolean follow; |