Skip to content

Commit 5a653d1

Browse files
committed
Merge remote-tracking branch 'origin/i1454' into ide-target-platform
2 parents b189bf1 + 644c9c9 commit 5a653d1

6 files changed

Lines changed: 120 additions & 33 deletions

File tree

plugins/com.google.cloud.tools.eclipse.appengine.newproject/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
name="%standard.wizard.name"
1010
class="com.google.cloud.tools.eclipse.util.service.ServiceContextFactory:com.google.cloud.tools.eclipse.appengine.newproject.standard.AppEngineStandardProjectWizard"
1111
icon="platform:/plugin/com.google.cloud.tools.eclipse.appengine.ui/icons/gae-16x16.png"
12+
finalPerspective="org.eclipse.jst.j2ee.J2EEPerspective"
13+
preferredPerspectives="org.eclipse.jst.j2ee.J2EEPerspective,org.eclipse.wst.web.ui.webDevPerspective"
1214
project="true"
1315
category="com.google.cloud.tools.eclipse.wizards">
1416
<description>%standard.wizard.description</description>

plugins/com.google.cloud.tools.eclipse.appengine.newproject/src/com/google/cloud/tools/eclipse/appengine/newproject/AppEngineProjectWizard.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,32 @@
2929
import com.google.common.base.Preconditions;
3030
import java.io.File;
3131
import java.lang.reflect.InvocationTargetException;
32+
import javax.inject.Inject;
3233
import org.eclipse.core.resources.IFile;
3334
import org.eclipse.core.runtime.IAdaptable;
35+
import org.eclipse.core.runtime.IConfigurationElement;
3436
import org.eclipse.core.runtime.IStatus;
3537
import org.eclipse.jface.viewers.IStructuredSelection;
3638
import org.eclipse.jface.wizard.Wizard;
3739
import org.eclipse.ui.INewWizard;
3840
import org.eclipse.ui.IWorkbench;
3941
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
42+
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
4043

44+
/**
45+
* Base class for App Engine projection creation.
46+
* <p>
47+
* Expected to be created via the {@link ServiceContextFactory}.
48+
*/
4149
public abstract class AppEngineProjectWizard extends Wizard implements INewWizard {
4250

4351
private AppEngineWizardPage page = null;
4452
protected final AppEngineProjectConfig config = new AppEngineProjectConfig();
4553
private IWorkbench workbench;
4654

55+
@Inject
56+
protected IConfigurationElement configElement;
57+
4758
public AppEngineProjectWizard() {
4859
setNeedsProgressMonitor(true);
4960
}
@@ -107,9 +118,13 @@ public boolean performFinish() {
107118
boolean fork = true;
108119
boolean cancelable = true;
109120
getContainer().run(fork, cancelable, runnable);
121+
122+
// prompt to switch to preferred perspective
123+
BasicNewProjectResourceWizard.updatePerspective(configElement);
110124

111125
// open most important file created by wizard in editor
112126
IFile file = runnable.getMostImportant();
127+
BasicNewProjectResourceWizard.selectAndReveal(file, workbench.getActiveWorkbenchWindow());
113128
WorkbenchUtil.openInEditor(workbench, file);
114129
return true;
115130
} catch (InterruptedException ex) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
2626
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
2727
import org.junit.After;
28+
import org.junit.Before;
2829
import org.junit.BeforeClass;
2930

3031
/**
@@ -36,7 +37,7 @@ public class BaseProjectTest {
3637
protected IProject project;
3738

3839
@BeforeClass
39-
public static void setUp() throws Exception {
40+
public static void setUpWorkbench() throws Exception {
4041
// verify we can find the Google Cloud SDK
4142
new CloudSdk.Builder().build().validateCloudSdk();
4243

@@ -48,6 +49,12 @@ public static void setUp() throws Exception {
4849
}
4950
}
5051

52+
@Before
53+
public void setUp() {
54+
// switch to J2EE to avoid new-project switch-perspective prompts
55+
bot.perspectiveById("org.eclipse.jst.j2ee.J2EEPerspective").activate();
56+
}
57+
5158
@After
5259
public void tearDown() {
5360
if (project != null) {

plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/project/ProjectUtils.java

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Collections;
3131
import java.util.Enumeration;
3232
import java.util.HashSet;
33+
import java.util.Iterator;
3334
import java.util.LinkedHashSet;
3435
import java.util.List;
3536
import java.util.Map;
@@ -38,12 +39,14 @@
3839
import java.util.concurrent.TimeUnit;
3940
import java.util.zip.ZipEntry;
4041
import java.util.zip.ZipFile;
42+
import org.eclipse.core.internal.jobs.InternalJob;
4143
import org.eclipse.core.resources.IMarker;
4244
import org.eclipse.core.resources.IProject;
4345
import org.eclipse.core.resources.IProjectDescription;
4446
import org.eclipse.core.resources.IResource;
4547
import org.eclipse.core.resources.IWorkspace;
4648
import org.eclipse.core.resources.IWorkspaceRoot;
49+
import org.eclipse.core.resources.IncrementalProjectBuilder;
4750
import org.eclipse.core.resources.ResourcesPlugin;
4851
import org.eclipse.core.runtime.CoreException;
4952
import org.eclipse.core.runtime.FileLocator;
@@ -266,14 +269,20 @@ public static void waitForProjects(Runnable delayTactic, IProject... projects) {
266269
Collection<Job> jobs = Collections.emptyList();
267270
Set<String> previousBuildErrors = Collections.emptySet();
268271
boolean buildErrorsChanging;
272+
for (IProject project : projects) {
273+
try {
274+
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
275+
} catch (Exception ex) {
276+
System.err.printf("ProjectUtils#waitForProjects[%s]: error building %s: %s\n", timer,
277+
project, ex);
278+
}
279+
}
269280
do {
270281
// wait a little bit to give the builders a chance
271282
delayTactic.run();
272283

273-
// wait for any previously-identified build jobs
274-
for (Job job : jobs) {
275-
job.join();
276-
}
284+
// NB: don't join jobs: see #1529
285+
// for details: https://github.com/GoogleCloudPlatform/google-cloud-eclipse/pull/1529
277286

278287
// identify any pending build-related jobs
279288
jobs = findPendingBuildJobs(projects);
@@ -293,20 +302,55 @@ public static void waitForProjects(Runnable delayTactic, IProject... projects) {
293302
timer, currentBuildErrors.size());
294303
}
295304
// Uncomment if tests are failing to identify any other build-related jobs.
296-
// Job[] otherJobs = Job.getJobManager().find(null);
297-
// if (otherJobs.length > 0) {
298-
// System.err.printf("Ignoring %d unrelated jobs:\n", otherJobs.length);
299-
// for (Job job : otherJobs) {
300-
// System.err.printf(" %s: %s\n", job.getClass().getName(), job);
301-
// }
302-
// }
305+
dumpJobsState();
303306
}
304307
} while (!jobs.isEmpty() || buildErrorsChanging);
305-
} catch (CoreException | InterruptedException ex) {
308+
} catch (CoreException ex) {
306309
throw new RuntimeException(ex);
307310
}
308311
}
309312

313+
private static void dumpJobsState() {
314+
Job[] otherJobs = Job.getJobManager().find(null);
315+
if (otherJobs.length == 0) {
316+
System.err.printf("ProjectUtils#dumpJobsState: no jobs\n");
317+
return;
318+
}
319+
320+
System.err.printf("ProjectUtils#dumpJobsState: %d jobs:\n", otherJobs.length);
321+
for (Job job : otherJobs) {
322+
String status;
323+
switch (job.getState()) {
324+
case Job.RUNNING:
325+
status = "RUNNING";
326+
break;
327+
case Job.WAITING:
328+
status = "WAITING";
329+
break;
330+
case Job.SLEEPING:
331+
status = "SLEEPING";
332+
break;
333+
case Job.NONE:
334+
status = "NONE";
335+
break;
336+
default:
337+
status = "UNKNOWN(" + job.getState() + ")";
338+
break;
339+
}
340+
Object blockingJob = null;
341+
try {
342+
blockingJob = ReflectionUtil.invoke(Job.getJobManager(), "findBlockingJob",
343+
new Class<?>[] {InternalJob.class}, InternalJob.class, job);
344+
} catch (Exception ex) {
345+
System.err.println("Unable to fetch blocking-job: " + ex);
346+
}
347+
System.err.printf(" %s[%d,%s%s%s%s]: %s%s\n", job.getClass().getName(), job.getPriority(),
348+
status, (job.isUser() ? ",user" : ""), (job.isSystem() ? ",system" : ""),
349+
(job.isBlocking() ? ",blocking" : ""), job,
350+
(blockingJob != null ? "; blocked by: " + blockingJob : ""));
351+
}
352+
}
353+
310354
/** Identify all jobs that we know of that are related to building. */
311355
private static Collection<Job> findPendingBuildJobs(IProject... projects) {
312356
Set<Job> jobs = new HashSet<>();
@@ -323,6 +367,13 @@ private static Collection<Job> findPendingBuildJobs(IProject... projects) {
323367
Collections.addAll(jobs, jobManager.find(
324368
project.getName() + ValidatorManager.VALIDATOR_JOB_FAMILY));
325369
}
370+
// remove sleeping jobs
371+
for (Iterator<Job> iter = jobs.iterator(); iter.hasNext();) {
372+
Job job = iter.next();
373+
if (job.getState() == Job.SLEEPING) {
374+
iter.remove();
375+
}
376+
}
326377
return jobs;
327378
}
328379

plugins/com.google.cloud.tools.eclipse.test.util/src/com/google/cloud/tools/eclipse/test/util/reflection/ReflectionUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public static <T> T invoke(Object object, String methodName, Class<T> returnType
4242
for (int i = 0; i < parameters.length; i++) {
4343
parameterTypes[i] = parameters[i] == null ? Object.class : parameters[i].getClass();
4444
}
45+
return invoke(object, methodName, parameterTypes, returnType, parameters);
46+
}
47+
48+
/** Invoke a method. */
49+
public static <T> T invoke(Object object, String methodName, Class<?>[] parameterTypes,
50+
Class<T> returnType, Object... parameters) throws NoSuchMethodException, SecurityException,
51+
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
4552
Method method = object.getClass().getDeclaredMethod(methodName, parameterTypes);
4653
method.setAccessible(true);
4754
return returnType.cast(method.invoke(object, parameters));

plugins/com.google.cloud.tools.eclipse.util/src/com/google/cloud/tools/eclipse/util/service/ServiceContextFactory.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

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

19+
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
1920
import org.eclipse.core.runtime.CoreException;
2021
import org.eclipse.core.runtime.IConfigurationElement;
2122
import org.eclipse.core.runtime.IExecutableExtension;
@@ -28,38 +29,42 @@
2829
import org.osgi.framework.BundleContext;
2930
import org.osgi.framework.FrameworkUtil;
3031

31-
import com.google.cloud.tools.eclipse.util.status.StatusUtil;
32-
3332
public class ServiceContextFactory implements IExecutableExtensionFactory, IExecutableExtension {
3433

3534
private Class<?> clazz;
35+
private IConfigurationElement configElement;
3636

3737
@Override
3838
public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
3939
throws CoreException {
40-
if (data == null || !(data instanceof String)) {
41-
throw new CoreException(StatusUtil.error(getClass(), "Data must be a class name"));
42-
}
43-
String className = (String) data;
44-
String bundleSymbolicName = config.getNamespaceIdentifier();
45-
Bundle bundle = Platform.getBundle(bundleSymbolicName);
46-
if (bundle == null) {
47-
throw new CoreException(StatusUtil.error(this, "Missing bundle " + bundleSymbolicName));
48-
}
49-
try {
50-
clazz = bundle.loadClass(className);
51-
} catch (ClassNotFoundException ex) {
52-
throw new CoreException(StatusUtil.error(this,
53-
"Could not load class " + className
54-
+ " from bundle " + bundle.getSymbolicName(),
55-
ex));
56-
}
40+
if (data == null || !(data instanceof String)) {
41+
throw new CoreException(StatusUtil.error(getClass(), "Data must be a class name"));
42+
}
43+
configElement = config;
44+
String className = (String) data;
45+
String bundleSymbolicName = config.getNamespaceIdentifier();
46+
Bundle bundle = Platform.getBundle(bundleSymbolicName);
47+
if (bundle == null) {
48+
throw new CoreException(StatusUtil.error(this, "Missing bundle " + bundleSymbolicName));
49+
}
50+
try {
51+
clazz = bundle.loadClass(className);
52+
} catch (ClassNotFoundException ex) {
53+
throw new CoreException(StatusUtil.error(this,
54+
"Could not load class " + className + " from bundle " + bundle.getSymbolicName(), ex));
55+
}
5756
}
5857

5958
@Override
6059
public Object create() throws CoreException {
6160
BundleContext bundleContext = FrameworkUtil.getBundle(clazz).getBundleContext();
6261
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext);
63-
return ContextInjectionFactory.make(clazz, serviceContext);
62+
IEclipseContext staticContext = EclipseContextFactory.create();
63+
staticContext.set(IConfigurationElement.class, configElement);
64+
try {
65+
return ContextInjectionFactory.make(clazz, serviceContext, staticContext);
66+
} finally {
67+
staticContext.dispose();
68+
}
6469
}
6570
}

0 commit comments

Comments
 (0)