package jetbrains.mps.testbench.junit.runners; /*Generated by MPS */ import jetbrains.mps.tool.environment.ProjectStrategyBase; import java.util.Set; import jetbrains.mps.vfs.IFile; import java.util.HashSet; import jetbrains.mps.vfs.impl.IoFileSystem; import java.io.File; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull; import jetbrains.mps.project.Project; import java.util.List; import jetbrains.mps.library.ModulesMiner; import jetbrains.mps.internal.collections.runtime.Sequence; import jetbrains.mps.internal.collections.runtime.IWhereFilter; public class FromDirWithModulesProjectStrategy extends ProjectStrategyBase { private static final String MODULES_ROOT_PROPERTY = "mps.junit.modules.root"; private static final String[] EXCLUDES = new String[]{"IdeaPlugin"}; private static final Set<IFile> EXCLUDE_SET = createExcludesSet(); private static Set<IFile> createExcludesSet() { Set<IFile> excludesSet = new HashSet<IFile>(); String userDir = System.getProperty("user.dir"); for (String exclude : EXCLUDES) { excludesSet.add(IoFileSystem.INSTANCE.getFile(userDir + File.separator + exclude)); } return excludesSet; } private final String myModulesRootPath; public FromDirWithModulesProjectStrategy(@Nullable String modulesRootPath) { myModulesRootPath = modulesRootPath; } public FromDirWithModulesProjectStrategy() { this(System.getProperty(MODULES_ROOT_PROPERTY)); } @NotNull @Override public Project construct(@NotNull Project emptyProject) { List<ModulesMiner.ModuleHandle> moduleHandles = collectHandles(new File(myModulesRootPath)); return loadProjectFromModuleHandles(emptyProject, moduleHandles); } private List<ModulesMiner.ModuleHandle> collectHandles(File rootFolder) { IFile fileByPath = IoFileSystem.INSTANCE.getFile(rootFolder.getAbsolutePath()); Iterable<ModulesMiner.ModuleHandle> minedHandles = new ModulesMiner(EXCLUDE_SET).collectModules(fileByPath).getCollectedModules(); return Sequence.fromIterable(minedHandles).where(new IWhereFilter<ModulesMiner.ModuleHandle>() { public boolean accept(ModulesMiner.ModuleHandle it) { // temporary ignore .iml files return !(it.getFile().getName().endsWith(".iml")); } }).toListSequence(); } @Override public boolean isApplicable() { return myModulesRootPath != null; } }