99import java .io .IOException ;
1010import java .io .InputStream ;
1111import java .io .PrintWriter ;
12+ import java .io .Reader ;
1213import java .io .Writer ;
1314import java .nio .charset .StandardCharsets ;
1415import java .nio .file .Files ;
@@ -46,6 +47,8 @@ public class CommandContextImpl implements Context {
4647
4748 private Properties versions ;
4849
50+ private Path configurationFile ;
51+
4952 public CommandContextImpl (LineReader reader , String version ) throws IOException {
5053 this .reader = reader ;
5154 this .out = reader .getTerminal ().writer ();
@@ -54,17 +57,27 @@ public CommandContextImpl(LineReader reader, String version) throws IOException
5457 this .templates .setPrettyPrint (true );
5558 this .version = version ;
5659
57- Path file = configurationPath ();
60+ // move from .jooby to .config/jooby.conf
61+ configurationFile = Paths .get (System .getProperty ("user.home" ), ".config" , "jooby.conf" );
62+ migrateOldConfiguration (Paths .get (System .getProperty ("user.home" ), ".jooby" ), configurationFile );
5863
59- if (Files .exists (file )) {
60- configuration = Cli .gson .fromJson (Files .newBufferedReader (file ), LinkedHashMap .class );
64+ if (Files .exists (configurationFile )) {
65+ try (Reader in = Files .newBufferedReader (configurationFile )) {
66+ configuration = Cli .gson .fromJson (in , LinkedHashMap .class );
67+ }
6168 } else {
6269 configuration = new LinkedHashMap ();
6370 }
6471 }
6572
66- private Path configurationPath () {
67- return Paths .get (System .getProperty ("user.home" ), ".jooby" );
73+ private void migrateOldConfiguration (Path from , Path to ) throws IOException {
74+ if (Files .exists (from )) {
75+ if (!Files .exists (to .getParent ())) {
76+ Files .createDirectories (to .getParent ());
77+ }
78+ Files .copy (from , to );
79+ Files .delete (from );
80+ }
6881 }
6982
7083 @ Nonnull @ Override public String getVersion () {
@@ -83,8 +96,7 @@ private Path configurationPath() {
8396 }
8497 configuration .put ("workspace" , workspace .toAbsolutePath ().toString ());
8598 String json = Cli .gson .toJson (configuration );
86- Files .write (configurationPath (), json .getBytes (StandardCharsets .UTF_8 ));
87-
99+ Files .write (configurationFile , json .getBytes (StandardCharsets .UTF_8 ));
88100 }
89101
90102 @ Override public void exit (int code ) {
@@ -154,4 +166,8 @@ public Map<String, String> getDependencyMap() throws IOException {
154166 }
155167 return result ;
156168 }
169+
170+ @ Override public String toString () {
171+ return "version: " + getVersion () + "; conf: " + configurationFile ;
172+ }
157173}
0 commit comments