diff options
author | Jeff Johnston | 2016-09-28 01:57:59 +0000 |
---|---|---|
committer | Jeff Johnston | 2016-09-28 19:54:20 +0000 |
commit | 7ecfc530c81519545d7d44087b13d56df87253cf (patch) | |
tree | b1a4dd9d3b93db71bd3fae13e5f124f688ee597a | |
parent | 743bf43bf7135d1708023d923236f7d442c8aa9c (diff) | |
download | org.eclipse.linuxtools-7ecfc530c81519545d7d44087b13d56df87253cf.tar.gz org.eclipse.linuxtools-7ecfc530c81519545d7d44087b13d56df87253cf.tar.xz org.eclipse.linuxtools-7ecfc530c81519545d7d44087b13d56df87253cf.zip |
Bug 499917 - Improve error message when tagging image
- add check in ImageTagPage validate() method to ensure
that repo section of tag does not contain upper-case
characters
- add new message regarding this to WizardMessages.properties
- fix DockerException getMessage() to massage the output if
it is in JSON format
Change-Id: Ie9d8403d4b017bf0261322a6c8ba96a0984b5ffe
Reviewed-on: https://git.eclipse.org/r/82035
Tested-by: Hudson CI
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
4 files changed, 82 insertions, 0 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerException.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerException.java index 34d00c9258..70fa0eb343 100644 --- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerException.java +++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerException.java @@ -17,6 +17,9 @@ public class DockerException extends Exception { */ private static final long serialVersionUID = 1L; + private String JSON_MESSAGE_PREFIX = "{\"message\":\""; //$NON-NLS-1$ + private String JSON_MESSAGE_SUFFIX = "\"}"; //$NON-NLS-1$ + public DockerException(final String message) { super(message); } @@ -29,4 +32,21 @@ public class DockerException extends Exception { super(cause); } + @Override + public String getMessage() { + String s = super.getMessage(); + // Bug 499917 - temporarily massage any message we get back from docker + // client if it is in JSON format. This code can be removed once docker + // client has fixed itself to work with error messages from docker + // 1.12.0 and beyond. + if (s.startsWith(JSON_MESSAGE_PREFIX)) { + s = s.substring(JSON_MESSAGE_PREFIX.length()); + if (s.endsWith(JSON_MESSAGE_SUFFIX)) { + s = s.substring(0, s.indexOf(JSON_MESSAGE_SUFFIX)); + return s; + } + } + return super.getMessage(); + } + } diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerExceptionTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerExceptionTest.java new file mode 100644 index 0000000000..30a9247ead --- /dev/null +++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerExceptionTest.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat - Initial Contribution + *******************************************************************************/ + +package org.eclipse.linuxtools.docker.core; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** + * Testing the {@link DockerException} class + */ +@RunWith(Parameterized.class) +public class DockerExceptionTest { + + @Parameters + public static Object[][] getData() { + final Object[][] data = new Object[][] { + new Object[] { new DockerException("this is an error"), "this is an error" }, + new Object[] { new DockerException("error with message: 232"), "error with message: 232" }, + new Object[] { + new DockerException( + "{\"message\":\"invalid reference format: repository name must be lowercase\"}"), + "invalid reference format: repository name must be lowercase" }, }; + return data; + } + + @Parameter(0) + public DockerException dockerException; + + @Parameter(1) + public String expectedMessage; + + @Test + public void shouldGetCorrectExceptionMessage() { + // when + final String message = dockerException.getMessage(); + // then + assertThat(message).isEqualTo(expectedMessage); + } +} diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagPage.java index a92fab4465..fe3b5a5458 100644 --- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagPage.java +++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagPage.java @@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.docker.ui.wizards; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.internal.docker.core.DockerImage; import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyListener; @@ -56,6 +57,13 @@ public class ImageTagPage extends WizardPage { complete = false; } + String repo = DockerImage.extractRepo(tagField); + + if (repo.matches(".*[A-Z]+.*")) { //$NON-NLS-1$ + setErrorMessage( + WizardMessages.getString("ImageTagUppercaseError.msg")); //$NON-NLS-1$ + error = true; + } if (!error) { setErrorMessage(null); tag = tagField; diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties index e2d85e74bf..45f0b51524 100644 --- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties +++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties @@ -151,6 +151,7 @@ ImageTag.title=Tag Image ImageTag.name=Tag Image ImageTagName.label=New Tag: ImageTagName.toolTip=Enter new tag for image [REGISTRYHOST/][USERNAME/]NAME[:TAG]] +ImageTagUppercaseError.msg=Repository section of a tag cannot contain upper-case characters. ImageRemoveTag.desc=Select tag to remove from image ImageRemoveTag.title=Remove Image Tag |