Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-08-12 14:25:30 +0000
committerJeff Johnston2016-08-13 00:43:50 +0000
commite4b973120d7b935bf3a579119a1047c0f7fca0ed (patch)
tree80f0fee1fe6e3a4ae60896b69161c73e192f45a3
parent296ed8eb4b67f88aeaec43d3c9ec2d6de0d1c13c (diff)
downloadorg.eclipse.linuxtools-e4b973120d7b935bf3a579119a1047c0f7fca0ed.tar.gz
org.eclipse.linuxtools-e4b973120d7b935bf3a579119a1047c0f7fca0ed.tar.xz
org.eclipse.linuxtools-e4b973120d7b935bf3a579119a1047c0f7fca0ed.zip
Bug 496922 - Improvements on the 'push image' dialog
Refactored the ImagePushPage to use JFace databinding Replaced button with link to open Registry account prefs Added options to tag with 'force' flag and to keep the tagged image upon completion. Refactored ImagePushPage and ImagePullPage to use the same base WizardPage to share the UI part that provides the registry selection and addition. Added SWTBot tests, refactored RegistryAccountManager by introducing a RegistryAccountStorageManager that can be replaced during tests. Changed the validation in the RegistryDialog to allow for null username/password since this should not be a requirement for pulling images (eg: DockerHub or other public registries) Checks the name of the image before tagging. Checks if the selected registry provides auth before pushing. Display push progress handlers in the Progress view only. Change-Id: I682b2cdace11c7124be691186ed31ea41741e2ba Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/76610 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/AbstractRegistry.java31
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java33
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImage.java3
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRegistry.java3
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultImagePushProgressHandler.java5
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java3
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java27
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java48
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountInfo.java82
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountManager.java94
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountStorageManager.java81
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java71
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java3
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerConfigFactory.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockRegistryAccountManagerFactory.java51
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ComboAssertion.java53
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionSWTBotTest.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java141
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java248
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java5
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java19
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.properties2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/plugin.xml4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PullImageCommandHandler.java15
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java83
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/TagImageCommandHandler.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunImageMainTab.java3
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/BasePropertySection.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPage.java172
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPageModel.java32
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPushPage.java184
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPushPageModel.java71
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePush.java78
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPage.java263
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPageModel.java118
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java3
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java8
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTag.java7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagPage.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnection.java6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/RegistryAccountDialog.java24
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties39
47 files changed, 1678 insertions, 483 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/AbstractRegistry.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/AbstractRegistry.java
index 1b2e2c64f5..d79b393fda 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/AbstractRegistry.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/AbstractRegistry.java
@@ -14,7 +14,6 @@ import static javax.ws.rs.HttpMethod.GET;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -45,11 +44,12 @@ import com.spotify.docker.client.messages.ImageSearchResult;
*/
public abstract class AbstractRegistry implements IRegistry {
+ /** Aliases of the Docker Hub hostname. */
public static final String[] DOCKERHUB_REGISTRY_ALIASES = new String[] {
"registry.hub.docker.com", //$NON-NLS-1$
"index.docker.io" //$NON-NLS-1$
};
- public static final String DOCKERHUB_REGISTRY = "index.docker.io"; //$NON-NLS-1$
+ public static final String DOCKERHUB_REGISTRY = "https://index.docker.io"; //$NON-NLS-1$
// Cache the URL for searches to avoid excessive calls
private String cachedHTTPServerAddress;
// Cache the result of isVersion2 to avoid excessive calls
@@ -58,6 +58,28 @@ public abstract class AbstractRegistry implements IRegistry {
@Override
public abstract String getServerAddress();
+ /**
+ *
+ * @return the server host (and optional port) to prepend to an image name
+ * when pushing or pulling
+ */
+ // TODO: add this method in the IRegistry interface
+ public abstract String getServerHost();
+
+ /**
+ * @return <code>true</code> if this {@link IRegistry} is for Docker Hub,
+ * <code>false</code> otherwise.
+ */
+ // TODO: add this method in the IRegistry interface
+ public abstract boolean isDockerHubRegistry();
+
+ /**
+ * @return <code>true</code> if this {@link IRegistry} includes credentials,
+ * <code>false</code> otherwise.
+ */
+ // TODO: add this method in the IRegistry interface
+ public abstract boolean isAuthProvided();
+
private String getHTTPServerAddress() {
if (cachedHTTPServerAddress != null) {
return cachedHTTPServerAddress;
@@ -160,8 +182,6 @@ public abstract class AbstractRegistry implements IRegistry {
final ClientConfig DEFAULT_CONFIG = new ClientConfig(
ObjectMapperProvider.class, JacksonFeature.class);
final Client client = ClientBuilder.newClient(DEFAULT_CONFIG);
- final List<String> dockerHubAliases = Arrays
- .asList(DOCKERHUB_REGISTRY_ALIASES);
WebTarget queryTagsResource;
List<IRepositoryTag> result = new ArrayList<>();
@@ -181,8 +201,7 @@ public abstract class AbstractRegistry implements IRegistry {
// Docker Hub Registry format is actually different from an actual
// registry
- } else if (dockerHubAliases.stream()
- .anyMatch(a -> getServerAddress().contains(a))) {
+ } else if (isDockerHubRegistry()) {
queryTagsResource = client.target(getHTTPServerAddress()).path("v1") //$NON-NLS-1$
.path("repositories").path(repository).path("tags"); //$NON-NLS-1$ //$NON-NLS-2$
GenericType<List<RepositoryTag>> REPOSITORY_TAGS_RESULT_LIST = new GenericType<List<RepositoryTag>>() {
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
index 84adaf08ab..e8f62d9285 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
@@ -69,7 +69,9 @@ public class DockerConnectionManager {
conn = new DockerConnection.Builder().name(tsetting.getName())
.tcpConnection(tsetting);
}
- addConnection(conn);
+ // add the connection but do not notify the listeners to avoid
+ // flickering on the Docker Explorer view for each entry
+ addConnection(conn, false);
}
}
@@ -112,12 +114,37 @@ public class DockerConnectionManager {
return null;
}
+ /**
+ * Adds the given connection and notifies all registered
+ * {@link IDockerConnectionManagerListener}
+ *
+ * @param dockerConnection
+ * the connection to add
+ */
public void addConnection(final IDockerConnection dockerConnection) {
+ addConnection(dockerConnection, true);
+ }
+
+ /**
+ * Adds the given connection and notifies optionally all registered
+ * {@link IDockerConnectionManagerListener}
+ *
+ * @param dockerConnection
+ * the connection to add
+ * @param notifyListeners
+ * flag to indicate if registered
+ * {@link IDockerConnectionManagerListener} should be notified
+ * about the {@link IDockerConnection} addition.
+ */
+ public void addConnection(final IDockerConnection dockerConnection,
+ final boolean notifyListeners) {
if (!connections.contains(dockerConnection)) {
connections.add(dockerConnection);
saveConnections();
- notifyListeners(dockerConnection,
- IDockerConnectionManagerListener.ADD_EVENT);
+ if (notifyListeners) {
+ notifyListeners(dockerConnection,
+ IDockerConnectionManagerListener.ADD_EVENT);
+ }
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImage.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImage.java
index bd880605d8..e8e123af7c 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImage.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerImage.java
@@ -21,6 +21,9 @@ public interface IDockerImage {
String createdDate();
+ /**
+ * @return the full image id
+ */
String id();
String parentId();
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRegistry.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRegistry.java
index ab00a436f4..f3a874105f 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRegistry.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IRegistry.java
@@ -14,6 +14,9 @@ import java.util.List;
public interface IRegistry {
+ /**
+ * @return the server address URL, including the scheme
+ */
String getServerAddress();
List<IDockerImageSearchResult> getImages(String term) throws DockerException;
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultImagePushProgressHandler.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultImagePushProgressHandler.java
index b5b1f8f80c..20bfa35a61 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultImagePushProgressHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultImagePushProgressHandler.java
@@ -60,7 +60,10 @@ public class DefaultImagePushProgressHandler implements IDockerProgressHandler {
IMAGE_UPLOADING_JOBNAME, image),
DockerMessages.getFormattedString(
IMAGE_UPLOADING_IMAGE, id));
- newJob.setUser(true);
+ // job.setUser(false) will show all pull job (one per image
+ // layer) in the progress
+ // view but not in multiple dialog
+ newJob.setUser(false);
newJob.setPriority(Job.LONG);
newJob.schedule();
progressJobs.put(id, newJob);
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
index e46742b0c1..e399903e55 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerClientFactory.java
@@ -100,7 +100,8 @@ public class DockerClientFactory {
.serverAddress(info.getServerAddress())
.username(info.getUsername())
.email(info.getEmail())
- .password(new String(info.getPassword()))
+ .password(info.getPassword() != null
+ ? new String(info.getPassword()) : null)
.build();
return authAccount;
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
index 11ae9c785f..f3a5a2c275 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
@@ -1169,8 +1169,30 @@ public class DockerConnection
@Override
public void tagImage(final String name, final String newTag) throws DockerException,
InterruptedException {
+ tagImage(name, newTag, false);
+ }
+
+ /**
+ * Adds a tag to an existing image while specifying the <code>force</code>
+ * flag.
+ *
+ * @param name
+ * the image id
+ * @param newTag
+ * the new tag to add to the given image
+ * @param force
+ * the {@code force} flag to force the operation if
+ * <code>true</code>.
+ * @throws DockerException
+ * in case of underlying problem (server error)
+ * @throws InterruptedException
+ * if the thread was interrupted
+ */
+ // TODO: add to the API in version 3.0.0
+ public void tagImage(final String name, final String newTag,
+ final boolean force) throws DockerException, InterruptedException {
try {
- client.tag(name, newTag);
+ client.tag(name, newTag, force);
} catch (com.spotify.docker.client.DockerRequestException e) {
throw new DockerException(e.message());
} catch (com.spotify.docker.client.DockerException e) {
@@ -1760,7 +1782,8 @@ public class DockerConnection
try {
AuthConfig authConfig = AuthConfig.builder()
.username(new String(cfg.getUsername()))
- .password(new String(cfg.getPassword()))
+ .password(cfg.getPassword() != null
+ ? new String(cfg.getPassword()) : null)
.email(new String(cfg.getEmail()))
.serverAddress(new String(cfg.getServerAddress())).build();
return client.auth(authConfig);
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java
index 838c70f351..b83d81e121 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerImage.java
@@ -24,6 +24,9 @@ import org.eclipse.linuxtools.docker.core.IDockerImage;
public class DockerImage implements IDockerImage {
+ /** The 'latest' tag. */
+ public static final String LATEST_TAG = "latest"; //$NON-NLS-1$
+
private static final String REGISTRY_HOST = "[a-zA-Z0-9]+([\\._-][a-zA-Z0-9]+)*"; //$NON-NLS-1$
private static final String REGISTRY_PORT = "[0-9]+"; //$NON-NLS-1$
private static final String REPOSITORY = "[a-z0-9]+([\\._-][a-z0-9]+)*"; //$NON-NLS-1$
@@ -49,6 +52,7 @@ public class DockerImage implements IDockerImage {
private final String created;
private final String createdDate;
private final String id;
+ private final String shortId;
private final String parentId;
private final List<String> repoTags;
private final String repo;
@@ -69,6 +73,7 @@ public class DockerImage implements IDockerImage {
this.repo = repo;
this.tags = tags;
this.id = id;
+ this.shortId = getShortId(id);
this.parentId = parentId;
this.created = created;
this.createdDate = created != null
@@ -83,6 +88,22 @@ public class DockerImage implements IDockerImage {
}
/**
+ * @param id
+ * the complete {@link IDockerImage} id
+ * @return the short id, excluding the {@code sha256:} prefix if present.
+ */
+ private static String getShortId(final String id) {
+ if (id.startsWith("sha256:")) {
+ return getShortId(id.substring("sha256:".length()));
+ }
+ if (id.length() > 12) {
+ return id.substring(0, 12);
+ } else {
+ return id;
+ }
+ }
+
+ /**
* Extracts the org/repo and all the associated tags from the given
* {@code repoTags}, assuming that the given repoTags elements have the
* following format: {@code [org/]repo[:tag]}. Tags are sorted by their
@@ -162,7 +183,7 @@ public class DockerImage implements IDockerImage {
*
* @param repoTag
* the repo/tag to analyze
- * @return the tag or null if none was found.
+ * @return the tag or <code>null</code> if none was found.
*/
public static String extractTag(final String repoTag) {
if (repoTag == null) {
@@ -197,7 +218,16 @@ public class DockerImage implements IDockerImage {
@Override
public String id() {
- return id;
+ return this.id;
+ }
+
+ /**
+ * @return the short image id, ie, the first 12 figures, excluding the
+ * <code>sha256:</code> prefix.
+ */
+ // TODO: add to the API in version 3.0.0
+ public String shortId() {
+ return this.shortId;
}
@Override
@@ -282,4 +312,18 @@ public class DockerImage implements IDockerImage {
return true;
}
+ /**
+ * Appends the <code>latest</code> tag to the given {@code imageName}
+ *
+ * @param imageName
+ * the image name to check
+ * @return the image name with the <code>latest</code> tag if none was set
+ */
+ public static String setDefaultTagIfMissing(final String imageName) {
+ if (DockerImage.extractTag(imageName) == null) {
+ return imageName + ':' + LATEST_TAG;
+ }
+ return imageName;
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountInfo.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountInfo.java
index 9c9e14e9e4..425d19d475 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountInfo.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountInfo.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.docker.core;
+import java.util.Arrays;
+
import org.eclipse.equinox.security.storage.ISecurePreferences;
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
import org.eclipse.equinox.security.storage.StorageException;
@@ -18,18 +20,25 @@ import org.eclipse.linuxtools.docker.core.IRegistryAccount;
public class RegistryAccountInfo extends RegistryInfo
implements IRegistryAccount {
- private String username;
- private String email;
- private char [] password;
+ private final String username;
+ private final String email;
+ private final char[] password;
- public RegistryAccountInfo(String serverAddress, String username, String email, char [] password) {
- super(serverAddress);
+ public RegistryAccountInfo(final String serverAddress,
+ final String username, final String email, final char[] password,
+ final boolean dockerHubRegistry) {
+ super(serverAddress, dockerHubRegistry);
this.username = username;
this.email = email;
this.password = password;
}
@Override
+ public boolean isAuthProvided() {
+ return this.username != null && this.password != null;
+ }
+
+ @Override
public String getUsername() {
return username;
}
@@ -45,14 +54,69 @@ public class RegistryAccountInfo extends RegistryInfo
return password;
}
char[] password = null;
- ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
- ISecurePreferences dockerNode = preferences.node("org.eclipse.linuxtools.docker.ui.accounts"); //$NON-NLS-1$
- String key = getServerAddress() + "," + getUsername() + "," + getEmail();
+ final ISecurePreferences preferences = SecurePreferencesFactory
+ .getDefault();
+ final ISecurePreferences dockerNode = preferences
+ .node("org.eclipse.linuxtools.docker.ui.accounts"); //$NON-NLS-1$
+ final String key = getServerAddress() + "," + getUsername() + ","
+ + getEmail();
try {
- password = dockerNode.get(key, null).toCharArray();
+ password = dockerNode.get(key, null) != null
+ ? dockerNode.get(key, null).toCharArray() : null;
} catch (StorageException e) {
}
return password;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((email == null) ? 0 : email.hashCode());
+ result = prime * result + Arrays.hashCode(password);
+ result = prime * result
+ + ((username == null) ? 0 : username.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ RegistryAccountInfo other = (RegistryAccountInfo) obj;
+ if (email == null) {
+ if (other.email != null) {
+ return false;
+ }
+ } else if (!email.equals(other.email)) {
+ return false;
+ }
+ if (!Arrays.equals(password, other.password)) {
+ return false;
+ }
+ if (username == null) {
+ if (other.username != null) {
+ return false;
+ }
+ } else if (!username.equals(other.username)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "RegistryAccountInfo [username=" + username + ", email=" + email
+ + ", getServerAddress()=" + getServerAddress()
+ + ", isDockerHubRegistry()=" + isDockerHubRegistry()
+ + ", isVersion2()=" + isVersion2() + "]";
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountManager.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountManager.java
index 5632c21d6b..602a037f20 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountManager.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountManager.java
@@ -10,81 +10,81 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.docker.core;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import org.eclipse.equinox.security.storage.ISecurePreferences;
-import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
-import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.linuxtools.docker.core.IRegistryAccount;
public class RegistryAccountManager {
private static RegistryAccountManager instance;
+ /** the storage manager. */
+ private RegistryAccountStorageManager storageManager = new RegistryAccountStorageManager();
+
+ /** local cache of accounts. */
+ private List<IRegistryAccount> registryAccounts;
+
+ /**
+ * Private constructor of the singleton
+ */
private RegistryAccountManager() {
+
}
public static RegistryAccountManager getInstance() {
if (instance == null) {
- return new RegistryAccountManager();
+ instance = new RegistryAccountManager();
}
return instance;
}
+ /**
+ * Replaces the default storage manager implementation instance,
+ * {@link RegistryAccountStorageManager} by another one. This can be used
+ * during tests if a mock instance is used to avoid actually storing
+ * registry accounts.
+ *
+ * @param storageManager
+ * the {@link RegistryAccountStorageManager} instance to use
+ */
+ public void setStorageManager(
+ final RegistryAccountStorageManager storageManager) {
+ this.storageManager = storageManager;
+ // make sure the registry accounts are bound to the new storage manager
+ this.registryAccounts = storageManager.getAccounts();
+ }
+
+ /**
+ * @return the underlying {@link RegistryAccountStorageManager}
+ */
+ public RegistryAccountStorageManager getStorageManager() {
+ return this.storageManager;
+ }
+
public List<IRegistryAccount> getAccounts() {
- List<IRegistryAccount> accounts = new ArrayList<>();
- ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
- ISecurePreferences dockerNode = preferences.node("org.eclipse.linuxtools.docker.ui.accounts"); //$NON-NLS-1$
- for (String key : dockerNode.keys()) {
- String[] tokens = key.split(","); //$NON-NLS-1$
- if (tokens.length > 1) {
- String serverAddress = tokens[0];
- String username = tokens[1];
- String email = ""; //$NON-NLS-1$
- if (tokens.length > 2) {
- email = tokens[2];
- }
- RegistryAccountInfo account = new RegistryAccountInfo(serverAddress, username, email, null);
- accounts.add(account);
- }
+ if (this.registryAccounts == null) {
+ this.registryAccounts = storageManager.getAccounts();
}
- return accounts;
+ return this.registryAccounts;
}
- public IRegistryAccount getAccount(String serverAddress, String username) {
- Iterator<IRegistryAccount> it = getAccounts().stream()
+ public IRegistryAccount getAccount(final String serverAddress,
+ final String username) {
+ return getAccounts().stream()
.filter(a -> a.getServerAddress().equals(serverAddress)
&& a.getUsername().equals(username))
- .iterator();
- return it.hasNext() ? it.next() : null;
+ .findFirst().orElse(null);
}
- public void add(IRegistryAccount info) {
- ISecurePreferences preferences = getDockerNode();
- char[] password = info.getPassword();
- String key = getKeyFor(info);
- try {
- preferences.put(key, new String(password), true);
- } catch (StorageException e) {
- }
+ public void add(final IRegistryAccount info) {
+ this.registryAccounts.add(info);
+ storageManager.add(info);
}
- public void remove(IRegistryAccount info) {
- ISecurePreferences preferences = getDockerNode();
- String key = getKeyFor(info);
- preferences.remove(key);
+ public void remove(final IRegistryAccount info) {
+ this.registryAccounts.remove(info);
+ storageManager.remove(info);
}
- private ISecurePreferences getDockerNode() {
- ISecurePreferences preferences = SecurePreferencesFactory.getDefault();
- ISecurePreferences dockerNode = preferences
- .node("org.eclipse.linuxtools.docker.ui.accounts"); //$NON-NLS-1$
- return dockerNode;
- }
- private String getKeyFor(IRegistryAccount info) {
- return info.getServerAddress() + "," + info.getUsername() + "," + info.getEmail(); //$NON-NLS-1$ //$NON-NLS-2$
- }
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountStorageManager.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountStorageManager.java
new file mode 100644
index 0000000000..8ae0253884
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryAccountStorageManager.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.internal.docker.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
+import org.eclipse.linuxtools.docker.core.Activator;
+import org.eclipse.linuxtools.docker.core.IRegistryAccount;
+
+public class RegistryAccountStorageManager {
+
+ public List<IRegistryAccount> getAccounts() {
+ final List<IRegistryAccount> accounts = new ArrayList<>();
+ final ISecurePreferences preferences = SecurePreferencesFactory
+ .getDefault();
+ final ISecurePreferences dockerNode = preferences
+ .node("org.eclipse.linuxtools.docker.ui.accounts"); //$NON-NLS-1$
+ for (String key : dockerNode.keys()) {
+ final String[] tokens = key.split(","); //$NON-NLS-1$
+ if (tokens.length > 1) {
+ final String serverAddress = tokens[0];
+ final String username = tokens[1];
+ final String email = tokens.length > 2 ? tokens[2] : ""; //$NON-NLS-1$
+ final RegistryAccountInfo account = new RegistryAccountInfo(
+ serverAddress, username, email, null, false);
+ accounts.add(account);
+ }
+ }
+ return accounts;
+ }
+
+ public IRegistryAccount getAccount(String serverAddress, String username) {
+ return getAccounts().stream()
+ .filter(a -> a.getServerAddress().equals(serverAddress)
+ && a.getUsername().equals(username))
+ .findFirst().orElse(null);
+ }
+
+ public void add(IRegistryAccount info) {
+ final ISecurePreferences preferences = getDockerNode();
+ final char[] password = info.getPassword();
+ final String key = getKeyFor(info);
+ try {
+ preferences.put(key,
+ (password != null ? new String(password) : null), true);
+ } catch (StorageException e) {
+ Activator.logErrorMessage(
+ "Failed to store Docker registry password", e);
+ }
+ }
+
+ public void remove(final IRegistryAccount info) {
+ final ISecurePreferences preferences = getDockerNode();
+ final String key = getKeyFor(info);
+ preferences.remove(key);
+ }
+
+ private ISecurePreferences getDockerNode() {
+ final ISecurePreferences preferences = SecurePreferencesFactory
+ .getDefault();
+ final ISecurePreferences dockerNode = preferences
+ .node("org.eclipse.linuxtools.docker.ui.accounts"); //$NON-NLS-1$
+ return dockerNode;
+ }
+
+ private String getKeyFor(final IRegistryAccount info) {
+ return info.getServerAddress() + "," + info.getUsername() + "," + info.getEmail(); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java
index 928715fdf3..5276ee74d0 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/RegistryInfo.java
@@ -10,14 +10,23 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.docker.core;
+import java.net.MalformedURLException;
+import java.net.URL;
+
import org.eclipse.linuxtools.docker.core.AbstractRegistry;
public class RegistryInfo extends AbstractRegistry {
- private String serverAddress;
+ /** the registry address. */
+ private final String serverAddress;
+
+ /** flag to indicate if the registry is the Docker Hub platform. */
+ private final boolean dockerHubRegistry;
- public RegistryInfo(String serverAddress) {
+ public RegistryInfo(final String serverAddress,
+ final boolean dockerHubRegistry) {
this.serverAddress = serverAddress;
+ this.dockerHubRegistry = dockerHubRegistry;
}
@Override
@@ -25,4 +34,62 @@ public class RegistryInfo extends AbstractRegistry {
return serverAddress;
}
+ @Override
+ public String getServerHost() {
+ try {
+ final URL serverAddress = new URL(getServerAddress());
+ return serverAddress.getHost() + (serverAddress.getPort() != -1
+ ? ':' + serverAddress.getPort() : ""); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ // assume there was no scheme, so just use the plain
+ // server address
+ return getServerAddress();
+ }
+ }
+
+ @Override
+ public boolean isDockerHubRegistry() {
+ return this.dockerHubRegistry;
+ }
+
+ @Override
+ public boolean isAuthProvided() {
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (dockerHubRegistry ? 1231 : 1237);
+ result = prime * result
+ + ((serverAddress == null) ? 0 : serverAddress.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ RegistryInfo other = (RegistryInfo) obj;
+ if (dockerHubRegistry != other.dockerHubRegistry) {
+ return false;
+ }
+ if (serverAddress == null) {
+ if (other.serverAddress != null) {
+ return false;
+ }
+ } else if (!serverAddress.equals(other.serverAddress)) {
+ return false;
+ }
+ return true;
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java
index d1fc486d5a..d954528553 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java
@@ -70,7 +70,10 @@ public class MockDockerConnectionFactory {
final DockerClientFactory dockerClientFactory = Mockito.mock(DockerClientFactory.class);
connection.setDockerClientFactory(dockerClientFactory);
try {
+ // return dockerClient without auth
Mockito.when(dockerClientFactory.getClient(Matchers.any())).thenReturn(dockerClient);
+ // return same dockerClient with auth arg
+ Mockito.when(dockerClientFactory.getClient(Matchers.any(), Matchers.any())).thenReturn(dockerClient);
} catch (DockerCertificateException e) {
// rest assured, nothing will happen while mocking the DockerClientFactory
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerConfigFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerConfigFactory.java
index acc318d7f8..b5b37fc86d 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerConfigFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerContainerConfigFactory.java
@@ -41,7 +41,7 @@ public class MockDockerContainerConfigFactory {
return this;
}
- public IDockerContainerConfig build() {
+ public DockerContainerConfig build() {
Mockito.when(this.containerConfig.exposedPorts()).thenReturn(Collections.emptySet());
Mockito.when(this.containerConfig.env()).thenReturn(Collections.emptyList());
Mockito.when(this.containerConfig.labels()).thenReturn(Collections.emptyMap());
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockRegistryAccountManagerFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockRegistryAccountManagerFactory.java
new file mode 100644
index 0000000000..caad717cfc
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockRegistryAccountManagerFactory.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.internal.docker.ui.testutils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.docker.core.IRegistryAccount;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountManager;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountStorageManager;
+import org.mockito.Mockito;
+
+/**
+ * Utility class to get mocked instances of {@link RegistryAccountManager}
+ */
+public class MockRegistryAccountManagerFactory {
+
+ public static MockRegistryAccountManagerBuilder registryAccount(IRegistryAccount registryAccount) {
+ return new MockRegistryAccountManagerBuilder().registryAccount(registryAccount);
+ }
+
+ public static class MockRegistryAccountManagerBuilder {
+
+ private final List<IRegistryAccount> registryAccounts = new ArrayList<>();
+
+ public MockRegistryAccountManagerBuilder registryAccount(IRegistryAccount registryAccount) {
+ registryAccounts.add(registryAccount);
+ return this;
+ }
+
+ public RegistryAccountManager build() {
+ final RegistryAccountStorageManager mockRegistryAccountStorageManager = Mockito
+ .mock(RegistryAccountStorageManager.class);
+ Mockito.when(mockRegistryAccountStorageManager.getAccounts()).thenReturn(registryAccounts);
+ final RegistryAccountManager registryAccountManager = RegistryAccountManager.getInstance();
+ registryAccountManager.setStorageManager(mockRegistryAccountStorageManager);
+ return registryAccountManager;
+ }
+
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.java
index f6536ad724..65f5820144 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.java
@@ -31,7 +31,7 @@ public class ClearConnectionManagerRule extends ExternalResource {
/**
* Removes all connections in the given {@link DockerConnectionManager}
- *
+ *
* @param dockerConnectionManager
*/
public static void removeAllConnections(final DockerConnectionManager dockerConnectionManager) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ComboAssertion.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ComboAssertion.java
new file mode 100644
index 0000000000..cb5229ebcb
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ComboAssertion.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.internal.docker.ui.testutils.swt;
+
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
+
+/**
+ * Custom assertions on a given {@link SWTBotCheckBox}.
+ */
+public class ComboAssertion extends AbstractSWTBotAssertion<ComboAssertion, SWTBotCombo> {
+
+ protected ComboAssertion(final SWTBotCombo actual) {
+ super(actual, ComboAssertion.class);
+ }
+
+ public static ComboAssertion assertThat(final SWTBotCombo actual) {
+ return new ComboAssertion(actual);
+ }
+
+ public ComboAssertion itemSelected(final String expectedItem) {
+ notNullValue();
+ if (actual.selectionIndex() < 0) {
+ failWithMessage("Expected combo to have selection to '%s' but it had none", expectedItem);
+ } else if (!actual.selection().equals(expectedItem)) {
+ failWithMessage("Expected combo to have selection to '%s' but it was '%s'", expectedItem,
+ actual.selection());
+ }
+ return this;
+ }
+
+ public ComboAssertion indexItemSelected(final int expectedItemIndex) {
+ notNullValue();
+ if (actual.selectionIndex() < 0) {
+ failWithMessage("Expected combo to have selection index to '%s' but it had none", expectedItemIndex);
+ } else if (actual.selectionIndex() != expectedItemIndex) {
+ failWithMessage("Expected combo to have selection index to '%s' but it was '%s'", expectedItemIndex,
+ actual.selectionIndex());
+ }
+ return this;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
index 36c6de139e..f4f0ee15d8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
@@ -513,7 +513,7 @@ public class DockerExplorerViewSWTBotTest {
// the properties view should be visible
assertThat(this.bot.viewById("org.eclipse.ui.views.PropertySheet").isActive()).isEqualTo(true);
SWTBotView propertiesViewBot = bot.viewById("org.eclipse.ui.views.PropertySheet");
- SWTUtils.getContextMenu(propertiesViewBot.bot().tree(), "Copy").click();
+ SWTUtils.getContextMenu(propertiesViewBot.bot().tree().select(1), "Copy").click();
this.dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference().getView(true));
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionSWTBotTest.java
index bbec32de7e..cffb330684 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/EditDockerConnectionSWTBotTest.java
@@ -26,11 +26,11 @@ import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
import org.eclipse.linuxtools.docker.core.EnumDockerConnectionState;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager;
-import org.eclipse.linuxtools.docker.core.IDockerContainerConfig;
import org.eclipse.linuxtools.docker.core.IDockerHostConfig;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.core.IDockerImageBuildOptions;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig;
import org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings;
import org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings;
import org.eclipse.linuxtools.internal.docker.ui.launch.IBuildDockerImageLaunchConfigurationConstants;
@@ -140,7 +140,7 @@ public class EditDockerConnectionSWTBotTest {
private String configureRunImageLaunchConfiguration(final IDockerConnection connection) {
final IDockerImage image = MockDockerImageFactory.name("image").connection(connection).build();
- final IDockerContainerConfig containerConfig = MockDockerContainerConfigFactory.cmd("cmd").build();
+ final DockerContainerConfig containerConfig = MockDockerContainerConfigFactory.cmd("cmd").build();
final IDockerHostConfig hostConfig = MockDockerHostConfigFactory.publishAllPorts(true).build();
final ILaunchConfiguration runImageLaunchConfiguration = LaunchConfigurationUtils
.createRunImageLaunchConfiguration(image, containerConfig, hostConfig, "some_container", false);
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java
new file mode 100644
index 0000000000..19e8156d9a
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullSWTBotTest.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * 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.internal.docker.ui.wizards;
+
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.core.DockerProgressHandler;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountInfo;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountManager;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountStorageManager;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockImageFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockRegistryAccountManagerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ButtonAssertion;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionManagerRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWizardRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.spotify.docker.client.DockerClient;
+import com.spotify.docker.client.DockerException;
+
+/**
+ * Testing the {@link ImagePull} wizard
+ */
+public class ImagePullSWTBotTest {
+
+ private SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ private DockerExplorerView dockerExplorerView;
+ private SWTBotView dockerExplorerViewBot;
+
+ @ClassRule
+ public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule();
+
+ @Rule
+ public ClearConnectionManagerRule clearConnectionManager = new ClearConnectionManagerRule();
+
+ @Rule
+ public CloseWizardRule closeWizard = new CloseWizardRule();
+ private RegistryAccountStorageManager defaultRegistryAccountStorageManager;
+ private DockerClient client;
+
+ @Before
+ public void lookupDockerExplorerView() {
+ this.dockerExplorerViewBot = bot.viewById("org.eclipse.linuxtools.docker.ui.dockerExplorerView");
+ this.dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference().getView(true));
+ this.dockerExplorerViewBot.show();
+ this.dockerExplorerViewBot.setFocus();
+ this.defaultRegistryAccountStorageManager = RegistryAccountManager.getInstance().getStorageManager();
+ }
+
+ @Before
+ public void setupDockerClient() {
+ this.client = MockDockerClientFactory.image(MockImageFactory.name("bar:latest", "foo/bar:latest").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client)
+ .withDefaultTCPConnectionSettings();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
+ }
+
+ @After
+ public void restoreRegistryAccountStorageManager() {
+ RegistryAccountManager.getInstance().setStorageManager(this.defaultRegistryAccountStorageManager);
+ }
+
+ private void openPullWizard() {
+ // when opening the "Push Image..." wizard
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images").select();
+ dockerExplorerViewBot.bot().tree().contextMenu("Pull...").click();
+ }
+
+ @Ignore
+ @Test
+ public void shoulDisableSearchButtonWhenNoRegistrySelected() {
+ // given
+ openPullWizard();
+ // when
+ bot.text(0).setText("jboss/wildfly:latest");
+ // then
+ ButtonAssertion.assertThat(bot.button("Finish")).isNotEnabled();
+ }
+
+ @Test
+ public void shouldNotAllowFinishWhenImageNameIsMissing() {
+ // given
+ openPullWizard();
+ // when no data is input for the image name
+ // then
+ ButtonAssertion.assertThat(bot.button("Finish")).isNotEnabled();
+ }
+
+ @Test
+ public void shouldPullImageFromDockerHub() throws DockerException, InterruptedException {
+ // given
+ openPullWizard();
+ // when
+ bot.text(0).setText("jboss/wildfly:latest");
+ bot.button("Finish").click();
+ // then
+ Mockito.verify(client, Mockito.times(1)).pull(Mockito.eq("jboss/wildfly:latest"),
+ Mockito.any(DockerProgressHandler.class));
+ }
+
+ @Test
+ public void shouldPullImageFromOtherRegistry() throws DockerException, InterruptedException {
+ // given
+ MockRegistryAccountManagerFactory
+ .registryAccount(
+ new RegistryAccountInfo("http://foo.com", "foo", null, "secret".toCharArray(), false))
+ .build();
+ openPullWizard();
+ // when selecting other registry
+ bot.comboBox(0).setSelection("foo@http://foo.com");
+ // when
+ bot.text(0).setText("jboss/wildfly:latest");
+ bot.button("Finish").click();
+ // then
+ Mockito.verify(client, Mockito.times(1)).pull(Mockito.eq("foo.com/jboss/wildfly:latest"),
+ Mockito.any(DockerProgressHandler.class));
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java
new file mode 100644
index 0000000000..811d5c37c1
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushSWTBotTests.java
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * 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.internal.docker.ui.wizards;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.linuxtools.docker.core.AbstractRegistry;
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountInfo;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountManager;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountStorageManager;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockImageFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockRegistryAccountManagerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionManagerRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWizardRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ComboAssertion;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+
+import com.spotify.docker.client.DockerClient;
+import com.spotify.docker.client.DockerException;
+
+/**
+ * Testing the {@link ImagePush} wizard
+ */
+public class ImagePushSWTBotTests {
+
+ private SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ private DockerExplorerView dockerExplorerView;
+ private SWTBotView dockerExplorerViewBot;
+
+ @ClassRule
+ public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule();
+
+ @Rule
+ public ClearConnectionManagerRule clearConnectionManager = new ClearConnectionManagerRule();
+
+ @Rule
+ public CloseWizardRule closeWizard = new CloseWizardRule();
+ private RegistryAccountStorageManager defaultRegistryAccountStorageManager;
+ private DockerClient client;
+
+ @Before
+ public void lookupDockerExplorerView() {
+ this.dockerExplorerViewBot = bot.viewById("org.eclipse.linuxtools.docker.ui.dockerExplorerView");
+ this.dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference().getView(true));
+ this.dockerExplorerViewBot.show();
+ this.dockerExplorerViewBot.setFocus();
+ this.defaultRegistryAccountStorageManager = RegistryAccountManager.getInstance().getStorageManager();
+ }
+
+ @Before
+ public void setupDockerClient() {
+ this.client = MockDockerClientFactory.image(MockImageFactory.name("bar:latest", "foo/bar:latest").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client)
+ .withDefaultTCPConnectionSettings();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
+ }
+
+ @After
+ public void restoreRegistryAccountStorageManager() {
+ RegistryAccountManager.getInstance().setStorageManager(this.defaultRegistryAccountStorageManager);
+ }
+
+ private void openPushWizard() {
+ SWTUtils.syncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem imageTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo/bar");
+ // when opening the "Push Image..." wizard
+ final SWTBotTree dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
+ dockerExplorerViewTreeBot.select(imageTreeItem);
+ dockerExplorerViewTreeBot.contextMenu("Push...").click();
+ }
+
+ @Test
+ public void shouldPrefillWizardWithSelectedImageTag() {
+ // given
+ MockRegistryAccountManagerFactory
+ .registryAccount(new RegistryAccountInfo("http://foo.com", "foo", null, "secret".toCharArray(), false))
+ .build();
+
+ // expand the 'Images' node
+ openPushWizard();
+ // then the registry should be set with the first element available, too
+ ComboAssertion.assertThat(bot.comboBox(0)).itemSelected(AbstractRegistry.DOCKERHUB_REGISTRY);
+ // and the "Image Name" combo should have a selection
+ ComboAssertion.assertThat(bot.comboBox(1)).itemSelected("foo/bar:latest");
+ }
+
+ @Test
+ public void shouldPushImage() throws DockerException, InterruptedException {
+ // given
+ MockRegistryAccountManagerFactory
+ .registryAccount(new RegistryAccountInfo("http://foo.com", null, null, null, false)).build();
+ openPushWizard();
+ // when selecting other registry
+ bot.comboBox(0).setSelection(1);
+ // when click on Finish
+ bot.button("Finish").click();
+ // wait for the push job to complete
+ // then the 'push()' method on the client should have been called
+ SWTUtils.wait(1, TimeUnit.SECONDS);
+ Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "foo.com/foo/bar:latest", false);
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.any(), Matchers.any());
+ Mockito.verify(client, Mockito.times(1)).removeImage("foo.com/foo/bar:latest", false, false);
+ }
+
+ @Test
+ public void shouldPushImageToDockerHub() throws DockerException, InterruptedException {
+ // when
+ openPushWizard();
+ // when click on Finish
+ bot.button("Finish").click();
+ // wait for the push job to complete
+ // then the 'push()' method on the client should have been called
+ SWTUtils.wait(1, TimeUnit.SECONDS);
+ Mockito.verify(client, Mockito.never()).tag(Matchers.anyString(), Matchers.anyString(), Matchers.anyBoolean());
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.any(), Matchers.any());
+ Mockito.verify(client, Mockito.never()).removeImage(Matchers.anyString(), Matchers.anyBoolean(),
+ Matchers.anyBoolean());
+ }
+
+ @Test
+ public void shouldPushImageWithForceTagging() throws DockerException, InterruptedException {
+ // given
+ MockRegistryAccountManagerFactory
+ .registryAccount(new RegistryAccountInfo("http://foo.com", "foo", null, "secret".toCharArray(), false))
+ .build();
+ // when
+ openPushWizard();
+ // when tagging image with '--force'
+ bot.checkBox(0).select();
+ // when selecting other registry
+ bot.comboBox(0).setSelection(1);
+ // when click on Finish
+ bot.button("Finish").click();
+ // wait for the push job to complete
+ // then the 'push()' method on the client should have been called
+ SWTUtils.wait(1, TimeUnit.SECONDS);
+ Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "foo.com/foo/bar:latest", true);
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.any(), Matchers.any());
+ Mockito.verify(client, Mockito.times(1)).removeImage("foo.com/foo/bar:latest", false, false);
+ }
+
+ @Test
+ public void shouldPushImageAndKeepTaggedImage() throws DockerException, InterruptedException {
+ // given
+ MockRegistryAccountManagerFactory
+ .registryAccount(new RegistryAccountInfo("http://foo.com", "foo", null, "secret".toCharArray(), false))
+ .build();
+ openPushWizard();
+ // when selecting other registry
+ bot.comboBox(0).setSelection(1);
+ // when keeping tagged image
+ bot.checkBox(1).select();
+ // when click on Finish
+ bot.button("Finish").click();
+ // wait for the push job to complete
+ // then the 'push()' method on the client should have been called
+ SWTUtils.wait(1, TimeUnit.SECONDS);
+ Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "foo.com/foo/bar:latest", false);
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.any(), Matchers.any());
+ Mockito.verify(client, Mockito.never()).removeImage(Matchers.anyString(), Matchers.anyBoolean(),
+ Matchers.anyBoolean());
+ }
+
+ @Test
+ public void shouldPushImageWithNewTagToDockerHub() throws DockerException, InterruptedException {
+ // given
+ openPushWizard();
+ // when providing a new name to the image
+ bot.comboBox(1).setText("another/name");
+ // when click on Finish
+ bot.button("Finish").click();
+ // wait for the push job to complete
+ // then the 'push()' method on the client should have been called
+ SWTUtils.wait(1, TimeUnit.SECONDS);
+ Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "another/name:latest", false);
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.any(), Matchers.any());
+ Mockito.verify(client, Mockito.times(1)).removeImage(Matchers.anyString(), Matchers.anyBoolean(),
+ Matchers.anyBoolean());
+ }
+
+ @Test
+ public void shouldPushImageWithNewTagToAnotherRepo() throws DockerException, InterruptedException {
+ // given
+ MockRegistryAccountManagerFactory
+ .registryAccount(new RegistryAccountInfo("http://foo.com", "foo", null, "secret".toCharArray(), false))
+ .build();
+ openPushWizard();
+ // when selecting other registry
+ bot.comboBox(0).setSelection(1);
+ // when providing a new name to the image
+ bot.comboBox(1).setText("another/name");
+ // when click on Finish
+ bot.button("Finish").click();
+ // wait for the push job to complete
+ // then the 'push()' method on the client should have been called
+ SWTUtils.wait(1, TimeUnit.SECONDS);
+ Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "foo.com/another/name:latest", false);
+ Mockito.verify(client, Mockito.times(1)).push(Matchers.any(), Matchers.any());
+ Mockito.verify(client, Mockito.times(1)).removeImage(Matchers.anyString(), Matchers.anyBoolean(),
+ Matchers.anyBoolean());
+ }
+
+ @Test
+ public void shouldAddRegistry() {
+ // given
+ final String registryAddress = "https://foo.com";
+ openPushWizard();
+ // when click on the "Add..." link
+ bot.link(0).click(WizardMessages.getString("ImagePullPushPage.add.label"));
+ // fill the registry settings
+ bot.text(0).setText(registryAddress);
+ // finish
+ bot.button("OK").click();
+ // wait for the model updates to complete
+ SWTUtils.wait(1, TimeUnit.SECONDS);
+ assertThat(bot.comboBox(0).getText()).isEqualTo(registryAddress);
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java
index a80d9e73fe..37a58ef0e7 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java
@@ -37,7 +37,6 @@ import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -143,10 +142,8 @@ public class ImageRunSWTBotTest {
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
// configure the Connection Manager
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
- SWTUtils.getTreeItem(dockerExplorerViewBot, "Test").expand();
- final SWTBotTreeItem imagesTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images").expand();
// when select image and click on run to open the wizard
- SWTUtils.getTreeItem(imagesTreeItem, "foo/bar").select();
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo/bar").select();
dockerExplorerViewBot.bot().tree().contextMenu("Run...").click();
bot.waitUntil(Conditions.shellIsActive("Run a Docker Image"), TimeUnit.SECONDS.toMillis(1)); //$NON-NLS-1$
// configure container
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java
index 79dfb3224b..5ef6009880 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java
@@ -69,7 +69,7 @@ public class ImageSearchSWTBotTest {
// when opening the pull wizard...
openPullWizard(client);
// ... and specifying a term...
- bot.textWithLabel(WizardMessages.getString("ImagePull.name.label")).setText("foo");
+ bot.textWithLabel(WizardMessages.getString("ImagePullPushPage.name.label")).setText("foo");
// ... and then opening the search wizard
openSearchWizard();
// then the search should have been triggered and results should be available
@@ -99,7 +99,7 @@ public class ImageSearchSWTBotTest {
// when opening the pull wizard...
openPullWizard(client);
// ... and specifying a term...
- bot.textWithLabel(WizardMessages.getString("ImagePull.name.label")).setText("foo/bar");
+ bot.textWithLabel(WizardMessages.getString("ImagePullPushPage.name.label")).setText("foo/bar");
// ... and then opening the search wizard
openSearchWizard();
// then the search should have been triggered and a single result should be
@@ -117,7 +117,7 @@ public class ImageSearchSWTBotTest {
// when opening the pull wizard...
openPullWizard(client);
// ... and specifying a term...
- bot.textWithLabel(WizardMessages.getString("ImagePull.name.label")).setText("bar");
+ bot.textWithLabel(WizardMessages.getString("ImagePullPushPage.name.label")).setText("bar");
// ... and then opening the search wizard
openSearchWizard();
// then the search should have been triggered and both results should be
@@ -149,17 +149,12 @@ public class ImageSearchSWTBotTest {
.onSearch("foo", MockImageSearchResultFactory.name("foo").build()).build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
- // expand the 'Images' node
- SWTUtils.syncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
- final SWTBotTreeItem imagesTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images");
-
// when opening the "Pull..." wizard
- final SWTBotTree dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
- dockerExplorerViewTreeBot.select(imagesTreeItem);
- dockerExplorerViewTreeBot.contextMenu("Pull...").click();
+ SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images").select();
+ dockerExplorerViewBot.bot().tree().contextMenu("Pull...").click();
// when specifying a term
- bot.textWithLabel(WizardMessages.getString("ImagePull.name.label")).setText("foo");
+ bot.textWithLabel(WizardMessages.getString("ImagePullPushPage.name.label")).setText("foo");
// when clicking on the "Search..." button
bot.button(WizardMessages.getString("ImagePull.search.label")).click();
@@ -172,7 +167,7 @@ public class ImageSearchSWTBotTest {
bot.button("Finish").click();
// when back to Pull wizard, the Image name field should be filled
- assertThat(bot.textWithLabel(WizardMessages.getString("ImagePull.name.label")).getText())
+ assertThat(bot.textWithLabel(WizardMessages.getString("ImagePullPushPage.name.label")).getText())
.isEqualTo("foo:latest");
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
index aea10c1c8a..2f7f1b66b0 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.properties
@@ -91,7 +91,7 @@ command.buildimage.description=Build Image from Dockerfile
command.pullimage.name=&Pull...
command.pullimage.description=Pull Image from registry
-command.pushimage.name=P&ush
+command.pushimage.name=P&ush...
command.pushimage.description=Push Image tag to registry
command.createcontainer.name=&Create Container
diff --git a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
index c859a2b114..9bb65a7ce9 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
+++ b/containers/org.eclipse.linuxtools.docker.ui/plugin.xml
@@ -1229,7 +1229,7 @@
</menuContribution>
<!-- explorer view context menu: push image -->
<menuContribution
- locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=org.eclipse.linuxtools.docker.ui.commands.removeImages">
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=group.tags">
<command
commandId="org.eclipse.linuxtools.docker.ui.commands.pushImage"
icon="icons/push.gif"
@@ -1279,7 +1279,7 @@
</menuContribution>
<!-- explorer view context menu: tag image -->
<menuContribution
- locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=group.tags">
+ locationURI="popup:org.eclipse.linuxtools.docker.ui.dockerExplorerView#PopupMenu?after=org.eclipse.linuxtools.docker.ui.commands.pushImage">
<command
commandId="org.eclipse.linuxtools.docker.ui.commands.tagImage"
icon="icons/tag.gif"
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PullImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PullImageCommandHandler.java
index cdb28e0f38..e7de66452e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PullImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PullImageCommandHandler.java
@@ -17,9 +17,9 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.linuxtools.docker.core.AbstractRegistry;
import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
-import org.eclipse.linuxtools.docker.core.IRegistry;
import org.eclipse.linuxtools.docker.core.IRegistryAccount;
import org.eclipse.linuxtools.docker.ui.wizards.ImageSearch;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
@@ -63,15 +63,17 @@ public class PullImageCommandHandler extends AbstractHandler {
final boolean pullImage = CommandUtils.openWizard(wizard,
HandlerUtil.getActiveShell(event));
if (pullImage) {
- performPullImage(connection, wizard.getImageName(),
- wizard.getRegistry());
+ performPullImage(connection, wizard.getSelectedImageName(),
+ // TODO: remove cast once AbstractRegistry methods are
+ // part of the IRegistry interface
+ (AbstractRegistry) wizard.getSelectedRegistryAccount());
}
}
return null;
}
private void performPullImage(final IDockerConnection connection,
- final String imageName, final IRegistry registry) {
+ final String imageName, final AbstractRegistry registry) {
final Job pullImageJob = new Job(DVMessages
.getFormattedString(PULL_IMAGE_JOB_TITLE, imageName)) {
@@ -82,12 +84,13 @@ public class PullImageCommandHandler extends AbstractHandler {
// pull the image and let the progress
// handler refresh the images when done
try {
- if (registry == null) {
+ if (registry == null || registry.isDockerHubRegistry()) {
((DockerConnection) connection).pullImage(imageName,
new DefaultImagePullProgressHandler(connection,
imageName));
} else {
- String fullImageName = registry.getServerAddress() + '/' + imageName;
+ String fullImageName = registry.getServerHost() + '/'
+ + imageName;
if (registry instanceof IRegistryAccount) {
IRegistryAccount account = (IRegistryAccount) registry;
((DockerConnection) connection).pullImage(fullImageName,
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
index 6bb55fa1b9..fe8058b0f1 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/PushImageCommandHandler.java
@@ -17,12 +17,13 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.linuxtools.docker.core.AbstractRegistry;
import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerImage;
-import org.eclipse.linuxtools.docker.core.IRegistry;
import org.eclipse.linuxtools.docker.core.IRegistryAccount;
import org.eclipse.linuxtools.internal.docker.core.DefaultImagePushProgressHandler;
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.ui.views.DVMessages;
import org.eclipse.linuxtools.internal.docker.ui.wizards.ImagePush;
import org.eclipse.swt.widgets.Display;
@@ -39,63 +40,80 @@ public class PushImageCommandHandler extends AbstractHandler {
private final static String PUSH_IMAGE_JOB_TASK = "ImagePush.msg"; //$NON-NLS-1$
private static final String ERROR_PUSHING_IMAGE = "ImagePushError.msg"; //$NON-NLS-1$
private static final String NO_CONNECTION = "NoConnection.error"; //$NON-NLS-1$
-
+
@Override
public Object execute(final ExecutionEvent event) {
final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final IDockerImage selectedImage = RunImageCommandHandler
.getSelectedImage(activePart);
- final ImagePush wizard = new ImagePush(selectedImage);
+ final ImagePush wizard = new ImagePush(selectedImage,
+ selectedImage.repo() + ":" + selectedImage.tags().get(0));
final boolean pushImage = CommandUtils.openWizard(wizard,
HandlerUtil.getActiveShell(event));
if (pushImage) {
final IDockerConnection connection = CommandUtils
.getCurrentConnection(activePart);
- IRegistry info = wizard.getRegistry();
- performPushImage(wizard, connection, info);
+ performPushImage(wizard, connection);
}
return null;
}
-
+
private void performPushImage(final ImagePush wizard,
- final IDockerConnection connection, final IRegistry info) {
+ final IDockerConnection connection) {
if (connection == null) {
Display.getDefault()
.syncExec(() -> MessageDialog.openError(
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell(),
DVMessages.getFormattedString(ERROR_PUSHING_IMAGE,
- wizard.getImageTag()),
+ wizard.getSelectedImageTag()),
DVMessages.getFormattedString(NO_CONNECTION)));
return;
}
final Job pushImageJob = new Job(DVMessages.getFormattedString(
- PUSH_IMAGE_JOB_TITLE, wizard.getImageTag())) {
+ PUSH_IMAGE_JOB_TITLE, wizard.getSelectedImageTag())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
- final String tag = wizard.getImageTag();
+ final IDockerImage image = wizard.getImage();
+ final String defaultImageNameTag = wizard.getDefaultImageName();
+ final String selectedImageNameTag = wizard
+ .getSelectedImageTag();
+ // TODO: remove cast once AbstractRegistry methods are
+ // part of the IRegistry interface
+ final AbstractRegistry registry = (AbstractRegistry) wizard
+ .getRegistry();
+ final boolean forceTagging = wizard.isForceTagging();
+ final boolean keepTaggedImage = wizard.isKeepTaggedImage();
+
monitor.beginTask(DVMessages.getString(PUSH_IMAGE_JOB_TASK),
IProgressMonitor.UNKNOWN);
+
// push the image and let the progress
// handler refresh the images when done
- String tmpRegistryTag = null;
- boolean createdTag = false;
+ final String tmpRegistryTag = getNameToTag(
+ selectedImageNameTag, registry);
+ boolean tagCreated = false;
try {
- String repo = info.getServerAddress();
- tmpRegistryTag = repo + '/' + tag;
- if (!connection.hasImage(repo, tag)) {
- connection.tagImage(tag, tmpRegistryTag);
- createdTag = true;
+ // tag image (if necessary or if '--force' option was
+ // selected)
+ if (!image.repoTags().contains(tmpRegistryTag)
+ || forceTagging) {
+ // TODO: remove cast to DockerConnection once the
+ // 'tagImage' is added in the public API
+ ((DockerConnection) connection).tagImage(
+ defaultImageNameTag, tmpRegistryTag,
+ forceTagging);
+ tagCreated = true;
}
-
- if (info instanceof IRegistryAccount) {
- IRegistryAccount acc = (IRegistryAccount) info;
- connection.pushImage(tmpRegistryTag, acc,
+ // push image
+ if (!registry.isAuthProvided()) {
+ connection.pushImage(tmpRegistryTag,
new DefaultImagePushProgressHandler(connection,
tmpRegistryTag));
} else {
- connection.pushImage(tmpRegistryTag,
+ final IRegistryAccount registryAccount = (IRegistryAccount) registry;
+ connection.pushImage(tmpRegistryTag, registryAccount,
new DefaultImagePushProgressHandler(connection,
tmpRegistryTag));
}
@@ -104,13 +122,13 @@ public class PushImageCommandHandler extends AbstractHandler {
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell(),
DVMessages.getFormattedString(ERROR_PUSHING_IMAGE,
- tag),
+ defaultImageNameTag),
e.getMessage()));
// for now
} catch (InterruptedException e) {
// do nothing
} finally {
- if (tmpRegistryTag != null && createdTag) {
+ if (tagCreated && !keepTaggedImage) {
try {
connection.removeTag(tmpRegistryTag);
connection.getImages(true);
@@ -127,5 +145,22 @@ public class PushImageCommandHandler extends AbstractHandler {
pushImageJob.schedule();
}
+ /**
+ * Computes the full repo/name/tag to apply on the given image
+ *
+ * @param repoTag
+ * the repo/tag that could be added
+ * @param registry
+ * the target registry where the image will be pushed
+ * @return the full image name to tag the image with, or <code>null</code>
+ * if the image already has this tag.
+ */
+ private static String getNameToTag(final String repoTag,
+ final AbstractRegistry registry) {
+ if (registry.isDockerHubRegistry()) {
+ return repoTag;
+ }
+ return registry.getServerHost() + '/' + repoTag;
+ }
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/TagImageCommandHandler.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/TagImageCommandHandler.java
index ea4b7e8d6f..e5722fbff7 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/TagImageCommandHandler.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/commands/TagImageCommandHandler.java
@@ -23,6 +23,7 @@ import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.core.DockerImage;
import org.eclipse.linuxtools.internal.docker.ui.views.DVMessages;
import org.eclipse.linuxtools.internal.docker.ui.wizards.ImageTag;
import org.eclipse.swt.widgets.Display;
@@ -30,6 +31,9 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
+/**
+ * Command handler add a tag tag on an {@link IDockerImage}
+ */
public class TagImageCommandHandler extends AbstractHandler {
private final static String TAG_IMAGE_JOB_TITLE = "ImageTagTitle.msg"; //$NON-NLS-1$
@@ -47,7 +51,9 @@ public class TagImageCommandHandler extends AbstractHandler {
return null;
}
final IDockerImage image = selectedImages.get(0);
- final ImageTag wizard = new ImageTag();
+ // TODO: remove the cast to DockerImage once the 'shortId' method has
+ // been added in the API
+ final ImageTag wizard = new ImageTag(((DockerImage) image).shortId());
final boolean tagImage = CommandUtils.openWizard(wizard,
HandlerUtil.getActiveShell(event));
if (tagImage) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunImageMainTab.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunImageMainTab.java
index 5dc9eeb9ef..69c65d080a 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunImageMainTab.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/launch/RunImageMainTab.java
@@ -465,7 +465,8 @@ public class RunImageMainTab extends AbstractLaunchConfigurationTab {
final ImageSearch imageSearchWizard = new ImageSearch(
RunImageMainTab.this.model.getSelectedConnection(),
RunImageMainTab.this.model.getSelectedImageName(),
- new RegistryInfo(AbstractRegistry.DOCKERHUB_REGISTRY));
+ new RegistryInfo(AbstractRegistry.DOCKERHUB_REGISTRY,
+ true));
final boolean completed = CommandUtils
.openWizard(imageSearchWizard, getShell());
if (completed) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/BasePropertySection.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/BasePropertySection.java
index acc96cb117..1e6e932ba0 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/BasePropertySection.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/BasePropertySection.java
@@ -171,6 +171,8 @@ public abstract class BasePropertySection extends AbstractPropertySection {
@Override
public void dispose() {
super.dispose();
- this.clipboard.dispose();
+ if (this.clipboard != null) {
+ this.clipboard.dispose();
+ }
}
} \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java
index 5bd0914a7d..2b7fa437c8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java
@@ -287,9 +287,9 @@ public class DockerExplorerView extends CommonNavigator implements
switch (type) {
case IDockerConnectionManagerListener.ADD_EVENT:
registerListeners(connection);
- getCommonViewer().refresh();
- getCommonViewer()
- .setSelection(new StructuredSelection(connection));
+ // getCommonViewer().refresh();
+ // getCommonViewer()
+ // .setSelection(new StructuredSelection(connection));
break;
case IDockerConnectionManagerListener.RENAME_EVENT:
getCommonViewer().refresh(connection);
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java
index 75a85b0a6e..641d1b145d 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/LabelProviderUtils.java
@@ -26,6 +26,7 @@ import org.eclipse.jface.viewers.StyledString;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.core.IDockerPortBinding;
import org.eclipse.linuxtools.docker.core.IDockerPortMapping;
+import org.eclipse.linuxtools.internal.docker.core.DockerImage;
import org.eclipse.swt.custom.StyledText;
/**
@@ -150,8 +151,6 @@ public class LabelProviderUtils {
* @return the {@link StyledText} for the given {@link IDockerImage}.
*/
public static StyledString getStyleString(final IDockerImage dockerImage) {
- final String imageShortId = (dockerImage.id().length() > 12)
- ? dockerImage.id().substring(0, 12) : dockerImage.id();
final StringBuilder messageBuilder = new StringBuilder(
dockerImage.repo());
final int startTags = messageBuilder.length();
@@ -168,7 +167,10 @@ public class LabelProviderUtils {
}
}
final int startImageId = messageBuilder.length();
- messageBuilder.append(" (").append(imageShortId).append(')');
+ // TODO: remove the cast to 'DockerImage' once the 'shortId()'
+ // method is in the public API
+ messageBuilder.append(" (")
+ .append(((DockerImage) dockerImage).shortId()).append(')');
final String message = messageBuilder.toString();
final StyledString styledString = new StyledString(message);
// styled tags
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java
index 60ee12b362..52f4c42f9d 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePull.java
@@ -54,12 +54,12 @@ public class ImagePull extends Wizard {
return true;
}
- public String getImageName() {
- return this.imagePullPage.getImageName();
+ public String getSelectedImageName() {
+ return this.imagePullPage.getSelectedImageName();
}
- public IRegistry getRegistry() {
- return this.imagePullPage.getRegistry();
+ public IRegistry getSelectedRegistryAccount() {
+ return this.imagePullPage.getSelectedRegistryAccount();
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPage.java
index c36ef1b040..d0fc173d30 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPage.java
@@ -11,12 +11,6 @@
package org.eclipse.linuxtools.internal.docker.ui.wizards;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
-import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
@@ -24,17 +18,9 @@ import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.linuxtools.docker.core.AbstractRegistry;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IRegistry;
-import org.eclipse.linuxtools.docker.core.IRegistryAccount;
import org.eclipse.linuxtools.docker.ui.wizards.ImageSearch;
-import org.eclipse.linuxtools.internal.docker.core.DockerImage;
-import org.eclipse.linuxtools.internal.docker.core.RegistryAccountManager;
-import org.eclipse.linuxtools.internal.docker.core.RegistryInfo;
-import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
import org.eclipse.linuxtools.internal.docker.ui.commands.CommandUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -42,7 +28,6 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
@@ -50,20 +35,21 @@ import org.eclipse.swt.widgets.Text;
/**
*
*/
-public class ImagePullPage extends WizardPage {
+public class ImagePullPage extends ImagePullPushPage<ImagePullPageModel> {
- private final ImagePullPageModel model;
- private final DataBindingContext dbc;
private final IDockerConnection connection;
- private final String DOCKER_DAEMON_DEFAULT = "Docker Daemon Registry (Default)"; //$NON-NLS-1$
+ /**
+ * Constructor.
+ *
+ * @param connection
+ * the {@link IDockerConnection} to use to pull the image
+ */
public ImagePullPage(final IDockerConnection connection) {
super("ImagePullPage", //$NON-NLS-1$
- WizardMessages.getString("ImagePull.label"), //$NON-NLS-1$
- SWTImagesFactory.DESC_BANNER_REPOSITORY);
+ WizardMessages.getString("ImagePull.label"),
+ new ImagePullPageModel());
setMessage(WizardMessages.getString("ImagePull.desc")); //$NON-NLS-1$
- this.model = new ImagePullPageModel();
- this.dbc = new DataBindingContext();
this.connection = connection;
}
@@ -73,31 +59,18 @@ public class ImagePullPage extends WizardPage {
super.dispose();
}
- public String getImageName() {
- final Matcher matcher = DockerImage.imageNamePattern
- .matcher(this.model.getImageName());
- // Matcher#matches() must be called before any attempt to access a given
- // named capturing-group.
- if (matcher.matches() && matcher.group("tag") == null) { //$NON-NLS-1$
- return this.model.getImageName() + ":latest"; //$NON-NLS-1$
- }
-
- return this.model.getImageName();
+ /**
+ * @return the tag to select/apply on the image
+ */
+ public String getSelectedImageName() {
+ return getModel().getSelectedImageName();
}
- public IRegistry getRegistry() {
- String registry = model.getRegistry();
- final String pattern = "(.*)@(.*)"; //$NON-NLS-1$
- Matcher m = Pattern.compile(pattern).matcher(registry);
- IRegistry info;
- if (m.matches()) {
- info = RegistryAccountManager.getInstance().getAccount(m.group(2), m.group(1));
- } else if (registry.equals(DOCKER_DAEMON_DEFAULT)) {
- info = null;
- } else {
- info = new RegistryInfo(registry);
- }
- return info;
+ /**
+ * @return the target {@link IRegistry} on which to push the image
+ */
+ public IRegistry getSelectedRegistryAccount() {
+ return getModel().getSelectedRegistry();
}
@Override
@@ -109,41 +82,34 @@ public class ImagePullPage extends WizardPage {
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1)
.grab(true, false).applyTo(container);
- // Registry
- final Label accountLabel = new Label(container, SWT.NULL);
- accountLabel.setText(WizardMessages.getString("ImagePullPage.registry.account.label")); //$NON-NLS-1$
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(false, false).applyTo(accountLabel);
+ // registry selection
+ super.createRegistrySelectionControls(container);
- final Combo accountCombo = new Combo(container, SWT.DROP_DOWN);
- accountCombo.setToolTipText(WizardMessages.getString("ImagePullPage.registry.account.desc")); //$NON-NLS-1$
- accountCombo.setItems(getAccountComboItems());
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(true, false).applyTo(accountCombo);
+ // image name selection
+ createImageNameSelectionControls(container);
- // Add
- final Button addButton = new Button(container, SWT.NONE);
- addButton.setText(
- WizardMessages.getString("ImagePullPushPage.add.label")); //$NON-NLS-1$
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(false, false).applyTo(addButton);
- addButton.addSelectionListener(onAdd(accountCombo));
+ // setup validation support
+ WizardPageSupport.create(this, dbc);
+ setControl(container);
+ }
+ @SuppressWarnings("unchecked")
+ void createImageNameSelectionControls(final Composite parent) {
// Image name
- final Label imageNameLabel = new Label(container, SWT.NONE);
- imageNameLabel
- .setText(WizardMessages.getString("ImagePull.name.label")); //$NON-NLS-1$
+ final Label imageNameLabel = new Label(parent, SWT.NONE);
+ imageNameLabel.setText(
+ WizardMessages.getString("ImagePullPushPage.name.label")); //$NON-NLS-1$
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
.grab(false, false).applyTo(imageNameLabel);
- final Text imageNameText = new Text(container, SWT.BORDER);
+ final Text imageNameText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
.grab(true, false).applyTo(imageNameText);
imageNameText.setToolTipText(
WizardMessages.getString("ImagePull.name.tooltip")); //$NON-NLS-1$
// search
- final Button searchButton = new Button(container, SWT.NONE);
+ final Button searchButton = new Button(parent, SWT.NONE);
searchButton
.setText(WizardMessages.getString("ImagePull.search.label")); //$NON-NLS-1$
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
@@ -151,48 +117,14 @@ public class ImagePullPage extends WizardPage {
searchButton.addSelectionListener(onSearchImage());
// binding
- final IObservableValue imgeNameObservable = BeanProperties
- .value(ImagePullPageModel.class, ImagePullPageModel.IMAGE_NAME)
- .observe(model);
+ final IObservableValue<String> imgeNameObservable = BeanProperties
+ .value(ImagePullPushPageModel.class,
+ ImagePullPushPageModel.SELECTED_IMAGE_NAME)
+ .observe(getModel());
dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(imageNameText),
imgeNameObservable, new UpdateValueStrategy()
.setAfterConvertValidator(new ImageNameValidator()),
null);
- final IObservableValue registryObservable = BeanProperties
- .value(ImagePullPageModel.class, ImagePullPageModel.REGISTRY)
- .observe(model);
- dbc.bindValue(WidgetProperties.selection().observe(accountCombo),
- registryObservable);
-
- // Set the Default registry and ensure it is observed
- accountCombo.select(0);
-
- // setup validation support
- WizardPageSupport.create(this, dbc);
- setControl(container);
- }
-
- private SelectionListener onAdd(Combo combo) {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- String selected = combo.getText();
- RegistryAccountDialog dialog = new RegistryAccountDialog(
- getShell(),
- WizardMessages
- .getString("ImagePullPushPage.login.title"), //$NON-NLS-1$
- AbstractRegistry.DOCKERHUB_REGISTRY,
- WizardMessages.getString(
- "RegistryAccountDialog.add.explanation")); ///$NON-NLS-1$
- if (dialog.open() == Window.OK) {
- IRegistryAccount acc = dialog.getSignonInformation();
- RegistryAccountManager.getInstance().add(acc);
- selected = acc.getUsername() + "@" + acc.getServerAddress(); //$NON-NLS-1$
- }
- combo.setItems(getAccountComboItems());
- combo.setText(selected);
- }
- };
}
/**
@@ -205,37 +137,19 @@ public class ImagePullPage extends WizardPage {
@Override
public void widgetSelected(final SelectionEvent e) {
- IRegistry reg;
- String [] tokens = model.getRegistry().split("@");
- if (tokens.length > 1) {
- reg = new RegistryInfo(tokens[1]);
- } else {
- if (DOCKER_DAEMON_DEFAULT.equals(model.getRegistry())) {
- reg = new RegistryInfo(AbstractRegistry.DOCKERHUB_REGISTRY);
- } else {
- reg = new RegistryInfo(model.getRegistry());
- }
- }
final ImageSearch imageSearchWizard = new ImageSearch(
ImagePullPage.this.connection,
- ImagePullPage.this.model.getImageName(),
- reg);
+ ImagePullPage.this.getModel().getSelectedImageName(),
+ ImagePullPage.this.getModel()
+ .getSelectedRegistry());
final boolean completed = CommandUtils
.openWizard(imageSearchWizard, getShell());
if (completed) {
- model.setImageName(imageSearchWizard.getSelectedImage());
+ ImagePullPage.this.getModel().setSelectedImageName(
+ imageSearchWizard.getSelectedImage());
}
}
};
}
- private String[] getAccountComboItems() {
- List<String> items = RegistryAccountManager.getInstance().getAccounts()
- .stream()
- .map(e -> e.getUsername() + "@" + e.getServerAddress()) //$NON-NLS-1$
- .collect(Collectors.toList());
- items.add(0, DOCKER_DAEMON_DEFAULT);
- return items.toArray(new String[0]);
- }
-
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPageModel.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPageModel.java
index 365ae90089..c63d46ba44 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPageModel.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPageModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 Red Hat.
+ * 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
@@ -11,32 +11,16 @@
package org.eclipse.linuxtools.internal.docker.ui.wizards;
-import org.eclipse.linuxtools.internal.docker.ui.databinding.BaseDatabindingModel;
-
/**
- *
+ * Model for the {@link ImagePullPage}
*/
-public class ImagePullPageModel extends BaseDatabindingModel {
-
- public static final String IMAGE_NAME = "imageName";
- public static final String REGISTRY = "registry";
-
- private String imageName;
- private String registry;
-
- public String getImageName() {
- return imageName;
- }
-
- public String getRegistry() {
- return registry;
- }
+public class ImagePullPageModel extends ImagePullPushPageModel {
- public void setImageName(final String imageName) {
- firePropertyChange(IMAGE_NAME, this.imageName, this.imageName = imageName);
+ /**
+ * Constructor.
+ */
+ public ImagePullPageModel() {
+ super();
}
- public void setRegistry(final String registry) {
- firePropertyChange(REGISTRY, this.registry, this.registry = registry);
- }
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPushPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPushPage.java
new file mode 100644
index 0000000000..e3f61c628f
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPushPage.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * 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.internal.docker.ui.wizards;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.databinding.viewers.ViewerProperties;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.linuxtools.docker.core.AbstractRegistry;
+import org.eclipse.linuxtools.docker.core.IRegistry;
+import org.eclipse.linuxtools.docker.core.IRegistryAccount;
+import org.eclipse.linuxtools.internal.docker.core.RegistryAccountManager;
+import org.eclipse.linuxtools.internal.docker.core.RegistryInfo;
+import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+
+/**
+ * Base {@link WizardPage} for {@link ImagePushPage} and {@link ImagePullPage}
+ *
+ * @param <M>
+ * the type of model associated with this {@link WizardPage}
+ */
+public abstract class ImagePullPushPage<M extends ImagePullPushPageModel>
+ extends WizardPage {
+
+ protected final DataBindingContext dbc;
+ protected final String DOCKER_DAEMON_DEFAULT = AbstractRegistry.DOCKERHUB_REGISTRY;
+
+ private final M model;
+
+ /**
+ * Constructor.
+ *
+ * @param pageName
+ * the name of the page
+ * @param title
+ * the title of the page
+ * @param model
+ * the databinding model associated with this page
+ *
+ */
+ public ImagePullPushPage(final String pageName, final String title,
+ final M model) {
+ super(pageName, title, SWTImagesFactory.DESC_BANNER_REPOSITORY);
+ setMessage(WizardMessages.getString("ImagePull.desc")); //$NON-NLS-1$
+ this.dbc = new DataBindingContext();
+ this.model = model;
+ }
+
+ M getModel() {
+ return this.model;
+ }
+
+ @SuppressWarnings("unchecked")
+ IObservableValue<IRegistry> createRegistrySelectionControls(
+ Composite parent) {
+ // registry selection
+ final Label accountLabel = new Label(parent, SWT.NULL);
+ accountLabel.setText(WizardMessages
+ .getString("ImagePullPushPage.registry.account.label")); //$NON-NLS-1$
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
+ .grab(false, false).applyTo(accountLabel);
+ final Combo registryAccountCombo = new Combo(parent,
+ SWT.DROP_DOWN | SWT.READ_ONLY);
+ registryAccountCombo.setToolTipText(WizardMessages
+ .getString("ImagePullPushPage.registry.account.desc")); //$NON-NLS-1$
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
+ .grab(true, false).applyTo(registryAccountCombo);
+ final ComboViewer registryAccountComboViewer = new ComboViewer(
+ registryAccountCombo);
+ registryAccountComboViewer
+ .setContentProvider(ArrayContentProvider.getInstance());
+ registryAccountComboViewer
+ .setLabelProvider(new RegistryAccountLabelProvider());
+ final List<IRegistry> allRegistryAccounts = getRegistryAccounts();
+ registryAccountComboViewer.setInput(allRegistryAccounts);
+ if (!allRegistryAccounts.isEmpty()) {
+ getModel().setSelectedRegistry(allRegistryAccounts.get(0));
+ }
+ final IObservableValue<IRegistry> registryAccountObservable = BeanProperties
+ .value(ImagePushPageModel.class,
+ ImagePullPushPageModel.SELECTED_REGISTRY)
+ .observe(model);
+ dbc.bindValue(ViewerProperties.singleSelection().observe(
+ registryAccountComboViewer), registryAccountObservable);
+ // link to add registries and accounts
+ final Link addRegistryLink = new Link(parent, SWT.NONE);
+ addRegistryLink.setText(
+ WizardMessages.getString("ImagePullPushPage.add.link")); //$NON-NLS-1$
+ GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER)
+ .grab(true, false).applyTo(addRegistryLink);
+ addRegistryLink.addSelectionListener(
+ onAddRegistry(registryAccountComboViewer));
+ return registryAccountObservable;
+ }
+
+ private SelectionListener onAddRegistry(
+ final ComboViewer registryAccountComboViewer) {
+ return new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ final RegistryAccountDialog dialog = new RegistryAccountDialog(
+ getShell(),
+ WizardMessages
+ .getString(
+ "ImagePullPushPage.addregistry.title"), //$NON-NLS-1$
+ AbstractRegistry.DOCKERHUB_REGISTRY,
+ WizardMessages.getString(
+ "RegistryAccountDialog.add.explanation")); ///$NON-NLS-1$
+ if (dialog.open() == Window.OK) {
+ RegistryAccountManager.getInstance()
+ .add(dialog.getSignonInformation());
+ final List<IRegistry> updatedRegistryAccounts = getRegistryAccounts();
+ registryAccountComboViewer
+ .setInput(updatedRegistryAccounts);
+ // set selection on the newly created registry
+ model.setSelectedRegistry(dialog.getSignonInformation());
+ }
+ }
+ };
+ }
+
+ /**
+ * @return all existing {@link IRegistryAccount} plus an entry at the first
+ * position for the registry configured in the selected Docker
+ * daemon.
+ */
+ protected List<IRegistry> getRegistryAccounts() {
+ final List<IRegistry> accounts = new ArrayList<>(
+ RegistryAccountManager.getInstance().getAccounts());
+ accounts.add(0, new RegistryInfo(DOCKER_DAEMON_DEFAULT, true));
+ return accounts;
+ }
+
+ static final class RegistryAccountLabelProvider
+ extends ColumnLabelProvider {
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IRegistryAccount) {
+ final IRegistryAccount registryAccount = (IRegistryAccount) element;
+ final StringBuilder textBuilder = new StringBuilder();
+ // only display account username if it is set.
+ if (registryAccount.getUsername() != null) {
+ textBuilder.append(registryAccount.getUsername())
+ .append('@'); // $NON-NLS-1$
+ }
+ textBuilder.append(registryAccount.getServerAddress());
+ return textBuilder.toString();
+ }
+ else if (element instanceof IRegistry) {
+ final IRegistry registry = (IRegistry) element;
+ return registry.getServerAddress();
+ }
+ return null;
+ }
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPushPageModel.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPushPageModel.java
new file mode 100644
index 0000000000..2adfc52d2a
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePullPushPageModel.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.internal.docker.ui.wizards;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IRegistry;
+import org.eclipse.linuxtools.internal.docker.ui.databinding.BaseDatabindingModel;
+
+/**
+ * Base {@link BaseDatabindingModel} for Push and Pull models.
+ */
+public abstract class ImagePullPushPageModel extends BaseDatabindingModel {
+
+ public static final String SELECTED_IMAGE_NAME = "selectedImageName"; //$NON-NLS-1$
+
+ public static final String SELECTED_REGISTRY = "selectedRegistry"; //$NON-NLS-1$
+
+ public static final String TAG = "tag"; //$NON-NLS-1$
+
+ private static final Pattern PATTERN = Pattern.compile("(.*)@(.*)"); //$NON-NLS-1$
+
+ private IRegistry selectedRegistry;
+
+ private String selectedImageName;
+
+ public ImagePullPushPageModel() {
+
+ }
+
+ /**
+ * Constructor
+ *
+ * @param image
+ * the selected {@link IDockerImage}
+ * @param selectedImageName
+ * the selected repo/name/tag of the given image
+ */
+ public ImagePullPushPageModel(final String selectedImageName) {
+ setSelectedImageName(selectedImageName);
+ }
+
+ public IRegistry getSelectedRegistry() {
+ return this.selectedRegistry;
+ }
+
+ public void setSelectedRegistry(final IRegistry selectedRegistry) {
+ firePropertyChange(SELECTED_REGISTRY, this.selectedRegistry,
+ this.selectedRegistry = selectedRegistry);
+ }
+
+ public String getSelectedImageName() {
+ return selectedImageName;
+ }
+
+ public void setSelectedImageName(final String selectedImageName) {
+ firePropertyChange(SELECTED_IMAGE_NAME, this.selectedImageName,
+ this.selectedImageName = selectedImageName);
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePush.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePush.java
index 2db23e07b8..4edb23fa07 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePush.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePush.java
@@ -13,46 +13,98 @@ package org.eclipse.linuxtools.internal.docker.ui.wizards;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.core.IRegistry;
+import org.eclipse.linuxtools.internal.docker.core.DockerImage;
+/**
+ * {@link Wizard} to push an {@link IDockerImage} to a registry
+ */
public class ImagePush extends Wizard {
private ImagePushPage mainPage;
- private String imageTag;
- private IDockerImage image;
+ private final IDockerImage image;
+ private final String defaultImageName;
- public ImagePush() {
+ /**
+ * Constructor
+ *
+ * @param image
+ * the image to push
+ * @param defautImageName
+ * the default tag to use to push the image
+ */
+ public ImagePush(final IDockerImage image, final String defautImageName) {
super();
+ setWindowTitle(WizardMessages.getString("ImagePush.name")); //$NON-NLS-1$
+ this.image = image;
+ this.defaultImageName = defautImageName;
}
- public ImagePush(IDockerImage image) {
- super();
- this.image = image;
+ /**
+ * @return the image name that was selected when opening this wizard.
+ */
+ public IDockerImage getImage() {
+ return this.image;
}
- public String getImageTag() {
- return imageTag;
+ /**
+ * @return the image name that was initially selected when opening this
+ * wizard.
+ */
+ public String getDefaultImageName() {
+ return this.defaultImageName;
}
+ /**
+ * <p>
+ * <strong>Note:</strong> If no tag was specified, then <code>latest</code>
+ * is set.
+ * </p>
+ *
+ * @return the repository/tag to select/apply on the image.
+ */
+ public String getSelectedImageTag() {
+ final String selectedImageName = this.mainPage.getSelectedImageName();
+ return DockerImage.setDefaultTagIfMissing(selectedImageName);
+ }
+
+ /**
+ * @return the target {@link IRegistry} on which to push the image
+ */
public IRegistry getRegistry() {
- return mainPage.getRegistry();
+ return this.mainPage.getSelectedRegistryAccount();
+ }
+
+ /**
+ * @return flag to indicate if the 'force' option should be used when
+ * tagging the image.
+ */
+ public boolean isForceTagging() {
+ return this.mainPage.isForceTagging();
+ }
+
+ /**
+ * @return flag to indicate if the tagged image should be kept upon
+ * completion.
+ */
+ public boolean isKeepTaggedImage() {
+ return this.mainPage.isKeepTaggedImage();
}
@Override
public void addPages() {
- mainPage = new ImagePushPage(image);
+ this.mainPage = new ImagePushPage(this.image, this.defaultImageName);
addPage(mainPage);
}
@Override
public boolean canFinish() {
- return mainPage.isPageComplete();
+ return this.mainPage.isPageComplete();
}
@Override
public boolean performFinish() {
- imageTag = mainPage.getImageTag();
-
return true;
}
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPage.java
index 87a4bdba45..4147c752f6 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPage.java
@@ -10,189 +10,158 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.docker.ui.wizards;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.databinding.wizard.WizardPageSupport;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.window.Window;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.linuxtools.docker.core.AbstractRegistry;
import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.eclipse.linuxtools.docker.core.IRegistry;
-import org.eclipse.linuxtools.docker.core.IRegistryAccount;
-import org.eclipse.linuxtools.internal.docker.core.RegistryAccountManager;
-import org.eclipse.linuxtools.internal.docker.core.RegistryInfo;
-import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-public class ImagePushPage extends WizardPage {
-
- private final static String NAME = "ImagePush.name"; //$NON-NLS-1$
- private final static String TITLE = "ImagePush.title"; //$NON-NLS-1$
- private final static String DESC = "ImagePush.desc"; //$NON-NLS-1$
- private final static String NAME_LABEL = "ImagePushName.label"; //$NON-NLS-1$
- private final static String NAME_TOOLTIP = "ImagePushName.toolTip"; //$NON-NLS-1$
- private Text nameText;
- private Combo nameCombo;
- private Combo accountCombo;
- private IDockerImage image;
- private String tag;
- private IRegistry info;
+/**
+ * {@link WizardPage} to push an image to a registry.
+ */
+public class ImagePushPage extends ImagePullPushPage<ImagePushPageModel> {
+
+ /**
+ * Constructor
+ *
+ * @param image
+ * the {@link IDockerImage} to push.
+ * @param selectedImageName
+ * the default image name/tag
+ */
+ public ImagePushPage(final IDockerImage image,
+ final String selectedImageName) {
+ super(WizardMessages.getString("ImagePush.name"), //$NON-NLS-1$
+ WizardMessages.getString("ImagePush.title"), //$NON-NLS-1$
+ new ImagePushPageModel(image, selectedImageName));
+ }
- public ImagePushPage() {
- this(null);
+ @Override
+ public void dispose() {
+ this.dbc.dispose();
+ super.dispose();
}
- public ImagePushPage(IDockerImage image) {
- super(WizardMessages.getString(NAME));
- this.image = image;
- setDescription(WizardMessages.getString(DESC));
- setTitle(WizardMessages.getString(TITLE));
- setImageDescriptor(SWTImagesFactory.DESC_WIZARD);
+ /**
+ * @return the tag to select/apply on the image
+ */
+ public String getSelectedImageName() {
+ return getModel().getSelectedImageName();
}
- public String getImageTag() {
- return tag;
+ /**
+ * @return the target {@link IRegistry} on which to push the image
+ */
+ public IRegistry getSelectedRegistryAccount() {
+ return getModel().getSelectedRegistry();
}
- public IRegistry getRegistry() {
- return info;
+ /**
+ * @return flag to indicate if the 'force' option should be used when
+ * tagging the image.
+ */
+ public boolean isForceTagging() {
+ return getModel().isForceTagging();
}
- private ModifyListener Listener = e -> validate();
-
- private void validate() {
- boolean complete = true;
- boolean error = false;
- String name = null;
- if (nameText != null) {
- name = nameText.getText();
- } else {
- name = nameCombo.getText();
- }
- if (accountCombo != null) {
- String account = accountCombo.getText();
- final String pattern = "(.*)@(.*)"; //$NON-NLS-1$
- Matcher m = Pattern.compile(pattern).matcher(account);
- if (m.matches()) {
- info = RegistryAccountManager.getInstance().getAccount(m.group(2), m.group(1));
- } else {
- info = new RegistryInfo(account);
- }
- } else {
- complete = false;
- error = true;
- setErrorMessage(WizardMessages.getString("ImagePushPage.empty.registry.account")); //$NON-NLS-1$
- }
-
- if (name.length() == 0) {
- complete = false;
- }
- if (!error) {
- setErrorMessage(null);
- tag = name;
- }
-
- setPageComplete(complete && !error);
+ /**
+ * @return flag to indicate if the tagged image should be kept upon
+ * completion.
+ */
+ public boolean isKeepTaggedImage() {
+ return getModel().isKeepTaggedImage();
}
+
+ @SuppressWarnings("unchecked")
@Override
public void createControl(final Composite parent) {
parent.setLayout(new GridLayout());
final Composite container = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(3).margins(6, 6)
.applyTo(container);
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1)
- .grab(true, false).applyTo(container);
- final Label nameLabel = new Label(container, SWT.NULL);
- nameLabel.setText(WizardMessages.getString(NAME_LABEL));
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(false, false).applyTo(nameLabel);
- if (image == null || image.repoTags().size() == 0) {
- nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
- nameText.addModifyListener(Listener);
- nameText.setToolTipText(WizardMessages.getString(NAME_TOOLTIP));
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(true, false).span(2, 1).applyTo(nameText);
- } else {
- nameCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
- nameCombo.addModifyListener(Listener);
- nameCombo.setToolTipText(WizardMessages.getString(NAME_TOOLTIP));
- nameCombo.setItems(image.repoTags().toArray(new String[0]));
- nameCombo.setText(image.repoTags().get(0));
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(true, false).span(2, 1).applyTo(nameCombo);
- }
-
- final Label accountLabel = new Label(container, SWT.NULL);
- accountLabel.setText(WizardMessages.getString("ImagePushPage.registry.account.label")); //$NON-NLS-1$
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(false, false).applyTo(accountLabel);
-
- accountCombo = new Combo(container, SWT.DROP_DOWN);
- accountCombo.addModifyListener(Listener);
- accountCombo.setToolTipText(WizardMessages.getString("ImagePushPage.registry.account.desc")); //$NON-NLS-1$
- accountCombo.setItems(getAccountComboItems());
- if (accountCombo.getItems().length > 0) {
- accountCombo.select(0);
- }
-
- // Add
- final Button addButton = new Button(container, SWT.NONE);
- addButton.setText(
- WizardMessages.getString("ImagePullPushPage.add.label")); //$NON-NLS-1$
- GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(false, false).applyTo(addButton);
- addButton.addSelectionListener(onAdd(accountCombo));
+ .grab(true, false).applyTo(container);
+ // registry selection
+ final IObservableValue<IRegistry> registryAccountObservable = super.createRegistrySelectionControls(
+ container);
+ // image selection
+ final IObservableValue<String> imageNameObservable = createImageSelectionControls(
+ container);
+
+ // force tagging
+ final Button forceTaggingButton = new Button(container, SWT.CHECK);
+ forceTaggingButton.setText(WizardMessages
+ .getString("ImagePushPage.forcetagging.label")); //$NON-NLS-1$ );
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
+ .grab(true, false).span(2, 1).applyTo(forceTaggingButton);
+ dbc.bindValue(WidgetProperties.selection().observe(forceTaggingButton),
+ BeanProperties.value(ImagePushPageModel.class,
+ ImagePushPageModel.FORCE_TAGGING).observe(getModel()));
+
+ // keep tagged image upon completion
+ final Button keepTaggedImageButton = new Button(container, SWT.CHECK);
+ keepTaggedImageButton.setText(WizardMessages
+ .getString("ImagePushPage.keeptaggedimage.label")); //$NON-NLS-1$ );
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
- .grab(true, false).applyTo(accountCombo);
+ .grab(true, false).span(2, 1).applyTo(keepTaggedImageButton);
+ dbc.bindValue(
+ WidgetProperties.selection().observe(keepTaggedImageButton),
+ BeanProperties
+ .value(ImagePushPageModel.class,
+ ImagePushPageModel.KEEP_TAGGED_IMAGE)
+ .observe(getModel()));
+
+ // setup validation support
+ WizardPageSupport.create(this, dbc);
+ dbc.addValidationStatusProvider(getModel().new ImagePushValidator(
+ imageNameObservable, registryAccountObservable));
setControl(container);
- validate();
}
- private SelectionListener onAdd(Combo combo) {
- return new SelectionAdapter() {
- @Override
- public void widgetSelected(final SelectionEvent e) {
- String selected = combo.getText();
- RegistryAccountDialog dialog = new RegistryAccountDialog(
- getShell(),
- WizardMessages.getString(
- "ImagePullPushPage.login.title"), //$NON-NLS-1$
- AbstractRegistry.DOCKERHUB_REGISTRY,
- WizardMessages.getString(
- "RegistryAccountDialog.add.explanation")); ///$NON-NLS-1$
- if (dialog.open() == Window.OK) {
- IRegistryAccount acc = dialog.getSignonInformation();
- RegistryAccountManager.getInstance().add(acc);
- selected = acc.getUsername() + "@" + acc.getServerAddress(); //$NON-NLS-1$
- }
- combo.setItems(getAccountComboItems());
- combo.setText(selected);
- }
- };
+ @SuppressWarnings("unchecked")
+ private IObservableValue<String> createImageSelectionControls(
+ final Composite container) {
+ final Label nameLabel = new Label(container, SWT.NULL);
+ nameLabel.setText(
+ WizardMessages.getString("ImagePullPushPage.name.label")); //$NON-NLS-1$
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
+ .grab(false, false).applyTo(nameLabel);
+ final Combo imageNameCombo = new Combo(container, SWT.DROP_DOWN);
+ imageNameCombo.setToolTipText(
+ WizardMessages.getString("ImagePushName.toolTip")); //$NON-NLS-1$
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
+ .grab(true, false).applyTo(imageNameCombo);
+ final ComboViewer imageNameComboViewer = new ComboViewer(
+ imageNameCombo);
+ imageNameComboViewer.setContentProvider(new ArrayContentProvider());
+ imageNameComboViewer.setInput(getModel().getImage().repoTags());
+ // binding must take place after the input is set, so that default
+ // repo/name can be selected.
+ final IObservableValue<String> imageNameObservable = BeanProperties
+ .value(ImagePushPageModel.class,
+ ImagePullPushPageModel.SELECTED_IMAGE_NAME)
+ .observe(getModel());
+ dbc.bindValue(WidgetProperties.selection().observe(imageNameCombo),
+ imageNameObservable);
+ // filler for the last column
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER)
+ .grab(false, false).applyTo(new Label(container, SWT.NONE));
+ return imageNameObservable;
}
- private String[] getAccountComboItems() {
- List<String> items = RegistryAccountManager.getInstance().getAccounts()
- .stream().map(e -> e.getUsername() + "@" + e.getServerAddress()) //$NON-NLS-1$
- .collect(Collectors.toList());
- return items.toArray(new String[0]);
- }
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPageModel.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPageModel.java
new file mode 100644
index 0000000000..b2d9b42e65
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImagePushPageModel.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.internal.docker.ui.wizards;
+
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.validation.MultiValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
+import org.eclipse.linuxtools.docker.core.IRegistry;
+import org.eclipse.linuxtools.internal.docker.ui.databinding.BaseDatabindingModel;
+
+/**
+ * {@link BaseDatabindingModel} for the {@link ImagePushPage}
+ */
+public class ImagePushPageModel extends ImagePullPushPageModel {
+
+ public static final String FORCE_TAGGING = "forceTagging"; //$NON-NLS-1$
+
+ public static final String KEEP_TAGGED_IMAGE = "keepTaggedImage"; //$NON-NLS-1$
+
+ private final IDockerImage image;
+
+ private boolean forceTagging;
+
+ private boolean keepTaggedImage;
+
+ /**
+ * Constructor
+ *
+ * @param image
+ * the selected {@link IDockerImage}
+ * @param selectedImageName
+ * the selected repo/name/tag of the given image
+ */
+ public ImagePushPageModel(final IDockerImage image,
+ final String selectedImageName) {
+ super(selectedImageName);
+ this.image = image;
+ }
+
+ public IDockerImage getImage() {
+ return this.image;
+ }
+
+ public boolean isForceTagging() {
+ return this.forceTagging;
+ }
+
+ public void setForceTagging(final boolean forceTagging) {
+ firePropertyChange(FORCE_TAGGING, this.forceTagging,
+ this.forceTagging = forceTagging);
+ }
+
+ public boolean isKeepTaggedImage() {
+ return this.keepTaggedImage;
+ }
+
+ public void setKeepTaggedImage(final boolean keepTaggedImage) {
+ firePropertyChange(KEEP_TAGGED_IMAGE, this.keepTaggedImage,
+ this.keepTaggedImage = keepTaggedImage);
+ }
+
+ class ImagePushValidator extends MultiValidator {
+
+ private final IObservableValue<String> imageNameObservable;
+
+ private final IObservableValue<IRegistry> registryAccountObservable;
+
+ public ImagePushValidator(
+ final IObservableValue<String> imageNameObservable,
+ final IObservableValue<IRegistry> registryAccountObservable) {
+ this.imageNameObservable = imageNameObservable;
+ this.registryAccountObservable = registryAccountObservable;
+ }
+
+ @Override
+ protected IStatus validate() {
+ final String selectedImageName = imageNameObservable.getValue();
+ final IRegistry selectedRegistryAcccount = registryAccountObservable
+ .getValue();
+ if (selectedImageName == null || selectedImageName.isEmpty()) {
+ return ValidationStatus
+ .error(WizardMessages.getString("ImagePush.desc")); //$NON-NLS-1$
+ } else if (selectedRegistryAcccount == null) {
+ return ValidationStatus.error(WizardMessages
+ .getString("ImagePushPage.empty.registry.account")); //$NON-NLS-1$
+ } else if (ImagePushPageModel.this.image.repoTags() == null
+ || !ImagePushPageModel.this.image.repoTags()
+ .contains(selectedImageName)) {
+ return ValidationStatus.warning(WizardMessages
+ .getString("ImagePushPage.repotag.unknown.msg")); //$NON-NLS-1$
+ }
+ return ValidationStatus.info(WizardMessages
+ .getString("ImagePushPage.repotag.default.msg")); //$NON-NLS-1$
+ }
+
+ @Override
+ public IObservableList<?> getTargets() {
+ final WritableList<IObservableValue<?>> targets = new WritableList<>();
+ targets.add(this.imageNameObservable);
+ targets.add(this.registryAccountObservable);
+ return targets;
+ }
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java
index ec30759af2..e9165a348f 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSelectionPage.java
@@ -759,7 +759,8 @@ public class ImageRunSelectionPage extends WizardPage {
.getSelectedConnection(),
ImageRunSelectionPage.this.model
.getSelectedImageName(),
- new RegistryInfo(AbstractRegistry.DOCKERHUB_REGISTRY));
+ new RegistryInfo(AbstractRegistry.DOCKERHUB_REGISTRY,
+ true));
final boolean completed = CommandUtils
.openWizard(imageSearchWizard, getShell());
if (completed) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java
index 4ebdffe5ad..eb10c3e749 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java
@@ -13,7 +13,6 @@ package org.eclipse.linuxtools.internal.docker.ui.wizards;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
@@ -294,8 +293,11 @@ public class ImageSearchPage extends WizardPage {
* results over HTTP so if we're dealing with
* DockerHub, we use the API.
*/
- List<String> dockerHubAliases = Arrays.asList(AbstractRegistry.DOCKERHUB_REGISTRY_ALIASES);
- if (dockerHubAliases.stream().anyMatch(a -> registry.getServerAddress().contains(a))) {
+ // TODO: remove cast once AbstractRegistry methods
+ // are
+ // part of the IRegistry interface
+ if (((AbstractRegistry) registry)
+ .isDockerHubRegistry()) {
searchResults = ImageSearchPage.this.model
.getSelectedConnection().searchImages(term);
} else {
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTag.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTag.java
index 938166c258..f965582bfa 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTag.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTag.java
@@ -16,8 +16,11 @@ public class ImageTag extends Wizard {
private ImageTagPage mainPage;
- public ImageTag() {
+ private final String imageName;
+
+ public ImageTag(final String imageName) {
super();
+ this.imageName = imageName;
}
public String getTag() {
@@ -29,7 +32,7 @@ public class ImageTag extends Wizard {
@Override
public void addPages() {
- this.mainPage = new ImageTagPage();
+ this.mainPage = new ImageTagPage(this.imageName);
addPage(mainPage);
}
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 317301ecb3..a92fab4465 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
@@ -33,10 +33,10 @@ public class ImageTagPage extends WizardPage {
private String tag;
- public ImageTagPage() {
+ public ImageTagPage(final String imageName) {
super(WizardMessages.getString(NAME));
- setDescription(WizardMessages.getString(DESC));
setTitle(WizardMessages.getString(TITLE));
+ setDescription(WizardMessages.getFormattedString(DESC, imageName));
setImageDescriptor(SWTImagesFactory.DESC_WIZARD);
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnection.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnection.java
index de9c07e8f8..4d43c17efe 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnection.java
@@ -44,7 +44,11 @@ public class NewDockerConnection extends Wizard {
@Override
public boolean performFinish() {
dockerConnection = wizardPage.getDockerConnection();
- DockerConnectionManager.getInstance().addConnection(dockerConnection);
+ // add the connection and notify the listeners, so that the Docker
+ // Explorer view can set the selection on
+ // this new entry
+ DockerConnectionManager.getInstance().addConnection(dockerConnection,
+ true);
return true;
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/RegistryAccountDialog.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/RegistryAccountDialog.java
index 416d5e8740..c6f597ab40 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/RegistryAccountDialog.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/RegistryAccountDialog.java
@@ -1,12 +1,16 @@
package org.eclipse.linuxtools.internal.docker.ui.wizards;
+import java.util.stream.Stream;
+
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.linuxtools.docker.core.AbstractRegistry;
import org.eclipse.linuxtools.docker.core.IRegistryAccount;
import org.eclipse.linuxtools.internal.docker.core.RegistryAccountInfo;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
@@ -23,6 +27,7 @@ public class RegistryAccountDialog extends Dialog {
private String explanation = WizardMessages
.getString("RegistryAccountDialog.add.edit.explanation"); //$NON-NLS-1$
+
public RegistryAccountDialog(Shell parentShell, String title) {
super(parentShell);
this.title = title;
@@ -43,6 +48,11 @@ public class RegistryAccountDialog extends Dialog {
}
@Override
+ protected Point getInitialSize() {
+ return new Point(350, super.getInitialSize().y);
+ }
+
+ @Override
protected Control createDialogArea(Composite parent) {
final int COLUMNS = 2;
@@ -127,13 +137,17 @@ public class RegistryAccountDialog extends Dialog {
validate();
});
+ // status message
+
return container;
}
private void validate() {
if (serverAddress != null && !serverAddress.isEmpty()
- && username != null && !username.isEmpty()
- && password != null && password.length > 0) {
+ // username and password should be optional
+ // && username != null && !username.isEmpty()
+ // && password != null && password.length > 0
+ ) {
getButton(IDialogConstants.OK_ID).setEnabled(true);
} else {
getButton(IDialogConstants.OK_ID).setEnabled(false);
@@ -148,7 +162,11 @@ public class RegistryAccountDialog extends Dialog {
}
public IRegistryAccount getSignonInformation() {
- return new RegistryAccountInfo(serverAddress, username, email, password);
+ final boolean dockerHubRegistryAlias = Stream
+ .of(AbstractRegistry.DOCKERHUB_REGISTRY_ALIASES)
+ .anyMatch(alias -> serverAddress.contains(alias));
+ return new RegistryAccountInfo(serverAddress, username, email, password,
+ dockerHubRegistryAlias);
}
}
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 0395ad7abd..74870d812b 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
@@ -81,10 +81,16 @@ EditButton.label=Edit Dockerfile
SaveButton.label=Save
CancelButton.label=Cancel
+ImagePullPushPage.name.label=Image name:
+ImagePullPushPage.add.link=<a>Add a registry account...</a>
+ImagePullPushPage.add.label=Add a registry account...
+ImagePullPushPage.registry.account.desc=Select a registry account to push the image to.
+ImagePullPushPage.registry.account.label=Registry account:
+ImagePullPushPage.addregistry.title=Add Registry Account
+
ImagePull.title=Pull Image
ImagePull.label=Pull an image or a repository from the registry
ImagePull.desc=Specify a repository or a single image to pull down to the host.
-ImagePull.name.label=Name:
ImagePull.name.tooltip=Enter either a REPOSITORY to load all its images or REPOSITORY:TAG to load a single image
ImagePull.search.label=Search...
ImagePull.name.invalidformat.msg=Image name is invalid.\nExpected [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG]
@@ -93,15 +99,16 @@ ImagePullPage.registry.account.desc=Select a Registry Account to use, or enter a
ImagePullPage.registry.account.label=Account / Server:
ImagePush.label=Push an image:
-ImagePush.desc=Specify the image tag to push to the host.
-ImagePush.title=Push Image
+ImagePush.desc=Select the repository name and tag of the image to push to the registry.
+ImagePush.title=Push Image to Registry
ImagePush.name=Push Image
-
-ImagePushName.label=Name:
-ImagePushName.toolTip=Enter or choose a name to upload to the host (either NAME or NAME:TAG)
+ImagePushName.toolTip=Enter or choose a name to upload to the host (either REPO/NAME or REPO/NAME:TAG)
ImagePushPage.empty.registry.account=A registry is necessary to push.
-ImagePushPage.registry.account.desc=Select a Registry Account to use, or enter a server (HOST/IP:PORT) for a registry.
-ImagePushPage.registry.account.label=Account / Server:
+ImagePushPage.repotag.default.msg=Select an image name (or input a new one), then select a target registry.
+ImagePushPage.repotag.unknown.msg=The selected repository name and tag will be added to the image.
+ImagePushPage.forcetagging.label=Force tagging image with selected registry
+ImagePushPage.keeptaggedimage.label=Keep tagged image upon completion
+
ErrorNameEmpty.msg=Name field cannot be empty
ErrorInvalidImageId.msg=Invalid image name specification
@@ -139,7 +146,7 @@ ImageRemoveName.toolTip=Enter one or more images by name or by id
ErrorRemoveNameEmpty.msg=Images field cannot be empty
ErrorRemoveInvalidImageId.msg=Invalid image name specification
-ImageTag.desc=Specify new additional tag for image
+ImageTag.desc=Specify new additional tag for image with id ''{0}''
ImageTag.title=Tag Image
ImageTag.name=Tag Image
ImageTagName.label=New Tag:
@@ -342,15 +349,11 @@ ImageBuildDialog.repoNameLabel=Repository Name:
ImageBuildDialog.error.unknownConnection=Connection {0} does not exist.
ImageBuildDialog.warning.missingRepoName=A repository name is recommended.
-RegistryAccountDialog.add.edit.explanation=Add/Edit a Registry Account
+RegistryAccountDialog.add.edit.explanation=Edit a Registry Account
RegistryAccountDialog.add.explanation=Add a Registry Account
-RegistryAccountDialog.email.label=Email
-RegistryAccountDialog.password.label=Password
-RegistryAccountDialog.server.label=Server Address
+RegistryAccountDialog.email.label=Email:
+RegistryAccountDialog.password.label=Password:
+RegistryAccountDialog.server.label=Server Address:
RegistryAccountDialog.server.desc=Enter a server address. This can be a host name or an IP address with a port specified.
-RegistryAccountDialog.username.label=Username
+RegistryAccountDialog.username.label=Username:
RegistryAccountDialog.username.desc=Enter username to use for this registry (eg. Docker Hub, OpenShift Docker Registry, etc.)
-
-ImagePullPushPage.browse.label=Browse
-ImagePullPushPage.add.label=Add...
-ImagePullPushPage.login.title=Registry Login \ No newline at end of file

Back to the top