protected void initialize() throws ExecutionException { JavaParametersUtil.configureConfiguration(myJavaParameters, myConfiguration); myJavaParameters.setMainClass(JUnitConfiguration.JUNIT_START_CLASS); final Module module = myConfiguration.getConfigurationModule().getModule(); if (myJavaParameters.getJdk() == null) { myJavaParameters.setJdk( module != null ? ModuleRootManager.getInstance(module).getSdk() : ProjectRootManager.getInstance(myProject).getProjectSdk()); } myJavaParameters.getClassPath().add(JavaSdkUtil.getIdeaRtJarPath()); myJavaParameters.getClassPath().add(PathUtil.getJarPathForClass(JUnitStarter.class)); myJavaParameters .getProgramParametersList() .add(JUnitStarter.IDE_VERSION + JUnitStarter.VERSION); for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) { ext.updateJavaParameters(myConfiguration, myJavaParameters, getRunnerSettings()); } final Object[] listeners = Extensions.getExtensions(IDEAJUnitListener.EP_NAME); final StringBuilder buf = new StringBuilder(); for (final Object listener : listeners) { boolean enabled = true; for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) { if (ext.isListenerDisabled(myConfiguration, listener, getRunnerSettings())) { enabled = false; break; } } if (enabled) { final Class classListener = listener.getClass(); buf.append(classListener.getName()).append("\n"); myJavaParameters.getClassPath().add(PathUtil.getJarPathForClass(classListener)); } } if (buf.length() > 0) { try { myListenersFile = FileUtil.createTempFile("junit_listeners_", ""); myListenersFile.deleteOnExit(); myJavaParameters.getProgramParametersList().add("@@" + myListenersFile.getPath()); FileUtil.writeToFile(myListenersFile, buf.toString().getBytes()); } catch (IOException e) { LOG.error(e); } } }
protected void collectListeners( JavaParameters javaParameters, StringBuilder buf, String epName, String delimiter) { final T configuration = getConfiguration(); final Object[] listeners = Extensions.getExtensions(epName); for (final Object listener : listeners) { boolean enabled = true; for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) { if (ext.isListenerDisabled(configuration, listener, getRunnerSettings())) { enabled = false; break; } } if (enabled) { if (buf.length() > 0) buf.append(delimiter); final Class classListener = listener.getClass(); buf.append(classListener.getName()); javaParameters.getClassPath().add(PathUtil.getJarPathForClass(classListener)); } } }
@Override protected JavaParameters createJavaParameters() throws ExecutionException { final JavaParameters javaParameters = new JavaParameters(); final Module module = getConfiguration().getConfigurationModule().getModule(); Project project = getConfiguration().getProject(); Sdk jdk = module == null ? ProjectRootManager.getInstance(project).getProjectSdk() : ModuleRootManager.getInstance(module).getSdk(); javaParameters.setJdk(jdk); final Object[] patchers = Extensions.getExtensions(ExtensionPoints.JUNIT_PATCHER); for (Object patcher : patchers) { ((JUnitPatcher) patcher).patchJavaParameters(module, javaParameters); } // Append coverage parameters if appropriate for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) { ext.updateJavaParameters(getConfiguration(), javaParameters, getRunnerSettings()); } final String parameters = getConfiguration().getProgramParameters(); getConfiguration().setProgramParameters(null); try { JavaParametersUtil.configureConfiguration(javaParameters, getConfiguration()); } finally { getConfiguration().setProgramParameters(parameters); } javaParameters.getClassPath().addFirst(JavaSdkUtil.getIdeaRtJarPath()); configureClasspath(javaParameters); if (!StringUtil.isEmptyOrSpaces(parameters)) { javaParameters.getProgramParametersList().add("@name" + parameters); } return javaParameters; }
@Nullable public RefactoringElementListener getRefactoringElementListener(final PsiElement element) { if (data.TEST_OBJECT.equals(TestType.PACKAGE.getType())) { if (!(element instanceof PsiPackage)) return null; final RefactoringElementListener listener = RefactoringListeners.getListener((PsiPackage) element, myPackage); return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener); } else if (data.TEST_OBJECT.equals(TestType.CLASS.getType())) { if (!(element instanceof PsiClass) && !(element instanceof PsiPackage)) return null; final RefactoringElementListener listener = RefactoringListeners.getClassOrPackageListener(element, myClass); return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener); } else if (data.TEST_OBJECT.equals(TestType.METHOD.getType())) { if (!(element instanceof PsiMethod)) { final RefactoringElementListener listener = RefactoringListeners.getClassOrPackageListener(element, myClass); return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener); } final PsiMethod method = (PsiMethod) element; if (!method.getName().equals(data.getMethodName())) return null; if (!method.getContainingClass().equals(myClass.getPsiElement())) return null; class Listener extends RefactoringElementAdapter implements UndoRefactoringElementListener { public void elementRenamedOrMoved(@NotNull final PsiElement newElement) { data.setTestMethod(PsiLocation.fromPsiElement((PsiMethod) newElement)); } @Override public void undoElementMovedOrRenamed( @NotNull PsiElement newElement, @NotNull String oldQualifiedName) { final int methodIdx = oldQualifiedName.indexOf("#") + 1; if (methodIdx <= 0 || methodIdx >= oldQualifiedName.length()) return; data.METHOD_NAME = oldQualifiedName.substring(methodIdx); } } return RunConfigurationExtension.wrapRefactoringElementListener( element, this, new Listener()); } return null; }
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) { final RefactoringElementListener listener = myData.getTestObject(getProject(), this).getListener(element, this); return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener); }