Skip to content

Commit 514cf8a

Browse files
authored
Remove .appengine.facets dependency from ui.util (#1183)
* Remove .appengine.facets dependency from ui.util * Make getProject static method * Don't call empty super method * Remove Preconditions * Throw NullPointerException
1 parent dbe4b7c commit 514cf8a

File tree

10 files changed

+62
-165
lines changed

10 files changed

+62
-165
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@
1818

1919
import static org.mockito.Mockito.mock;
2020

21-
import org.eclipse.core.runtime.CoreException;
21+
import com.google.cloud.tools.eclipse.util.FacetedProjectHelper;
2222
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
2323
import org.junit.Test;
2424

25-
import com.google.cloud.tools.eclipse.util.FacetedProjectHelper;
26-
2725
public class FacetedProjectHelperTest {
2826

29-
@Test(expected = NullPointerException.class)
30-
public void testGetFacetedProject_nullArgument() throws CoreException {
31-
new FacetedProjectHelper().getFacetedProject(null);
32-
}
33-
3427
@Test(expected = NullPointerException.class)
3528
public void testProjectHasFacet_projectNull() {
3629
new FacetedProjectHelper().projectHasFacet(null, null);
@@ -40,7 +33,7 @@ public void testProjectHasFacet_projectNull() {
4033
public void testProjectHasFacet_facetIdNull() {
4134
new FacetedProjectHelper().projectHasFacet(mock(IFacetedProject.class), null);
4235
}
43-
36+
4437
@Test(expected = IllegalArgumentException.class)
4538
public void testProjectHasFacet_facetIdEmpty() {
4639
new FacetedProjectHelper().projectHasFacet(mock(IFacetedProject.class), "");

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

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

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

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,29 @@
1616

1717
package com.google.cloud.tools.eclipse.appengine.deploy.ui.standard;
1818

19+
import com.google.api.client.auth.oauth2.Credential;
20+
import com.google.cloud.tools.appengine.api.deploy.DefaultDeployConfiguration;
21+
import com.google.cloud.tools.eclipse.appengine.deploy.CleanupOldDeploysJob;
22+
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployJob;
23+
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployJobConfig;
24+
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployPreferences;
25+
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployPreferencesConverter;
26+
import com.google.cloud.tools.eclipse.appengine.deploy.ui.DeployConsole;
27+
import com.google.cloud.tools.eclipse.appengine.deploy.ui.DeployPreferencesDialog;
28+
import com.google.cloud.tools.eclipse.appengine.deploy.ui.Messages;
29+
import com.google.cloud.tools.eclipse.appengine.login.IGoogleLoginService;
30+
import com.google.cloud.tools.eclipse.sdk.ui.MessageConsoleWriterOutputLineListener;
31+
import com.google.cloud.tools.eclipse.ui.util.MessageConsoleUtilities;
32+
import com.google.cloud.tools.eclipse.ui.util.ProjectFromSelectionHelper;
33+
import com.google.cloud.tools.eclipse.ui.util.ServiceUtils;
34+
import com.google.cloud.tools.eclipse.usagetracker.AnalyticsEvents;
35+
import com.google.cloud.tools.eclipse.usagetracker.AnalyticsPingManager;
1936
import java.io.IOException;
2037
import java.nio.file.Files;
2138
import java.text.DateFormat;
2239
import java.text.MessageFormat;
2340
import java.util.Date;
2441
import java.util.Locale;
25-
2642
import org.eclipse.core.commands.AbstractHandler;
2743
import org.eclipse.core.commands.ExecutionEvent;
2844
import org.eclipse.core.commands.ExecutionException;
@@ -40,26 +56,8 @@
4056
import org.eclipse.ui.console.IConsoleManager;
4157
import org.eclipse.ui.console.MessageConsoleStream;
4258
import org.eclipse.ui.handlers.HandlerUtil;
43-
44-
import com.google.api.client.auth.oauth2.Credential;
45-
import com.google.cloud.tools.appengine.api.deploy.DefaultDeployConfiguration;
46-
import com.google.cloud.tools.eclipse.appengine.deploy.CleanupOldDeploysJob;
47-
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployJob;
48-
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployJobConfig;
49-
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployPreferences;
50-
import com.google.cloud.tools.eclipse.appengine.deploy.standard.StandardDeployPreferencesConverter;
51-
import com.google.cloud.tools.eclipse.appengine.deploy.ui.DeployConsole;
52-
import com.google.cloud.tools.eclipse.appengine.deploy.ui.DeployPreferencesDialog;
53-
import com.google.cloud.tools.eclipse.appengine.deploy.ui.Messages;
54-
import com.google.cloud.tools.eclipse.appengine.login.IGoogleLoginService;
55-
import com.google.cloud.tools.eclipse.sdk.ui.MessageConsoleWriterOutputLineListener;
56-
import com.google.cloud.tools.eclipse.ui.util.MessageConsoleUtilities;
57-
import com.google.cloud.tools.eclipse.ui.util.ProjectFromSelectionHelper;
58-
import com.google.cloud.tools.eclipse.ui.util.ServiceUtils;
59-
import com.google.cloud.tools.eclipse.usagetracker.AnalyticsEvents;
60-
import com.google.cloud.tools.eclipse.usagetracker.AnalyticsPingManager;
61-
import com.google.cloud.tools.eclipse.util.FacetedProjectHelper;
62-
import com.google.common.annotations.VisibleForTesting;
59+
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
60+
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
6361

6462
/**
6563
* Command handler to deploy a web application project to App Engine Standard.
@@ -71,40 +69,36 @@ public class StandardDeployCommandHandler extends AbstractHandler {
7169

7270
private static final String CONSOLE_NAME = "App Engine Deploy";
7371

74-
private ProjectFromSelectionHelper helper;
75-
76-
public StandardDeployCommandHandler() {
77-
this(new FacetedProjectHelper());
78-
}
79-
80-
@VisibleForTesting
81-
StandardDeployCommandHandler(FacetedProjectHelper facetedProjectHelper) {
82-
this.helper = new ProjectFromSelectionHelper(facetedProjectHelper);
83-
}
84-
8572
@Override
8673
public Object execute(ExecutionEvent event) throws ExecutionException {
8774
try {
88-
IProject project = helper.getAppEngineStandardProject(event);
89-
if (project != null) {
90-
if (!checkProjectErrors(project)) {
91-
MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
92-
Messages.getString("build.error.dialog.title"),
93-
Messages.getString("build.error.dialog.message"));
94-
return null;
95-
}
96-
97-
IGoogleLoginService loginService = ServiceUtils.getService(event, IGoogleLoginService.class);
98-
DeployPreferencesDialog dialog =
99-
new DeployPreferencesDialog(HandlerUtil.getActiveShell(event), project, loginService);
100-
if (dialog.open() == Window.OK) {
101-
launchDeployJob(project, dialog.getCredential());
102-
}
75+
IProject project = ProjectFromSelectionHelper.getProject(event);
76+
if (project == null) {
77+
throw new NullPointerException("Deploy menu enabled for non-project resources");
78+
}
79+
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
80+
if (facetedProject == null) {
81+
throw new NullPointerException("Deploy menu enabled for non-faceted projects");
82+
}
83+
84+
if (!checkProjectErrors(project)) {
85+
MessageDialog.openInformation(HandlerUtil.getActiveShell(event),
86+
Messages.getString("build.error.dialog.title"),
87+
Messages.getString("build.error.dialog.message"));
88+
return null;
89+
}
90+
91+
IGoogleLoginService loginService = ServiceUtils.getService(event, IGoogleLoginService.class);
92+
DeployPreferencesDialog dialog =
93+
new DeployPreferencesDialog(HandlerUtil.getActiveShell(event), project, loginService);
94+
if (dialog.open() == Window.OK) {
95+
launchDeployJob(project, dialog.getCredential());
10396
}
10497
// return value must be null, reserved for future use
10598
return null;
10699
} catch (CoreException | IOException exception) {
107-
throw new ExecutionException(Messages.getString("deploy.failed.error.message"), exception); //$NON-NLS-1$
100+
throw new ExecutionException(
101+
Messages.getString("deploy.failed.error.message"), exception); //$NON-NLS-1$
108102
}
109103
}
110104

@@ -137,14 +131,13 @@ private void launchDeployJob(IProject project, Credential credential)
137131

138132
@Override
139133
public void done(IJobChangeEvent event) {
140-
super.done(event);
141134
AnalyticsPingManager.getInstance().sendPing(AnalyticsEvents.APP_ENGINE_DEPLOY_SUCCESS,
142135
AnalyticsEvents.APP_ENGINE_DEPLOY_STANDARD, null);
143136
launchCleanupJob();
144137
}
145138
});
146139
deploy.schedule();
147-
140+
148141
IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
149142
consoleManager.showConsoleView(messageConsole);
150143
}

plugins/com.google.cloud.tools.eclipse.appengine.facets.test/src/com/google/cloud/tools/eclipse/appengine/facets/StandardFacetInstallationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import static org.junit.Assert.assertTrue;
2222

2323
import com.google.cloud.tools.eclipse.test.util.project.ProjectUtils;
24-
import com.google.cloud.tools.eclipse.util.FacetedProjectHelper;
2524
import java.io.IOException;
2625
import java.util.List;
2726
import org.eclipse.core.resources.IFile;
2827
import org.eclipse.core.resources.IProject;
2928
import org.eclipse.core.runtime.CoreException;
3029
import org.eclipse.core.runtime.Path;
3130
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
31+
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
3232
import org.eclipse.wst.common.project.facet.core.runtime.IRuntime;
3333
import org.junit.After;
3434
import org.junit.Test;
@@ -54,7 +54,7 @@ public void testStandardFacetInstallation() throws IOException, CoreException {
5454
ProjectUtils.importProjects(getClass(), "projects/test-dynamic-web-project.zip", null);
5555
assertEquals(1, projects.size());
5656
IProject project = projects.get(0);
57-
IFacetedProject facetedProject = new FacetedProjectHelper().getFacetedProject(project);
57+
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
5858
// verify that the appengine-web.xml is installed in the dynamic web root folder
5959
AppEngineStandardFacet.installAppEngineFacet(facetedProject, true, null);
6060
IFile correctAppEngineWebXml = project.getFile(new Path("war/WEB-INF/appengine-web.xml"));

plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/DeployPropertyPageTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525

2626
import org.eclipse.core.runtime.CoreException;
2727
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
28+
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
2829
import org.junit.Test;
2930

3031
public class DeployPropertyPageTest extends AbstractProjectTests {
3132
@Test
3233
public void testPropertyPageTitle_standardProject() throws CoreException {
3334
String projectName = "foo";
3435
project = SwtBotAppEngineActions.createNativeWebAppProject(bot, projectName, null, null);
35-
IFacetedProject facetedProject = new FacetedProjectHelper().getFacetedProject(project);
36+
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
3637
assertNotNull("Native App Engine projects should be faceted", facetedProject);
3738
assertTrue(
3839
new FacetedProjectHelper().projectHasFacet(facetedProject, AppEngineStandardFacet.ID));

plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/NewMavenBasedAppEngineProjectWizardTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.core.runtime.Path;
3232
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
3333
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
34+
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
3435
import org.junit.Test;
3536
import org.junit.runner.RunWith;
3637

@@ -96,7 +97,7 @@ private void createAndCheck(String artifactId, String location,
9697
project.getLocation().toFile().getParentFile().getCanonicalPath());
9798
}
9899

99-
IFacetedProject facetedProject = new FacetedProjectHelper().getFacetedProject(project);
100+
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
100101
assertNotNull("m2e-wtp should create a faceted project", facetedProject);
101102
assertTrue("Project does not have standard facet",
102103
new FacetedProjectHelper().projectHasFacet(facetedProject, AppEngineStandardFacet.ID));

plugins/com.google.cloud.tools.eclipse.integration.appengine/src/com/google/cloud/tools/eclipse/integration/appengine/NewNativeAppEngineStandardProjectTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.core.runtime.Path;
2929
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
3030
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
31+
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
3132
import org.junit.Test;
3233
import org.junit.runner.RunWith;
3334

@@ -61,7 +62,7 @@ private void createAndCheck(String projectName, String packageName, String[] pro
6162
packageName);
6263
assertTrue(project.exists());
6364

64-
IFacetedProject facetedProject = new FacetedProjectHelper().getFacetedProject(project);
65+
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
6566
assertNotNull("Native App Engine projects should be faceted", facetedProject);
6667
assertTrue("Project does not have standard facet",
6768
new FacetedProjectHelper().projectHasFacet(facetedProject, AppEngineStandardFacet.ID));

plugins/com.google.cloud.tools.eclipse.ui.util/META-INF/MANIFEST.MF

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Bundle-Localization: plugin
88
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
99
Bundle-ActivationPolicy: lazy
1010
Require-Bundle: org.eclipse.ui.workbench
11-
Import-Package: com.google.cloud.tools.eclipse.appengine.facets,
12-
com.google.cloud.tools.eclipse.ui.util,
11+
Import-Package: com.google.cloud.tools.eclipse.ui.util,
1312
com.google.cloud.tools.eclipse.util,
1413
com.google.cloud.tools.eclipse.util.status,
1514
com.google.cloud.tools.project;version="0.1.9",

plugins/com.google.cloud.tools.eclipse.ui.util/src/com/google/cloud/tools/eclipse/ui/util/ProjectFromSelectionHelper.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,22 @@
1616

1717
package com.google.cloud.tools.eclipse.ui.util;
1818

19-
import com.google.cloud.tools.eclipse.appengine.facets.AppEngineStandardFacet;
2019
import com.google.cloud.tools.eclipse.util.AdapterUtil;
21-
import com.google.cloud.tools.eclipse.util.FacetedProjectHelper;
2220
import org.eclipse.core.commands.ExecutionEvent;
2321
import org.eclipse.core.commands.ExecutionException;
2422
import org.eclipse.core.resources.IProject;
25-
import org.eclipse.core.runtime.CoreException;
2623
import org.eclipse.jface.viewers.ISelection;
2724
import org.eclipse.jface.viewers.IStructuredSelection;
2825
import org.eclipse.ui.handlers.HandlerUtil;
29-
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
3026

3127
public class ProjectFromSelectionHelper {
3228

33-
private FacetedProjectHelper facetedProjectHelper;
34-
35-
public ProjectFromSelectionHelper(FacetedProjectHelper facetedProjectHelper) {
36-
this.facetedProjectHelper = facetedProjectHelper;
37-
}
38-
39-
public IProject getAppEngineStandardProject(ExecutionEvent event)
40-
throws CoreException, ExecutionException {
29+
public static IProject getProject(ExecutionEvent event) throws ExecutionException {
4130
ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
4231
if (selection instanceof IStructuredSelection) {
4332
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
4433
if (structuredSelection.size() == 1) {
45-
IProject project = AdapterUtil.adapt(structuredSelection.getFirstElement(), IProject.class);
46-
if (project == null) {
47-
return null;
48-
}
49-
50-
IFacetedProject facetedProject = facetedProjectHelper.getFacetedProject(project);
51-
if (AppEngineStandardFacet.hasAppEngineFacet(facetedProject)) {
52-
return project;
53-
}
34+
return AdapterUtil.adapt(structuredSelection.getFirstElement(), IProject.class);
5435
}
5536
}
5637
return null;

0 commit comments

Comments
 (0)