@Test public void findUserDir() { Path userDir = ContextImpl.findUserDir(); assertThat(userDir, is(not(nullValue()))); assertThat(Files.isDirectory(userDir), is(true)); }
static public Path findUserDir() { Optional<Path> dir = dirIfExists(System.getenv("HOME")); if (!dir.isPresent()) { String homeDrive = System.getenv("HOMEDRIVE"); String homePath = System.getenv("HOMEPATH"); dir = dirIfExists((homeDrive != null ? homeDrive : "") + (homePath != null ? homePath : "")); if (!dir.isPresent()) { dir = dirIfExists(System.getProperty("user.home")); } } try { return dir.orElseThrow(() -> new IOException("Unable to find user home dir!")); } catch (IOException e){ throw new UncheckedIOException(e); } }
ContextImpl implements Context { static public Path findUserDir() { Optional<Path> dir = dirIfExists(System.getenv("HOME")); if (!dir.isPresent()) { String homeDrive = System.getenv("HOMEDRIVE"); String homePath = System.getenv("HOMEPATH"); dir = dirIfExists((homeDrive != null ? homeDrive : "") + (homePath != null ? homePath : "")); if (!dir.isPresent()) { dir = dirIfExists(System.getProperty("user.home")); } } try { return dir.orElseThrow(() -> new IOException("Unable to find user home dir!")); } catch (IOException e){ throw new UncheckedIOException(e); } } }
ContextImpl implements Context { static public Path findUserDir() { Optional<Path> dir = dirIfExists(System.getenv("HOME")); if (!dir.isPresent()) { String homeDrive = System.getenv("HOMEDRIVE"); String homePath = System.getenv("HOMEPATH"); dir = dirIfExists((homeDrive != null ? homeDrive : "") + (homePath != null ? homePath : "")); if (!dir.isPresent()) { dir = dirIfExists(System.getProperty("user.home")); } } try { return dir.orElseThrow(() -> new IOException("Unable to find user home dir!")); } catch (IOException e){ throw new UncheckedIOException(e); } } ContextImpl(Path baseDir, Path userDir, Path scriptFile, Config config); }
ContextImpl implements Context { static public Path findUserDir() { Optional<Path> dir = dirIfExists(System.getenv("HOME")); if (!dir.isPresent()) { String homeDrive = System.getenv("HOMEDRIVE"); String homePath = System.getenv("HOMEPATH"); dir = dirIfExists((homeDrive != null ? homeDrive : "") + (homePath != null ? homePath : "")); if (!dir.isPresent()) { dir = dirIfExists(System.getProperty("user.home")); } } try { return dir.orElseThrow(() -> new IOException("Unable to find user home dir!")); } catch (IOException e){ throw new UncheckedIOException(e); } } ContextImpl(Path baseDir, Path userDir, Path scriptFile, Config config); Prompter getPrompter(); void prompter(Prompter prompter); void baseDir(Path baseDir); void userDir(Path userDir); void scriptFile(Path scriptFile); @Override Logger logger(); @Override Path baseDir(); @Override Path withBaseDir(Path path); @Override Path withBaseDir(File file); @Override Path withBaseDir(String path); @Override Path scriptFile(); @Override Config config(); @Override Path userDir(); @Override Path withUserDir(Path path); @Override Path withUserDir(File file); @Override Path withUserDir(String path); @Override void fail(String message); @Override String prompt(String prompt, Object... args); @Override char[] passwordPrompt(String prompt, Object... args); static Path findUserDir(); static Optional<Path> dirIfExists(String path); }
ContextImpl implements Context { static public Path findUserDir() { Optional<Path> dir = dirIfExists(System.getenv("HOME")); if (!dir.isPresent()) { String homeDrive = System.getenv("HOMEDRIVE"); String homePath = System.getenv("HOMEPATH"); dir = dirIfExists((homeDrive != null ? homeDrive : "") + (homePath != null ? homePath : "")); if (!dir.isPresent()) { dir = dirIfExists(System.getProperty("user.home")); } } try { return dir.orElseThrow(() -> new IOException("Unable to find user home dir!")); } catch (IOException e){ throw new UncheckedIOException(e); } } ContextImpl(Path baseDir, Path userDir, Path scriptFile, Config config); Prompter getPrompter(); void prompter(Prompter prompter); void baseDir(Path baseDir); void userDir(Path userDir); void scriptFile(Path scriptFile); @Override Logger logger(); @Override Path baseDir(); @Override Path withBaseDir(Path path); @Override Path withBaseDir(File file); @Override Path withBaseDir(String path); @Override Path scriptFile(); @Override Config config(); @Override Path userDir(); @Override Path withUserDir(Path path); @Override Path withUserDir(File file); @Override Path withUserDir(String path); @Override void fail(String message); @Override String prompt(String prompt, Object... args); @Override char[] passwordPrompt(String prompt, Object... args); static Path findUserDir(); static Optional<Path> dirIfExists(String path);  }