LoadUserArtifactsCommand extends AbstractCommand { boolean isArtifactDir(Path dir, Path startPath) { String dirStr = dir.toString(); String startPathStr = Pattern.quote(startPath.toString()); String regex = startPathStr + "[/\\\\][^/\\\\]+$"; return dirStr.matches(regex); } LoadUserArtifactsCommand();  LoadUserArtifactsCommand(HubConfig hubConfig); void setForceLoad(boolean forceLoad); @Override void execute(CommandContext context); void setHubConfig(HubConfig hubConfig); void setObjectMapper(ObjectMapper objectMapper);  }
@Test public void testIsEntityDir() { Path startPath = Paths.get("/tmp/my-project/plugins/entities"); Path dir = Paths.get("/tmp/my-project/plugins/entities/my-entity"); assertTrue(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("/tmp/my-project/plugins/entities"); dir = Paths.get("/tmp/my-project/plugins/entities"); assertFalse(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("/tmp/my-project/plugins/entities"); dir = Paths.get("/tmp/my-project/plugins/entities/my-entity/input"); assertFalse(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("/tmp/my-project/plugins/entities"); dir = Paths.get("/tmp/my-project/plugins/entities/my-entity/input/my-input-flow"); assertFalse(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("/tmp/my-project/plugins/mappings"); dir = Paths.get("/tmp/my-project/plugins/mappings/my-mappings/input"); assertFalse(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("/tmp/my-project/plugins/mappings"); dir = Paths.get("/tmp/my-project/plugins/mappings/my-mappings"); assertTrue(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("c:\\temp\\my-project\\plugins\\entities"); dir = Paths.get("c:\\temp\\my-project\\plugins\\entities\\my-entity"); assertTrue(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("c:\\temp\\my-project\\plugins\\entities"); dir = Paths.get("c:\\temp\\my-project\\plugins\\entities"); assertFalse(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("c:\\temp\\my-project\\plugins\\entities"); dir = Paths.get("c:\\temp\\my-project\\plugins\\entities\\my-entity\\input"); assertFalse(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("c:\\temp\\my-project\\plugins\\entities"); dir = Paths.get("c:\\temp\\my-project\\plugins\\entities\\my-entity\\input\\my-input-flow"); assertFalse(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("c:\\temp\\my-project\\plugins\\mappings"); dir = Paths.get("c:\\temp\\my-project\\plugins\\mappings\\my-mappings\\path1\\path2"); assertFalse(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); startPath = Paths.get("c:\\temp\\my-project\\plugins\\mappings"); dir = Paths.get("c:\\temp\\my-project\\plugins\\mappings\\my-mappings"); assertTrue(loadUserArtifactsCommand.isArtifactDir(dir, startPath)); }