@@ -101,8 +101,8 @@ public int cloneCmd(@Parameters(index = "0") String url) {
101101 filePath = Paths .get (clone_path ,repo_name ,filePath ).toAbsolutePath ().toString ();
102102
103103 // Launching Editor on the Cloned Directory
104- System .out .println ("Opening " + filePath );
105- launch_editor (directory , ide , directory .toAbsolutePath ().toString (),filePath );
104+ System .out .println ("Launching Editor Now..." );
105+ getIDE ( ide ). launch_editor (directory , ide , directory .toAbsolutePath ().toString (),filePath );
106106 } catch (Exception e ) {
107107 throw new IllegalStateException (e );
108108 }
@@ -248,37 +248,79 @@ public static String runCommand(Path directory, String... command) throws IOExce
248248 }
249249
250250
251- public static void launch_editor (Path directory , String ide , String path , String filePath ) throws IOException , InterruptedException {
251+ public static abstract class IDE {
252+ public abstract void launch_editor (Path directory , String ide , String path , String filePath )throws IOException , InterruptedException ;
252253
253- if (filePath .indexOf ("#" )>0 ){
254- filePath = filePath .replace ("#L" ,"#" );
255- // ==== VS CODE ====
256- // code -g file:line
257- if (ide .equals ("code" )||ide .equals ("code.cmd" )){
254+ }
255+
256+ public static IDE getIDE (String ide ){
257+ // Will return IDE based on String
258+ switch (ide ){
259+ case "code" :
260+ case "code.cmd" :
261+ return new VsCode ();
262+
263+ case "idea" :
264+ case "idea64.exe" :
265+ return new IntelliJIdea ();
266+
267+ case "eclipse" :
268+ case "eclipse.exe" :
269+ return new Eclipse ();
270+ default :
271+ throw new IllegalArgumentException ("IDE not supported" );
272+ }
273+
274+ }
275+
276+ public static class VsCode extends IDE {
277+
278+ public void launch_editor (Path directory , String ide , String path , String filePath ) throws IOException , InterruptedException {
279+ if (filePath .indexOf ("#" )>0 ){
280+ // code -g file:line
281+ filePath = filePath .replace ("#L" ,"#" );
258282 filePath = filePath .replace ("#" ,":" );
259283 runCommand (directory .getParent (), ide ,"-g" ,path ,filePath );
260284 }
261- // ===== IntelliJ =====
262- // idea64.exe [--line <number>] [--column <number>] <path ...>
263- // idea /home/fahad/MyProjects/testings/jbang --line 3 /home/fahad/MyProjects/testings/jbang/otp.java
264- if (ide .equals ("idea" )||ide .equals ("idea.exe" )||ide .equals ("idea64.exe" )){
285+ else {
286+ runCommand (directory .getParent (),ide ,path ,filePath );
287+ }
288+ }
289+ }
290+
291+ public static class IntelliJIdea extends IDE {
292+
293+ public void launch_editor (Path directory , String ide , String path , String filePath ) throws IOException , InterruptedException {
294+ if (filePath .indexOf ("#" )>0 ){
295+ filePath = filePath .replace ("#L" ,"#" );
296+ // idea64.exe [--line <number>] [--column <number>] <path ...>
297+ // idea /home/fahad/MyProjects/testings/jbang --line 3 /home/fahad/MyProjects/testings/jbang/otp.java
265298 String lineNumber = filePath .substring (filePath .lastIndexOf ("#" )+1 );
266299 filePath = filePath .substring (0 ,filePath .lastIndexOf ("#" ));
267300 runCommand (directory .getParent (), ide ,path ,"--line" ,lineNumber ,filePath );
268301 }
269- // === Eclipse =====
270- // eclipse.exe file.txt:22
271- if (ide .equals ("eclipse" )){
272- filePath = filePath .replace ("#" ,":" );
273- runCommand (directory .getParent (), ide ,path ,filePath );
302+ else {
303+ runCommand (directory .getParent (),ide ,path ,filePath );
274304 }
275-
276- }
277- else {
278- runCommand (directory .getParent (),ide ,path ,filePath );// Launching the editor now
279305 }
280306 }
281307
308+ public static class Eclipse extends IDE {
309+
310+ public void launch_editor (Path directory , String ide , String path , String filePath ) throws IOException , InterruptedException {
311+ if (filePath .indexOf ("#" )>0 ){
312+ filePath = filePath .replace ("#L" ,"#" );
313+ // eclipse.exe file.txt:22
314+ if (ide .equals ("eclipse" )){
315+ filePath = filePath .replace ("#" ,":" );
316+ runCommand (directory .getParent (), ide ,path ,filePath );
317+ }
282318
319+ }
320+ else {
321+ runCommand (directory .getParent (),ide ,path ,filePath );
322+ }
323+ }
324+ }
283325
284326}
0 commit comments