Skip to content

Commit 9281131

Browse files
sheche@microsoft.comjdneo
authored andcommitted
use the customized exception in azuretools-core
1 parent d4f2add commit 9281131

File tree

3 files changed

+44
-75
lines changed

3 files changed

+44
-75
lines changed

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.container/src/com/microsoft/azuretools/container/InvalidDataException.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.container/src/com/microsoft/azuretools/container/ui/PublishWebAppOnLinuxDialog.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
import com.microsoft.azure.management.resources.ResourceGroup;
5454
import com.microsoft.azure.management.resources.Subscription;
5555
import com.microsoft.azuretools.authmanage.AuthMethodManager;
56+
import com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException;
5657
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
5758
import com.microsoft.azuretools.azurecommons.util.Utils;
5859
import com.microsoft.azuretools.container.ConsoleLogger;
5960
import com.microsoft.azuretools.container.Constant;
6061
import com.microsoft.azuretools.container.DockerProgressHandler;
61-
import com.microsoft.azuretools.container.InvalidDataException;
6262
import com.microsoft.azuretools.container.ui.common.ContainerSettingComposite;
6363
import com.microsoft.azuretools.container.utils.DockerUtil;
6464
import com.microsoft.azuretools.core.components.AzureTitleAreaDialogWrapper;
@@ -163,7 +163,7 @@ protected void okPressed() {
163163
validation();
164164
execute();
165165
super.okPressed();
166-
} catch (InvalidDataException e) {
166+
} catch (InvalidFormDataException e) {
167167
this.onErrorWithException("Validation Failure", e);
168168
}
169169
}
@@ -279,7 +279,7 @@ private void apply() {
279279
System.getenv("AcrPassword"), // cpAcr.getPassword(),
280280
"eclipse:latest", // cpAcr.getImageTag(),
281281
"" // cpAcr.getStartupFile()
282-
));
282+
));
283283
// set target
284284
model.setTargetPath(targetPath);
285285
model.setTargetName(Paths.get(targetPath).getFileName().toString());
@@ -356,96 +356,96 @@ private void apply() {
356356
}
357357
}
358358

359-
private void validation() throws InvalidDataException {
359+
private void validation() throws InvalidFormDataException {
360360
try {
361361
if (!AuthMethodManager.getInstance().isSignedIn()) {
362-
throw new InvalidDataException(NEED_SIGN_IN);
362+
throw new InvalidFormDataException(NEED_SIGN_IN);
363363
}
364364
} catch (IOException e) {
365-
throw new InvalidDataException(NEED_SIGN_IN);
365+
throw new InvalidFormDataException(NEED_SIGN_IN);
366366
}
367367
if (Utils.isEmptyString(model.getDockerFilePath()) || !Paths.get(model.getDockerFilePath()).toFile().exists()) {
368-
throw new InvalidDataException(INVALID_DOCKER_FILE);
368+
throw new InvalidFormDataException(INVALID_DOCKER_FILE);
369369
}
370370
// acr
371371
PrivateRegistryImageSetting setting = model.getPrivateRegistryImageSetting();
372372
if (Utils.isEmptyString(setting.getServerUrl()) || !setting.getServerUrl().matches(DOMAIN_NAME_REGEX)) {
373-
throw new InvalidDataException(MISSING_SERVER_URL);
373+
throw new InvalidFormDataException(MISSING_SERVER_URL);
374374
}
375375
if (Utils.isEmptyString(setting.getUsername())) {
376-
throw new InvalidDataException(MISSING_USERNAME);
376+
throw new InvalidFormDataException(MISSING_USERNAME);
377377
}
378378
if (Utils.isEmptyString(setting.getPassword())) {
379-
throw new InvalidDataException(MISSING_PASSWORD);
379+
throw new InvalidFormDataException(MISSING_PASSWORD);
380380
}
381381
String imageTag = setting.getImageTagWithServerUrl();
382382
if (Utils.isEmptyString(imageTag)) {
383-
throw new InvalidDataException(MISSING_IMAGE_WITH_TAG);
383+
throw new InvalidFormDataException(MISSING_IMAGE_WITH_TAG);
384384
}
385385
if (imageTag.endsWith(":")) {
386-
throw new InvalidDataException(CANNOT_END_WITH_COLON);
386+
throw new InvalidFormDataException(CANNOT_END_WITH_COLON);
387387
}
388388
final String[] repoAndTag = imageTag.split(":");
389389

390390
// check repository first
391391
if (repoAndTag[0].length() < 1 || repoAndTag[0].length() > REPO_LENGTH) {
392-
throw new InvalidDataException(REPO_LENGTH_INVALID);
392+
throw new InvalidFormDataException(REPO_LENGTH_INVALID);
393393
}
394394
if (repoAndTag[0].endsWith("/")) {
395-
throw new InvalidDataException(CANNOT_END_WITH_SLASH);
395+
throw new InvalidFormDataException(CANNOT_END_WITH_SLASH);
396396
}
397397
final String[] repoComponents = repoAndTag[0].split("/");
398398
for (String component : repoComponents) {
399399
if (!component.matches(REPO_COMPONENTS_REGEX)) {
400-
throw new InvalidDataException(String.format(REPO_COMPONENT_INVALID, component, REPO_COMPONENTS_REGEX));
400+
throw new InvalidFormDataException(String.format(REPO_COMPONENT_INVALID, component, REPO_COMPONENTS_REGEX));
401401
}
402402
}
403403
// check when contains tag
404404
if (repoAndTag.length == 2) {
405405
if (repoAndTag[1].length() > TAG_LENGTH) {
406-
throw new InvalidDataException(TAG_LENGTH_INVALID);
406+
throw new InvalidFormDataException(TAG_LENGTH_INVALID);
407407
}
408408
if (!repoAndTag[1].matches(TAG_REGEX)) {
409-
throw new InvalidDataException(String.format(TAG_INVALID, repoAndTag[1], TAG_REGEX));
409+
throw new InvalidFormDataException(String.format(TAG_INVALID, repoAndTag[1], TAG_REGEX));
410410
}
411411
}
412412
if (repoAndTag.length > 2) {
413-
throw new InvalidDataException(INVALID_IMAGE_WITH_TAG);
413+
throw new InvalidFormDataException(INVALID_IMAGE_WITH_TAG);
414414
}
415415
// web app
416416
if (model.isCreatingNewWebAppOnLinux()) {
417417
if (Utils.isEmptyString(model.getWebAppName())) {
418-
throw new InvalidDataException(MISSING_WEB_APP);
418+
throw new InvalidFormDataException(MISSING_WEB_APP);
419419
}
420420
if (Utils.isEmptyString(model.getSubscriptionId())) {
421-
throw new InvalidDataException(MISSING_SUBSCRIPTION);
421+
throw new InvalidFormDataException(MISSING_SUBSCRIPTION);
422422
}
423423
if (Utils.isEmptyString(model.getResourceGroupName())) {
424-
throw new InvalidDataException(MISSING_RESOURCE_GROUP);
424+
throw new InvalidFormDataException(MISSING_RESOURCE_GROUP);
425425
}
426426

427427
if (model.isCreatingNewAppServicePlan()) {
428428
if (Utils.isEmptyString(model.getAppServicePlanName())) {
429-
throw new InvalidDataException(MISSING_APP_SERVICE_PLAN);
429+
throw new InvalidFormDataException(MISSING_APP_SERVICE_PLAN);
430430
}
431431
} else {
432432
if (Utils.isEmptyString(model.getAppServicePlanId())) {
433-
throw new InvalidDataException(MISSING_APP_SERVICE_PLAN);
433+
throw new InvalidFormDataException(MISSING_APP_SERVICE_PLAN);
434434
}
435435
}
436436

437437
} else {
438438
if (Utils.isEmptyString(model.getWebAppId())) {
439-
throw new InvalidDataException(MISSING_WEB_APP);
439+
throw new InvalidFormDataException(MISSING_WEB_APP);
440440
}
441441
}
442442

443443
// target package
444444
if (Utils.isEmptyString(model.getTargetName())) {
445-
throw new InvalidDataException(MISSING_ARTIFACT);
445+
throw new InvalidFormDataException(MISSING_ARTIFACT);
446446
}
447447
if (!model.getTargetName().matches(ARTIFACT_NAME_REGEX)) {
448-
throw new InvalidDataException(String.format(INVALID_WAR_FILE, model.getTargetName()));
448+
throw new InvalidFormDataException(String.format(INVALID_WAR_FILE, model.getTargetName()));
449449
}
450450
}
451451

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.container/src/com/microsoft/azuretools/container/ui/PushImageDialog.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
import org.eclipse.swt.widgets.Control;
4343
import org.eclipse.swt.widgets.Shell;
4444

45+
import com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException;
4546
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
4647
import com.microsoft.azuretools.azurecommons.util.Utils;
4748
import com.microsoft.azuretools.container.ConsoleLogger;
4849
import com.microsoft.azuretools.container.Constant;
4950
import com.microsoft.azuretools.container.DockerProgressHandler;
50-
import com.microsoft.azuretools.container.InvalidDataException;
5151
import com.microsoft.azuretools.container.ui.common.ContainerSettingComposite;
5252
import com.microsoft.azuretools.container.utils.DockerUtil;
5353
import com.microsoft.azuretools.core.mvp.model.container.pojo.PushImageRunModel;
@@ -168,7 +168,7 @@ protected void okPressed() {
168168
validate();
169169
execute();
170170
super.okPressed();
171-
} catch (InvalidDataException e) {
171+
} catch (InvalidFormDataException e) {
172172
showErrorMessage("Error", e.getMessage());
173173
}
174174
}
@@ -186,64 +186,64 @@ private void apply() {
186186
model.setTargetName(Paths.get(targetPath).getFileName().toString());
187187
}
188188

189-
private void validate() throws InvalidDataException {
189+
private void validate() throws InvalidFormDataException {
190190
if (model == null) {
191-
throw new InvalidDataException(MISSING_MODEL);
191+
throw new InvalidFormDataException(MISSING_MODEL);
192192
}
193193
if (Utils.isEmptyString(model.getDockerFilePath()) || !Paths.get(model.getDockerFilePath()).toFile().exists()) {
194-
throw new InvalidDataException(INVALID_DOCKER_FILE);
194+
throw new InvalidFormDataException(INVALID_DOCKER_FILE);
195195
}
196196
// acr
197197
PrivateRegistryImageSetting setting = model.getPrivateRegistryImageSetting();
198198
if (Utils.isEmptyString(setting.getServerUrl()) || !setting.getServerUrl().matches(DOMAIN_NAME_REGEX)) {
199-
throw new InvalidDataException(MISSING_SERVER_URL);
199+
throw new InvalidFormDataException(MISSING_SERVER_URL);
200200
}
201201
if (Utils.isEmptyString(setting.getUsername())) {
202-
throw new InvalidDataException(MISSING_USERNAME);
202+
throw new InvalidFormDataException(MISSING_USERNAME);
203203
}
204204
if (Utils.isEmptyString(setting.getPassword())) {
205-
throw new InvalidDataException(MISSING_PASSWORD);
205+
throw new InvalidFormDataException(MISSING_PASSWORD);
206206
}
207207
String imageTag = setting.getImageTagWithServerUrl();
208208
if (Utils.isEmptyString(imageTag)) {
209-
throw new InvalidDataException(MISSING_IMAGE_WITH_TAG);
209+
throw new InvalidFormDataException(MISSING_IMAGE_WITH_TAG);
210210
}
211211
if (imageTag.endsWith(":")) {
212-
throw new InvalidDataException(CANNOT_END_WITH_COLON);
212+
throw new InvalidFormDataException(CANNOT_END_WITH_COLON);
213213
}
214214
final String[] repoAndTag = imageTag.split(":");
215215

216216
// check repository first
217217
if (repoAndTag[0].length() < 1 || repoAndTag[0].length() > REPO_LENGTH) {
218-
throw new InvalidDataException(REPO_LENGTH_INVALID);
218+
throw new InvalidFormDataException(REPO_LENGTH_INVALID);
219219
}
220220
if (repoAndTag[0].endsWith("/")) {
221-
throw new InvalidDataException(CANNOT_END_WITH_SLASH);
221+
throw new InvalidFormDataException(CANNOT_END_WITH_SLASH);
222222
}
223223
final String[] repoComponents = repoAndTag[0].split("/");
224224
for (String component : repoComponents) {
225225
if (!component.matches(REPO_COMPONENTS_REGEX)) {
226-
throw new InvalidDataException(String.format(REPO_COMPONENT_INVALID, component, REPO_COMPONENTS_REGEX));
226+
throw new InvalidFormDataException(String.format(REPO_COMPONENT_INVALID, component, REPO_COMPONENTS_REGEX));
227227
}
228228
}
229229
// check when contains tag
230230
if (repoAndTag.length == 2) {
231231
if (repoAndTag[1].length() > TAG_LENGTH) {
232-
throw new InvalidDataException(TAG_LENGTH_INVALID);
232+
throw new InvalidFormDataException(TAG_LENGTH_INVALID);
233233
}
234234
if (!repoAndTag[1].matches(TAG_REGEX)) {
235-
throw new InvalidDataException(String.format(TAG_INVALID, repoAndTag[1], TAG_REGEX));
235+
throw new InvalidFormDataException(String.format(TAG_INVALID, repoAndTag[1], TAG_REGEX));
236236
}
237237
}
238238
if (repoAndTag.length > 2) {
239-
throw new InvalidDataException(INVALID_IMAGE_WITH_TAG);
239+
throw new InvalidFormDataException(INVALID_IMAGE_WITH_TAG);
240240
}
241241
// target package
242242
if (Utils.isEmptyString(model.getTargetName())) {
243-
throw new InvalidDataException(MISSING_ARTIFACT);
243+
throw new InvalidFormDataException(MISSING_ARTIFACT);
244244
}
245245
if (!model.getTargetName().matches(ARTIFACT_NAME_REGEX)) {
246-
throw new InvalidDataException(String.format(INVALID_ARTIFACT_FILE, model.getTargetName()));
246+
throw new InvalidFormDataException(String.format(INVALID_ARTIFACT_FILE, model.getTargetName()));
247247
}
248248
}
249249

0 commit comments

Comments
 (0)