package jetbrains.mps.baseLanguage.unitTest.execution.client;
/*Generated by MPS */
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.smodel.behaviour.BHReflection;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.core.aspects.behaviour.SMethodTrimmedId;
import org.jetbrains.annotations.NotNull;
import jetbrains.mps.internal.collections.runtime.Sequence;
import java.util.Collections;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.List;
import jetbrains.mps.internal.collections.runtime.ISelector;
import jetbrains.mps.smodel.ModelAccessHelper;
import jetbrains.mps.util.Computable;
import java.util.Set;
import com.intellij.openapi.application.PathMacros;
import jetbrains.mps.execution.configurations.implementation.plugin.plugin.JvmArgs;
import jetbrains.mps.internal.collections.runtime.SetSequence;
import jetbrains.mps.baseLanguage.unitTest.execution.server.CachingTestExecutor;
import java.util.ArrayList;
import com.intellij.openapi.application.PathManager;
import java.io.File;
import com.intellij.util.lang.UrlClassLoader;
import java.net.URL;
import java.net.URI;
import org.jetbrains.mps.openapi.module.SModuleReference;
import org.jetbrains.mps.openapi.module.SModule;
import jetbrains.mps.project.facets.JavaModuleFacet;
import org.jetbrains.annotations.NonNls;
public class LanguageTestWrapper extends AbstractTestWrapper<SNode> {
public LanguageTestWrapper(SNode test) {
super(test);
}
@Override
public boolean isTestCase() {
return check_9og6tg_a0a2(getNode(), this);
}
private boolean isTestMethod() {
return check_9og6tg_a0a4(getNode(), this);
}
@Nullable
@Override
public ITestNodeWrapper getTestCase() {
if (check_9og6tg_a0a6(getNode(), this)) {
return TestNodeWrapperFactory.tryToWrap(((SNode) BHReflection.invoke(SNodeOperations.cast(getNode(), MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b27438a3dL, "jetbrains.mps.baseLanguage.unitTest.structure.ITestMethod")), SMethodTrimmedId.create("getTestCase", null, "hGBgWVd"))));
}
if (isTestCase()) {
return null;
}
return null;
}
@NotNull
@Override
public Iterable<ITestNodeWrapper> getTestMethods() {
if (!(isTestCase())) {
return super.getTestMethods();
}
SNode node = getNode();
if (node == null) {
return Sequence.fromIterable(Collections.<ITestNodeWrapper>emptyList());
}
return ListSequence.fromList(((List<SNode>) BHReflection.invoke(SNodeOperations.cast(node, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b2709bd56L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase")), SMethodTrimmedId.create("getTestMethods", null, "1RfJDyhAUar")))).select(new ISelector<SNode, ITestNodeWrapper>() {
public ITestNodeWrapper select(SNode it) {
return TestNodeWrapperFactory.tryToWrap(it);
}
});
}
@Override
@NotNull
public TestParameters getTestRunParameters() {
final SNode node = getNode();
return new ModelAccessHelper(getRepo()).runReadAction(new Computable<TestParameters>() {
public TestParameters compute() {
if (node != null && ((boolean) (Boolean) BHReflection.invoke(node, SMethodTrimmedId.create("isMpsStartRequired", null, "2RMg39tmiFh")))) {
Set<String> userMacroNames = PathMacros.getInstance().getUserMacroNames();
List<String> jvmArgsWithMacros = ListSequence.fromList(JvmArgs.getDefaultJvmArgs()).union(SetSequence.fromSet(userMacroNames).select(new ISelector<String, String>() {
public String select(String key) {
return String.format("-Dpath.macro.%s=\"%s\"", key, jetbrains.mps.project.PathMacros.getInstance().getValue(key));
}
})).toListSequence();
List<String> classPath = getIdeaClasspath();
return new TestParameters(CachingTestExecutor.class, ListSequence.fromList(classPath).union(ListSequence.fromList(LanguageTestWrapper.super.getTestRunParameters().getClassPath())).toListSequence(), jvmArgsWithMacros);
} else {
return LanguageTestWrapper.super.getTestRunParameters();
}
}
});
}
private List<String> getPluginClasspath() {
List<String> path = ListSequence.fromList(new ArrayList<String>());
String pluginsPath = PathManager.getPreInstalledPluginsPath();
File pluginsDir = new File(pluginsPath);
for (File pluginDirFile : pluginsDir.listFiles()) {
if (pluginDirFile.isDirectory()) {
// adding classes dir
File classesDir = new File(pluginDirFile, "classes");
if (classesDir.exists()) {
ListSequence.fromList(path).addElement(classesDir.getAbsolutePath());
}
// adding contents of lib dir
File libDir = new File(pluginDirFile, "lib");
if (libDir.exists()) {
for (File libChild : libDir.listFiles()) {
if (libChild.isFile()) {
String name = libChild.getName();
if (name.toLowerCase().endsWith(".jar") || name.toLowerCase().endsWith(".zip")) {
ListSequence.fromList(path).addElement(libChild.getAbsolutePath());
}
} else {
ListSequence.fromList(path).addElement(libChild.getAbsolutePath());
}
}
}
} else {
ListSequence.fromList(path).addElement(pluginDirFile.getAbsolutePath());
}
}
return path;
}
private List<String> getIdeaClasspath() {
final List<String> result = ListSequence.fromList(new ArrayList<String>());
ClassLoader classLoader = UrlClassLoader.class.getClassLoader();
Class cls = classLoader.getClass();
try {
List<URL> urls = ((List<URL>) cls.getMethod("getUrls", new Class[0]).invoke(classLoader, new Object[0]));
for (URL url : urls) {
ListSequence.fromList(result).addElement(new URI(url.toString()).getPath());
}
} catch (Exception ignored) {
}
getRepo().getModelAccess().runReadAction(new Runnable() {
public void run() {
Iterable<SModuleReference> languageRuntimes = MetaAdapterFactory.getLanguage(0x8585453e6bfb4d80L, 0x98deb16074f1d86cL, "jetbrains.mps.lang.test").getLanguageRuntimes();
for (SModuleReference dep : Sequence.fromIterable(languageRuntimes)) {
SModule module = dep.resolve(getRepo());
JavaModuleFacet facet = module.getFacet(JavaModuleFacet.class);
if (facet != null) {
ListSequence.fromList(result).addSequence(SetSequence.fromSet(facet.getClassPath()));
}
}
ListSequence.fromList(result).addSequence(ListSequence.fromList(getPluginClasspath()));
}
});
return result;
}
@NonNls
@Override
public String getFqName() {
return new ModelAccessHelper(getRepo()).runReadAction(new Computable<String>() {
public String compute() {
if (isTestCase()) {
return check_9og6tg_a0a0a0a0a0q(SNodeOperations.cast(getNode(), MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b2709bd56L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase")), LanguageTestWrapper.this);
}
return LanguageTestWrapper.super.getFqName();
}
});
}
@NonNls
@Override
public String getName() {
return new ModelAccessHelper(getRepo()).runReadAction(new Computable<String>() {
public String compute() {
if (isTestMethod()) {
return check_9og6tg_a0a0a0a0a0s(SNodeOperations.cast(getNode(), MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b27438a3dL, "jetbrains.mps.baseLanguage.unitTest.structure.ITestMethod")), LanguageTestWrapper.this);
}
return check_9og6tg_a1a0a0a0s(SNodeOperations.cast(getNode(), MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b2709bd56L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase")), LanguageTestWrapper.this);
}
});
}
private static boolean check_9og6tg_a0a2(SNode checkedDotOperand, LanguageTestWrapper checkedDotThisExpression) {
if (null != checkedDotOperand) {
return SNodeOperations.isInstanceOf(checkedDotOperand, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b2709bd56L, "jetbrains.mps.baseLanguage.unitTest.structure.ITestCase"));
}
return false;
}
private static boolean check_9og6tg_a0a4(SNode checkedDotOperand, LanguageTestWrapper checkedDotThisExpression) {
if (null != checkedDotOperand) {
return SNodeOperations.isInstanceOf(checkedDotOperand, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b27438a3dL, "jetbrains.mps.baseLanguage.unitTest.structure.ITestMethod"));
}
return false;
}
private static boolean check_9og6tg_a0a6(SNode checkedDotOperand, LanguageTestWrapper checkedDotThisExpression) {
if (null != checkedDotOperand) {
return SNodeOperations.isInstanceOf(checkedDotOperand, MetaAdapterFactory.getInterfaceConcept(0xf61473f9130f42f6L, 0xb98d6c438812c2f6L, 0x11b27438a3dL, "jetbrains.mps.baseLanguage.unitTest.structure.ITestMethod"));
}
return false;
}
private static String check_9og6tg_a0a0a0a0a0q(SNode checkedDotOperand, LanguageTestWrapper checkedDotThisExpression) {
if (null != checkedDotOperand) {
return ((String) BHReflection.invoke(checkedDotOperand, SMethodTrimmedId.create("getClassName", null, "hGBnqtL")));
}
return null;
}
private static String check_9og6tg_a0a0a0a0a0s(SNode checkedDotOperand, LanguageTestWrapper checkedDotThisExpression) {
if (null != checkedDotOperand) {
return ((String) BHReflection.invoke(checkedDotOperand, SMethodTrimmedId.create("getTestName", null, "hGBohAB")));
}
return null;
}
private static String check_9og6tg_a1a0a0a0s(SNode checkedDotOperand, LanguageTestWrapper checkedDotThisExpression) {
if (null != checkedDotOperand) {
return ((String) BHReflection.invoke(checkedDotOperand, SMethodTrimmedId.create("getSimpleClassName", null, "hSQIE8p")));
}
return null;
}
}