Skip to content

Commit 3c839bb

Browse files
committed
Merge with HEAD
2 parents d5827f2 + f2c7220 commit 3c839bb

29 files changed

Lines changed: 294 additions & 190 deletions

File tree

features/com.google.cloud.tools.eclipse.suite.e45.feature/feature.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feature
33
id="com.google.cloud.tools.eclipse.suite.e45.feature"
44
label="Google Cloud Platform for Eclipse 4.5 and later"
5-
version="1.0.0.qualifier"
5+
version="1.0.1.qualifier"
66
provider-name="Google, Inc."
77
plugin="com.google.cloud.tools.eclipse.appengine.ui"
88
license-feature="com.google.licenses.apache_v2">

features/com.google.cloud.tools.eclipse.suite.e45.feature/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<relativePath>../../</relativePath>
1010
</parent>
1111
<artifactId>com.google.cloud.tools.eclipse.suite.e45.feature</artifactId>
12-
<version>1.0.0-SNAPSHOT</version>
12+
<version>1.0.1-SNAPSHOT</version>
1313
<packaging>eclipse-feature</packaging>
1414

1515
</project>

gcp-repo/metadata.p2.inf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
requires.1.namespace=org.eclipse.equinox.p2.iu
1212
requires.1.name=com.google.cloud.tools.eclipse.category
13-
requires.1.range=[1.0.0,1.0.0]
13+
requires.1.range=[1.0.0,1.0.1]
1414
requires.1.greedy=true
1515

1616
units.1.id=com.google.cloud.tools.eclipse.category
17-
units.1.version=1.0.0
17+
units.1.version=1.0.1
1818
units.1.properties.1.name=org.eclipse.equinox.p2.type.category
1919
units.1.properties.1.value=true
2020
units.1.properties.2.name=org.eclipse.equinox.p2.name
@@ -27,7 +27,7 @@ units.1.properties.5.name=org.eclipse.equinox.p2.doc.url
2727
units.1.properties.5.value=https://cloud.google.com/eclipse/docs/
2828
units.1.provides.1.namespace=org.eclipse.equinox.p2.iu
2929
units.1.provides.1.name=com.google.cloud.tools.eclipse.category
30-
units.1.provides.1.version=1.0.0
30+
units.1.provides.1.version=1.0.1
3131
units.1.copyright =Copyright 2016, 2017 Google Inc.
3232
units.1.licenses.0 =\
3333
Cloud Tools for Eclipse is made available under the Apache License, Version 2.0. \

gcp-repo/metadata.product

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This product exists to (1) bring in any required features, and
55
(2) add any additional metadata for the CT4E repository.
66
-->
7-
<product uid="com.google.cloud.tools.eclipse.dist" version="1.0.0.qualifier" useFeatures="true" includeLaunchers="false">
7+
<product uid="com.google.cloud.tools.eclipse.dist" version="1.0.1.qualifier" useFeatures="true" includeLaunchers="false">
88

99
<configIni use="default">
1010
</configIni>

plugins/com.google.cloud.tools.eclipse.appengine.deploy.ui.test/src/com/google/cloud/tools/eclipse/appengine/deploy/ui/StandardDeployPreferencesPanelTest.java

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
import com.google.api.client.auth.oauth2.Credential;
3030
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployPreferences;
31+
import com.google.cloud.tools.eclipse.appengine.deploy.ui.StandardDeployPreferencesPanel.ProjectSelectionValidator;
3132
import com.google.cloud.tools.eclipse.login.IGoogleLoginService;
33+
import com.google.cloud.tools.eclipse.login.ui.AccountSelector;
3234
import com.google.cloud.tools.eclipse.login.ui.AccountSelectorObservableValue;
3335
import com.google.cloud.tools.eclipse.projectselector.ProjectRepository;
3436
import com.google.cloud.tools.eclipse.projectselector.ProjectRepositoryException;
@@ -65,6 +67,7 @@ public class StandardDeployPreferencesPanelTest {
6567
private static final String EMAIL_1 = "some-email-1@example.com";
6668

6769
private Composite parent;
70+
private StandardDeployPreferencesPanel deployPanel;
6871
@Mock private IProject project;
6972
@Mock private IGoogleLoginService loginService;
7073
@Mock private Runnable layoutChangedHandler;
@@ -87,14 +90,13 @@ public void setUp() throws Exception {
8790
@Test
8891
public void testSelectSingleAccount() {
8992
when(loginService.getAccounts()).thenReturn(new HashSet<>(Arrays.asList(account1)));
90-
StandardDeployPreferencesPanel deployPanel = new StandardDeployPreferencesPanel(
91-
parent, project, loginService, layoutChangedHandler, true, projectRepository);
93+
deployPanel = createPanel(true /* requireValues */);
9294
assertThat(deployPanel.getSelectedCredential(), is(credential));
9395

9496
// todo? assertTrue(deployPanel.getAccountSelector().isAutoSelectAccountIfNone()
9597

9698
// verify not in error
97-
IStatus status = getAccountSelectorValidationStatus(deployPanel);
99+
IStatus status = getAccountSelectorValidationStatus();
98100
assertTrue("account selector is in error: " + status.getMessage(), status.isOK());
99101

100102
assertThat("auto-selected value should be propagated back to model",
@@ -103,10 +105,8 @@ public void testSelectSingleAccount() {
103105

104106
@Test
105107
public void testValidationMessageWhenNotSignedIn() {
106-
StandardDeployPreferencesPanel deployPanel =
107-
new StandardDeployPreferencesPanel(parent, project, loginService, layoutChangedHandler,
108-
true, projectRepository);
109-
IStatus status = getAccountSelectorValidationStatus(deployPanel);
108+
deployPanel = createPanel(true /* requireValues */);
109+
IStatus status = getAccountSelectorValidationStatus();
110110
assertThat(status.getMessage(), is("Sign in to Google."));
111111
}
112112

@@ -115,34 +115,19 @@ public void testValidationMessageWhenSignedIn() {
115115
// Return two accounts because the account selector will auto-select if there exists only one.
116116
when(loginService.getAccounts()).thenReturn(new HashSet<>(Arrays.asList(account1, account2)));
117117

118-
StandardDeployPreferencesPanel deployPanel =
119-
new StandardDeployPreferencesPanel(parent, project, loginService, layoutChangedHandler,
120-
true, projectRepository);
121-
IStatus status = getAccountSelectorValidationStatus(deployPanel);
118+
deployPanel = createPanel(true /* requireValues */);
119+
IStatus status = getAccountSelectorValidationStatus();
122120
assertThat(status.getMessage(), is("Select an account."));
123121
}
124122

125-
private static Button getButtonWithText(Composite parent, String text) {
126-
for (Control control : parent.getChildren()) {
127-
if (control instanceof Button) {
128-
Button button = (Button) control;
129-
if (button.getText().equals(text)) {
130-
return button;
131-
}
132-
}
133-
}
134-
return null;
135-
}
136-
137123
// https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/1229
138124
@Test
139125
public void testUncheckStopPreviousVersionButtonWhenDisabled() {
140-
StandardDeployPreferencesPanel panel = new StandardDeployPreferencesPanel(
141-
parent, project, loginService, layoutChangedHandler, true, projectRepository);
126+
deployPanel = createPanel(true /* requireValues */);
142127

143128
Button promoteButton =
144-
getButtonWithText(panel, "Promote the deployed version to receive all traffic");
145-
Button stopButton = getButtonWithText(panel, "Stop previous version");
129+
getButtonWithText("Promote the deployed version to receive all traffic");
130+
Button stopButton = getButtonWithText("Stop previous version");
146131
SWTBotCheckBox promote = new SWTBotCheckBox(promoteButton);
147132
SWTBotCheckBox stop = new SWTBotCheckBox(stopButton);
148133

@@ -183,11 +168,9 @@ public void testProjectSavedInPreferencesSelected() throws ProjectRepositoryExce
183168
new ProjectScope(project).getNode(StandardDeployPreferences.PREFERENCE_STORE_QUALIFIER);
184169
node.put("project.id", "projectId1");
185170
node.put("account.email", EMAIL_1);
186-
initializeProjectRepository(projectRepository);
171+
initializeProjectRepository();
187172
when(loginService.getAccounts()).thenReturn(new HashSet<>(Arrays.asList(account1, account2)));
188-
StandardDeployPreferencesPanel deployPanel =
189-
new StandardDeployPreferencesPanel(parent, project, loginService, layoutChangedHandler,
190-
true, projectRepository);
173+
deployPanel = createPanel(true /* requireValues */);
191174
Queue<Control> children = new ArrayDeque<>(Arrays.asList(deployPanel.getChildren()));
192175
while (!children.isEmpty()) {
193176
Control control = children.poll();
@@ -204,7 +187,65 @@ public void testProjectSavedInPreferencesSelected() throws ProjectRepositoryExce
204187
fail("Did not find ProjectSelector widget");
205188
}
206189

207-
private void initializeProjectRepository(ProjectRepository projectRepository)
190+
@Test
191+
public void testProjectNotSelectedIsAnErrorWhenRequireValuesIsTrue() {
192+
deployPanel = createPanel(true /* requireValues */);
193+
assertThat(getProjectSelectionValidator().getSeverity(), is(IStatus.ERROR));
194+
}
195+
196+
@Test
197+
public void testProjectNotSelectedIsNotAnErrorWhenRequireValuesIsFalse() {
198+
deployPanel = createPanel(false /* requireValues */);
199+
assertThat(getProjectSelectionValidator().getSeverity(), is(IStatus.INFO));
200+
}
201+
202+
@Test
203+
public void testProjectsExistThenNoProjectNotFoundError() throws ProjectRepositoryException {
204+
when(loginService.getAccounts()).thenReturn(new HashSet<>(Arrays.asList(account1)));
205+
initializeProjectRepository();
206+
deployPanel = createPanel(false /* requireValues */);
207+
selectAccount(account1);
208+
assertThat(getProjectSelectionValidator().getSeverity(), is(IStatus.OK));
209+
}
210+
211+
private Button getButtonWithText(String text) {
212+
for (Control control : deployPanel.getChildren()) {
213+
if (control instanceof Button) {
214+
Button button = (Button) control;
215+
if (button.getText().equals(text)) {
216+
return button;
217+
}
218+
}
219+
}
220+
return null;
221+
}
222+
223+
private void selectAccount(Account account) {
224+
for (Control control : deployPanel.getChildren()) {
225+
if (control instanceof AccountSelector) {
226+
AccountSelector accountSelector = (AccountSelector) control;
227+
accountSelector.selectAccount(account.getEmail());
228+
}
229+
}
230+
}
231+
232+
private StandardDeployPreferencesPanel createPanel(boolean requireValues) {
233+
return new StandardDeployPreferencesPanel(parent, project, loginService, layoutChangedHandler,
234+
requireValues, projectRepository);
235+
}
236+
237+
private IStatus getProjectSelectionValidator() {
238+
for (Object object : deployPanel.getDataBindingContext().getValidationStatusProviders()) {
239+
if (object instanceof ProjectSelectionValidator) {
240+
ProjectSelectionValidator projectSelectionValidator = (ProjectSelectionValidator) object;
241+
return (IStatus) projectSelectionValidator.getValidationStatus().getValue();
242+
}
243+
}
244+
fail("Could not find ProjectSelectionValidator.");
245+
return null;
246+
}
247+
248+
private void initializeProjectRepository()
208249
throws ProjectRepositoryException {
209250
GcpProject project1 = new GcpProject("Project1", "projectId1");
210251
GcpProject project2 = new GcpProject("Project2", "projectId2");
@@ -216,7 +257,7 @@ private void initializeProjectRepository(ProjectRepository projectRepository)
216257
.thenReturn(project2);
217258
}
218259

219-
private IStatus getAccountSelectorValidationStatus(StandardDeployPreferencesPanel deployPanel) {
260+
private IStatus getAccountSelectorValidationStatus() {
220261
IStatus status = null;
221262
for (Object object : deployPanel.getDataBindingContext().getValidationStatusProviders()) {
222263
ValidationStatusProvider statusProvider = (ValidationStatusProvider) object;

plugins/com.google.cloud.tools.eclipse.appengine.deploy.ui/src/com/google/cloud/tools/eclipse/appengine/deploy/ui/DeployPropertyPage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
public class DeployPropertyPage extends PropertyPage {
4848

4949
private DeployPreferencesPanel content;
50-
private boolean canSetMessage;
50+
private boolean canSetMessage = true;
5151
private boolean isStandardPanel;
5252
private IFacetedProject facetedProject = null;
5353
private String invalidFacetConfigErrorMessage = "";
@@ -202,7 +202,7 @@ private void evaluateFacetConfiguration() {
202202
private void updatePageBasedOnFacetConfig(boolean hasCorrectFacetConfiguration) {
203203
if (hasCorrectFacetConfiguration) {
204204
canSetMessage = true;
205-
setErrorMessage(null);
205+
content.getDataBindingContext().updateModels();
206206
} else {
207207
setErrorMessage(invalidFacetConfigErrorMessage);
208208
canSetMessage = false;

plugins/com.google.cloud.tools.eclipse.appengine.deploy.ui/src/com/google/cloud/tools/eclipse/appengine/deploy/ui/StandardDeployPreferencesPanel.java

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.google.cloud.tools.eclipse.projectselector.model.GcpProject;
2828
import com.google.cloud.tools.eclipse.ui.util.FontUtil;
2929
import com.google.cloud.tools.eclipse.ui.util.databinding.BucketNameValidator;
30-
import com.google.cloud.tools.eclipse.ui.util.databinding.ProjectSelectorValidator;
3130
import com.google.cloud.tools.eclipse.ui.util.databinding.ProjectVersionValidator;
3231
import com.google.cloud.tools.eclipse.ui.util.event.OpenUriSelectionListener;
3332
import com.google.cloud.tools.eclipse.ui.util.event.OpenUriSelectionListener.ErrorDialogErrorHandler;
@@ -36,6 +35,7 @@
3635
import com.google.common.annotations.VisibleForTesting;
3736
import com.google.common.base.Preconditions;
3837
import com.google.common.base.Strings;
38+
import java.util.Collection;
3939
import java.util.Collections;
4040
import java.util.List;
4141
import java.util.logging.Level;
@@ -51,7 +51,6 @@
5151
import org.eclipse.core.databinding.observable.value.ComputedValue;
5252
import org.eclipse.core.databinding.observable.value.IObservableValue;
5353
import org.eclipse.core.databinding.observable.value.WritableValue;
54-
import org.eclipse.core.databinding.validation.IValidator;
5554
import org.eclipse.core.databinding.validation.MultiValidator;
5655
import org.eclipse.core.databinding.validation.ValidationStatus;
5756
import org.eclipse.core.resources.IProject;
@@ -156,7 +155,7 @@ private void setupDataBinding() {
156155
bindingContext = new DataBindingContext();
157156

158157
setupAccountEmailDataBinding(bindingContext);
159-
setupProjectIdDataBinding(bindingContext);
158+
setupProjectSelectorDataBinding(bindingContext);
160159
setupProjectVersionDataBinding(bindingContext);
161160
setupAutoPromoteDataBinding(bindingContext);
162161
setupBucketDataBinding(bindingContext);
@@ -198,7 +197,14 @@ public Object convert(Object expectedEmail) {
198197
accountSelectorObservableValue));
199198
}
200199

201-
private void setupProjectIdDataBinding(DataBindingContext context) {
200+
private void setupProjectSelectorDataBinding(DataBindingContext context) {
201+
IViewerObservableValue projectInput =
202+
ViewerProperties.input().observe(projectSelector.getViewer());
203+
IViewerObservableValue projectSelection =
204+
ViewerProperties.singleSelection().observe(projectSelector.getViewer());
205+
context.addValidationStatusProvider(
206+
new ProjectSelectionValidator(projectInput, projectSelection, requireValues));
207+
202208
IViewerObservableValue projectList =
203209
ViewerProperties.singleSelection().observe(projectSelector.getViewer());
204210
IObservableValue projectIdModel = PojoProperties.value("projectId").observe(model);
@@ -207,11 +213,6 @@ private void setupProjectIdDataBinding(DataBindingContext context) {
207213
new UpdateValueStrategy().setConverter(new GcpProjectToProjectIdConverter());
208214
UpdateValueStrategy projectIdToGcpProject =
209215
new UpdateValueStrategy().setConverter(new ProjectIdToGcpProjectConverter());
210-
if (requireValues) {
211-
IValidator validator = new ProjectSelectorValidator();
212-
gcpProjectToProjectId.setAfterConvertValidator(validator);
213-
projectIdToGcpProject.setAfterGetValidator(validator);
214-
}
215216

216217
context.bindValue(projectList, projectIdModel, gcpProjectToProjectId, projectIdToGcpProject);
217218
}
@@ -523,6 +524,42 @@ public Object convert(Object fromObject) {
523524
}
524525
}
525526

527+
static class ProjectSelectionValidator extends FixedMultiValidator {
528+
529+
private final IViewerObservableValue projectInput;
530+
private final IViewerObservableValue projectSelection;
531+
private final boolean requireValues;
532+
533+
private ProjectSelectionValidator(IViewerObservableValue projectInput,
534+
IViewerObservableValue projectSelection,
535+
boolean requireValues) {
536+
this.projectInput = projectInput;
537+
this.projectSelection = projectSelection;
538+
this.requireValues = requireValues;
539+
}
540+
541+
@Override
542+
protected IStatus validate() {
543+
// this access is recorded and ensures that changes are tracked, don't move it inside the if
544+
Collection<?> projects = (Collection<?>) projectInput.getValue();
545+
// this access is recorded and ensures that changes are tracked, don't move it inside the if
546+
Object selectedProject = projectSelection.getValue();
547+
if (projects.isEmpty()) {
548+
if (requireValues) {
549+
return ValidationStatus.error(Messages.getString("projectselector.no.projects")); //$NON-NLS-1$
550+
} else {
551+
return ValidationStatus.info(Messages.getString("projectselector.no.projects")); //$NON-NLS-1$
552+
}
553+
}
554+
if (requireValues) {
555+
if (selectedProject == null) {
556+
return ValidationStatus.error(Messages.getString("projectselector.project.not.selected")); //$NON-NLS-1$
557+
}
558+
}
559+
return ValidationStatus.ok();
560+
}
561+
}
562+
526563
/**
527564
* Validates the {@link AccountSelector account selector} state against the panel settings.
528565
* Reports an error if the panel requires all values to be set, but the account selector does not

plugins/com.google.cloud.tools.eclipse.appengine.deploy.ui/src/com/google/cloud/tools/eclipse/appengine/deploy/ui/messages.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ tooltip.staging.bucket=The Google Cloud Storage bucket used to stage files for d
4242
If not specified, the application''s default code bucket is used.
4343

4444
#Project selector
45-
projectselector.selectProject=Select a Google Cloud Platform project
4645
projectselector.createproject=Create a project in the <a href="{0}">Cloud Console</a>. Then refresh this list.
4746
projectselector.createproject.tooltip=Opens the Cloud Console in a browser. You will need to refresh the project list \
4847
after the project is created.
48+
projectselector.no.projects=No projects found
49+
projectselector.project.not.selected=Select a project
50+
projectselector.selectProject=Select a Google Cloud Platform project
4951
projectselector.retrieveproject.error.title=Failed to retrieve projects
5052
projectselector.retrieveproject.error.message=An error occurred while retrieving projects: {0}
5153
projectselector.retrieveapplication.error.title=Failed to retrieve App Engine application

0 commit comments

Comments
 (0)