@Override public String apply(final String filename) { return join(this.fileRoot, filename); } }
public void register(final File file, final Function<File, Void> listener) { Path directory = Files.directoryOf(file).toPath(); WatchKey key = registerDirectory(directory); Path path = file.toPath(); keys.put(key, path); listeners.put(path, listener); directoryToFiles.put(directory, path); idle(REGISTER_INTERVAL, TimeUnit.MILLISECONDS); }
public static String join(final String path1, final String path2, final String... paths) { String finalPath = actualJoin(path1, path2); for (String path : paths) { finalPath = actualJoin(finalPath, path); } return finalPath; }
private Runner createDynamicConfigurationRunner(final StartArgs startArgs) { String pathname = startArgs.getConfigurationFile().get(); ImmutableList<String> glob = glob(pathname); Iterable<File> files = from(glob).transform(filenameToFile()); final FileRunner fileRunner = createConfigurationFileRunner(files, startArgs); Watcher watcher = factory.createConfigurationWatcher(files, fileRunner); return new WatcherRunner(fileRunner, watcher); } }
private static String actualJoin(final String path1, final String path2) { return joinFiles(path1, path2).getPath(); }
private Runner createDynamicConfigurationRunner(final StartArgs startArgs) { String pathname = startArgs.getConfigurationFile().get(); ImmutableList<String> glob = glob(pathname); Iterable<File> files = from(glob).transform(filenameToFile()); final FileRunner fileRunner = createConfigurationFileRunner(files, startArgs); Watcher watcher = factory.createConfigurationWatcher(files, fileRunner); return new WatcherRunner(fileRunner, watcher); } }
public ImmutableList<String> includes() { return Globs.glob(join(fileRoot, include)); }
public void unregister(final File file) { Path directory = Files.directoryOf(file).toPath(); Path path = file.toPath(); if (!directoryToFiles.containsEntry(directory, path)) { return; } directoryToFiles.remove(directory, path); if (!directoryToFiles.containsKey(directory)) { WatchKey key = directoryToKey.remove(directory); if (key != null) { key.cancel(); } } if (directoryToFiles.isEmpty()) { this.stop(); } } }
@Test public void should_parse_settings_file() { InputStream stream = getResourceAsStream("settings/settings.json"); ImmutableList<GlobalSetting> globalSettings = parser.parse(stream); assertThat(globalSettings.get(0).includes().get(0), is(join("src", "test", "resources", "settings", "details", "foo.json"))); assertThat(globalSettings.get(1).includes().get(0), is(join("src", "test", "resources", "settings", "details", "bar.json"))); }
public void register(final File file, final Function<File, Void> listener) { Path directory = Files.directoryOf(file).toPath(); WatchKey key = registerDirectory(directory); Path path = file.toPath(); keys.put(key, path); listeners.put(path, listener); directoryToFiles.put(directory, path); idle(REGISTER_INTERVAL, TimeUnit.MILLISECONDS); }
@Test public void should_parse_settings_file_with_context() { InputStream stream = getResourceAsStream("settings/context-settings.json"); ImmutableList<GlobalSetting> globalSettings = parser.parse(stream); assertThat(globalSettings.get(0).includes().get(0), is(join("src", "test", "resources", "settings", "details", "foo.json"))); assertThat(globalSettings.get(0).getContext(), is("/foo")); assertThat(globalSettings.get(1).includes().get(0), is(join("src", "test", "resources", "settings", "details", "bar.json"))); assertThat(globalSettings.get(1).getContext(), is("/bar")); }
public void unregister(final File file) { Path directory = Files.directoryOf(file).toPath(); Path path = file.toPath(); if (!directoryToFiles.containsEntry(directory, path)) { return; } directoryToFiles.remove(directory, path); if (!directoryToFiles.containsKey(directory)) { WatchKey key = directoryToKey.remove(directory); if (key != null) { key.cancel(); } } if (directoryToFiles.isEmpty()) { this.stop(); } } }
@Test public void should_parse_setting_file_with_env() { InputStream stream = getResourceAsStream("settings/env-settings.json"); ImmutableList<GlobalSetting> globalSettings = parser.parse(stream); assertThat(globalSettings.get(0).includes().get(0), is(join("src", "test", "resources", "settings", "details", "foo.json"))); assertThat(globalSettings.get(0).getContext(), is("/foo")); assertThat(globalSettings.get(0).getEnv(), is("foo")); assertThat(globalSettings.get(1).includes().get(0), is(join("src", "test", "resources", "settings", "details", "bar.json"))); assertThat(globalSettings.get(1).getContext(), is("/bar")); assertThat(globalSettings.get(1).getEnv(), is("bar")); }
@Test public void should_parse_setting_file_with_file_root() { InputStream stream = getResourceAsStream("settings/fileroot-settings.json"); ImmutableList<GlobalSetting> globalSettings = parser.parse(stream); assertThat(globalSettings.get(0).includes().get(0), is(join("src", "test", "resources", "settings", "fileroot.json"))); assertThat(globalSettings.get(0).getContext(), is("/fileroot")); assertThat(globalSettings.get(0).getFileRoot(), is("src/test/resources")); }
@Test public void should_parse_glob_settings_file() { InputStream stream = getResourceAsStream("settings/glob-settings.json"); ImmutableList<GlobalSetting> globalSettings = parser.parse(stream); ImmutableList<String> includes = globalSettings.get(0).includes(); assertThat(includes.contains(join("src", "test", "resources", "settings", "details", "foo.json")), is(true)); assertThat(includes.contains(join("src", "test", "resources", "settings", "details", "bar.json")), is(true)); }
@Test public void should_glob_absolute_files_with_glob() throws IOException { File file = folder.newFile("glob.json"); String glob = Files.join(folder.getRoot().getAbsolutePath(), "*.json"); ImmutableList<String> files = Globs.glob(glob); assertThat(files.contains(file.getAbsolutePath()), is(true)); }
@Test public void should_load_glob_configuration() throws IOException, InterruptedException { final File config = tempFolder.newFile("config.json"); changeFileContent(config, "[{\"response\" :{" + "\"text\" : \"foo\"" + "}}]"); RunnerFactory factory = new RunnerFactory("SHUTDOWN"); String absolutePath = config.getParent(); String result = Files.join(absolutePath, "*.json"); runner = factory.createRunner(httpArgs() .withPort(port()) .withShutdownPort(9090) .withConfigurationFile(result) .build()); runner.run(); assertThat(helper.get(root()), is("foo")); }
public ImmutableList<String> includes() { return Globs.glob(join(fileRoot, include)); }