package jetbrains.mps.baseLanguage.unitTest.execution.client; /*Generated by MPS */ import java.util.List; import java.io.File; import java.util.ArrayList; import java.io.IOException; public class RunCachesManager { private static final Object ourLock = new Object(); private static List<File> ourDirectories = new ArrayList<File>(); private static boolean isChild(File child, File parent) { return parent.getAbsolutePath().startsWith(child.getAbsolutePath()); } public static boolean acquireLock(String path) { synchronized (ourLock) { try { File newDir = new File(path).getCanonicalFile(); for (File dir : ourDirectories) { if (isChild(dir, newDir) || isChild(newDir, dir)) { return false; } } return ourDirectories.add(newDir); } catch (IOException e) { e.printStackTrace(); return false; } } } public static boolean isLocked(String path) { synchronized (ourLock) { try { File newDir = new File(path).getCanonicalFile(); for (File dir : ourDirectories) { if (isChild(dir, newDir) || isChild(newDir, dir)) { return true; } } return false; } catch (IOException e) { e.printStackTrace(); return true; } } } public static void releaseLock(String path) { synchronized (ourLock) { try { File dir = new File(path).getCanonicalFile(); boolean result = ourDirectories.remove(dir); assert result : "There is no lock to release for the directory " + dir; } catch (IOException e) { e.printStackTrace(); } } } }