Throw exception when user set unknown deployment type (#321)

This commit is contained in:
Summer 2018-08-07 09:52:04 +08:00 коммит произвёл GitHub
Родитель 2c53ab16c3
Коммит dc36b25294
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 26 добавлений и 18 удалений

Просмотреть файл

@ -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>