Skip to content

Commit 4558bc8

Browse files
committed
Adding the git location as the location to place themanufacturing file
instead of the directory the target file is locatted in .
1 parent 5ca389d commit 4558bc8

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/BowlerKernel.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,12 @@ public static void runArgumentsAfterStartup(String[] args, long startTime)
196196
try {
197197

198198
File f = new File(s);
199-
File parentFile = f.getParentFile();
200-
if(parentFile==null) {
201-
parentFile=new File(".");
199+
String location;
200+
try {
201+
location =ScriptingEngine.locateGitTopLevelDirectory(f).getAbsolutePath();
202+
}catch(Exception ex) {
203+
location= new File(".").getAbsolutePath();
202204
}
203-
String location =parentFile.getAbsolutePath();
204205
if(location.endsWith(".")) {
205206
location=location.substring(0,location.length()-1);
206207
}
@@ -209,8 +210,8 @@ public static void runArgumentsAfterStartup(String[] args, long startTime)
209210
}
210211
baseWorkspaceFile = new File(location);
211212

212-
com.neuronrobotics.sdk.common.Log.error("Using working directory "+baseWorkspaceFile.getAbsolutePath());
213-
f=new File(baseWorkspaceFile.getAbsolutePath()+"/"+f.getName());
213+
System.out.println("Using working directory "+baseWorkspaceFile.getAbsolutePath());
214+
f=new File(baseWorkspaceFile.getAbsolutePath()+"/"+s);
214215
com.neuronrobotics.sdk.common.Log.error("File "+f.getName());
215216
ret = ScriptingEngine.inlineFileScriptRun(f, null);
216217
} catch (Throwable e) {

src/main/java/com/neuronrobotics/bowlerstudio/scripting/ScriptingEngine.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -413,36 +413,35 @@ public static boolean isUrlAlreadyOpen(File URL) {
413413

414414
public static void openGit(Repository localRepo, IGitAccessor accessor) {
415415
Git git = null;
416-
boolean alreadyOpen= false;
416+
boolean alreadyOpen = false;
417417
try {
418418
String absolutePath = localRepo.getDirectory().getAbsolutePath();
419419
for (String s : open.keySet()) {
420420
Git g = open.get(s);
421-
if(g!=null)
422-
if (g.getRepository().getDirectory().getAbsolutePath()
423-
.contentEquals(absolutePath)) {
424-
git=g;
425-
alreadyOpen=true;
426-
break;
427-
}
421+
if (g != null)
422+
if (g.getRepository().getDirectory().getAbsolutePath().contentEquals(absolutePath)) {
423+
git = g;
424+
alreadyOpen = true;
425+
break;
426+
}
428427
}
429-
if(!alreadyOpen) {
428+
if (!alreadyOpen) {
430429
git = new Git(localRepo);
431430
open.put(absolutePath, git);
432431
}
433432
if (accessor != null) {
434433
try {
435434
accessor.run(git);
436435
} catch (Throwable t) {
437-
//new IssueReportingExceptionHandler().except(t);
436+
// new IssueReportingExceptionHandler().except(t);
438437
throw new RuntimeException(t);
439438
}
440439
}
441-
if(!alreadyOpen)
440+
if (!alreadyOpen)
442441
gitclose(git);
443442
} catch (Throwable t) {
444-
//new IssueReportingExceptionHandler().except(t);
445-
if(!alreadyOpen)
443+
// new IssueReportingExceptionHandler().except(t);
444+
if (!alreadyOpen)
446445
if (git != null) {
447446
gitclose(git);
448447
}
@@ -459,7 +458,7 @@ private static void gitclose(Git git) {
459458
if (git == null)
460459
return;
461460
open.remove(git.getRepository().getDirectory().getAbsolutePath());
462-
//git.getRepository().close();
461+
// git.getRepository().close();
463462
git.close();
464463
}
465464

@@ -1765,23 +1764,23 @@ public static String locateGitUrl(File f, Git ref) throws IOException {
17651764
return null;
17661765
}
17671766

1768-
public static void locateGit(File f, IGitAccessor access) throws IOException {
1767+
public static File locateGitTopLevelDirectory(File f) throws IOException {
17691768
File gitRepoFile = f;
17701769
while (gitRepoFile != null) {
17711770
gitRepoFile = gitRepoFile.getParentFile();
17721771
if (gitRepoFile != null)
17731772
if (new File(gitRepoFile.getAbsolutePath() + "/.git/config").exists()) {
1774-
// com.neuronrobotics.sdk.common.Log.error("Fount git repo for file:
1775-
// "+gitRepoFile);
1776-
Repository localRepo = new FileRepository(gitRepoFile.getAbsoluteFile() + "/.git");
1777-
openGit(localRepo, access);
1778-
return;
1773+
return gitRepoFile;
17791774
}
17801775
}
1781-
17821776
throw new RuntimeException("File " + f + " is not in a git repository");
17831777
}
17841778

1779+
public static void locateGit(File f, IGitAccessor access) throws IOException {
1780+
Repository localRepo = new FileRepository(locateGitTopLevelDirectory(f).getAbsoluteFile() + "/.git");
1781+
openGit(localRepo, access);
1782+
}
1783+
17851784
public static String getText(URL website) throws Exception {
17861785

17871786
URLConnection connection = website.openConnection();
@@ -2090,16 +2089,18 @@ public static List<String> getAllLangauges() {
20902089
}
20912090
return langs;
20922091
}
2092+
20932093
public static List<String> getAllExtentions() {
20942094
ArrayList<String> langs = new ArrayList<>();
20952095
for (String L : getLangaugesMap().keySet()) {
20962096
IScriptingLanguage lang = getLangaugesMap().get(L);
2097-
for(String s:lang.getFileExtenetion()) {
2097+
for (String s : lang.getFileExtenetion()) {
20982098
langs.add(s);
20992099
}
21002100
}
21012101
return langs;
21022102
}
2103+
21032104
public static HashMap<String, IScriptingLanguage> getLangaugesMap() {
21042105
return langauges;
21052106
}
@@ -2164,7 +2165,7 @@ public static String[] copyGitFile(String sourceGit, String targetGit, String fi
21642165
}
21652166
String[] newFileCode;
21662167
try {
2167-
System.out.println("Opening "+targetFilename+" from "+targetGit);
2168+
System.out.println("Opening " + targetFilename + " from " + targetGit);
21682169
newFileCode = ScriptingEngine.codeFromGit(targetGit, targetFilename);
21692170
if (newFileCode == null)
21702171
newFileCode = new String[] { "" };

0 commit comments

Comments
 (0)