From 4aa5deab6c4fd67cd6ba1887ef6f7cdf0ae19d30 Mon Sep 17 00:00:00 2001 From: zedbeit Date: Tue, 5 Oct 2021 07:55:55 +0100 Subject: [PATCH 1/5] added starfix to work without default config --- cli/src/main/java/dev/starfix/Starfix.java | 59 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/dev/starfix/Starfix.java b/cli/src/main/java/dev/starfix/Starfix.java index 66f9d04..e6b76ef 100644 --- a/cli/src/main/java/dev/starfix/Starfix.java +++ b/cli/src/main/java/dev/starfix/Starfix.java @@ -55,6 +55,14 @@ public int config() throws Exception { @Command(name = "clone") public int cloneCmd(@Parameters(index = "0") String url) { + String userHome = System.getProperty("user.home"); // Get User Home Directory: /home/user_name + Path configPath = Paths.get(userHome + "/.config/starfix.yaml"); + + //Check if config file does not exist + if(!Files.exists(configPath)){ + defaultConfig(); + } + CloneUrl cloneUrl = new CloneUrl(url); // URL Validation to check a valid git repository if (!validate_url(cloneUrl.url)) { // Incase URI doesn't macth our scheme we'll terminate @@ -116,11 +124,21 @@ public static boolean isBlob(String url){ return Pattern.matches(pattern,url); } - // Function yo determine if the current OS is Windows + // Function to determine if the current OS is Windows public static boolean isWindows() { return System.getProperty("os.name").toLowerCase().contains("windows"); } + // Function to determine if the current OS is Linux + public static boolean isLinux() { + return System.getProperty("os.name").toLowerCase().contains("linux"); + } + + // Function to determine if the current OS is MacOS + public static boolean isMac() { + return System.getProperty("os.name").toLowerCase().contains("mac"); + } + // Function to fetch config file public static File getConfigFile() { String userHome = System.getProperty("user.home"); // Get User Home Directory: /home/user_name @@ -134,6 +152,44 @@ public static File getConfigFile() { return new File(userHome + "/.config/starfix.yaml"); } + // Function to load default config + public void defaultConfig() { + String path_env = System.getenv("Path"); // System PATH variable + clone_path = System.getProperty("user.home") + "/code"; // set clone_path to /home/user_name/code + File configFile = getConfigFile(); + + try { + configFile.createNewFile(); + + if(isWindows()){// check if Windows OS + if(path_env.contains("Microsoft VS Code")){ // If PATH has VScode + ide = "code.cmd"; + writeToYAMLFile(ide, clone_path,configFile); + } else if(path_env.contains("IntelliJ IDEA")){ // If PATH has IntelliJ + ide = "idea64.exe"; + writeToYAMLFile(ide, clone_path,configFile); + } + } + // check if Linux OS + // if(isLinux()){} + + // check if Mac OS + // if(isMac()){} + + } catch (Exception e) { + e.printStackTrace(); + + } + } + // Function to write configurations to the YAML FILE + public void writeToYAMLFile(String ide, String clone_path, File configFile) throws Exception{ + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + Properties configuration = new Properties(); + + configuration.put("ide", ide); + configuration.put("clone_path",clone_path); + mapper.writeValue(configFile, configuration); + } // Function to edit configuration and serves for command line starfix config // editor @@ -146,6 +202,7 @@ public void editConfig() throws Exception { System.out.println("IDE: "+ide); System.out.println("Clone Path: "+clone_path); + // return a File File configFile = getConfigFile(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); From 4438ac4ec99357318982c461198311a5cdfcf0ff Mon Sep 17 00:00:00 2001 From: zedbeit Date: Wed, 6 Oct 2021 23:31:01 +0100 Subject: [PATCH 2/5] use getConfig and avoid write to disk --- cli/src/main/java/dev/starfix/Starfix.java | 30 +++++++--------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/cli/src/main/java/dev/starfix/Starfix.java b/cli/src/main/java/dev/starfix/Starfix.java index e6b76ef..484ba28 100644 --- a/cli/src/main/java/dev/starfix/Starfix.java +++ b/cli/src/main/java/dev/starfix/Starfix.java @@ -55,12 +55,15 @@ public int config() throws Exception { @Command(name = "clone") public int cloneCmd(@Parameters(index = "0") String url) { - String userHome = System.getProperty("user.home"); // Get User Home Directory: /home/user_name - Path configPath = Paths.get(userHome + "/.config/starfix.yaml"); - - //Check if config file does not exist - if(!Files.exists(configPath)){ - defaultConfig(); + File configFile = getConfigFile(); + + try { + if (!configFile.exists()) { + defaultConfig(); + } + } catch (Exception e) { + e.printStackTrace(); + } CloneUrl cloneUrl = new CloneUrl(url); @@ -156,18 +159,13 @@ public static File getConfigFile() { public void defaultConfig() { String path_env = System.getenv("Path"); // System PATH variable clone_path = System.getProperty("user.home") + "/code"; // set clone_path to /home/user_name/code - File configFile = getConfigFile(); try { - configFile.createNewFile(); - if(isWindows()){// check if Windows OS if(path_env.contains("Microsoft VS Code")){ // If PATH has VScode ide = "code.cmd"; - writeToYAMLFile(ide, clone_path,configFile); } else if(path_env.contains("IntelliJ IDEA")){ // If PATH has IntelliJ ide = "idea64.exe"; - writeToYAMLFile(ide, clone_path,configFile); } } // check if Linux OS @@ -181,16 +179,6 @@ public void defaultConfig() { } } - // Function to write configurations to the YAML FILE - public void writeToYAMLFile(String ide, String clone_path, File configFile) throws Exception{ - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - Properties configuration = new Properties(); - - configuration.put("ide", ide); - configuration.put("clone_path",clone_path); - mapper.writeValue(configFile, configuration); - } - // Function to edit configuration and serves for command line starfix config // editor public void editConfig() throws Exception { From e073891ca2e929aa84e88b9f5a9fc36262150bc6 Mon Sep 17 00:00:00 2001 From: zedbeit Date: Sat, 9 Oct 2021 20:50:24 +0100 Subject: [PATCH 3/5] made changes to getconfigfile --- cli/src/main/java/dev/starfix/Starfix.java | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/cli/src/main/java/dev/starfix/Starfix.java b/cli/src/main/java/dev/starfix/Starfix.java index 484ba28..b588c34 100644 --- a/cli/src/main/java/dev/starfix/Starfix.java +++ b/cli/src/main/java/dev/starfix/Starfix.java @@ -55,10 +55,10 @@ public int config() throws Exception { @Command(name = "clone") public int cloneCmd(@Parameters(index = "0") String url) { - File configFile = getConfigFile(); + File configFilePath = getConfigFilePath(); // Get path for config file try { - if (!configFile.exists()) { + if (!configFilePath.exists()) {// Check if config file exist defaultConfig(); } } catch (Exception e) { @@ -142,19 +142,25 @@ public static boolean isMac() { return System.getProperty("os.name").toLowerCase().contains("mac"); } + // Function to fetch config file path + public static File getConfigFilePath(){ + String userHome = System.getProperty("user.home"); + return new File(userHome + "/.config/starfix.yaml"); + } + // Function to fetch config file public static File getConfigFile() { - String userHome = System.getProperty("user.home"); // Get User Home Directory: /home/user_name - File configDir = new File(userHome+ "/.config"); - - if(!configDir.exists()){ // If .config directory does not exist we create it - if(!configDir.mkdirs()){ // If creation failed - throw new IllegalStateException("Cannot create .config directory: " + configDir.getAbsolutePath()); + File configFilePath = getConfigFilePath(); + + if(!configFilePath.getParentFile().exists()){// Check if parent directory exists + if(!configFilePath.getParentFile().mkdirs()){// Create parent dir if not exist + throw new IllegalStateException("Cannot create .config directory: " + configFilePath.getParentFile().getAbsolutePath()); } } - return new File(userHome + "/.config/starfix.yaml"); + return configFilePath; } + // Function to load default config public void defaultConfig() { String path_env = System.getenv("Path"); // System PATH variable From a43eb4aacd4521c22f4da30e10c7b737f3a7e816 Mon Sep 17 00:00:00 2001 From: zedbeit Date: Sun, 28 Nov 2021 11:57:39 +0100 Subject: [PATCH 4/5] removed unneccassary exception handling --- cli/src/main/java/dev/starfix/Starfix.java | 39 ++++++++-------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/cli/src/main/java/dev/starfix/Starfix.java b/cli/src/main/java/dev/starfix/Starfix.java index b588c34..5145ccd 100644 --- a/cli/src/main/java/dev/starfix/Starfix.java +++ b/cli/src/main/java/dev/starfix/Starfix.java @@ -57,13 +57,8 @@ public int config() throws Exception { public int cloneCmd(@Parameters(index = "0") String url) { File configFilePath = getConfigFilePath(); // Get path for config file - try { - if (!configFilePath.exists()) {// Check if config file exist - defaultConfig(); - } - } catch (Exception e) { - e.printStackTrace(); - + if (!configFilePath.exists()) {// Check if config file exist + defaultConfig(); // Sets up default config } CloneUrl cloneUrl = new CloneUrl(url); @@ -161,29 +156,23 @@ public static File getConfigFile() { } - // Function to load default config - public void defaultConfig() { + // Function to setup default config + void defaultConfig() { String path_env = System.getenv("Path"); // System PATH variable clone_path = System.getProperty("user.home") + "/code"; // set clone_path to /home/user_name/code - try { - if(isWindows()){// check if Windows OS - if(path_env.contains("Microsoft VS Code")){ // If PATH has VScode - ide = "code.cmd"; - } else if(path_env.contains("IntelliJ IDEA")){ // If PATH has IntelliJ - ide = "idea64.exe"; - } + if(isWindows()){// check if Windows OS + if(path_env.contains("Microsoft VS Code")){ // If PATH has VScode + ide = "code.cmd"; + } else if(path_env.contains("IntelliJ IDEA")){ // If PATH has IntelliJ + ide = "idea64.exe"; } - // check if Linux OS - // if(isLinux()){} - - // check if Mac OS - // if(isMac()){} - - } catch (Exception e) { - e.printStackTrace(); - } + // check if Linux OS + // if(isLinux()){} + + // check if Mac OS + // if(isMac()){} } // Function to edit configuration and serves for command line starfix config // editor From bb195dbb446550286c27365f9f2a986ecc279e24 Mon Sep 17 00:00:00 2001 From: zedbeit Date: Tue, 7 Dec 2021 22:59:20 +0100 Subject: [PATCH 5/5] get starfix to work without config for linux OS --- cli/src/main/java/dev/starfix/Starfix.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cli/src/main/java/dev/starfix/Starfix.java b/cli/src/main/java/dev/starfix/Starfix.java index 5145ccd..04a7be7 100644 --- a/cli/src/main/java/dev/starfix/Starfix.java +++ b/cli/src/main/java/dev/starfix/Starfix.java @@ -158,7 +158,7 @@ public static File getConfigFile() { // Function to setup default config void defaultConfig() { - String path_env = System.getenv("Path"); // System PATH variable + String path_env = System.getenv("PATH"); // System PATH variable clone_path = System.getProperty("user.home") + "/code"; // set clone_path to /home/user_name/code if(isWindows()){// check if Windows OS @@ -168,8 +168,20 @@ void defaultConfig() { ide = "idea64.exe"; } } - // check if Linux OS - // if(isLinux()){} + + if(isLinux()){// check if Linux OS + String[] sub_paths = path_env.split(":"); + + for (String sub_path : sub_paths) { + if(Files.exists(Paths.get(sub_path+"/code"))){ + ide = "code"; + }else if(Files.exists(Paths.get(sub_path+"/idea"))){ + ide = "idea"; + }else if(Files.exists(Paths.get(sub_path+"/eclipse"))){ + ide = "eclipse"; + } + } + } // check if Mac OS // if(isMac()){}