From e6941b799bae633b8b21765559bce06a643a7e99 Mon Sep 17 00:00:00 2001 From: Sergey Karashevich Date: Fri, 7 Oct 2016 13:11:43 +0300 Subject: [PATCH] gui-tests-framework: run test for different IDE with the different classpath --- .../gui/fixtures/FrameworksTreeFixture.java | 2 - .../framework/GuiTestRunner.java | 10 +- .../framework/GuiTestUtil.java | 2 +- .../framework/IdeTestApplication.java | 210 ++++++++++++++- .../framework/TestWithIde.java | 32 --- .../testGuiFramework/impl/GuiTestCase.java | 2 - .../testGuiFramework/impl/IdeaGuiTestApp.java | 243 ------------------ .../testGuiFramework/testGuiFramework.iml | 4 +- .../tests/JavaEEProjectTest.java | 110 -------- 9 files changed, 208 insertions(+), 407 deletions(-) delete mode 100644 platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/TestWithIde.java delete mode 100644 platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/IdeaGuiTestApp.java delete mode 100644 platform/testGuiFramework/testSrc/com/intellij/testGuiFramework/tests/JavaEEProjectTest.java diff --git a/community-tests/src/com/intellij/tests/gui/fixtures/FrameworksTreeFixture.java b/community-tests/src/com/intellij/tests/gui/fixtures/FrameworksTreeFixture.java index 725a725c50b3..2ae9289086ac 100644 --- a/community-tests/src/com/intellij/tests/gui/fixtures/FrameworksTreeFixture.java +++ b/community-tests/src/com/intellij/tests/gui/fixtures/FrameworksTreeFixture.java @@ -26,7 +26,6 @@ import org.fest.swing.edt.GuiActionRunner; import org.fest.swing.edt.GuiTask; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.junit.Assert; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -80,7 +79,6 @@ public class FrameworksTreeFixture { return this; } } - Assert.fail(); return this; } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestRunner.java b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestRunner.java index 5c932c25e380..9d6a9574faeb 100755 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestRunner.java +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestRunner.java @@ -49,18 +49,11 @@ public class GuiTestRunner extends BlockJUnit4ClassRunner { private final List myGarbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); private final MemoryMXBean myMemoryMXBean = ManagementFactory.getMemoryMXBean(); - private Class myIdeTestApplicationClass; @Nullable private final ScreenshotTaker myScreenshotTaker; public GuiTestRunner(Class testClass) throws InitializationError { super(testClass); - - Class guiTestCaseClass = testClass.getSuperclass(); - //check test extends GuiTestBase - guiTestCaseClass.isInstance(GuiTestBase.class); - myIdeTestApplicationClass = guiTestCaseClass.getAnnotation(TestWithIde.class).value(); - myScreenshotTaker = canRunGuiTests() ? new ScreenshotTaker() : null; } @@ -144,8 +137,7 @@ public class GuiTestRunner extends BlockJUnit4ClassRunner { } private void loadClassesWithIdeClassLoader() throws Exception { - IdeTestApplication ideTestApplication = (IdeTestApplication) myIdeTestApplicationClass.getMethod("getInstance").invoke(null); - ClassLoader ideClassLoader = ideTestApplication.getIdeClassLoader(); + ClassLoader ideClassLoader = IdeTestApplication.getInstance().getIdeClassLoader(); Thread.currentThread().setContextClassLoader(ideClassLoader); Class testClass = getTestClass().getJavaClass(); diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestUtil.java b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestUtil.java index d33e096b545e..81dd2ff0d83b 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestUtil.java +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/GuiTestUtil.java @@ -313,7 +313,7 @@ public final class GuiTestUtil { } }).withTimeout(LONG_TIMEOUT.duration()).using(robot); - //TODO: clarify here what the hell is going on? + //TODO: clarify why we are skipping event here? // We know the IDE event queue was pushed in front of the AWT queue. Some JDKs will leave a dummy event in the AWT queue, which // we attempt to clear here. All other events, including those posted by the Robot, will go through the IDE event queue. //try { diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/IdeTestApplication.java b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/IdeTestApplication.java index 64eeb0cb2449..9a148541cf27 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/IdeTestApplication.java +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/IdeTestApplication.java @@ -15,21 +15,47 @@ */ package com.intellij.testGuiFramework.framework; +import com.intellij.ide.BootstrapClassLoaderUtil; +import com.intellij.ide.IdeEventQueue; +import com.intellij.ide.WindowsCommandLineProcessor; +import com.intellij.ide.startup.StartupActionScriptManager; +import com.intellij.idea.Main; +import com.intellij.openapi.application.Application; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.application.impl.ApplicationImpl; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.util.SystemProperties; +import com.intellij.util.lang.UrlClassLoader; +import com.intellij.util.text.StringTokenizer; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.*; +import java.util.regex.Pattern; -import static com.intellij.openapi.util.io.FileUtil.ensureExists; -import static com.intellij.openapi.util.io.FileUtil.toSystemDependentName; +import static com.intellij.openapi.application.PathManager.PROPERTY_CONFIG_PATH; +import static com.intellij.openapi.util.io.FileUtil.*; import static com.intellij.openapi.util.text.StringUtil.isNotEmpty; +import static com.intellij.testGuiFramework.framework.GuiTestUtil.getProjectCreationDirPath; +import static com.intellij.util.ArrayUtil.EMPTY_STRING_ARRAY; +import static com.intellij.util.ui.UIUtil.initDefaultLAF; import static org.fest.assertions.Assertions.assertThat; +import static org.fest.reflect.core.Reflection.method; +import static org.junit.Assert.assertNotNull; -/** - * @author Sergey Karashevich - */ -public abstract class IdeTestApplication { +public class IdeTestApplication { + + private static final Logger LOG = Logger.getInstance(IdeTestApplication.class); + private static final String PROPERTY_IGNORE_CLASSPATH = "ignore.classpath"; + private static final String PROPERTY_ALLOW_BOOTSTRAP_RESOURCES = "idea.allow.bootstrap.resources"; + private static final String PROPERTY_ADDITIONAL_CLASSPATH = "idea.additional.classpath"; + + private static IdeTestApplication ourInstance; protected ClassLoader myIdeClassLoader; @@ -62,4 +88,176 @@ public abstract class IdeTestApplication { } + @NotNull + public static synchronized IdeTestApplication getInstance() throws Exception { + File configDirPath = getConfigDirPath(); + System.setProperty(PROPERTY_CONFIG_PATH, configDirPath.getPath()); + + //Force Swing FileChooser on Mac (instead of native one) to be able to use FEST to drive it. + System.setProperty("native.mac.file.chooser.enabled", "false"); + + //We are using this property to skip testProjectLeak in _LastSuiteTests + System.setProperty("idea.test.guimode", "true"); + + if (!isLoaded()) { + ourInstance = new IdeTestApplication(); + recreateDirectory(configDirPath); + + File newProjectsRootDirPath = getProjectCreationDirPath(); + recreateDirectory(newProjectsRootDirPath); + + ClassLoader ideClassLoader = ourInstance.getIdeClassLoader(); + Class clazz = ideClassLoader.loadClass(GuiTestUtil.class.getCanonicalName()); + method("waitForIdeToStart").in(clazz).invoke(); + method("setUpDefaultGeneralSettings").in(clazz).invoke(); + } + + return ourInstance; + } + + @NotNull + private static File getConfigDirPath() throws IOException { + File dirPath = new File(getGuiTestRootDirPath(), "config"); + ensureExists(dirPath); + return dirPath; + } + + private static void recreateDirectory(@NotNull File path) throws IOException { + delete(path); + ensureExists(path); + } + + private IdeTestApplication() throws Exception { + String[] args = EMPTY_STRING_ARRAY; + + LOG.assertTrue(ourInstance == null, "Only one instance allowed."); + ourInstance = this; + + pluginManagerStart(args); + mainMain(); + + myIdeClassLoader = createClassLoader(); + + WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, myIdeClassLoader); + + Class classUtilCoreClass = Class.forName("com.intellij.ide.ClassUtilCore", true, myIdeClassLoader); + method("clearJarURLCache").in(classUtilCoreClass).invoke(); + + Class pluginManagerClass = Class.forName("com.intellij.ide.plugins.PluginManager", true, myIdeClassLoader); + method("start").withParameterTypes(String.class, String.class, String[].class) + .in(pluginManagerClass) + .invoke("com.intellij.idea.MainImpl", "start", args); + } + + // This method replaces BootstrapClassLoaderUtil.initClassLoader. The reason behind it is that when running UI tests the ClassLoader + // containing the URLs for the plugin jars is loaded by a different ClassLoader and it gets ignored. The result is test failing because + // classes like AndroidPlugin cannot be found. + @NotNull + private static ClassLoader createClassLoader() throws MalformedURLException, URISyntaxException { + Collection classpath = new LinkedHashSet<>(); + addIdeaLibraries(classpath); + addAdditionalClassPath(classpath); + + UrlClassLoader.Builder builder = UrlClassLoader.build() + .urls(filterClassPath(new ArrayList<>(classpath))) + .parent(IdeTestApplication.class.getClassLoader()) + .allowLock(false) + .usePersistentClasspathIndexForLocalClassDirectories(); + if (SystemProperties.getBooleanProperty(PROPERTY_ALLOW_BOOTSTRAP_RESOURCES, true)) { + builder.allowBootstrapResources(); + } + + UrlClassLoader newClassLoader = builder.get(); + + // prepare plugins + try { + StartupActionScriptManager.executeActionScript(); + } + catch (IOException e) { + Main.showMessage("Plugin Installation Error", e); + } + + Thread.currentThread().setContextClassLoader(newClassLoader); + return newClassLoader; + } + + private static void addIdeaLibraries(@NotNull Collection classpath) throws MalformedURLException { + Class aClass = BootstrapClassLoaderUtil.class; + String selfRoot = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class"); + assertNotNull(selfRoot); + + URL selfRootUrl = new File(selfRoot).getAbsoluteFile().toURI().toURL(); + classpath.add(selfRootUrl); + + File libFolder = new File(PathManager.getLibPath()); + addLibraries(classpath, libFolder, selfRootUrl); + addLibraries(classpath, new File(libFolder, "ext"), selfRootUrl); + addLibraries(classpath, new File(libFolder, "ant/lib"), selfRootUrl); + } + + private static void addLibraries(@NotNull Collection classPath, @NotNull File fromDir, @NotNull URL selfRootUrl) + throws MalformedURLException { + for (File file : notNullize(fromDir.listFiles())) { + if (isJarOrZip(file)) { + URL url = file.toURI().toURL(); + if (!selfRootUrl.equals(url)) { + classPath.add(url); + } + } + } + } + + private static void addAdditionalClassPath(@NotNull Collection classpath) throws MalformedURLException { + StringTokenizer tokenizer = new StringTokenizer(System.getProperty(PROPERTY_ADDITIONAL_CLASSPATH, ""), File.pathSeparator, false); + while (tokenizer.hasMoreTokens()) { + String pathItem = tokenizer.nextToken(); + classpath.add(new File(pathItem).toURI().toURL()); + } + } + + private static List filterClassPath(@NotNull List classpath) { + String ignoreProperty = System.getProperty(PROPERTY_IGNORE_CLASSPATH); + if (ignoreProperty != null) { + Pattern pattern = Pattern.compile(ignoreProperty); + for (Iterator i = classpath.iterator(); i.hasNext(); ) { + String url = i.next().toExternalForm(); + if (pattern.matcher(url).matches()) { + i.remove(); + } + } + } + return classpath; + } + + private static void pluginManagerStart(@NotNull String[] args) { + // Duplicates what PluginManager#start does. + Main.setFlags(args); + initDefaultLAF(); + } + + private static void mainMain() { + // Duplicates what Main#main does. + method("installPatch").in(Main.class).invoke(); + } + + public void dispose() { + disposeInstance(); + } + + public static synchronized void disposeInstance() { + if (!isLoaded()) { + return; + } + + IdeEventQueue.getInstance().flushQueue(); + final Application application = ApplicationManager.getApplication(); + ((ApplicationImpl)application).exit(true, true, false, false); + + ourInstance = null; + } + + public static synchronized boolean isLoaded() { + return ourInstance != null; + } + } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/TestWithIde.java b/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/TestWithIde.java deleted file mode 100644 index 0abb6c2f87b3..000000000000 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/framework/TestWithIde.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.testGuiFramework.framework; - -import java.lang.annotation.*; - -/** - * @author Sergey Karashevich - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Inherited -public @interface TestWithIde { - /** - * @return a IdeTestApplication class (must have a getInstance() method that runs apropriate IDE) - */ - Class value(); -} \ No newline at end of file diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.java b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.java index 0cf6daa7c50b..43691a032a34 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.java +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/GuiTestCase.java @@ -17,7 +17,6 @@ package com.intellij.testGuiFramework.impl; import com.intellij.testFramework.vcs.ExecutableHelper; import com.intellij.testGuiFramework.framework.GuiTestBase; -import com.intellij.testGuiFramework.framework.TestWithIde; import com.intellij.util.net.HttpConfigurable; import git4idea.config.GitVcsApplicationSettings; import org.fest.swing.core.FastRobot; @@ -28,7 +27,6 @@ import static com.intellij.testGuiFramework.framework.GuiTestUtil.setUpSdks; /** * @author Sergey Karashevich */ -@TestWithIde(IdeaGuiTestApp.class) public class GuiTestCase extends GuiTestBase { public GuiTestCase() { diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/IdeaGuiTestApp.java b/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/IdeaGuiTestApp.java deleted file mode 100644 index 284aa4c601e3..000000000000 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/impl/IdeaGuiTestApp.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.testGuiFramework.impl; - -import com.intellij.ide.BootstrapClassLoaderUtil; -import com.intellij.ide.IdeEventQueue; -import com.intellij.ide.WindowsCommandLineProcessor; -import com.intellij.ide.startup.StartupActionScriptManager; -import com.intellij.idea.Main; -import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.PathManager; -import com.intellij.openapi.application.impl.ApplicationImpl; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.testGuiFramework.framework.GuiTestUtil; -import com.intellij.testGuiFramework.framework.IdeTestApplication; -import com.intellij.util.SystemProperties; -import com.intellij.util.lang.UrlClassLoader; -import com.intellij.util.text.StringTokenizer; -import org.jetbrains.annotations.NotNull; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.*; -import java.util.regex.Pattern; - -import static com.intellij.openapi.application.PathManager.PROPERTY_CONFIG_PATH; -import static com.intellij.openapi.util.io.FileUtil.*; -import static com.intellij.testGuiFramework.framework.GuiTestUtil.getProjectCreationDirPath; -import static com.intellij.util.ArrayUtil.EMPTY_STRING_ARRAY; -import static com.intellij.util.ui.UIUtil.initDefaultLAF; -import static org.fest.reflect.core.Reflection.method; -import static org.junit.Assert.assertNotNull; - -public class IdeaGuiTestApp extends IdeTestApplication implements Disposable { - private static final Logger LOG = Logger.getInstance(IdeTestApplication.class); - private static final String PROPERTY_IGNORE_CLASSPATH = "ignore.classpath"; - private static final String PROPERTY_ALLOW_BOOTSTRAP_RESOURCES = "idea.allow.bootstrap.resources"; - private static final String PROPERTY_ADDITIONAL_CLASSPATH = "idea.additional.classpath"; - - private static IdeTestApplication ourInstance; - - @NotNull - public static synchronized IdeTestApplication getInstance() throws Exception { - File configDirPath = getConfigDirPath(); - System.setProperty(PROPERTY_CONFIG_PATH, configDirPath.getPath()); - - //Force Swing FileChooser on Mac (instead of native one) to be able to use FEST to drive it. - System.setProperty("native.mac.file.chooser.enabled", "false"); - - //We are using this property to skip testProjectLeak in _LastSuiteTests - System.setProperty("idea.test.guimode", "true"); - - if (!isLoaded()) { - ourInstance = new IdeaGuiTestApp(); - recreateDirectory(configDirPath); - - File newProjectsRootDirPath = getProjectCreationDirPath(); - recreateDirectory(newProjectsRootDirPath); - - ClassLoader ideClassLoader = ourInstance.getIdeClassLoader(); - Class clazz = ideClassLoader.loadClass(GuiTestUtil.class.getCanonicalName()); - method("waitForIdeToStart").in(clazz).invoke(); - method("setUpDefaultGeneralSettings").in(clazz).invoke(); - } - - return ourInstance; - } - - @NotNull - private static File getConfigDirPath() throws IOException { - File dirPath = new File(getGuiTestRootDirPath(), "config"); - ensureExists(dirPath); - return dirPath; - } - - private static void recreateDirectory(@NotNull File path) throws IOException { - delete(path); - ensureExists(path); - } - - private IdeaGuiTestApp() throws Exception { - String[] args = EMPTY_STRING_ARRAY; - - LOG.assertTrue(ourInstance == null, "Only one instance allowed."); - ourInstance = this; - - pluginManagerStart(args); - mainMain(); - - myIdeClassLoader = createClassLoader(); - //myIdeClassLoader = BootstrapClassLoaderUtil.initClassLoader(false); - - - WindowsCommandLineProcessor.ourMirrorClass = Class.forName(WindowsCommandLineProcessor.class.getName(), true, myIdeClassLoader); - - // We turn on "GUI Testing Mode" right away, even before loading the IDE. - //Class androidPluginClass = Class.forName("org.jetbrains.android.AndroidPlugin", true, myIdeClassLoader); - //method("setGuiTestingMode").withParameterTypes(boolean.class).in(androidPluginClass).invoke(true); - - Class classUtilCoreClass = Class.forName("com.intellij.ide.ClassUtilCore", true, myIdeClassLoader); - method("clearJarURLCache").in(classUtilCoreClass).invoke(); - - Class pluginManagerClass = Class.forName("com.intellij.ide.plugins.PluginManager", true, myIdeClassLoader); - method("start").withParameterTypes(String.class, String.class, String[].class) - .in(pluginManagerClass) - .invoke("com.intellij.idea.MainImpl", "start", args); - } - - // This method replaces BootstrapClassLoaderUtil.initClassLoader. The reason behind it is that when running UI tests the ClassLoader - // containing the URLs for the plugin jars is loaded by a different ClassLoader and it gets ignored. The result is test failing because - // classes like AndroidPlugin cannot be found. - @NotNull - private static ClassLoader createClassLoader() throws MalformedURLException, URISyntaxException { - Collection classpath = new LinkedHashSet<>(); - addIdeaLibraries(classpath); - addAdditionalClassPath(classpath); - - UrlClassLoader.Builder builder = UrlClassLoader.build() - .urls(filterClassPath(new ArrayList<>(classpath))) - .parent(IdeTestApplication.class.getClassLoader()) - .allowLock(false) - .usePersistentClasspathIndexForLocalClassDirectories(); - if (SystemProperties.getBooleanProperty(PROPERTY_ALLOW_BOOTSTRAP_RESOURCES, true)) { - builder.allowBootstrapResources(); - } - - UrlClassLoader newClassLoader = builder.get(); - - // prepare plugins - try { - StartupActionScriptManager.executeActionScript(); - } - catch (IOException e) { - Main.showMessage("Plugin Installation Error", e); - } - - Thread.currentThread().setContextClassLoader(newClassLoader); - return newClassLoader; - } - - private static void addIdeaLibraries(@NotNull Collection classpath) throws MalformedURLException { - Class aClass = BootstrapClassLoaderUtil.class; - String selfRoot = PathManager.getResourceRoot(aClass, "/" + aClass.getName().replace('.', '/') + ".class"); - assertNotNull(selfRoot); - - URL selfRootUrl = new File(selfRoot).getAbsoluteFile().toURI().toURL(); - classpath.add(selfRootUrl); - - File libFolder = new File(PathManager.getLibPath()); - addLibraries(classpath, libFolder, selfRootUrl); - addLibraries(classpath, new File(libFolder, "ext"), selfRootUrl); - addLibraries(classpath, new File(libFolder, "ant/lib"), selfRootUrl); - } - - private static void addLibraries(@NotNull Collection classPath, @NotNull File fromDir, @NotNull URL selfRootUrl) - throws MalformedURLException { - for (File file : notNullize(fromDir.listFiles())) { - if (isJarOrZip(file)) { - URL url = file.toURI().toURL(); - if (!selfRootUrl.equals(url)) { - classPath.add(url); - } - } - } - } - - private static void addAdditionalClassPath(@NotNull Collection classpath) throws MalformedURLException { - StringTokenizer tokenizer = new StringTokenizer(System.getProperty(PROPERTY_ADDITIONAL_CLASSPATH, ""), File.pathSeparator, false); - while (tokenizer.hasMoreTokens()) { - String pathItem = tokenizer.nextToken(); - classpath.add(new File(pathItem).toURI().toURL()); - } - } - - private static List filterClassPath(@NotNull List classpath) { - String ignoreProperty = System.getProperty(PROPERTY_IGNORE_CLASSPATH); - if (ignoreProperty != null) { - Pattern pattern = Pattern.compile(ignoreProperty); - for (Iterator i = classpath.iterator(); i.hasNext(); ) { - String url = i.next().toExternalForm(); - if (pattern.matcher(url).matches()) { - i.remove(); - } - } - } - return classpath; - } - - private static void pluginManagerStart(@NotNull String[] args) { - // Duplicates what PluginManager#start does. - Main.setFlags(args); - initDefaultLAF(); - } - - private static void mainMain() { - // Duplicates what Main#main does. - method("installPatch").in(Main.class).invoke(); - } - - @NotNull - public ClassLoader getIdeClassLoader() { - return myIdeClassLoader; - } - - @Override - public void dispose() { - disposeInstance(); - } - - public static synchronized void disposeInstance() { - if (!isLoaded()) { - return; - } - - IdeEventQueue.getInstance().flushQueue(); - final Application application = ApplicationManager.getApplication(); - ((ApplicationImpl)application).exit(true, true, false, false); - - ourInstance = null; - } - - public static synchronized boolean isLoaded() { - return ourInstance != null; - } -} diff --git a/platform/testGuiFramework/testGuiFramework.iml b/platform/testGuiFramework/testGuiFramework.iml index 9dfed1885fac..21ecfdc1302d 100644 --- a/platform/testGuiFramework/testGuiFramework.iml +++ b/platform/testGuiFramework/testGuiFramework.iml @@ -9,7 +9,7 @@ - + @@ -20,7 +20,6 @@ - @@ -34,5 +33,6 @@ + \ No newline at end of file diff --git a/platform/testGuiFramework/testSrc/com/intellij/testGuiFramework/tests/JavaEEProjectTest.java b/platform/testGuiFramework/testSrc/com/intellij/testGuiFramework/tests/JavaEEProjectTest.java deleted file mode 100644 index 7551176f4b26..000000000000 --- a/platform/testGuiFramework/testSrc/com/intellij/testGuiFramework/tests/JavaEEProjectTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.testGuiFramework.tests; - -import com.intellij.openapi.application.ApplicationBundle; -import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.project.ProjectBundle; -import com.intellij.testGuiFramework.fixtures.ProjectViewFixture; -import com.intellij.testGuiFramework.fixtures.ToolWindowFixture; -import com.intellij.testGuiFramework.fixtures.WelcomeFrameFixture; -import com.intellij.testGuiFramework.fixtures.newProjectWizard.NewProjectWizardFixture; -import com.intellij.testGuiFramework.framework.GuiTestUtil; -import com.intellij.testGuiFramework.impl.GuiTestCase; -import org.junit.Test; - -import javax.swing.*; -import java.io.File; -import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static com.intellij.testGuiFramework.framework.GuiTestUtil.getSystemJdk; - -/** - * @author Sergey Karashevich - */ -public class JavaEEProjectTest extends GuiTestCase { - - @Test - public void testJavaEEProject() throws IOException, InterruptedException { - - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm"); - Date date = new Date(); - String projectName = "smoke-test-project-" + dateFormat.format(date); - - WelcomeFrameFixture welcomeFrame = findWelcomeFrame(); - welcomeFrame.createNewProject(); - NewProjectWizardFixture newProjectWizard = findNewProjectWizard(); - - setupJdk(newProjectWizard); - - //select project type and framework - newProjectWizard. - selectProjectType("Java"). - selectFramework("JavaEE Persistence"); - newProjectWizard.clickNext(); - newProjectWizard.setProjectName(projectName); - final File locationInFileSystem = newProjectWizard.getLocationInFileSystem(); - newProjectWizard.clickFinish(); - - myProjectFrame = findIdeFrame(projectName, locationInFileSystem); - myProjectFrame.waitForBackgroundTasksToFinish(); - - final ProjectViewFixture projectView = myProjectFrame.getProjectView(); - final ProjectViewFixture.PaneFixture paneFixture = projectView.selectProjectPane(); - - paneFixture.selectByPath(projectName, "src", "META-INF", "persistence.xml"); - ToolWindowFixture.showToolwindowStripes(myRobot); - - //prevent from ProjectLeak (if the project is closed during the indexing - DumbService.getInstance(myProjectFrame.getProject()).waitForSmartMode(); - - //final JToggleButtonFixture persistence = (new JToggleButtonFinder("Persistence")).withTimeout(THIRTY_SEC_TIMEOUT.duration()).using(myRobot); - //persistence.click(); - - //ToolWindowFixture.clickToolwindowButton("Persistence", myRobot); - //ToolWindowFixture.clickToolwindowButton("Java Enterprise", myRobot); - } - - private void setupJdk(NewProjectWizardFixture newProjectWizard) { - if (newProjectWizard.isJdkEmpty()) { - JButton newButton = GuiTestUtil.findButton(newProjectWizard, - GuiTestUtil.adduction(ApplicationBundle.message("button.new")), - myRobot); - myRobot.click(newButton); - File javaSdkPath = new File(getSystemJdk()); - String sdkType = GuiTestUtil.adduction(ProjectBundle.message("sdk.java.name")); - GuiTestUtil.clickPopupMenuItem(sdkType, newButton, myRobot); - newProjectWizard.selectSdkPath(javaSdkPath, sdkType); - } - } - - private void setupJdk(NewProjectWizardFixture newProjectWizard, String customPath){ - if (newProjectWizard.isJdkEmpty()) { - JButton newButton = GuiTestUtil.findButton(newProjectWizard, - GuiTestUtil.adduction(ApplicationBundle.message("button.new")), - myRobot); - myRobot.click(newButton); - File javaSdkPath = new File(customPath); - String sdkType = GuiTestUtil.adduction(ProjectBundle.message("sdk.java.name")); - GuiTestUtil.clickPopupMenuItem(sdkType, newButton, myRobot); - newProjectWizard.selectSdkPath(javaSdkPath, sdkType); - } - } - -}