diff --git a/azure-webapp-maven-plugin/src/main/java/com/microsoft/azure/maven/webapp/AbstractWebAppMojo.java b/azure-webapp-maven-plugin/src/main/java/com/microsoft/azure/maven/webapp/AbstractWebAppMojo.java index 95dc34ebe..10f18aa87 100644 --- a/azure-webapp-maven-plugin/src/main/java/com/microsoft/azure/maven/webapp/AbstractWebAppMojo.java +++ b/azure-webapp-maven-plugin/src/main/java/com/microsoft/azure/maven/webapp/AbstractWebAppMojo.java @@ -18,6 +18,7 @@ import com.microsoft.azure.maven.webapp.configuration.ContainerSetting; import com.microsoft.azure.maven.webapp.configuration.DeploymentSlotSetting; import com.microsoft.azure.maven.webapp.configuration.DeploymentType; import org.apache.maven.model.Resource; +import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.util.StringUtils; @@ -256,7 +257,7 @@ public abstract class AbstractWebAppMojo extends AbstractAppServiceMojo { return containerSettings; } - public DeploymentType getDeploymentType() { + public DeploymentType getDeploymentType() throws MojoExecutionException { return DeploymentType.fromString(deploymentType); } @@ -329,7 +330,12 @@ public abstract class AbstractWebAppMojo extends AbstractAppServiceMojo { map.put(JAVA_WEB_CONTAINER_KEY, getJavaWebContainer().toString()); map.put(LINUX_RUNTIME_KEY, StringUtils.isEmpty(linuxRuntime) ? "" : linuxRuntime); map.put(DOCKER_IMAGE_TYPE_KEY, WebAppUtils.getDockerImageType(getContainerSettings()).toString()); - map.put(DEPLOYMENT_TYPE_KEY, getDeploymentType().toString()); + + try { + map.put(DEPLOYMENT_TYPE_KEY, getDeploymentType().toString()); + } catch (MojoExecutionException e) { + map.put(DEPLOYMENT_TYPE_KEY, DeploymentType.UNKNOWN_DEPLOYMENT_TYPE); + } return map; } diff --git a/azure-webapp-maven-plugin/src/main/java/com/microsoft/azure/maven/webapp/configuration/DeploymentType.java b/azure-webapp-maven-plugin/src/main/java/com/microsoft/azure/maven/webapp/configuration/DeploymentType.java index d6f4237a7..9868347ca 100644 --- a/azure-webapp-maven-plugin/src/main/java/com/microsoft/azure/maven/webapp/configuration/DeploymentType.java +++ b/azure-webapp-maven-plugin/src/main/java/com/microsoft/azure/maven/webapp/configuration/DeploymentType.java @@ -29,11 +29,12 @@ public enum DeploymentType { ZIP(new ZIPHandler()), WAR(new WARHandler()), JAR(new JARHandler()), - AUTO(new AUTOHandler()), - UNKNOWN(new UNKNOWNHandler()); + AUTO(new AUTOHandler()); private Handler handler; + public static final String UNKNOWN_DEPLOYMENT_TYPE = "Unknown deployment type."; + DeploymentType(Handler handler) { this.handler = handler; } @@ -50,9 +51,9 @@ public enum DeploymentType { return handler.apply(mojo); } - public static DeploymentType fromString(final String input) { + public static DeploymentType fromString(final String input) throws MojoExecutionException { if (StringUtils.isEmpty(input)) { - return NONE; + throw new MojoExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } switch (input.toUpperCase(Locale.ENGLISH)) { @@ -69,7 +70,7 @@ public enum DeploymentType { case "AUTO": return AUTO; default: - return UNKNOWN; + throw new MojoExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } @@ -85,16 +86,16 @@ public enum DeploymentType { } static class AUTOHandler implements Handler { - public ArtifactHandler apply(AbstractWebAppMojo m) { + public ArtifactHandler apply(AbstractWebAppMojo m) throws MojoExecutionException { String packaging = m.getProject().getPackaging(); - packaging = packaging != null ? packaging.toLowerCase(Locale.ENGLISH) : ""; - switch (packaging.trim()) { + packaging = packaging != null ? packaging.toLowerCase(Locale.ENGLISH).trim() : ""; + switch (packaging) { case "war": return new WarArtifactHandlerImpl(m); case "jar": return new JarArtifactHandlerImpl(m); default: - return new NONEArtifactHandlerImpl(m); + throw new MojoExecutionException(UNKNOWN_DEPLOYMENT_TYPE); } } } @@ -122,10 +123,4 @@ public enum DeploymentType { return new JarArtifactHandlerImpl(m); } } - - static class UNKNOWNHandler implements Handler { - public ArtifactHandler apply(AbstractWebAppMojo m) { - throw new RuntimeException("Unknown deployment type."); - } - } } diff --git a/azure-webapp-maven-plugin/src/test/java/com/microsoft/azure/maven/webapp/DeployMojoTest.java b/azure-webapp-maven-plugin/src/test/java/com/microsoft/azure/maven/webapp/DeployMojoTest.java index 96574b2a5..ca2d73e05 100644 --- a/azure-webapp-maven-plugin/src/test/java/com/microsoft/azure/maven/webapp/DeployMojoTest.java +++ b/azure-webapp-maven-plugin/src/test/java/com/microsoft/azure/maven/webapp/DeployMojoTest.java @@ -143,13 +143,19 @@ public class DeployMojoTest { assertEquals(1, mojo.getAppSettings().size()); - assertEquals(DeploymentType.NONE, mojo.getDeploymentType()); + assertEquals(DeploymentType.AUTO, mojo.getDeploymentType()); assertEquals(1, mojo.getResources().size()); assertFalse(mojo.isStopAppDuringDeployment()); } + @Test(expected = MojoExecutionException.class) + public void getDeploymentTypeThrowException() throws Exception { + final DeployMojo mojo = getMojoFromPom("/pom-slot.xml"); + mojo.getDeploymentType(); + } + @Test public void getConfigurationForWindows() throws Exception { final DeployMojo mojo = getMojoFromPom("/pom-windows.xml"); diff --git a/azure-webapp-maven-plugin/src/test/resources/pom-linux.xml b/azure-webapp-maven-plugin/src/test/resources/pom-linux.xml index e5d36421a..e2e130370 100644 --- a/azure-webapp-maven-plugin/src/test/resources/pom-linux.xml +++ b/azure-webapp-maven-plugin/src/test/resources/pom-linux.xml @@ -25,6 +25,7 @@ 80 + auto ${baseDir}/target