Throw exception when user set unknown deployment type (#321)
This commit is contained in:
Родитель
2c53ab16c3
Коммит
dc36b25294
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<value>80</value>
|
||||
</property>
|
||||
</appSettings>
|
||||
<deploymentType>auto</deploymentType>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${baseDir}/target</directory>
|
||||
|
|
Загрузка…
Ссылка в новой задаче