Skip to content

Commit

Permalink
Fix compatibility with Eclipse 4.4
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fredg02 committed Aug 4, 2015
1 parent 10ca954 commit 0c846a2
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String, String>)wcSwt.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map<String, String>)null));
wc.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, wcSwt.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, false));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion com.windowtester.swt.runtime/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -65,40 +65,49 @@ public CTabItemReference[] call() throws Exception {
}
});
}

/**
* Returns "ViewMenu" ToolItemReference <br/>
* Works only with Eclipse 4.x!
*
* @return
*/
public ToolItemReference getViewMenu(){
return displayRef.execute(new Callable<ToolItemReference>() {
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 <br/>
* Works only with Eclipse 4.x!
*
* @return
*/
public ToolItemReference getViewMenu(){
return displayRef.execute(new Callable<ToolItemReference>() {
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)
// */
Expand Down
6 changes: 3 additions & 3 deletions com.windowtester_parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

<repositories>
<repository>
<id>juno</id>
<id>luna</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/juno</url>
<url>http://download.eclipse.org/releases/luna</url>
</repository>
</repositories>

Expand Down Expand Up @@ -133,7 +133,7 @@
<artifactId>tycho-packaging-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<format>'e4x'yyyyMMddHHmm</format>
<format>'e44x'yyyyMMddHHmm</format>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@
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;
import com.windowtester.test.eclipse.EclipseUtil;
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;
Expand Down Expand Up @@ -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));
}

////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 0c846a2

Please sign in to comment.