public void clean(final Set<? extends SModule> modules, @NotNull final ProgressMonitor monitor) { monitor.start("Cleaning...", modules.size()); try { for (SModule module : modules) { if (isExcluded(module)) { monitor.advance(1); continue; } if (monitor.isCanceled()) break; monitor.step(module.getModuleName()); JavaModuleFacet facet = module.getFacet(JavaModuleFacet.class); assert facet != null && facet.getClassesGen() != null; String path = facet.getClassesGen().getPath(); FileUtil.delete(new File(path)); ClassPathFactory.getInstance().invalidate(Collections.singleton(path)); monitor.advance(1); } } finally { monitor.done(); } }
public static boolean testOnProjectCopy( final File source, final File destinationDir, final String projectName, ProjectRunnable pr, final String... plugins) { IdeMain.setTestMode(TestMode.CORE_TEST); Logger.setThreshold("WARN"); org.apache.log4j.BasicConfigurator.configure(); TestMain.configureMPS(plugins); if (destinationDir.exists()) { FileUtil.delete(destinationDir); } if (source.isDirectory()) { FileUtil.copyDir(source, destinationDir); } else { // it is allowed to have zipped directory here try { destinationDir.mkdir(); UnzipUtil.unzip(source, destinationDir); } catch (IOException e) { e.printStackTrace(); return false; } } final Project[] project = new MPSProject[] {null}; try { // load a project ThreadUtils.runInUIThreadAndWait( new Runnable() { public void run() { try { project[0] = loadProject(new File(destinationDir, projectName)); VirtualFile projectVirtualDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(destinationDir); assert projectVirtualDir != null; projectVirtualDir.refresh(false, true); } catch (Throwable t) { t.printStackTrace(); } } }); waitUntilAllEventsFlushed(); // execute test return pr.execute(project[0]); } catch (Throwable t) { t.printStackTrace(); return false; } finally { waitUntilAllEventsFlushed(); // clean up ThreadUtils.runInUIThreadAndWait( new Runnable() { public void run() { if (project[0] != null) { project[0].dispose(); } FileUtil.delete(destinationDir); } }); } }