From 0c846a2dff8e1d98645bd4ae4729249a5a6633ab Mon Sep 17 00:00:00 2001 From: Fred G Date: Tue, 4 Aug 2015 17:07:39 +0200 Subject: [PATCH] Fix compatibility with Eclipse 4.4 Replace BaseClassLoader with EquinoxClassLoader, fix ViewMenu recognition, fix dependency in com.windowtester.swt.runtime, fix method call after signature changed, fix AbstractRecorderSmokeTest.closeWelcomePageIfNecessary(), use Eclipse Luna repository --- .../RecorderSWTLaunchConfDelegate.java | 22 ++-- .../runtime/bundle/BundleResolver.java | 37 +++--- .../META-INF/MANIFEST.MF | 3 +- .../internal/widgets/CTabFolderReference.java | 107 ++++++++++-------- com.windowtester_parent/pom.xml | 6 +- .../codegen/AbstractRecorderSmokeTest.java | 50 ++++---- 6 files changed, 120 insertions(+), 105 deletions(-) diff --git a/com.windowtester.eclipse.ui/src/com/windowtester/eclipse/ui/launcher/RecorderSWTLaunchConfDelegate.java b/com.windowtester.eclipse.ui/src/com/windowtester/eclipse/ui/launcher/RecorderSWTLaunchConfDelegate.java index 9197000a..03c20f44 100644 --- a/com.windowtester.eclipse.ui/src/com/windowtester/eclipse/ui/launcher/RecorderSWTLaunchConfDelegate.java +++ b/com.windowtester.eclipse.ui/src/com/windowtester/eclipse/ui/launcher/RecorderSWTLaunchConfDelegate.java @@ -1,13 +1,13 @@ -/******************************************************************************* - * Copyright (c) 2012 Google, Inc. - * 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: - * Google, Inc. - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc. + * 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: + * Google, Inc. - initial API and implementation + *******************************************************************************/ package com.windowtester.eclipse.ui.launcher; import java.util.ArrayList; @@ -91,7 +91,7 @@ protected void mapSources(ILaunchConfigurationWorkingCopy wc) throws CoreExcepti * @throws CoreException */ private void setEnvironment(ILaunchConfigurationWorkingCopy wc) throws CoreException { - wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map)wcSwt.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map)null)); + wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map)wcSwt.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map)null)); wc.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, wcSwt.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, false)); } diff --git a/com.windowtester.runtime/src/com/windowtester/internal/runtime/bundle/BundleResolver.java b/com.windowtester.runtime/src/com/windowtester/internal/runtime/bundle/BundleResolver.java index 5392701b..66e1e8ba 100644 --- a/com.windowtester.runtime/src/com/windowtester/internal/runtime/bundle/BundleResolver.java +++ b/com.windowtester.runtime/src/com/windowtester/internal/runtime/bundle/BundleResolver.java @@ -1,17 +1,16 @@ -/******************************************************************************* - * Copyright (c) 2012 Google, Inc. - * 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: - * Google, Inc. - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc. + * 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: + * Google, Inc. - initial API and implementation + *******************************************************************************/ package com.windowtester.internal.runtime.bundle; -import org.eclipse.osgi.baseadaptor.BaseData; -import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader; +import org.eclipse.osgi.internal.loader.EquinoxClassLoader; import org.osgi.framework.Bundle; /** @@ -24,12 +23,18 @@ public class BundleResolver { * Get the bundle associated with this class. */ public static Bundle bundleForClass(Class cls) { + ClassLoader classLoader = cls.getClassLoader(); - if (classLoader instanceof BaseClassLoader) { - BaseClassLoader loader = (BaseClassLoader)classLoader; - BaseData baseData = loader.getClasspathManager().getBaseData(); - return baseData.getBundle(); + if (classLoader instanceof EquinoxClassLoader) { + EquinoxClassLoader loader = (EquinoxClassLoader) classLoader; + return loader.getBundle(); } + /* Does not work anymore in Eclipse 4.4.2 */ +// if (classLoader instanceof BaseClassLoader) { +// BaseClassLoader loader = (BaseClassLoader)classLoader; +// BaseData baseData = loader.getClasspathManager().getBaseData(); +// return baseData.getBundle(); +// } return null; } diff --git a/com.windowtester.swt.runtime/META-INF/MANIFEST.MF b/com.windowtester.swt.runtime/META-INF/MANIFEST.MF index 479460eb..9f491908 100644 --- a/com.windowtester.swt.runtime/META-INF/MANIFEST.MF +++ b/com.windowtester.swt.runtime/META-INF/MANIFEST.MF @@ -90,6 +90,7 @@ Require-Bundle: org.eclipse.swt, com.windowtester.runtime;visibility:=reexport, com.windowtester.swing.runtime, org.eclipse.e4.ui.model.workbench, - org.eclipse.e4.ui.workbench.renderers.swt + org.eclipse.e4.ui.workbench.renderers.swt, + org.eclipse.e4.ui.workbench Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/com.windowtester.swt.runtime/src/com/windowtester/runtime/swt/internal/widgets/CTabFolderReference.java b/com.windowtester.swt.runtime/src/com/windowtester/runtime/swt/internal/widgets/CTabFolderReference.java index 2ceefc44..69466b2d 100644 --- a/com.windowtester.swt.runtime/src/com/windowtester/runtime/swt/internal/widgets/CTabFolderReference.java +++ b/com.windowtester.swt.runtime/src/com/windowtester/runtime/swt/internal/widgets/CTabFolderReference.java @@ -1,24 +1,24 @@ -/******************************************************************************* - * Copyright (c) 2012 Google, Inc. - * 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: - * Google, Inc. - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc. + * 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: + * Google, Inc. - initial API and implementation + *******************************************************************************/ package com.windowtester.runtime.swt.internal.widgets; import java.util.concurrent.Callable; -import org.eclipse.e4.ui.model.application.ui.menu.MMenu; -import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer; +import org.eclipse.e4.ui.model.application.ui.menu.MMenu; +import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; /** * A {@link CTabFolder} reference. @@ -65,40 +65,49 @@ public CTabItemReference[] call() throws Exception { } }); } - - /** - * Returns "ViewMenu" ToolItemReference
- * Works only with Eclipse 4.x! - * - * @return - */ - public ToolItemReference getViewMenu(){ - return displayRef.execute(new Callable() { - public ToolItemReference call() throws Exception { - for(Control control : widget.getChildren()){ - if(control instanceof Composite){ - Composite comp = (Composite) control; - for(Control compChildren : comp.getChildren()){ - if(compChildren instanceof ToolBar){ - ToolBar compChildrenToolBar = (ToolBar) compChildren; - for(ToolItem compChildrenToolBarItem : compChildrenToolBar.getItems()){ - //TODO: Improve check (without internal classes?) - MMenu mmenu = (MMenu) compChildrenToolBarItem.getData("theMenu"); - if(mmenu != null && mmenu.getTags().contains(StackRenderer.TAG_VIEW_MENU)){ - //System.out.println("View Menu found!"); - return asReferenceOfType(compChildrenToolBarItem, ToolItemReference.class); - } - } - } - } - } - } - return null; - } - }); - - } - + + /** + * Returns "ViewMenu" ToolItemReference
+ * Works only with Eclipse 4.x! + * + * @return + */ + public ToolItemReference getViewMenu(){ + return displayRef.execute(new Callable() { + public ToolItemReference call() throws Exception { + for(Control control : widget.getChildren()){ + if(control instanceof Composite){ + Composite comp = (Composite) control; + for(Control compChildren : comp.getChildren()){ + //System.out.println("compChildren: " + compChildren.getClass().getSimpleName() + " " + compChildren.getData()); + if(compChildren instanceof ToolBar){ + ToolBar compChildrenToolBar = (ToolBar) compChildren; + //Works only with Eclipse 4.4 + if("ViewMenu".equals(compChildrenToolBar.getData())) { + ToolItem compChildrenToolBarItem = compChildrenToolBar.getItems()[0]; + return asReferenceOfType(compChildrenToolBarItem, ToolItemReference.class); + } + + //Works only with Eclipse 4.x - 4.3 + for(ToolItem compChildrenToolBarItem : compChildrenToolBar.getItems()){ + //System.out.println("compChildrenToolBarItem: " + compChildrenToolBarItem.getClass().getSimpleName() + " " + compChildrenToolBarItem.getData()); + //TODO: Improve check (without internal classes?) + MMenu mmenu = (MMenu) compChildrenToolBarItem.getData("theMenu"); + if(mmenu != null && mmenu.getTags().contains(StackRenderer.TAG_VIEW_MENU)){ + //System.out.println("View Menu found!"); + return asReferenceOfType(compChildrenToolBarItem, ToolItemReference.class); + } + } + } + } + } + } + return null; + } + }); + + } + // /* (non-Javadoc) // * @see com.windowtester.runtime.swt.internal.widgets.SWTWidgetReference#accept(com.windowtester.runtime.swt.internal.widgets.SWTWidgetReference.Visitor) // */ diff --git a/com.windowtester_parent/pom.xml b/com.windowtester_parent/pom.xml index cd869a81..5cfd6c04 100644 --- a/com.windowtester_parent/pom.xml +++ b/com.windowtester_parent/pom.xml @@ -26,9 +26,9 @@ - juno + luna p2 - http://download.eclipse.org/releases/juno + http://download.eclipse.org/releases/luna @@ -133,7 +133,7 @@ tycho-packaging-plugin ${tycho-version} - 'e4x'yyyyMMddHHmm + 'e44x'yyyyMMddHHmm diff --git a/com.windowtester_test/src/com/windowtester/test/eclipse/codegen/AbstractRecorderSmokeTest.java b/com.windowtester_test/src/com/windowtester/test/eclipse/codegen/AbstractRecorderSmokeTest.java index ac00bd4c..2ef3d2df 100644 --- a/com.windowtester_test/src/com/windowtester/test/eclipse/codegen/AbstractRecorderSmokeTest.java +++ b/com.windowtester_test/src/com/windowtester/test/eclipse/codegen/AbstractRecorderSmokeTest.java @@ -13,9 +13,7 @@ import org.osgi.framework.Bundle; import com.windowtester.recorder.event.ISemanticEvent; -import com.windowtester.runtime.WidgetSearchException; -import com.windowtester.runtime.locator.IWidgetLocator; -import com.windowtester.runtime.locator.XYLocator; +import com.windowtester.runtime.WaitTimedOutException; import com.windowtester.runtime.swt.UITestCaseSWT; import com.windowtester.runtime.swt.locator.CTabItemLocator; import com.windowtester.runtime.util.TestMonitor; @@ -23,16 +21,16 @@ import com.windowtester.test.util.PlatformEventWatcherAndCodegenerator; import com.windowtester.test.util.PlatformEventWatcherAndCodegenerator.API; -/******************************************************************************* - * Copyright (c) 2012 Google, Inc. - * 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: - * Google, Inc. - initial API and implementation - *******************************************************************************/ +/******************************************************************************* + * Copyright (c) 2012 Google, Inc. + * 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: + * Google, Inc. - initial API and implementation + *******************************************************************************/ public abstract class AbstractRecorderSmokeTest extends UITestCaseSWT { private static final boolean DISPLAY_EVENTS = true; @@ -175,19 +173,21 @@ private PlatformEventWatcherAndCodegenerator getWatcher() { /** * Recent versions of Eclipse do not close the welcome page when view * is opened. Make sure it gets closed. - * @throws WidgetSearchException + * @throws Exception + * @throws WaitTimedOutException */ - protected void closeWelcomePageIfNecessary() throws WidgetSearchException { - IWidgetLocator[] welcomeTab = getUI().findAll(new CTabItemLocator("Welcome")); - if (welcomeTab.length == 0) - return; - // TODO: compute x based on tab width to avoid font dependencies - int x = 88; - if (abbot.Platform.isOSX()) - x = 95; - else if (abbot.Platform.isLinux()) - x = 100; - getUI().click(new XYLocator(welcomeTab[0], x, 12)); + protected void closeWelcomePageIfNecessary() throws WaitTimedOutException, Exception { + getUI().ensureThat(new CTabItemLocator("Welcome").isClosed()); +// IWidgetLocator[] welcomeTab = getUI().findAll(new CTabItemLocator("Welcome")); +// if (welcomeTab.length == 0) +// return; +// // TODO: compute x based on tab width to avoid font dependencies +// int x = 88; +// if (abbot.Platform.isOSX()) +// x = 95; +// else if (abbot.Platform.isLinux()) +// x = 100; +// getUI().click(new XYLocator(welcomeTab[0], x, 12)); } ////////////////////////////////////////////////////////////////////////////////////////